Re: [PATCH v2] tag: support --sort=spec
Jeff King p...@peff.net writes: On Sat, Feb 22, 2014 at 10:29:22AM +0700, Nguyễn Thái Ngọc Duy wrote: Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- The new prereq GNULINUX is an ugly workaround until people provide strverscmp compat implementation. I hope that will happen soon as strverscmp.c does not look very complex. Should GNULINUX be called HAVE_STRVERSCMP in the Makefile? Then this: --- a/git-compat-util.h +++ b/git-compat-util.h @@ -721,4 +721,11 @@ void warn_on_inaccessible(const char *path); /* Get the passwd entry for the UID of the current process. */ struct passwd *xgetpwuid_self(void); +#ifndef __GNU_LIBRARY__ +static inline int strverscmp(const char *s1, const char *s2) +{ +die(strverscmp() not supported); +} +#endif becomes #ifndef HAVE_STRVERSCMP, and this: diff --git a/t/test-lib.sh b/t/test-lib.sh index 1531c24..5e8c39a 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -771,6 +771,8 @@ case $(uname -s) in ;; esac +[ $(uname -o) = GNU/Linux ] test_set_prereq GNULINUX + can pick up the value from GIT-BUILD-OPTIONS as a prerequisite (see the way we handle NO_PERL for an example). Though if we can just grab the glibc version as a fallback, we can do away with that completely. ;-) I like that. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] tag: support --sort=spec
On Mon, Feb 24, 2014 at 11:39 PM, Junio C Hamano gits...@pobox.com wrote: diff --git a/t/test-lib.sh b/t/test-lib.sh index 1531c24..5e8c39a 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -771,6 +771,8 @@ case $(uname -s) in ;; esac +[ $(uname -o) = GNU/Linux ] test_set_prereq GNULINUX + can pick up the value from GIT-BUILD-OPTIONS as a prerequisite (see the way we handle NO_PERL for an example). Though if we can just grab the glibc version as a fallback, we can do away with that completely. ;-) I like that. Jeff, I'm still waiting if you agree to go with this syntax or put version before refname before rerolling (either with build time option like this, or implement the compat function myself). -- Duy -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] tag: support --sort=spec
On Tue, Feb 25, 2014 at 06:30:35AM +0700, Duy Nguyen wrote: +[ $(uname -o) = GNU/Linux ] test_set_prereq GNULINUX + can pick up the value from GIT-BUILD-OPTIONS as a prerequisite (see the way we handle NO_PERL for an example). Though if we can just grab the glibc version as a fallback, we can do away with that completely. ;-) I like that. Jeff, I'm still waiting if you agree to go with this syntax or put version before refname before rerolling (either with build time option like this, or implement the compat function myself). Sorry. I didn't respond because I was trying to think of something to say besides no, I still like mine better. I admit that it's mostly a gut feeling, and I don't have any argument beyond what I've already made (your it's like a typecast does make some sense, but I think that is a convoluted way of thinking about it). -Peff -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] tag: support --sort=spec
On Sat, Feb 22, 2014 at 10:29:22AM +0700, Nguyễn Thái Ngọc Duy wrote: Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- The new prereq GNULINUX is an ugly workaround until people provide strverscmp compat implementation. I hope that will happen soon as strverscmp.c does not look very complex. Should GNULINUX be called HAVE_STRVERSCMP in the Makefile? Then this: --- a/git-compat-util.h +++ b/git-compat-util.h @@ -721,4 +721,11 @@ void warn_on_inaccessible(const char *path); /* Get the passwd entry for the UID of the current process. */ struct passwd *xgetpwuid_self(void); +#ifndef __GNU_LIBRARY__ +static inline int strverscmp(const char *s1, const char *s2) +{ + die(strverscmp() not supported); +} +#endif becomes #ifndef HAVE_STRVERSCMP, and this: diff --git a/t/test-lib.sh b/t/test-lib.sh index 1531c24..5e8c39a 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -771,6 +771,8 @@ case $(uname -s) in ;; esac +[ $(uname -o) = GNU/Linux ] test_set_prereq GNULINUX + can pick up the value from GIT-BUILD-OPTIONS as a prerequisite (see the way we handle NO_PERL for an example). Though if we can just grab the glibc version as a fallback, we can do away with that completely. -Peff -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] tag: support --sort=spec
--sort=refname:version (or --sort=refname:v for short) sorts tags as if they are versions. --sort=-refname reverses the order (with or without :version). This syntax is chosen to make it compatible with future extension in for-each-ref --sort GNU extension strverscmp is used so this is Linux only. Mac and Windows will need to bundle a compat implementation (and long term we may want to use compat version only so we can make XXX-rc, XXX-pre... appear before XXX) Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- The new prereq GNULINUX is an ugly workaround until people provide strverscmp compat implementation. I hope that will happen soon as strverscmp.c does not look very complex. Documentation/git-tag.txt | 6 + builtin/tag.c | 69 +++ git-compat-util.h | 7 + t/t7004-tag.sh| 43 + t/test-lib.sh | 2 ++ 5 files changed, 122 insertions(+), 5 deletions(-) diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt index 404257d..d8633bb 100644 --- a/Documentation/git-tag.txt +++ b/Documentation/git-tag.txt @@ -95,6 +95,12 @@ OPTIONS using fnmatch(3)). Multiple patterns may be given; if any of them matches, the tag is shown. +--sort=type:: + Sort in a specific order. Supported type is refname + (lexical order), refname:version or refname:v (tag names + are treated as version strings). Prepend - to reverse sorting + order. + --column[=options]:: --no-column:: Display tag listing in columns. See configuration variable diff --git a/builtin/tag.c b/builtin/tag.c index 74d3780..483d293 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -27,9 +27,16 @@ static const char * const git_tag_usage[] = { NULL }; +#define STRCMP_SORT 0 /* must be zero */ +#define STRVERSCMP_SORT 1 +#define SORT_MASK 0x7fff +#define REVERSE_SORT0x8000 + struct tag_filter { const char **patterns; int lines; + int sort; + struct string_list tags; struct commit_list *with_commit; }; @@ -166,7 +173,10 @@ static int show_reference(const char *refname, const unsigned char *sha1, return 0; if (!filter-lines) { - printf(%s\n, refname); + if (filter-sort) + string_list_append(filter-tags, refname); + else + printf(%s\n, refname); return 0; } printf(%-15s , refname); @@ -177,17 +187,39 @@ static int show_reference(const char *refname, const unsigned char *sha1, return 0; } +static int sort_by_version(const void *a_, const void *b_) +{ + const struct string_list_item *a = a_; + const struct string_list_item *b = b_; + return strverscmp(a-string, b-string); +} + static int list_tags(const char **patterns, int lines, - struct commit_list *with_commit) +struct commit_list *with_commit, int sort) { struct tag_filter filter; filter.patterns = patterns; filter.lines = lines; + filter.sort = sort; filter.with_commit = with_commit; + memset(filter.tags, 0, sizeof(filter.tags)); + filter.tags.strdup_strings = 1; for_each_tag_ref(show_reference, (void *) filter); - + if (sort) { + int i; + if ((sort SORT_MASK) == STRVERSCMP_SORT) + qsort(filter.tags.items, filter.tags.nr, + sizeof(struct string_list_item), sort_by_version); + if (sort REVERSE_SORT) + for (i = filter.tags.nr - 1; i = 0; i--) + printf(%s\n, filter.tags.items[i].string); + else + for (i = 0; i filter.tags.nr; i++) + printf(%s\n, filter.tags.items[i].string); + string_list_clear(filter.tags, 0); + } return 0; } @@ -427,6 +459,27 @@ static int parse_opt_points_at(const struct option *opt __attribute__((unused)), return 0; } +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, refname) || + (arg[7] != ':' arg[7] != '\0')) + die(_(unsupported sort field %s), arg); + if (arg[7] == ':') { + const char *modifier = arg + 8; + if (!strcmp(modifier, version) || !strcmp(modifier, v)) + *sort |= STRVERSCMP_SORT; + else + die(_(unsupported modifier %s), modifier); + } + return