Backport @peff's fix for duplicates in sha1_lookup