Re: please don't git describe in 0.12

Kalle Olavi Niemitalo <[email protected]> Sun, 10 Aug 2008 19:32:03 +0300
Newsgroups gmane.comp.web.links
Message-ID <[email protected]>
I have now patched Git to hide my local tags from git describe.
I am intentionally not sending this to the git mailing list
because I'm not sure I can satisfy their Signed-Off-By
requirements right away.  The "Modified on" comments are for
GPLv2 clause 2. a).


Add describe.ignoretags config variable

In my elinks.git repository, I have many annotated tags that do not
correspond to ELinks releases.  For example, a tag called
email/elinks-users/2007-07-30 refers to a commit that I posted as
a patch to elinks-users on 2007-07-30; the tag object contains the
Message-ID and some other email headers.  These tags were affecting
the result of "git describe" called by a Makefile.  Now I can
prevent that by setting describe.ignoretags in elinks.git/config.

In Git 1.5.5 and later, it was already possible to limit the set
of tags considered, with git describe --match=PATTERN.  To match
"elinks-0.11.4" and "elinks-0.12pre1", we could use
--match="elinks-*".  However, the naming scheme has been changed
in the past (from e.g. REL_0_10_6) and may be changed again in the
future.  Besides, ignoring the email tags is what I want for
interactive use of git describe as well.

There are no new tests in this commit.

---
commit c97654d02a95e6701481204121a4f4c59e8f3088
tree 9abf39a8d8dca5308ae77923702606bf630778b1
parent 71b9979bc74b66c1cf961d5c74de5c0b3cbf00a4
author Kalle Olavi Niemitalo <[email protected]> Sun, 10 Aug 2008 17:56:45 +0300
committer Kalle Olavi Niemitalo <[email protected]> Sun, 10 Aug 2008 17:56:45 +0300

 Documentation/config.txt       |   11 +++++++++++
 Documentation/git-describe.txt |    5 ++++-
 builtin-describe.c             |   29 ++++++++++++++++++++++++++++-
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index b8ec01c..c9270b5 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1,3 +1,5 @@
+// Modified on 2008-08-10 by Kalle Olavi Niemitalo
+
 CONFIGURATION FILE
 ------------------
 
@@ -557,6 +559,15 @@ color.ui::
 	terminal. When more specific variables of color.* are set, they always
 	take precedence over this setting. Defaults to false.
 
+describe.excludetags::
+	Makes 'git-describe' ignore tags that match a pattern.  Some
+	programs call 'git-describe' at build time and display the
+	result as a version number; if you have made some annotated
+	tags for your local use, set this option to prevent them from
+	affecting the displayed version number.  The value should be a
+	pattern of tag names, e.g. `local/*`.  You can set this option
+	multiple times.
+
 diff.autorefreshindex::
 	When using 'git-diff' to compare with work tree
 	files, do not consider stat-only change as changed.
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index c4dbc2a..33a923e 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -68,7 +68,9 @@ OPTIONS
 
 --match <pattern>::
 	Only consider tags matching the given pattern (can be used to avoid
-	leaking private tags made from the repository).
+	leaking private tags made from the repository).  Alternatively,
+	you could set the describe.excludetags configuration variable;
+	see linkgit:git-config[1] for details.
 
 --always::
 	Show uniquely abbreviated commit object as fallback.
@@ -138,6 +140,7 @@ Author
 Written by Linus Torvalds <[email protected]>, but somewhat
 butchered by Junio C Hamano <[email protected]>.  Later significantly
 updated by Shawn Pearce <[email protected]>.
+Modified on 2008-08-10 by Kalle Olavi Niemitalo.
 
 Documentation
 --------------
diff --git a/builtin-describe.c b/builtin-describe.c
index ec404c8..4367ab9 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -1,3 +1,5 @@
+/* Modified on 2008-08-10 by Kalle Olavi Niemitalo */
+
 #include "cache.h"
 #include "commit.h"
 #include "tag.h"
@@ -5,6 +7,7 @@
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "parse-options.h"
+#include "string-list.h"
 
 #define SEEN		(1u<<0)
 #define MAX_TAGS	(FLAG_BITS - 1)
@@ -22,6 +25,28 @@ static int abbrev = DEFAULT_ABBREV;
 static int max_candidates = 10;
 static const char *pattern;
 static int always;
+static struct string_list exclude_patterns = { .strdup_strings = 1 };
+
+static int git_describe_config(const char *var, const char *value, void *cb)
+{
+	if (!strcmp(var, "describe.excludetags")) {
+		if (!value)
+			return config_error_nonbool(var);
+		string_list_append(value, &exclude_patterns);
+		return 0;
+	}
+	return git_default_config(var, value, cb);
+}
+
+static int matches_any_exclude_pattern(const char *tagname)
+{
+	unsigned int i;
+
+	for (i = 0; i < exclude_patterns.nr; i++)
+		if (!fnmatch(exclude_patterns.items[i].string, tagname, 0))
+			return 1;
+	return 0;
+}
 
 struct commit_name {
 	struct tag *tag;
@@ -85,7 +110,8 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
 		else
 			prio = 1;
 
-		if (pattern && fnmatch(pattern, path + 10, 0))
+		if ((pattern && fnmatch(pattern, path + 10, 0))
+		    || matches_any_exclude_pattern(path + 10))
 			prio = 0;
 	}
 	else
@@ -324,6 +350,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 		OPT_END(),
 	};
 
+	git_config(git_describe_config, NULL);
 	argc = parse_options(argc, argv, options, describe_usage, 0);
 	if (max_candidates < 0)
 		max_candidates = 0;

_______________________________________________
elinks-dev mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-dev
signature.asc (application/pgp-signature, 188 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFInxgPHm9IGt60eMgRAk2UAJwJpMJXXp8HyLZ2g4VNpBC01/395gCfX1KI
Oq4qg7f/2GS2nUd7f9aEXXI=
=97Sz
-----END PGP SIGNATURE-----