From 34fc390e138f57deaa798b2e0d3ec2eee5a7707e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 8 May 2018 23:12:13 +0200 Subject: [PATCH] [git completions] Shorten commit SHA ourselves This is much quicker - on the order of 100ms vs 50ms. We shorten to 10 characters, which is statistically suitable - 3 out of 600k commits in the linux kernel need 11 characters. --- share/completions/git.fish | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index 8a982f326..dd827c884 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -6,7 +6,15 @@ function __fish_git_commits # This allows filtering by subject with the new pager! # Because even subject lines can be quite long, # trim them (abbrev'd hash+tab+subject) to 73 characters - command git log --pretty=tformat:"%h"\t"%<(64,trunc)%s" --all --max-count=1000 2>/dev/null + # + # Hashes we just truncate ourselves to 10 characters, without disambiguating. + # That technically means that sometimes we don't give usable SHAs, + # but according to https://stackoverflow.com/a/37403152/3150338, + # that happens for 3 commits out of 600k. + # For fish, at the time of writing, out of 12200 commits, 7 commits need 8 characters. + # And since this takes about 1/3rd of the time that disambiguating takes... + command git log --pretty=tformat:"%H"\t"%<(64,trunc)%s" --all --max-count=1000 2>/dev/null \ + | string replace -r '^([0-9a-f]{10})[0-9a-f]*\t(.*)' '$1\t$2' end function __fish_git_recent_commits