git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v3] tag: support --sort=<spec>
Date: Wed, 26 Feb 2014 04:05:11 -0500	[thread overview]
Message-ID: <20140226090511.GA32537@sigill.intra.peff.net> (raw)
In-Reply-To: <1393330935-22229-1-git-send-email-pclouds@gmail.com>

On Tue, Feb 25, 2014 at 07:22:15PM +0700, Nguyễn Thái Ngọc Duy wrote:

> versioncmp() is copied from string/strverscmp.c in glibc commit
> ee9247c38a8def24a59eb5cfb7196a98bef8cfdc, reformatted to Git coding
> style. The implementation is under LGPL-2.1 and according to [1] I can
> relicense it to GPLv2.

Cool. I think doing this makes the most sense, as we do not have to
worry about build-time config (and I do not see any particular reason
why we would want to use the system strverscmp on glibc systems).

> +static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
> +{
> +	int *sort = opt->value;
> +	if (*arg == '-') {
> +		*sort = REVERSE_SORT;
> +		arg++;
> +	} else
> +		*sort = STRCMP_SORT;
> +	if (starts_with(arg, "version:")) {
> +		*sort |= VERCMP_SORT;
> +		arg += 8;
> +	} else if (starts_with(arg, "v:")) {
> +		*sort |= VERCMP_SORT;
> +		arg += 2;
> +	}
> +	if (strcmp(arg, "refname"))
> +		die(_("unsupported sort specification %s"), arg);

I found this logic a bit weird, as STRCMP_SORT and VERCMP_SORT are not
mutually exclusive flags, but REVERSE and STRCMP are. I would have
thought REVERSE is the flag, and the other two are selections. Like:

  int flags = 0;

  if (*arg == '-') {
          flags |= REVERSE_SORT;
          arg++;
  }
  if (starts_with(arg, "version:")) {
          *sort = VERCMP_SORT;
          arg += 8;
  } else
          *sort = STRCMP_SORT;

  *sort |= flags;

I think they end up doing the same thing, but maybe I am missing
something.

-Peff

  parent reply	other threads:[~2014-02-26  9:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-19 13:39 [PATCH] tag: support --sort=version Nguyễn Thái Ngọc Duy
2014-02-19 14:09 ` Jeff King
2014-02-19 14:19   ` Duy Nguyen
2014-02-20 20:43     ` Jeff King
2014-02-21 11:58       ` Duy Nguyen
2014-02-21 17:48         ` Junio C Hamano
2014-02-22  7:59         ` Jeff King
2014-02-22  9:07           ` Duy Nguyen
2014-02-19 18:43 ` Eric Sunshine
2014-02-22  3:29 ` [PATCH v2] tag: support --sort=<spec> Nguyễn Thái Ngọc Duy
2014-02-22  8:04   ` Jeff King
2014-02-24 16:39     ` Junio C Hamano
2014-02-24 23:30       ` Duy Nguyen
2014-02-24 23:33         ` Jeff King
2014-02-25 12:22   ` [PATCH v3] " Nguyễn Thái Ngọc Duy
2014-02-25 17:42     ` Junio C Hamano
2014-02-26  9:05     ` Jeff King [this message]
2014-02-26 11:03       ` Duy Nguyen
2014-02-26 11:08         ` Jeff King
2014-02-26 11:11           ` Duy Nguyen
2014-02-26 11:17             ` Jeff King
2014-02-26 11:31           ` Duy Nguyen
2014-02-27 12:56     ` [PATCH v4] " Nguyễn Thái Ngọc Duy
2014-02-27 13:11       ` Jeff King
2014-02-27 13:23         ` Duy Nguyen

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

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

  git send-email \
    --in-reply-to=20140226090511.GA32537@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /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.
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 NNTP newsgroup(s).