Skip to content

Instantly share code, notes, and snippets.

@wellington1993
Created May 19, 2016 20:24
Show Gist options
  • Save wellington1993/64993816eab4e9d1e0e77f509c962e12 to your computer and use it in GitHub Desktop.
Save wellington1993/64993816eab4e9d1e0e77f509c962e12 to your computer and use it in GitHub Desktop.
git-unique-abbrev calc from: How short can Git abbreviate?(Josh Stone)
#!/bin/bash
# git-unique-abbrev
OBJECTS="$(mktemp)"
git rev-list --all --objects | cut -c1-40 | sort >"$OBJECTS"
printf "%d objects\n" $(wc -l <"$OBJECTS")
for abbrev in $(seq 4 40); do
DUPES="$(mktemp)"
uniq -D -w $abbrev <"$OBJECTS" >"$DUPES"
count=$(wc -l <"$DUPES")
acount=$(uniq -w $abbrev <"$DUPES" | wc -l)
printf "%2d: %d / %d\n" $abbrev $count $acount
test $count -eq 0 && cat "$OBJECTS"
mv "$DUPES" "$OBJECTS"
test $count -eq 0 && break
done
rm -f "$OBJECTS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment