git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] blame: introduce -u/--unique option

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 9, 2011, 19:45 UTC
Message-ID
<7vy64o9ixz.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1299581951-4670-2-git-send-email-namhyung@gmail.com>
Namhyung Kim <namhyung@gmail.com> writes:
> -u/--unique option will find and use minimum length of unique
> SHA-1 name. If -l option is specified also, it will have higher
> priority, IOW git blame will use full 40-length SHA-1 name.
Show 8 quoted lines
> @@ -1867,6 +1878,10 @@ static void find_alignment(struct scoreboard *sb, int *option)
>  			longest_dst_lines = num;
>  		if (largest_score < ent_score(sb, e))
>  			largest_score = ent_score(sb, e);
> +		sha1 = find_unique_abbrev(suspect->commit->object.sha1,
> +					  MINIMUM_ABBREV);
> +		if (longest_uniq_sha1 < strlen(sha1))
> +			longest_uniq_sha1 = strlen(sha1);

The logic to determine and keep track of the longuest-unique looks correct, but I was hoping that we already have an easy optimization codepath to do this only once per commit, not for every blame-entry in the result. Doesn't the code have a similar optimization to figure out the necessary number of columns to show author names (I haven't read the code recently, though)?

Also we might find that the performance impact of doing this may be so miniscule that it is not worth wasting a short option name. If we were to use an option, I was actually hoping that the option would let the users specify a value different from the hardcoded 8 at the same time. E.g.

    git blame --abbrev=8 ;# current default with uniquefy applied
    git blame --abbrev=4 ;# equivalent to your "blame -u"

Can we have a benchmark of this feature in a largish and busy file in a project with a deep history?

Previous: Namhyung KimNext: Namhyung Kim
Message 3 of 13 in “sha1_name: try to use same abbrev length when core.abbrevguard is specified”
  1. 1/2 sha1_name: try to use same abbrev length when core.abbrevguard is specifiedNamhyung Kim, Mar 8, 2011
  2. 2/2 blame: introduce -u/--unique optionNamhyung Kim, Mar 8, 2011
  3. Junio C HamanoMar 9, 2011
  4. Namhyung KimMar 10, 2011
  5. Junio C HamanoMar 10, 2011
  6. Namhyung KimMar 10, 2011
  7. Junio C HamanoMar 9, 2011
  8. Junio C HamanoMar 9, 2011
  9. Re* [PATCH 1/2] sha1_name: try to use same abbrev length when core.abbrevguard is specifiedJunio C Hamano, Mar 10, 2011
  10. Namhyung KimMar 10, 2011
  11. Namhyung KimMar 10, 2011
  12. Junio C HamanoMar 10, 2011
  13. Namhyung KimMar 10, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.