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

Re: [PATCH 19/20] abbrev: support relative abbrev values

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 13, 2018, 22:22 UTC
Message-ID
<871sdawcmh.fsf@evledraar.gmail.com>
In-Reply-To
<xmqqvaan95os.fsf@gitster-ct.c.googlers.com>
On Tue, Jun 12 2018, Junio C Hamano wrote:
Show 40 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> Change the core.abbrev config variable and the corresponding --abbrev
>> command-line option to support relative values such as +1 or -1.
>>
>> Before Linus's e6c587c733 ("abbrev: auto size the default
>> abbreviation", 2016-09-30) git would default to abbreviating object
>> names to 7-hexdigits, and only picking longer SHA-1s as needed if that
>> was ambiguous.
>>
>> That change instead set the default length as a function of the
>> estimated current count of objects:
>>
>>     Based on the expectation that we would see collision in a
>>     repository with 2^(2N) objects when using object names shortened
>>     to first N bits, use sufficient number of hexdigits to cover the
>>     number of objects in the repository.  Each hexdigit (4-bits) we
>>     add to the shortened name allows us to have four times (2-bits) as
>>     many objects in the repository.
>>
>> By supporting relative values for core.abbrev we can allow users to
>> consistently opt-in for either a higher or lower probability of
>> collision, without needing to hardcode a given numeric value like
>> "10", which would be overkill on some repositories, and far to small
>> on others.
>
> Nicely explained and calculated ;-)
>
>>  test_expect_success 'describe core.abbrev=[-+]1 and --abbrev=[-+]1' '
>> -	test_must_fail git -c core.abbrev=+1 describe | sed_g_tr_d_n >describe &&
>> -	test_must_fail git -c core.abbrev=-1 describe | sed_g_tr_d_n >describe &&
>> +	git -c core.abbrev=-1 describe | sed_g_tr_d_n >describe &&
>> +	test_byte_count = 6 describe &&
>> +
>> +	git -c core.abbrev=+1 describe | sed_g_tr_d_n >describe &&
>> +	test_byte_count = 8 describe &&
>
> Even though I see the point of supporting absurdly small absolute
> values like 4, I do not quite see the point of supporting negative
> relative values here.  What's the expected use case?
I'll add a better explanation for this to the commit message.

Initially I did this for consistency, since it was easy to implement, and there's no reason to have that arbitrary limitation, but thinking about it again I think I'll use this for some of my projects.

E.g. here's a breakdown of my dotfiles repo:
    $ git -c core.abbrev=4 log  --pretty=format:%h|perl -nE 'chomp;say length'|sort|uniq -c|sort -nr
        784 4
         59 5
          7 6

I don't have a single commit that needs 7 characters, yet that's our default. This is a sane trade-off for the kernel, but for something that's just a toy or something you're playing around with something shorter can make sense.

SHA-1s aren't just written down, but also e.g. remembered in wetware short-term memory.

