{"thread":{"id":"30931","subject":"git blame gives an ambiguous short revision","startedAt":"2012-07-01T12:30:11Z","lastAt":"2012-07-02T07:54:00Z","messageCount":5,"participants":["Julia Lawall","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"194455","messageId":"alpine.DEB.2.02.1207010825370.1873@hadrien","threadId":"30931","inReplyTo":null,"subject":"git blame gives an ambiguous short revision","fromName":"Julia Lawall","fromEmail":"julia.lawall@lip6.fr","sentAt":"2012-07-01T12:30:11Z","receivedAt":"2012-07-01T12:30:11Z","isPatch":false,"sender":{"key":"julia.lawall@lip6.fr","avatar":null},"body":"Using linux-next cloned today (July 1), I then checkout out the\nrevision 60d5c9f5b.  The command\n\ngit blame drivers/staging/brcm80211/brcmfmac/wl_iw.c -L3675,3675\n\nthen gives:\n\n60d5c9f5 (Julia Lawall 2011-04-01 16:23:42 +0200 3675)  if (!iscan->iscan_ex_params_p) {\n\nThen I try:\n\ngit show 60d5c9f5\n\nwhich gives:\n\nerror: short SHA1 60d5c9f5 is ambiguous.\nerror: short SHA1 60d5c9f5 is ambiguous.\nfatal: ambiguous argument '60d5c9f5': unknown revision or path not in the\nworking tree.\nUse '--' to separate paths from revisions\n\nIf I give git blame the -l option, every thing is fine.\n\nthanks,\njulia\n"},{"id":"194456","messageId":"alpine.DEB.2.02.1207010830371.1873@hadrien","threadId":"30931","inReplyTo":"alpine.DEB.2.02.1207010825370.1873@hadrien","subject":"Re: git blame gives an ambiguous short revision","fromName":"Julia Lawall","fromEmail":"julia.lawall@lip6.fr","sentAt":"2012-07-01T12:31:09Z","receivedAt":"2012-07-01T12:31:09Z","isPatch":false,"sender":{"key":"julia.lawall@lip6.fr","avatar":null},"body":"Sorry, I forgot the git version number:\n\ngit version 1.7.3.4\n\non Ubuntu.\n\njulia\n\nOn Sun, 1 Jul 2012, Julia Lawall wrote:\n\n> Using linux-next cloned today (July 1), I then checkout out the\n> revision 60d5c9f5b.  The command\n>\n> git blame drivers/staging/brcm80211/brcmfmac/wl_iw.c -L3675,3675\n>\n> then gives:\n>\n> 60d5c9f5 (Julia Lawall 2011-04-01 16:23:42 +0200 3675)  if (!iscan->iscan_ex_params_p) {\n>\n> Then I try:\n>\n> git show 60d5c9f5\n>\n> which gives:\n>\n> error: short SHA1 60d5c9f5 is ambiguous.\n> error: short SHA1 60d5c9f5 is ambiguous.\n> fatal: ambiguous argument '60d5c9f5': unknown revision or path not in the\n> working tree.\n> Use '--' to separate paths from revisions\n>\n> If I give git blame the -l option, every thing is fine.\n>\n> thanks,\n> julia\n>\n"},{"id":"194460","messageId":"7vipe63a4r.fsf@alter.siamese.dyndns.org","threadId":"30931","inReplyTo":"alpine.DEB.2.02.1207010825370.1873@hadrien","subject":"Re: git blame gives an ambiguous short revision","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-02T07:17:08Z","receivedAt":"2012-07-02T07:17:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Julia Lawall <julia.lawall@lip6.fr> writes:\n\n> Using linux-next cloned today (July 1), I then checkout out the\n> revision 60d5c9f5b.  The command\n>\n> git blame drivers/staging/brcm80211/brcmfmac/wl_iw.c -L3675,3675\n>\n> then gives:\n>\n> 60d5c9f5 (Julia Lawall 2011-04-01 16:23:42 +0200 3675)  if (!iscan->iscan_ex_params_p) {\n>\n> Then I try:\n>\n> git show 60d5c9f5\n>\n> which gives:\n>\n> error: short SHA1 60d5c9f5 is ambiguous.\n> error: short SHA1 60d5c9f5 is ambiguous.\n> fatal: ambiguous argument '60d5c9f5': unknown revision or path not in the\n> working tree.\n> Use '--' to separate paths from revisions\n>\n> If I give git blame the -l option, every thing is fine.\n\nOr you can use --abbrev to explicitly set the width; as the length\nnecessary to make the abbreviated object names depends on the\nproject, there is no good default.\n\nI think it should be an easy patch to add a post-processing phase\nafter all lines are blamed to automatically compute an appropriate\nvalue of abbreviation to ensure the uniqueness, but the current\nblame output does not bother to do so.\n"},{"id":"194462","messageId":"7vehou39mk.fsf@alter.siamese.dyndns.org","threadId":"30931","inReplyTo":"7vipe63a4r.fsf@alter.siamese.dyndns.org","subject":"Re: git blame gives an ambiguous short revision","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-02T07:28:03Z","receivedAt":"2012-07-02T07:28:03Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> I think it should be an easy patch to add a post-processing phase\n> after all lines are blamed to automatically compute an appropriate\n> value of abbreviation to ensure the uniqueness, but the current\n> blame output does not bother to do so.\n\nSomething like this, perhaps, but I didn't test the patch beyond \"it\ncompiles\".\n\n builtin/blame.c | 25 +++++++++++++++++++++----\n 1 file changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 24d3dd5..960c58d 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1837,6 +1837,16 @@ static int read_ancestry(const char *graft_file)\n \treturn 0;\n }\n \n+static int update_auto_abbrev(int auto_abbrev, struct origin *suspect)\n+{\n+\tconst char *uniq = find_unique_abbrev(suspect->commit->object.sha1,\n+\t\t\t\t\t      auto_abbrev);\n+\tint len = strlen(uniq);\n+\tif (auto_abbrev < len)\n+\t\treturn len;\n+\treturn auto_abbrev;\n+}\n+\n /*\n  * How many columns do we need to show line numbers, authors,\n  * and filenames?\n@@ -1847,12 +1857,16 @@ static void find_alignment(struct scoreboard *sb, int *option)\n \tint longest_dst_lines = 0;\n \tunsigned largest_score = 0;\n \tstruct blame_entry *e;\n+\tint compute_auto_abbrev = (abbrev < 0);\n+\tint auto_abbrev = default_abbrev;\n \n \tfor (e = sb->ent; e; e = e->next) {\n \t\tstruct origin *suspect = e->suspect;\n \t\tstruct commit_info ci;\n \t\tint num;\n \n+\t\tif (compute_auto_abbrev)\n+\t\t\tauto_abbrev = update_auto_abbrev(auto_abbrev, suspect);\n \t\tif (strcmp(suspect->path, sb->path))\n \t\t\t*option |= OUTPUT_SHOW_NAME;\n \t\tnum = strlen(suspect->path);\n@@ -1880,6 +1894,10 @@ static void find_alignment(struct scoreboard *sb, int *option)\n \tmax_orig_digits = decimal_width(longest_src_lines);\n \tmax_digits = decimal_width(longest_dst_lines);\n \tmax_score_digits = decimal_width(largest_score);\n+\n+\tif (compute_auto_abbrev)\n+\t\t/* one more abbrev length is needed for the boundary commit */\n+\t\tabbrev = auto_abbrev + 1;\n }\n \n /*\n@@ -2353,10 +2371,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n parse_done:\n \targc = parse_options_end(&ctx);\n \n-\tif (abbrev == -1)\n-\t\tabbrev = default_abbrev;\n-\t/* one more abbrev length is needed for the boundary commit */\n-\tabbrev++;\n+\tif (0 < abbrev)\n+\t\t/* one more abbrev length is needed for the boundary commit */\n+\t\tabbrev++;\n \n \tif (revs_file && read_ancestry(revs_file))\n \t\tdie_errno(\"reading graft file '%s' failed\", revs_file);\n"},{"id":"194463","messageId":"7v8vf238fb.fsf@alter.siamese.dyndns.org","threadId":"30931","inReplyTo":"7vehou39mk.fsf@alter.siamese.dyndns.org","subject":"Re: git blame gives an ambiguous short revision","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-02T07:54:00Z","receivedAt":"2012-07-02T07:54:00Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Something like this, perhaps, but I didn't test the patch beyond \"it\n> compiles\".\n\nOK, now I tested it ;-)  I'll queue this and eventually merge down\nto older maintenance releases.\n\n-- >8 --\nSubject: [PATCH] blame: compute abbreviation width that ensures uniqueness\n\nJulia Lawall noticed that in linux-next repository the commit object\n60d5c9f5 (shown with the default abbreviation width baked into \"git\nblame\") in output from\n\n  $ git blame -L 3675,3675 60d5c9f5b -- \\\n      drivers/staging/brcm80211/brcmfmac/wl_iw.c\n\nis no longer unique in the repository, which results in \"short SHA1\n60d5c9f5 is ambiguous\".\n\nCompute the minimum abbreviation width that ensures uniqueness when\nthe user did not specify the --abbrev option to avoid this.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\nIncidentally, \"git show v2.6.39-rc4-181-g60d5c9f5\" is resolved\ncorrectly with the recent \"prolong the shelf-life of decribed name\"\ntopic that will hopefully be ready by the next release, and it\nresolves even shorter \"v2.6.39-rc4-181-g60d5c\" just fine ;-).\n\n builtin/blame.c | 25 +++++++++++++++++++++----\n 1 file changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 3e1f7e1..f13ec32 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1828,6 +1828,16 @@ static int read_ancestry(const char *graft_file)\n \treturn 0;\n }\n \n+static int update_auto_abbrev(int auto_abbrev, struct origin *suspect)\n+{\n+\tconst char *uniq = find_unique_abbrev(suspect->commit->object.sha1,\n+\t\t\t\t\t      auto_abbrev);\n+\tint len = strlen(uniq);\n+\tif (auto_abbrev < len)\n+\t\treturn len;\n+\treturn auto_abbrev;\n+}\n+\n /*\n  * How many columns do we need to show line numbers in decimal?\n  */\n@@ -1850,12 +1860,16 @@ static void find_alignment(struct scoreboard *sb, int *option)\n \tint longest_dst_lines = 0;\n \tunsigned largest_score = 0;\n \tstruct blame_entry *e;\n+\tint compute_auto_abbrev = (abbrev < 0);\n+\tint auto_abbrev = default_abbrev;\n \n \tfor (e = sb->ent; e; e = e->next) {\n \t\tstruct origin *suspect = e->suspect;\n \t\tstruct commit_info ci;\n \t\tint num;\n \n+\t\tif (compute_auto_abbrev)\n+\t\t\tauto_abbrev = update_auto_abbrev(auto_abbrev, suspect);\n \t\tif (strcmp(suspect->path, sb->path))\n \t\t\t*option |= OUTPUT_SHOW_NAME;\n \t\tnum = strlen(suspect->path);\n@@ -1883,6 +1897,10 @@ static void find_alignment(struct scoreboard *sb, int *option)\n \tmax_orig_digits = lineno_width(longest_src_lines);\n \tmax_digits = lineno_width(longest_dst_lines);\n \tmax_score_digits = lineno_width(largest_score);\n+\n+\tif (compute_auto_abbrev)\n+\t\t/* one more abbrev length is needed for the boundary commit */\n+\t\tabbrev = auto_abbrev + 1;\n }\n \n /*\n@@ -2360,10 +2378,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n parse_done:\n \targc = parse_options_end(&ctx);\n \n-\tif (abbrev == -1)\n-\t\tabbrev = default_abbrev;\n-\t/* one more abbrev length is needed for the boundary commit */\n-\tabbrev++;\n+\tif (0 < abbrev)\n+\t\t/* one more abbrev length is needed for the boundary commit */\n+\t\tabbrev++;\n \n \tif (revs_file && read_ancestry(revs_file))\n \t\tdie_errno(\"reading graft file '%s' failed\", revs_file);\n-- \n1.7.11.1.212.g52fe12e\n"}]}