From a096f7ea194cfd150627b644096a6d92b4e7ab65 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 9 Mar 2013 09:44:37 -0500 Subject: [PATCH] hashcache now permits partial hash matches (common practice in git) --- hashcache | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hashcache b/hashcache index 7645973..d616b03 100755 --- a/hashcache +++ b/hashcache @@ -39,8 +39,16 @@ _retrieve() hash="$1" # if multiple identical hashes exist, then the last one takes precedence - # (ideally, such a thing should never happen, but it's best to be prepared) - grep "^$hash " "$cachefile" \ + # (ideally, such a thing should never happen, but it's best to be prepared); + # note that we *do not* check for a space after the hash, which allows for + # partial hashes to be matched (common practice for Git due to its long + # hashes); this may cause problems with other version control systems---such + # as SVN---that use revision numbers, in which case this implementation will + # have to be changed to accept a flag for whether or not to accept partial + # matches, or it must operate under the assumption that the commits are always + # processed in reverse order and (as such) the tail in this pipeline will + # always return the intended result + grep "^$hash" "$cachefile" \ | tail -n1 \ | cut -d' ' -f2- }