Show 24 quoted lines
>>  	git log --abbrev=+1 --pretty=format:%h -1 | tr_d_n >log &&
>> -	test_byte_count = 4 log &&
>> +	test_byte_count = 8 log &&
>
> This, together with many many others in the rest of the patch, is
> cute but confusing in that the diff shows change from 4 to 8 due to
> the redefinition of what abbrev=+1 means.  I have a feeling that it
> may not be worth doing it "right", but if we were doing it "right",
> we would probably have done it in multiple steps:
>
>     - the earlier patches in this series that demonstrates
>       --abbrev=+1 is --abbrev=1 and core.abbrev=+1 is an error.
>
>     - ensure --abbrev=+1 is rejected as syntax error just like
>       core.abbrev=+1 was, without introducing relative values
>
>     - introduce relative value.
>
> That way, the last step (which corresponds to this patch) would show
> change from "log --abbrev=+1" failing due to syntax error to showing
> abbreviated value that is slightly longer than the default.
>
> But a I said, it may not be worth doing so.  "Is it worth supporting
> negative relative length?" still stands, though.
I'll see what I can do about this value churn.
Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 37 in “unconditional O(1) SHA-1 abbreviation”
  1. 00/20 unconditional O(1) SHA-1 abbreviationÆvar Arnfjörð Bjarmason, Jun 8, 2018
  2. 01/20 t/README: clarify the description of test_line_countÆvar Arnfjörð Bjarmason, Jun 8, 2018
  3. 02/20 test library: add a test_byte_countÆvar Arnfjörð Bjarmason, Jun 8, 2018
  4. 04/20 abbrev tests: add tests for core.abbrev and --abbrevÆvar Arnfjörð Bjarmason, Jun 8, 2018
  5. Junio C HamanoJun 12, 2018
  6. 07/20 abbrev tests: test "git branch" behaviorÆvar Arnfjörð Bjarmason, Jun 8, 2018
  7. 10/20 abbrev tests: test for "git-diff" behaviorÆvar Arnfjörð Bjarmason, Jun 8, 2018
  8. 14/20 config.c: use braces on multiple conditional armsÆvar Arnfjörð Bjarmason, Jun 8, 2018
  9. 16/20 abbrev: unify the handling of non-numeric valuesÆvar Arnfjörð Bjarmason, Jun 8, 2018
  10. 17/20 abbrev: unify the handling of empty valuesÆvar Arnfjörð Bjarmason, Jun 8, 2018
  11. Martin ÅgrenJun 9, 2018
  12. Martin ÅgrenJun 9, 2018
  13. 19/20 abbrev: support relative abbrev valuesÆvar Arnfjörð Bjarmason, Jun 8, 2018
  14. Martin ÅgrenJun 9, 2018
  15. Junio C HamanoJun 12, 2018
  16. Ævar Arnfjörð BjarmasonJun 13, 2018
  17. Junio C HamanoJun 13, 2018
  18. Ævar Arnfjörð BjarmasonJun 14, 2018
  19. Junio C HamanoJun 14, 2018
  20. Ævar Arnfjörð BjarmasonJun 14, 2018
  21. 20/20 abbrev: add a core.validateAbbrev settingÆvar Arnfjörð Bjarmason, Jun 8, 2018
  22. Martin ÅgrenJun 9, 2018
  23. Junio C HamanoJun 12, 2018
  24. 18/20 abbrev parsing: use braces on multiple conditional armsÆvar Arnfjörð Bjarmason, Jun 8, 2018
  25. 09/20 abbrev tests: test for "git-log" behaviorÆvar Arnfjörð Bjarmason, Jun 8, 2018
  26. Martin ÅgrenJun 9, 2018
  27. Ævar Arnfjörð BjarmasonJun 9, 2018
  28. Martin ÅgrenJun 9, 2018
  29. 15/20 parse-options-cb.c: use braces on multiple conditional armsÆvar Arnfjörð Bjarmason, Jun 8, 2018
  30. 12/20 abbrev tests: test for --abbrev and core.abbrev=[+-]NÆvar Arnfjörð Bjarmason, Jun 8, 2018
  31. 13/20 parse-options-cb.c: convert uses of 40 to GIT_SHA1_HEXSZÆvar Arnfjörð Bjarmason, Jun 8, 2018
  32. 06/20 blame: fix a bug, core.abbrev should work like --abbrevÆvar Arnfjörð Bjarmason, Jun 8, 2018
  33. 08/20 abbrev tests: test for "git-describe" behaviorÆvar Arnfjörð Bjarmason, Jun 8, 2018
  34. 11/20 abbrev tests: test for plumbing behaviorÆvar Arnfjörð Bjarmason, Jun 8, 2018
  35. 03/20 blame doc: explicitly note how --abbrev=40 gives 39 charsÆvar Arnfjörð Bjarmason, Jun 8, 2018
  36. Junio C HamanoJun 12, 2018
  37. 05/20 abbrev tests: test "git-blame" behaviorÆvar Arnfjörð Bjarmason, Jun 8, 2018

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.