Skip to contentSkip to conversation

describe: support the syntax "--abbrev=+"

PATCH In review Jonh Wendell 2 participants 6 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

cover describe: support the syntax "--abbrev=+"

Sometimes it's interesting to have a simple output that answers the question:
Are there commits after the latest tag?

One possible solution is to just print a "+" (plus) signal after the tag. Example:

Quoted 1 line

git describe --abbrev=1 5261ec5d5

v2.1.0-rc1-2-g5261ec

Quoted 1 line

git describe --abbrev=+ 5261ec5d5

v2.1.0-rc1+

Jonh Wendell (2):
describe: support the syntax "--abbrev=+"
describe: Add documentation for "--abbrev=+"

 Documentation/git-describe.txt |  6 ++++++
 builtin/describe.c             | 26 +++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/2 describe: support the syntax "--abbrev=+"

It will print just a "+" sign appended to the found tag, if there are commits between the tag and the supplied commit.

It's useful when you just need a simple output to know if the supplied commit is an exact match or not.

---
 builtin/describe.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)
builtin/describe.c +21 -5
index ee6a3b9..3a5c052 100644
@@ -30,6 +30,7 @@ static int have_util;
 static const char *pattern;
 static int always;
 static const char *dirty;
+static int simple_abbrev = 0;
 
 /* diff-index command arguments to check if working tree is dirty. */
 static const char *diff_index_args[] = {
@@ -378,8 +379,12 @@ static void describe(const char *arg, int last_one)
 	}
 
 	display_name(all_matches[0].name);
-	if (abbrev)
-		show_suffix(all_matches[0].depth, cmit->object.sha1);
+	if (abbrev) {
+		if (simple_abbrev)
+			printf("+");
+		else
+			show_suffix(all_matches[0].depth, cmit->object.sha1);
+	}
 	if (dirty)
 		printf("%s", dirty);
 	printf("\n");
@@ -388,6 +393,16 @@ static void describe(const char *arg, int last_one)
 		clear_commit_marks(cmit, -1);
 }
 
+static int parse_opt_abbrev_for_describe_cb(const struct option *opt, const char *arg, int unset)
+{
+	if (arg && !strncmp(arg, "+", 1)) {
+		simple_abbrev = 1;
+		return 0;
+	}
+
+	return parse_opt_abbrev_cb(opt, arg, unset);
+}
+
 int cmd_describe(int argc, const char **argv, const char *prefix)
 {
 	int contains = 0;
@@ -398,7 +413,6 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "tags",       &tags, N_("use any tag, even unannotated")),
 		OPT_BOOL(0, "long",       &longformat, N_("always use long format")),
 		OPT_BOOL(0, "first-parent", &first_parent, N_("only follow first parent")),
-		OPT__ABBREV(&abbrev),
 		OPT_SET_INT(0, "exact-match", &max_candidates,
 			    N_("only output exact matches"), 0),
 		OPT_INTEGER(0, "candidates", &max_candidates,
@@ -410,6 +424,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 		{OPTION_STRING, 0, "dirty",  &dirty, N_("mark"),
 			N_("append <mark> on dirty working tree (default: \"-dirty\")"),
 			PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
+		{OPTION_CALLBACK, 0, "abbrev", &abbrev, N_("n"), N_("use <n> digits to display SHA-1s"),
+			PARSE_OPT_OPTARG, &parse_opt_abbrev_for_describe_cb, 0},
 		OPT_END(),
 	};
 
@@ -425,8 +441,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 
 	save_commit_buffer = 0;
 
-	if (longformat && abbrev == 0)
-		die(_("--long is incompatible with --abbrev=0"));
+	if (longformat && (abbrev == 0 || simple_abbrev))
+		die(_("--long is incompatible with --abbrev=+ or --abbrev=0"));
 
 	if (contains) {
 		struct argv_array args;
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/2 describe: Add documentation for "--abbrev=+"

In reply to Jonh Wendell
---
 Documentation/git-describe.txt | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/git-describe.txt +6 -0
index d20ca40..e291770 100644
@@ -54,6 +54,12 @@ OPTIONS
 	abbreviated object name, use <n> digits, or as many digits
 	as needed to form a unique object name.  An <n> of 0
 	will suppress long format, only showing the closest tag.
+	+
+	+
+	A special case of <n> equals to "\+" (without quotes) will print
+	just a "+" sign instead of the whole suffix. This is useful if you
+	only need to know if the supplied <commit-ish> points to an exact
+	match or if there are commits between the tag found and the <commit-ish>.
 
 --candidates=<n>::
 	Instead of considering only the 10 most recent tags as
Signature · 1 line
1.9.3
#3 lore raw

Re: [PATCH 2/2] describe: Add documentation for "--abbrev=+"

Quoted 9 lines · Jonh Wendell
---
 Documentation/git-describe.txt | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/git-describe.txt +0 -0
index d20ca40..e291770 100644

Documentation/git-describe.txt OPTIONS · line 58

Quoted 5 lines
Documentation/git-describe.txt +2 -0
@@ -54,6 +54,12 @@ OPTIONS
 	abbreviated object name, use <n> digits, or as many digits
 	as needed to form a unique object name.  An <n> of 0
 	will suppress long format, only showing the closest tag.
+	+
+	+

Did you intend to have two lines with just plus signs here? I'm not aware of anywhere else in the Documentation where we do that.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
#4 lore raw

Re: [PATCH 2/2] describe: Add documentation for "--abbrev=+"

2014-08-24 3:35 GMT-03:00 brian m. carlson <[email protected]>:

Quoted 5 lines · Jonh Wendell
Quoted 4 lines
---
 Documentation/git-describe.txt | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 14 lines

Documentation/git-describe.txt OPTIONS · line 58

Quoted 10 lines
Documentation/git-describe.txt +2 -0
index d20ca40..e291770 100644
@@ -54,6 +54,12 @@ OPTIONS
      abbreviated object name, use <n> digits, or as many digits
      as needed to form a unique object name.  An <n> of 0
      will suppress long format, only showing the closest tag.
+     +
+     +

Did you intend to have two lines with just plus signs here? I'm not aware of anywhere else in the Documentation where we do that. --

In my tests just one line was not enough to produce a proper line break in the html output.
With two lines like above the output in man and html are ok (just 1 line break).

Signature · 2 lines
Jonh Wendell
http://www.bani.com.br
#5 lore raw
In reply to Jonh Wendell

hi there!
just a ping here, these are my first patches to git. any comment, feedback?

2014-08-23 14:13 GMT-03:00 Jonh Wendell <[email protected]>:

Quoted 23 lines

Sometimes it's interesting to have a simple output that answers the question:
Are there commits after the latest tag?

One possible solution is to just print a "+" (plus) signal after the tag. Example:

Quoted 1 line

git describe --abbrev=1 5261ec5d5

v2.1.0-rc1-2-g5261ec

Quoted 1 line

git describe --abbrev=+ 5261ec5d5

v2.1.0-rc1+

Jonh Wendell (2):
describe: support the syntax "--abbrev=+"
describe: Add documentation for "--abbrev=+"

 Documentation/git-describe.txt |  6 ++++++
 builtin/describe.c             | 26 +++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)

--
1.9.3

Signature · 2 lines
Jonh Wendell
http://www.bani.com.br