Re: [PATCH] describe: when failing, tell the user about options that work

4 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] describe: when failing, tell the user about options that work

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:36

Thomas Rast [off-list ref] writes:
quoted hunk
@@ -259,7 +260,14 @@ static void describe(const char *arg, int last_one)
 			printf("%s\n", find_unique_abbrev(sha1, abbrev));
 			return;
 		}
-		die("cannot describe '%s'", sha1_to_hex(sha1));
+		if (unannotated_cnt)
+			die("cannot describe '%s'"
+			    " with only\nannotated tags. Try --tags.",
Did you mean UNannotated tags here?
+			    sha1_to_hex(sha1));
+		else
+			die("cannot describe '%s'"
+			    " with tags\nTry --always, or create some tags.",
+			    sha1_to_hex(sha1));
 	}
 
 	qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);

Re: [PATCH] describe: when failing, tell the user about options that work

From: Thomas Rast <hidden>
Date: 2016-06-15 22:47:36

Junio C Hamano wrote:
Thomas Rast [off-list ref] writes:
quoted
@@ -259,7 +260,14 @@ static void describe(const char *arg, int last_one)
 			printf("%s\n", find_unique_abbrev(sha1, abbrev));
 			return;
 		}
-		die("cannot describe '%s'", sha1_to_hex(sha1));
+		if (unannotated_cnt)
+			die("cannot describe '%s'"
+			    " with only\nannotated tags. Try --tags.",
Did you mean UNannotated tags here?
No, but I think I see where the misunderstanding came from.

This code path means that we did not find a tag to describe with, but
we counted some unannotated tags (and because of how the counting
logic is wrapped, this only triggers when neither --all nor --tags are
in effect).

So I wanted it to say "it is impossible to describe this with the tags
you told me to use", which in this case are the annotated ones.

I tried to keep the general structure of the message ("cannot describe
..."), and with this restriction I can't seem to find a clearer
wording.  However, it could be written e.g.

  No annotated tags can describe '%s'.  However, there were
  unannotated tags: try --tags.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

Re: [PATCH] describe: when failing, tell the user about options that work

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:36

Thomas Rast [off-list ref] writes:
Junio C Hamano wrote:
quoted
Thomas Rast [off-list ref] writes:
quoted
@@ -259,7 +260,14 @@ static void describe(const char *arg, int last_one)
 			printf("%s\n", find_unique_abbrev(sha1, abbrev));
 			return;
 		}
-		die("cannot describe '%s'", sha1_to_hex(sha1));
+		if (unannotated_cnt)
+			die("cannot describe '%s'"
+			    " with only\nannotated tags. Try --tags.",
Did you mean UNannotated tags here?
No, but I think I see where the misunderstanding came from.

This code path means that we did not find a tag to describe with, but
we counted some unannotated tags (and because of how the counting
logic is wrapped, this only triggers when neither --all nor --tags are
in effect).
I think I read the code right ;-).
So I wanted it to say "it is impossible to describe this with the tags
you told me to use", which in this case are the annotated ones.
The way I read it was "it is impossible to describe it in the way you told
me to, when the tags you have are only unannotated kind."
However, it could be written e.g.

  No annotated tags can describe '%s'.  However, there were
  unannotated tags: try --tags.
Sounds better.

[PATCH v2] describe: when failing, tell the user about options that work

From: Thomas Rast <hidden>
Date: 2016-06-15 22:47:37

Users seem to call git-describe without reading the manpage, and then
wonder why it doesn't work with unannotated tags by default.

Make a minimal effort towards seeing if there would have been
unannotated tags, and tell the user.  Specifically, we say that --tags
could work if we found any unannotated tags.  If not, we say that
--always would have given results.

Signed-off-by: Thomas Rast <redacted>
---

Junio C Hamano wrote:
Thomas Rast [off-list ref] writes:
quoted
However, it could be written e.g.

  No annotated tags can describe '%s'.  However, there were
  unannotated tags: try --tags.
Sounds better.
Then let's make it so.  Sorry for taking so long.


 builtin-describe.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/builtin-describe.c b/builtin-describe.c
index 2dcfd3d..4ea6f88 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -96,8 +96,6 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void 
 	if (!all) {
 		if (!prio)
 			return 0;
-		if (!tags && prio < 2)
-			return 0;
 	}
 	add_to_known_names(all ? path + 5 : path + 10, commit, prio, sha1);
 	return 0;
@@ -184,6 +182,7 @@ static void describe(const char *arg, int last_one)
 	struct possible_tag all_matches[MAX_TAGS];
 	unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
 	unsigned long seen_commits = 0;
+	unsigned int unannotated_cnt = 0;
 
 	if (get_sha1(arg, sha1))
 		die("Not a valid object name %s", arg);
@@ -217,7 +216,9 @@ static void describe(const char *arg, int last_one)
 		seen_commits++;
 		n = c->util;
 		if (n) {
-			if (match_cnt < max_candidates) {
+			if (!tags && !all && n->prio < 2) {
+				unannotated_cnt++;
+			} else if (match_cnt < max_candidates) {
 				struct possible_tag *t = &all_matches[match_cnt++];
 				t->name = n;
 				t->depth = seen_commits - 1;
@@ -259,7 +260,14 @@ static void describe(const char *arg, int last_one)
 			printf("%s\n", find_unique_abbrev(sha1, abbrev));
 			return;
 		}
-		die("cannot describe '%s'", sha1_to_hex(sha1));
+		if (unannotated_cnt)
+			die("No annotated tags can describe '%s'.\n"
+			    "However, there were unannotated tags: try --tags.",
+			    sha1_to_hex(sha1));
+		else
+			die("No tags can describe '%s'.\n"
+			    "Try --always, or create some tags.",
+			    sha1_to_hex(sha1));
 	}
 
 	qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);
-- 
1.6.5.1.161.g3b9c0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help