Re: easy way to demonstrate length of colliding SHA-1 prefixes?
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Dec 2, 2018, 13:23 UTC
- Message-ID
- <87y398uknn.fsf@evledraar.gmail.com>
- In-Reply-To
- <alpine.LFD.2.21.1812020647440.32023@localhost.localdomain>
On Sun, Dec 02 2018, Robert P. J. Day wrote:
Show 11 quoted lines
> as part of an upcoming git class i'm delivering, i thought it would > be amusing to demonstrate the maximum length of colliding SHA-1 > prefixes in a repository (in my case, i use the linux kernel git repo > for most of my examples). > > is there a way to display the objects in the object database that > clash in the longest object name SHA-1 prefix; i mean, short of > manually listing all object names, running that through cut and sort > and uniq and ... you get the idea. > > is there a cute way to do that? thanks.
You'll always need to list them all. It's inherently an operation where for each SHA-1 you need to search for other ones with that prefix up to a given length.
Perhaps you've missed that you can use --abbrev=N for this, and just grep for things that are loger than that N, e.g. for linux.git:
git log --oneline --abbrev=10 --pretty=format:%h |
grep -E -v '^.{10}$' |
perl -pe 's/^(.{10}).*/$1/'This will list the 4 objects that need more than 10 characters to be shown unambiguously. If you then "git cat-file -t" them you'll get the disambiguation help.