Web lists-archives.com

Re: What's so special about objects/17/ ?

Am 07.10.18 um 20:28 schrieb Ævar Arnfjörð Bjarmason:
In 2007 Junio wrote

     +static int need_to_gc(void)
     +	/*
     +	 * Quickly check if a "gc" is needed, by estimating how
     +	 * many loose objects there are.  Because SHA-1 is evenly
     +	 * distributed, we can check only one and get a reasonable
     +	 * estimate.
     +	 */

1. We still have this check of objects/17/ in builtin/gc.c today. Why
    objects/17/ and not e.g. objects/00/ to go with other 000* magic such
    as the 0000000000000000000000000000000000000000 SHA-1?  Statistically
    it doesn't matter, but 17 seems like an odd thing to pick at random
    out of 00..ff, does it have any significance?

The reason is explained in the comment. And, BTW, you do know about this one: https://xkcd.com/221/ don't you? (TLDR: the title is "Random Number")

2. It seems overly paranoid to be checking that the files in
   .git/objects/17/ look like a SHA-1. If we have stuff not generated by
   git in .git/objects/??/ we probably have bigger problems than
   prematurely triggering auto gc, can this just be removed as
   redundant. Was this some check e.g. expecting that this would need to
   deal with tempfiles in these directories that we created at the time
   (but no longer do?)?

It's not about that there are SHA-1s in there, it's about how many there are.

-- Hannes