From 17bf4ff3cd3d7fd4b252b81417df8be1b3b2b128 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Wed, 22 May 2013 16:09:54 +0530 Subject: sha1_name: fix error message for @{u} Currently, when no (valid) upstream is configured for a branch, you get an error like: $ git show @{u} error: No upstream configured for branch 'upstream-error' error: No upstream configured for branch 'upstream-error' fatal: ambiguous argument '@{u}': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]' The "error: " line actually appears twice, and the rest of the error message is useless. In sha1_name.c:interpret_branch_name(), there is really no point in processing further if @{u} couldn't be resolved, and we might as well die() instead of returning an error(). After making this change, you get: $ git show @{u} fatal: No upstream configured for branch 'upstream-error' Also tweak a few tests in t1507 to expect this output. This only turns error() that may be called after we know we are dealing with an @{upstream} marker into die(), without touching silent error returns "return -1" from the function. Any caller that wants to handle an error condition itself will not be hurt by this change, unless they want to see the message from error() and then exit silently without giving its own message, which needs to be fixed anyway. Signed-off-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano --- sha1_name.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'sha1_name.c') diff --git a/sha1_name.c b/sha1_name.c index 3820f28ae7..416a673d68 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -1033,14 +1033,15 @@ int interpret_branch_name(const char *name, struct strbuf *buf) * points to something different than a branch. */ if (!upstream) - return error(_("HEAD does not point to a branch")); + die(_("HEAD does not point to a branch")); if (!upstream->merge || !upstream->merge[0]->dst) { if (!ref_exists(upstream->refname)) - return error(_("No such branch: '%s'"), cp); - if (!upstream->merge) - return error(_("No upstream configured for branch '%s'"), - upstream->name); - return error( + die(_("No such branch: '%s'"), cp); + if (!upstream->merge) { + die(_("No upstream configured for branch '%s'"), + upstream->name); + } + die( _("Upstream branch '%s' not stored as a remote-tracking branch"), upstream->merge[0]->src); } -- cgit v1.2.3 From 305ebea06d5e633e3d648c798b5e6bb2b9abf361 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Wed, 22 May 2013 16:09:55 +0530 Subject: sha1_name: fix error message for @{}, @{} Currently, when we try to resolve @{} or @{} when the reflog doesn't go back far enough, we get errors like: # on branch master $ git show @{10000} fatal: Log for '' only has 7 entries. $ git show @{10000.days.ago} warning: Log for '' only goes back to Tue, 21 May 2013 14:14:45 +0530. ... # detached HEAD case $ git show @{10000} fatal: Log for '' only has 2005 entries. $ git show master@{10000} fatal: Log for 'master' only has 7 entries. The empty string '' is confusing and does not convey information about whose logs we are inspecting. Change this so that we get: # on branch master $ git show @{10000} fatal: Log for 'master' only has 7 entries. $ git show @{10000.days.ago} warning: Log for 'master' only goes back to Tue, 21 May 2013 14:14:45 +0530. ... # detached HEAD case $ git show @{10000} fatal: Log for 'HEAD' only has 2005 entries. $ git show master@{10000} fatal: Log for 'master' only has 7 entries. Also one of the message strings given to die() now points into real_ref that was not used in that fashion, so stop freeing the underlying storage for it. Signed-off-by: Ramkumar Ramachandra Bug-spotted-and-fixed-by: Thomas Rast Signed-off-by: Junio C Hamano --- sha1_name.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'sha1_name.c') diff --git a/sha1_name.c b/sha1_name.c index 416a673d68..01b36ead42 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -517,12 +517,21 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) } if (read_ref_at(real_ref, at_time, nth, sha1, NULL, &co_time, &co_tz, &co_cnt)) { + if (!len) { + if (!prefixcmp(real_ref, "refs/heads/")) { + str = real_ref + 11; + len = strlen(real_ref + 11); + } else { + /* detached HEAD */ + str = "HEAD"; + len = 4; + } + } if (at_time) warning("Log for '%.*s' only goes " "back to %s.", len, str, show_date(co_time, co_tz, DATE_RFC2822)); else { - free(real_ref); die("Log for '%.*s' only has %d entries.", len, str, co_cnt); } -- cgit v1.2.3