Skip to content

Commit 826f08c

Browse files
bk2204gitster
authored andcommitted
object-file-convert: always make sure object ID algo is valid
In some cases, we zero-initialize our object IDs, which sets the algo member to zero as well, which is not a valid algorithm number. This is a bad practice, but we typically paper over it in many cases by simply substituting the repository's hash algorithm. However, our new Rust loose object map code doesn't handle this gracefully and can't find object IDs when the algorithm is zero because they don't compare equal to those with the correct algo field. In addition, the comparison code doesn't have any knowledge of what the main algorithm is because that's global state, so we can't adjust the comparison. To make our code function properly and to avoid propagating these bad entries, if we get a source object ID with a zero algo, just make a copy of it with the fixed algorithm. This has the benefit of also fixing the object IDs if we're in a single algorithm mode as well. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1fc338a commit 826f08c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

object-file-convert.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@
1313
#include "gpg-interface.h"
1414
#include "object-file-convert.h"
1515

16-
int repo_oid_to_algop(struct repository *repo, const struct object_id *src,
16+
int repo_oid_to_algop(struct repository *repo, const struct object_id *srcoid,
1717
const struct git_hash_algo *to, struct object_id *dest)
1818
{
1919
/*
2020
* If the source algorithm is not set, then we're using the
2121
* default hash algorithm for that object.
2222
*/
2323
const struct git_hash_algo *from =
24-
src->algo ? &hash_algos[src->algo] : repo->hash_algo;
24+
srcoid->algo ? &hash_algos[srcoid->algo] : repo->hash_algo;
25+
struct object_id temp;
26+
const struct object_id *src = srcoid;
27+
28+
if (!srcoid->algo) {
29+
oidcpy(&temp, srcoid);
30+
temp.algo = hash_algo_by_ptr(repo->hash_algo);
31+
src = &temp;
32+
}
2533

2634
if (from == to || !to) {
2735
if (src != dest)

0 commit comments

Comments
 (0)