git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH v2 1/2] format-patch: Add a config option format.from to set the default for --from
Date: Sun, 7 Aug 2016 12:57:01 -1000	[thread overview]
Message-ID: <20160807225701.ucv2xunq5vs4uedk@x> (raw)
In-Reply-To: <20160801173847.qph2tora75h6ebsk@sigill.intra.peff.net>

On Mon, Aug 01, 2016 at 01:38:47PM -0400, Jeff King wrote:
> On Sat, Jul 30, 2016 at 12:11:11PM -0700, Josh Triplett wrote:
> 
> > +enum from {
> > +	FROM_AUTHOR,
> > +	FROM_USER,
> > +	FROM_VALUE,
> > +};
> > +
> > +static void set_from(enum from type, const char *value)
> > +{
> > +	free(from);
> > +	switch (type) {
> > +	case FROM_AUTHOR:
> > +		from = NULL;
> > +		break;
> > +	case FROM_USER:
> > +		from = xstrdup(git_committer_info(IDENT_NO_DATE));
> > +		break;
> > +	case FROM_VALUE:
> > +		from = xstrdup(value);
> > +		break;
> > +	}
> > +}
> 
> Thanks for looking into reducing the duplication. TBH, I am not sure it
> is really an improvement, just because of the amount of boilerplate (and
> this function interface is kind of weird, because of the rules for when
> "value" should or should not be NULL).
> 
> I guess another way to do it would be:
> 
>   #define FROM_AUTO_IDENT ((const char *)(intptr_t)1))
>   void set_from(const char *value)
>   {
> 	if (value == FROM_AUTO_IDENT)
> 		value = git_committer_info(IDENT_NO_DATE);
> 	free(from);
> 	from = xstrdup_or_null(value);
>   }

I'd actually seriously considered this exact approach, which I preferred
as well, but I'd discarded it because I figured it'd get rejected.
Given your suggestion, and Junio's comment, I'll go with this version.

- Josh Triplett

  reply	other threads:[~2016-08-07 22:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.4d006cadf197f80d899ad7d7d56d8ba41f574adf.1469905775.git-series.josh@joshtriplett.org>
2016-07-30 19:11 ` [PATCH v2 1/2] format-patch: Add a config option format.from to set the default for --from Josh Triplett
2016-08-01 17:38   ` Jeff King
2016-08-07 22:57     ` Josh Triplett [this message]
2016-08-08  1:59       ` Junio C Hamano
2016-08-08  4:34         ` Josh Triplett
2016-08-08 18:01           ` Junio C Hamano
2016-08-01 21:18   ` Junio C Hamano
2016-08-08  4:42     ` Josh Triplett
2016-08-08  4:54       ` Jeff King
2016-08-08  5:02         ` Josh Triplett
2016-08-08  5:06           ` Jeff King
2016-07-30 19:11 ` [PATCH v2 2/2] format-patch: Default to --from Josh Triplett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160807225701.ucv2xunq5vs4uedk@x \
    --to=josh@joshtriplett.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).