diff --git a/builtin/show-index.c b/builtin/show-index.c
index 0e0b9fb95bc..b63a3bf60b9 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -74,7 +74,6 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
for (i = 0; i < nr; i++) {
if (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)
die("unable to read sha1 %u/%u", i, nr);
- entries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);
}
for (i = 0; i < nr; i++)
if (fread(&entries[i].crc, 4, 1, stdin) != 1)diff --git a/hash.h b/hash.h
index 9e25c40e9ac..bd1855b65ec 100644
--- a/hash.h
+++ b/hash.h
@@ -115,7 +115,6 @@ static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *s
struct object_id {
unsigned char hash[GIT_MAX_RAWSZ];
- int algo; /* XXX requires 4-byte alignment */
};
/* A suitably aligned type for stack allocations of hash contexts. */@@ -213,12 +212,7 @@ static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
{
- const struct git_hash_algo *algop;
- if (!oid1->algo)
- algop = the_hash_algo;
- else
- algop = &hash_algos[oid1->algo];
- return hashcmp_algop(oid1->hash, oid2->hash, algop);
+ return hashcmp_algop(oid1->hash, oid2->hash, the_hash_algo);
}
static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)@@ -239,12 +233,7 @@ static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
{
- const struct git_hash_algo *algop;
- if (!oid1->algo)
- algop = the_hash_algo;
- else
- algop = &hash_algos[oid1->algo];
- return hasheq_algop(oid1->hash, oid2->hash, algop);
+ return hasheq_algop(oid1->hash, oid2->hash, the_hash_algo);
}
static inline int is_null_oid(const struct object_id *oid)@@ -260,23 +249,16 @@ static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
- dst->algo = src->algo;
}
/* Like oidcpy() but zero-pads the unused bytes in dst's hash array. */
static inline void oidcpy_with_padding(struct object_id *dst,
const struct object_id *src)
{
- size_t hashsz;
-
- if (!src->algo)
- hashsz = the_hash_algo->rawsz;
- else
- hashsz = hash_algos[src->algo].rawsz;
+ size_t hashsz = the_hash_algo->rawsz;
memcpy(dst->hash, src->hash, hashsz);
memset(dst->hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
- dst->algo = src->algo;
}
static inline struct object_id *oiddup(const struct object_id *src)@@ -294,13 +276,11 @@ static inline void hashclr(unsigned char *hash)
static inline void oidclr(struct object_id *oid)
{
memset(oid->hash, 0, GIT_MAX_RAWSZ);
- oid->algo = hash_algo_by_ptr(the_hash_algo);
}
static inline void oidread(struct object_id *oid, const unsigned char *hash)
{
memcpy(oid->hash, hash, the_hash_algo->rawsz);
- oid->algo = hash_algo_by_ptr(the_hash_algo);
}
static inline int is_empty_blob_sha1(const unsigned char *sha1)@@ -325,7 +305,7 @@ static inline int is_empty_tree_oid(const struct object_id *oid)
static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
{
- oid->algo = hash_algo_by_ptr(algop);
+ return;
}
const char *empty_tree_oid_hex(void);diff --git a/hex.c b/hex.c
index 4f64d346963..6538e415a37 100644
--- a/hex.c
+++ b/hex.c
@@ -143,7 +143,7 @@ char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash,
char *oid_to_hex_r(char *buffer, const struct object_id *oid)
{
- return hash_to_hex_algop_r(buffer, oid->hash, &hash_algos[oid->algo]);
+ return hash_to_hex_algop_r(buffer, oid->hash, &hash_algos[GIT_HASH_SHA1]);
}
char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *algop)@@ -161,5 +161,5 @@ char *hash_to_hex(const unsigned char *hash)
char *oid_to_hex(const struct object_id *oid)
{
- return hash_to_hex_algop(oid->hash, &hash_algos[oid->algo]);
+ return hash_to_hex_algop(oid->hash, &hash_algos[GIT_HASH_SHA1]);
}diff --git a/http-push.c b/http-push.c
index 3309aaf004a..3ce453e14a4 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1011,8 +1011,6 @@ static void remote_ls(const char *path, int flags,
/* extract hex from sharded "xx/x{38}" filename */
static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
{
- oid->algo = hash_algo_by_ptr(the_hash_algo);
-
if (strlen(path) != the_hash_algo->hexsz + 1)
return -1;
diff --git a/object-file.c b/object-file.c
index be4f94ecf3b..be1385c5e72 100644
--- a/object-file.c
+++ b/object-file.c
@@ -58,27 +58,21 @@
static const struct object_id empty_tree_oid = {
.hash = EMPTY_TREE_SHA1_BIN_LITERAL,
- .algo = GIT_HASH_SHA1,
};
static const struct object_id empty_blob_oid = {
.hash = EMPTY_BLOB_SHA1_BIN_LITERAL,
- .algo = GIT_HASH_SHA1,
};
static const struct object_id null_oid_sha1 = {
.hash = {0},
- .algo = GIT_HASH_SHA1,
};
static const struct object_id empty_tree_oid_sha256 = {
.hash = EMPTY_TREE_SHA256_BIN_LITERAL,
- .algo = GIT_HASH_SHA256,
};
static const struct object_id empty_blob_oid_sha256 = {
.hash = EMPTY_BLOB_SHA256_BIN_LITERAL,
- .algo = GIT_HASH_SHA256,
};
static const struct object_id null_oid_sha256 = {
.hash = {0},
- .algo = GIT_HASH_SHA256,
};
static void git_hash_sha1_init(git_hash_ctx *ctx)@@ -105,7 +99,6 @@ static void git_hash_sha1_final_oid(struct object_id *oid, git_hash_ctx *ctx)
{
git_SHA1_Final(oid->hash, &ctx->sha1);
memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ);
- oid->algo = GIT_HASH_SHA1;
}
@@ -137,7 +130,6 @@ static void git_hash_sha256_final_oid(struct object_id *oid, git_hash_ctx *ctx)
* but keep it in case we extend the hash size again.
*/
memset(oid->hash + GIT_SHA256_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA256_RAWSZ);
- oid->algo = GIT_HASH_SHA256;
}
static void git_hash_unknown_init(git_hash_ctx *ctx)
diff --git a/oidtree.c b/oidtree.c
index 0d39389bee2..61f4d9515b5 100644
--- a/oidtree.c
+++ b/oidtree.c
@@ -33,9 +33,6 @@ void oidtree_insert(struct oidtree *ot, const struct object_id *oid)
struct cb_node *on;
struct object_id k;
- if (!oid->algo)
- BUG("oidtree_insert requires oid->algo");
-
on = mem_pool_alloc(&ot->mem_pool, sizeof(*on) + sizeof(*oid));
/*@@ -62,13 +59,6 @@ int oidtree_contains(struct oidtree *ot, const struct object_id *oid)
oidcpy_with_padding(&k, oid);
- if (oid->algo == GIT_HASH_UNKNOWN)
- klen -= sizeof(oid->algo);
-
- /* cb_lookup relies on memcmp on the struct, so order matters: */
- klen += BUILD_ASSERT_OR_ZERO(offsetof(struct object_id, hash) <
- offsetof(struct object_id, algo));
-
return cb_lookup(&ot->tree, (const uint8_t *)&k, klen) ? 1 : 0;
}
@@ -80,9 +70,6 @@ static enum cb_next iter(struct cb_node *n, void *arg)
/* Copy to provide 4-byte alignment needed by struct object_id. */
memcpy(&k, n->k, sizeof(k));
- if (x->algo != GIT_HASH_UNKNOWN && x->algo != k.algo)
- return CB_CONTINUE;
-
if (x->last_nibble_at) {
if ((k.hash[*x->last_nibble_at] ^ x->last_byte) & 0xf0)
return CB_CONTINUE;@@ -100,7 +87,6 @@ void oidtree_each(struct oidtree *ot, const struct object_id *oid,
x.fn = fn;
x.arg = arg;
- x.algo = oid->algo;
if (oidhexsz & 1) {
x.last_byte = oid->hash[klen];
x.last_nibble_at = &klen;diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c
index 180ee28dd93..6e22b422ddc 100644
--- a/t/helper/test-oidtree.c
+++ b/t/helper/test-oidtree.c
@@ -13,7 +13,7 @@ int cmd__oidtree(int argc, const char **argv)
struct oidtree ot;
struct strbuf line = STRBUF_INIT;
int nongit_ok;
- int algo = GIT_HASH_UNKNOWN;
+ int algo = GIT_HASH_SHA1;
oidtree_init(&ot);
setup_git_directory_gently(&nongit_ok);
@@ -25,7 +25,6 @@ int cmd__oidtree(int argc, const char **argv)
if (skip_prefix(line.buf, "insert ", &arg)) {
if (get_oid_hex_any(arg, &oid) == GIT_HASH_UNKNOWN)
die("insert not a hexadecimal oid: %s", arg);
- algo = oid.algo;
oidtree_insert(&ot, &oid);
} else if (skip_prefix(line.buf, "contains ", &arg)) {
if (get_oid_hex(arg, &oid))@@ -37,7 +36,6 @@ int cmd__oidtree(int argc, const char **argv)
memcpy(buf, arg, strlen(arg));
buf[hash_algos[algo].hexsz] = '\0';
get_oid_hex_any(buf, &oid);
- oid.algo = algo;
oidtree_each(&ot, &oid, strlen(arg), print_oid, NULL);
} else if (!strcmp(line.buf, "clear")) {
oidtree_clear(&ot);