Skip to content

Commit 098c173

Browse files
peffgitster
authored andcommitted
rerere: tighten rr-cache dirname check
We check only that get_sha1_hex() doesn't complain, which means we'd match an all-hex name with trailing cruft after it. This probably doesn't matter much in practice, since there shouldn't be anything else in the rr-cache directory, but it could possibly cause us to mix up sha1 and sha256 entries (which also shouldn't be intermingled, but could be leftovers from a repository conversion). Note that "get_sha1_hex()" is a confusing historical name. It is actually using the_hash_algo, so it would be sha256 in a sha256 repo. We'll switch to using parse_oid_hex(), because that conveniently advances our pointer. But it also gets rid of the sha1 name. Arguably it's a little funny to use "object_id" here for something that isn't actually naming an object, but it's unlikely to be a problem (and is contained in a single function). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2bc1a87 commit 098c173

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

rerere.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,9 @@ static void prune_one(struct rerere_id *id,
11811181
/* Does the basename in "path" look plausibly like an rr-cache entry? */
11821182
static int is_rr_cache_dirname(const char *path)
11831183
{
1184-
unsigned char hash[GIT_MAX_RAWSZ];
1185-
return !get_sha1_hex(path, hash);
1184+
struct object_id oid;
1185+
const char *end;
1186+
return !parse_oid_hex(path, &oid, &end) && !*end;
11861187
}
11871188

11881189
void rerere_gc(struct repository *r, struct string_list *rr)

0 commit comments

Comments
 (0)