* [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
@ 2024-06-11 11:57 Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 01/21] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
` (23 more replies)
0 siblings, 24 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:57 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 19524 bytes --]
Hi,
use of the `the_repository` variable is nowadays considered to be
deprecated, and over time we want to convert our codebase to stop using
it in favor of explicitly passing down the repository to functions via
parameters. This effort faces some important problems though.
- It is hard to prove that a certain code unit does not use
`the_repository` anymore when sending patch series. The reviewer has
no way to verify that it's not used anymore without reading through
the code itself.
- It is easy to sneak in new usages of `the_repository` by accident
into a code unit that is already `the_repository`-clean.
- There are many functions which implicitly use `the_repository`,
which is really hard to spot.
This patch series aims to address those problems by introducing a new
`USE_THE_REPOSITORY_VARIABLE` macro. When unset, then the declarations
of `the_repository`, `the_hash_algo` and some functions that implicitly
depend on them will be hidden away. This makes it trivial to demonstrate
that a code unit is `the_repository`-free by removing the definition of
any such macro.
The patch series doesn't aim to be perfect. There are still many
functions that implicitly depend on `the_repository` which are not
hidden away. Those can be addressed over time, either by guarding them
as required or, even better, removing such functions altogether.
The series is structured as follows:
- Patches 1 to 8 refactor "hash.h" such that its functions do not
depend on `the_repository` anymore. As these are used almost
everywhere, the whole patch series would be rather moot without such
a refactoring as everything would depend on `the_repository`.
- Patch 9 introduces `USE_THE_REPOSITORY_VARIABLE`, guarding the
declaration of `the_repository` and `the_hash_algo`.
- Patch 11 merges "hash-ll.h" back into "hash.h" as the split is now
mostly pointless.
- Patches 12 to 20 refactor various users of "hex.h" to not use
functions depending on `the_repository` anymore.
- Patch 21 guards declarations of functions that depend on
`the_repository` in "hex.h".
The series depends on ps/ref-sotrage-migration at 25a0023f28
(builtin/refs: new command to migrate ref storage formats, 2024-06-06).
This is moslty due to patch 10, which fixes a cyclic include that breaks
the build once we merge "hash-ll.h" back into "hash.h".
There are some minor textual and semantic conflicts with "seen" that can
be fixed as shown below.
Thanks!
Patrick
diff --cc bloom.c
index bbf146fc30,d080a1b616..0000000000
--- a/bloom.c
+++ b/bloom.c
@@@ -6,7 -6,9 +6,10 @@@
#include "commit-graph.h"
#include "commit.h"
#include "commit-slab.h"
+#include "repository.h"
+ #include "tree.h"
+ #include "tree-walk.h"
+ #include "config.h"
define_commit_slab(bloom_filter_slab, struct bloom_filter);
diff --cc midx.c
index 3992b05465,5aa7e2a6e6..0000000000
--- a/midx.c
+++ b/midx.c
@@@ -303,11 -530,12 +532,13 @@@ struct object_id *nth_midxed_object_oid
struct multi_pack_index *m,
uint32_t n)
{
- if (n >= m->num_objects)
+ if (n >= m->num_objects + m->num_objects_in_base)
return NULL;
+ n = midx_for_object(&m, n);
+
- oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
+ oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
+ the_repository->hash_algo);
return oid;
}
diff --cc pack-bitmap-write.c
index 37a8ad0fb3,6e8060f8a0..0000000000
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@@ -817,8 -1022,8 +1024,8 @@@ void bitmap_writer_finish(struct bitmap
memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE));
header.version = htons(default_version);
header.options = htons(flags | options);
- header.entry_count = htonl(writer->selected_nr);
+ header.entry_count = htonl(bitmap_writer_nr_selected_commits(writer));
- hashcpy(header.checksum, writer->pack_checksum);
+ hashcpy(header.checksum, writer->pack_checksum, the_repository->hash_algo);
hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz);
dump_bitmap(f, writer->commits);
diff --git a/pseudo-merge.c b/pseudo-merge.c
index e3e0393f11..f0fde13c47 100644
--- a/pseudo-merge.c
+++ b/pseudo-merge.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "pseudo-merge.h"
#include "date.h"
diff --git a/t/unit-tests/lib-oid.h b/t/unit-tests/lib-oid.h
index bfde639190..8d2acca768 100644
--- a/t/unit-tests/lib-oid.h
+++ b/t/unit-tests/lib-oid.h
@@ -1,7 +1,7 @@
#ifndef LIB_OID_H
#define LIB_OID_H
-#include "hash-ll.h"
+#include "hash.h"
/*
* Convert arbitrary hex string to object_id.
diff --git a/t/unit-tests/t-example-decorate.c b/t/unit-tests/t-example-decorate.c
index 3c856a8cf2..a4a75db735 100644
--- a/t/unit-tests/t-example-decorate.c
+++ b/t/unit-tests/t-example-decorate.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-lib.h"
#include "object.h"
#include "decorate.h"
Patrick Steinhardt (21):
hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
hash: require hash algorithm in `hasheq()`, `hashcmp()` and
`hashclr()`
hash: require hash algorithm in `oidread()` and `oidclr()`
global: ensure that object IDs are always padded
hash: convert `oidcmp()` and `oideq()` to compare whole hash
hash: make `is_null_oid()` independent of `the_repository`
hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
hash: require hash algorithm in `empty_tree_oid_hex()`
global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
refs: avoid include cycle with "repository.h"
hash-ll: merge with "hash.h"
http-fetch: don't crash when parsing packfile without a repo
oidset: pass hash algorithm when parsing file
protocol-caps: use hash algorithm from passed-in repository
replace-object: use hash algorithm from passed-in repository
compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC
t/helper: use correct object hash in partial-clone helper
t/helper: fix segfault in "oid-array" command without repository
t/helper: remove dependency on `the_repository` in "oidtree"
t/helper: remove dependency on `the_repository` in "proc-receive"
hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
add-interactive.c | 4 +-
add-patch.c | 4 +-
apply.c | 4 +-
apply.h | 2 +-
archive-tar.c | 3 +
archive-zip.c | 3 +
archive.c | 2 +
attr.c | 2 +
bisect.c | 2 +
blame.c | 4 +-
bloom.c | 1 +
branch.c | 2 +
builtin.h | 8 +
builtin/am.c | 8 +-
builtin/blame.c | 3 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 43 ++-
builtin/fetch-pack.c | 4 +-
builtin/index-pack.c | 11 +-
builtin/log.c | 4 +-
builtin/merge.c | 7 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 3 +-
builtin/pack-redundant.c | 10 +-
builtin/patch-id.c | 6 +-
builtin/pull.c | 6 +-
builtin/receive-pack.c | 4 +-
builtin/replace.c | 2 +-
builtin/rm.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-objects.c | 9 +-
builtin/update-ref.c | 8 +-
bulk-checkin.c | 3 +
bundle-uri.c | 2 +
bundle.c | 2 +
cache-tree.c | 7 +-
checkout.c | 2 +
checkout.h | 2 +-
chunk-format.c | 2 +
chunk-format.h | 2 +-
combine-diff.c | 2 +
commit-graph.c | 22 +-
commit-graph.h | 2 +
commit-reach.c | 2 +
commit.c | 2 +
common-main.c | 2 +
compat/fsmonitor/fsm-ipc-darwin.c | 5 +-
compat/sha1-chunked.c | 2 +-
compat/win32/trace2_win32_process_info.c | 2 +
config.c | 3 +
connected.c | 2 +
convert.c | 2 +
convert.h | 2 +-
csum-file.c | 9 +-
csum-file.h | 2 +-
delta-islands.c | 2 +
diagnose.c | 2 +
diff-lib.c | 7 +-
diff.c | 9 +-
diff.h | 2 +-
diffcore-break.c | 3 +
diffcore-rename.c | 7 +-
diffcore.h | 2 +-
dir.c | 9 +-
dir.h | 2 +-
entry.c | 2 +
environment.c | 3 +
fetch-pack.c | 2 +
fmt-merge-msg.c | 2 +
fsck.c | 5 +-
fsmonitor-ipc.c | 2 +
git.c | 2 +
hash-ll.h | 310 ----------------
hash-lookup.c | 5 +-
hash.h | 366 ++++++++++++++++---
help.c | 2 +
hex.c | 8 +-
hex.h | 28 +-
http-backend.c | 2 +
http-fetch.c | 8 +-
http-push.c | 5 +-
http-walker.c | 6 +-
http.c | 2 +
list-objects-filter-options.c | 2 +
list-objects-filter.c | 2 +
list-objects.c | 2 +
log-tree.c | 2 +
loose.c | 2 +
loose.h | 2 +
ls-refs.c | 2 +
mailmap.c | 2 +
match-trees.c | 6 +-
merge-blobs.c | 2 +
merge-ort.c | 2 +
merge-ort.h | 2 +-
merge-recursive.c | 3 +
merge.c | 2 +
midx-write.c | 2 +
midx.c | 5 +-
negotiator/default.c | 2 +
negotiator/skipping.c | 2 +
notes-cache.c | 2 +
notes-merge.c | 8 +-
notes-utils.c | 2 +
notes.c | 14 +-
object-file-convert.c | 6 +-
object-file.c | 19 +-
object-name.c | 2 +
object.c | 2 +
object.h | 2 +-
oid-array.c | 2 +
oidmap.h | 2 +-
oidset.c | 8 +-
oidset.h | 4 +-
oidtree.c | 4 +-
oidtree.h | 2 +-
oss-fuzz/fuzz-commit-graph.c | 2 +
pack-bitmap-write.c | 6 +-
pack-bitmap.c | 5 +-
pack-check.c | 7 +-
pack-revindex.c | 2 +
pack-write.c | 5 +-
packfile.c | 20 +-
packfile.h | 2 +
parallel-checkout.c | 8 +-
parse-options-cb.c | 2 +
path.c | 3 +
pathspec.c | 2 +
pretty.c | 2 +
progress.c | 2 +
promisor-remote.c | 2 +
protocol-caps.c | 5 +-
range-diff.c | 2 +
reachable.c | 2 +
read-cache-ll.h | 2 +-
read-cache.c | 21 +-
rebase-interactive.c | 2 +
ref-filter.c | 2 +
reflog-walk.c | 2 +
reflog.c | 2 +
refs.c | 8 +-
refs.h | 8 +-
refs/files-backend.c | 8 +-
refs/packed-backend.c | 8 +-
refs/ref-cache.h | 2 +-
refs/reftable-backend.c | 39 +-
refspec.c | 2 +
reftable/dump.c | 2 +-
reftable/reftable-record.h | 2 +-
reftable/system.h | 2 +-
remote-curl.c | 2 +
remote.c | 10 +-
remote.h | 2 +-
replace-object.c | 2 +-
repository.h | 9 +-
rerere.c | 2 +
reset.c | 2 +
reset.h | 2 +-
resolve-undo.c | 5 +-
resolve-undo.h | 2 +-
revision.c | 2 +
run-command.c | 2 +
scalar.c | 2 +
send-pack.c | 2 +
sequencer.c | 8 +-
serve.c | 4 +-
server-info.c | 2 +
setup.c | 2 +
shallow.c | 2 +
split-index.c | 4 +-
split-index.h | 2 +-
streaming.c | 3 +
submodule-config.c | 4 +-
submodule.c | 8 +-
t/helper/test-bitmap.c | 2 +
t/helper/test-bloom.c | 2 +
t/helper/test-cache-tree.c | 2 +
t/helper/test-dump-cache-tree.c | 2 +
t/helper/test-dump-fsmonitor.c | 2 +
t/helper/test-dump-split-index.c | 2 +
t/helper/test-dump-untracked-cache.c | 2 +
t/helper/test-example-decorate.c | 2 +
t/helper/test-find-pack.c | 2 +
t/helper/test-fsmonitor-client.c | 2 +
t/helper/test-hash-speed.c | 2 +-
t/helper/test-lazy-init-name-hash.c | 2 +
t/helper/test-match-trees.c | 2 +
t/helper/test-oid-array.c | 4 +
t/helper/test-oidmap.c | 2 +
t/helper/test-oidtree.c | 5 +-
t/helper/test-pack-mtimes.c | 2 +
t/helper/test-partial-clone.c | 2 +-
t/helper/test-proc-receive.c | 9 +-
t/helper/test-reach.c | 2 +
t/helper/test-read-cache.c | 2 +
t/helper/test-read-graph.c | 2 +
t/helper/test-read-midx.c | 2 +
t/helper/test-ref-store.c | 2 +
t/helper/test-repository.c | 2 +
t/helper/test-revision-walking.c | 2 +
t/helper/test-scrap-cache-tree.c | 2 +
t/helper/test-sha1.c | 2 +-
t/helper/test-sha256.c | 2 +-
t/helper/test-submodule-config.c | 4 +-
t/helper/test-submodule-nested-repo-config.c | 2 +
t/helper/test-submodule.c | 2 +
t/helper/test-trace2.c | 2 +
t/helper/test-write-cache.c | 2 +
t/t0064-oid-array.sh | 18 +
t/t5550-http-fetch-dumb.sh | 6 +
t/test-lib-functions.sh | 5 +
tag.c | 2 +
tmp-objdir.c | 2 +
transport-helper.c | 2 +
transport.c | 2 +
tree-diff.c | 1 +
tree-walk.c | 6 +-
tree-walk.h | 2 +-
tree.c | 2 +
unpack-trees.c | 2 +
upload-pack.c | 2 +
walker.c | 2 +
worktree.c | 2 +
wt-status.c | 6 +-
xdiff-interface.c | 2 +
xdiff-interface.h | 2 +-
226 files changed, 993 insertions(+), 619 deletions(-)
delete mode 100644 hash-ll.h
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* [PATCH 01/21] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
@ 2024-06-11 11:57 ` Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 02/21] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
` (22 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:57 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]
The functions `is_empty_{blob,tree}_sha1()` are mostly unused, except
for a single callsite in "read-cache.c". Most callsites have long since
been converted to use the equivalents that accept a `struct object_id`
instead of a string.
Adapt the remaining callsite and drop those functions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash.h | 10 ----------
read-cache.c | 2 +-
2 files changed, 1 insertion(+), 11 deletions(-)
diff --git a/hash.h b/hash.h
index e064807c17..a1161e1b22 100644
--- a/hash.h
+++ b/hash.h
@@ -84,21 +84,11 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash)
oidread_algop(oid, hash, the_hash_algo);
}
-static inline int is_empty_blob_sha1(const unsigned char *sha1)
-{
- return hasheq(sha1, the_hash_algo->empty_blob->hash);
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
}
-static inline int is_empty_tree_sha1(const unsigned char *sha1)
-{
- return hasheq(sha1, the_hash_algo->empty_tree->hash);
-}
-
static inline int is_empty_tree_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_tree);
diff --git a/read-cache.c b/read-cache.c
index 447109aa76..10e002ce6d 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
/* Racily smudged entry? */
if (!ce->ce_stat_data.sd_size) {
- if (!is_empty_blob_sha1(ce->oid.hash))
+ if (!is_empty_blob_oid(&ce->oid))
changed |= DATA_CHANGED;
}
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 02/21] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()`
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 01/21] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
@ 2024-06-11 11:57 ` Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 03/21] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
` (21 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:57 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 17356 bytes --]
Many of our hash functions have two variants, one receiving a `struct
git_hash_algo` and one that derives it via `the_repository`. Adapt all
of those functions to always require the hash algorithm as input and
drop the variants that do not accept one.
As those functions are now independent of `the_repository`, we can move
them from "hash.h" to "hash-ll.h".
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/index-pack.c | 6 +++---
builtin/pack-redundant.c | 8 +++++---
builtin/unpack-objects.c | 3 ++-
commit-graph.c | 3 ++-
csum-file.c | 6 +++---
hash-ll.h | 15 +++++++++++++--
hash-lookup.c | 3 ++-
hash.h | 24 ++----------------------
http-walker.c | 2 +-
match-trees.c | 2 +-
notes.c | 2 +-
pack-bitmap-write.c | 4 ++--
pack-bitmap.c | 3 ++-
pack-check.c | 5 +++--
pack-write.c | 3 ++-
packfile.c | 8 ++++----
read-cache.c | 8 ++++----
17 files changed, 52 insertions(+), 53 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 856428fef9..ea727fba16 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1204,7 +1204,7 @@ static void parse_pack_objects(unsigned char *hash)
the_hash_algo->init_fn(&tmp_ctx);
the_hash_algo->clone_fn(&tmp_ctx, &input_ctx);
the_hash_algo->final_fn(hash, &tmp_ctx);
- if (!hasheq(fill(the_hash_algo->rawsz), hash))
+ if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo))
die(_("pack is corrupted (SHA1 mismatch)"));
use(the_hash_algo->rawsz);
@@ -1307,11 +1307,11 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
stop_progress_msg(&progress, msg.buf);
strbuf_release(&msg);
finalize_hashfile(f, tail_hash, FSYNC_COMPONENT_PACK, 0);
- hashcpy(read_hash, pack_hash);
+ hashcpy(read_hash, pack_hash, the_repository->hash_algo);
fixup_pack_header_footer(output_fd, pack_hash,
curr_pack, nr_objects,
read_hash, consumed_bytes-the_hash_algo->rawsz);
- if (!hasheq(read_hash, tail_hash))
+ if (!hasheq(read_hash, tail_hash, the_repository->hash_algo))
die(_("Unexpected tail checksum for %s "
"(disk corruption?)"), curr_pack);
}
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 4c735ba069..103c11b9d3 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -155,7 +155,7 @@ static inline struct llist_item * llist_sorted_remove(struct llist *list, const
l = (hint == NULL) ? list->front : hint;
prev = NULL;
while (l) {
- const int cmp = hashcmp(l->oid.hash, oid);
+ const int cmp = hashcmp(l->oid.hash, oid, the_repository->hash_algo);
if (cmp > 0) /* not in list, since sorted */
return prev;
if (!cmp) { /* found */
@@ -258,7 +258,8 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
while (p1_off < p1->pack->num_objects * p1_step &&
p2_off < p2->pack->num_objects * p2_step)
{
- const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
+ const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off,
+ the_repository->hash_algo);
/* cmp ~ p1 - p2 */
if (cmp == 0) {
p1_hint = llist_sorted_remove(p1->unique_objects,
@@ -296,7 +297,8 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
while (p1_off < p1->num_objects * p1_step &&
p2_off < p2->num_objects * p2_step)
{
- int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
+ int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off,
+ the_repository->hash_algo);
/* cmp ~ p1 - p2 */
if (cmp == 0) {
ret++;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f1c85a00ae..0855572c27 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -674,7 +674,8 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
if (fsck_finish(&fsck_options))
die(_("fsck error in pack objects"));
}
- if (!hasheq(fill(the_hash_algo->rawsz), oid.hash))
+ if (!hasheq(fill(the_hash_algo->rawsz), oid.hash,
+ the_repository->hash_algo))
die("final sha1 did not match");
use(the_hash_algo->rawsz);
diff --git a/commit-graph.c b/commit-graph.c
index e5dd3553df..3429156b28 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -565,7 +565,8 @@ static int add_graph_to_chain(struct commit_graph *g,
if (!cur_g ||
!oideq(&oids[n], &cur_g->oid) ||
- !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n))) {
+ !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n),
+ the_repository->hash_algo)) {
warning(_("commit-graph chain does not match"));
return 0;
}
diff --git a/csum-file.c b/csum-file.c
index 870748e016..f4be0804b7 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -68,12 +68,12 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
hashflush(f);
if (f->skip_hash)
- hashclr(f->buffer);
+ hashclr(f->buffer, the_repository->hash_algo);
else
the_hash_algo->final_fn(f->buffer, &f->ctx);
if (result)
- hashcpy(result, f->buffer);
+ hashcpy(result, f->buffer, the_repository->hash_algo);
if (flags & CSUM_HASH_IN_STREAM)
flush(f, f->buffer, the_hash_algo->rawsz);
if (flags & CSUM_FSYNC)
@@ -237,5 +237,5 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
the_hash_algo->update_fn(&ctx, data, data_len);
the_hash_algo->final_fn(got, &ctx);
- return hasheq(got, data + data_len);
+ return hasheq(got, data + data_len, the_repository->hash_algo);
}
diff --git a/hash-ll.h b/hash-ll.h
index 2cfde63ae1..fabdd8ecc7 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -245,7 +245,7 @@ static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
const struct object_id *null_oid(void);
-static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* Teach the compiler that there are only two possibilities of hash size
@@ -256,7 +256,7 @@ static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *
return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
-static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* We write this here instead of deferring to hashcmp so that the
@@ -267,6 +267,17 @@ static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *s
return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
+static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
+ const struct git_hash_algo *algop)
+{
+ memcpy(sha_dst, sha_src, algop->rawsz);
+}
+
+static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
+{
+ memset(hash, 0, algop->rawsz);
+}
+
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
diff --git a/hash-lookup.c b/hash-lookup.c
index 9f0f95e2b9..9aa6b82eb7 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -112,7 +112,8 @@ int bsearch_hash(const unsigned char *hash, const uint32_t *fanout_nbo,
while (lo < hi) {
unsigned mi = lo + (hi - lo) / 2;
- int cmp = hashcmp(table + mi * stride, hash);
+ int cmp = hashcmp(table + mi * stride, hash,
+ the_repository->hash_algo);
if (!cmp) {
if (result)
diff --git a/hash.h b/hash.h
index a1161e1b22..714938e2eb 100644
--- a/hash.h
+++ b/hash.h
@@ -6,11 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
-{
- return hashcmp_algop(sha1, sha2, the_hash_algo);
-}
-
static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
{
const struct git_hash_algo *algop;
@@ -18,12 +13,7 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o
algop = the_hash_algo;
else
algop = &hash_algos[oid1->algo];
- return hashcmp_algop(oid1->hash, oid2->hash, algop);
-}
-
-static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
-{
- return hasheq_algop(sha1, sha2, the_hash_algo);
+ return hashcmp(oid1->hash, oid2->hash, algop);
}
static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
@@ -33,7 +23,7 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi
algop = the_hash_algo;
else
algop = &hash_algos[oid1->algo];
- return hasheq_algop(oid1->hash, oid2->hash, algop);
+ return hasheq(oid1->hash, oid2->hash, algop);
}
static inline int is_null_oid(const struct object_id *oid)
@@ -41,11 +31,6 @@ static inline int is_null_oid(const struct object_id *oid)
return oideq(oid, null_oid());
}
-static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
-{
- memcpy(sha_dst, sha_src, the_hash_algo->rawsz);
-}
-
/* 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)
@@ -62,11 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
dst->algo = src->algo;
}
-static inline void hashclr(unsigned char *hash)
-{
- memset(hash, 0, the_hash_algo->rawsz);
-}
-
static inline void oidclr(struct object_id *oid)
{
memset(oid->hash, 0, GIT_MAX_RAWSZ);
diff --git a/http-walker.c b/http-walker.c
index b395ef1327..cf7f8c82bc 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -485,7 +485,7 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
list_for_each(pos, head) {
obj_req = list_entry(pos, struct object_request, node);
- if (hasheq(obj_req->oid.hash, hash))
+ if (hasheq(obj_req->oid.hash, hash, the_repository->hash_algo))
break;
}
if (!obj_req)
diff --git a/match-trees.c b/match-trees.c
index 3412b6a140..849b391d3d 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -237,7 +237,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
} else {
rewrite_with = oid2;
}
- hashcpy(rewrite_here, rewrite_with->hash);
+ hashcpy(rewrite_here, rewrite_with->hash, the_repository->hash_algo);
status = write_object_file(buf, sz, OBJ_TREE, result);
free(buf);
return status;
diff --git a/notes.c b/notes.c
index 53ca25c814..5296fd863f 100644
--- a/notes.c
+++ b/notes.c
@@ -149,7 +149,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
void **p = note_tree_search(t, &tree, &n, key_sha1);
if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
- if (hasheq(key_sha1, l->key_oid.hash))
+ if (hasheq(key_sha1, l->key_oid.hash, the_repository->hash_algo))
return l;
}
return NULL;
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 6cae670412..59d2e3a387 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -790,7 +790,7 @@ static void write_hash_cache(struct hashfile *f,
void bitmap_writer_set_checksum(struct bitmap_writer *writer,
const unsigned char *sha1)
{
- hashcpy(writer->pack_checksum, sha1);
+ hashcpy(writer->pack_checksum, sha1, the_repository->hash_algo);
}
void bitmap_writer_finish(struct bitmap_writer *writer,
@@ -816,7 +816,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
header.version = htons(default_version);
header.options = htons(flags | options);
header.entry_count = htonl(writer->selected_nr);
- hashcpy(header.checksum, writer->pack_checksum);
+ hashcpy(header.checksum, writer->pack_checksum, the_repository->hash_algo);
hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz);
dump_bitmap(f, writer->commits);
diff --git a/pack-bitmap.c b/pack-bitmap.c
index fe8e8a51d3..184d28f05c 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -367,7 +367,8 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
if (load_bitmap_header(bitmap_git) < 0)
goto cleanup;
- if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum)) {
+ if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum,
+ the_repository->hash_algo)) {
error(_("checksum doesn't match in MIDX and bitmap"));
goto cleanup;
}
diff --git a/pack-check.c b/pack-check.c
index 25104d5b14..288f5a3479 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -78,10 +78,11 @@ static int verify_packfile(struct repository *r,
} while (offset < pack_sig_ofs);
r->hash_algo->final_fn(hash, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
- if (!hasheq(hash, pack_sig))
+ if (!hasheq(hash, pack_sig, r->hash_algo))
err = error("%s pack checksum mismatch",
p->pack_name);
- if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig))
+ if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig,
+ r->hash_algo))
err = error("%s pack checksum does not match its index",
p->pack_name);
unuse_pack(w_curs);
diff --git a/pack-write.c b/pack-write.c
index 80ecfa544c..eef625fa5b 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -428,7 +428,8 @@ void fixup_pack_header_footer(int pack_fd,
if (partial_pack_offset == 0) {
unsigned char hash[GIT_MAX_RAWSZ];
the_hash_algo->final_fn(hash, &old_hash_ctx);
- if (!hasheq(hash, partial_pack_hash))
+ if (!hasheq(hash, partial_pack_hash,
+ the_repository->hash_algo))
die("Unexpected checksum for %s "
"(disk corruption?)", pack_name);
/*
diff --git a/packfile.c b/packfile.c
index d4df7fdeea..9156e9122c 100644
--- a/packfile.c
+++ b/packfile.c
@@ -242,7 +242,7 @@ struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
struct packed_git *p = alloc_packed_git(alloc);
memcpy(p->pack_name, path, alloc); /* includes NUL */
- hashcpy(p->hash, sha1);
+ hashcpy(p->hash, sha1, the_repository->hash_algo);
if (check_packed_git_idx(idx_path, p)) {
free(p);
return NULL;
@@ -596,7 +596,7 @@ static int open_packed_git_1(struct packed_git *p)
if (read_result != hashsz)
return error("packfile %s signature is unavailable", p->pack_name);
idx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;
- if (!hasheq(hash, idx_hash))
+ if (!hasheq(hash, idx_hash, the_repository->hash_algo))
return error("packfile %s does not match index", p->pack_name);
return 0;
}
@@ -751,7 +751,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
p->mtime = st.st_mtime;
if (path_len < the_hash_algo->hexsz ||
get_hash_hex(path + path_len - the_hash_algo->hexsz, p->hash))
- hashclr(p->hash);
+ hashclr(p->hash, the_repository->hash_algo);
return p;
}
@@ -1971,7 +1971,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
return 0;
}
- hashcpy(oid.hash, sha1);
+ hashcpy(oid.hash, sha1, the_repository->hash_algo);
if (bsearch_pack(&oid, p, &result))
return nth_packed_object_offset(p, result);
return 0;
diff --git a/read-cache.c b/read-cache.c
index 10e002ce6d..2642ac9558 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1735,7 +1735,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
the_hash_algo->final_fn(hash, &c);
- if (!hasheq(hash, start))
+ if (!hasheq(hash, start, the_repository->hash_algo))
return error(_("bad index file sha1 signature"));
return 0;
}
@@ -2641,7 +2641,7 @@ static void copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,
ondisk->uid = htonl(ce->ce_stat_data.sd_uid);
ondisk->gid = htonl(ce->ce_stat_data.sd_gid);
ondisk->size = htonl(ce->ce_stat_data.sd_size);
- hashcpy(ondisk->data, ce->oid.hash);
+ hashcpy(ondisk->data, ce->oid.hash, the_repository->hash_algo);
flags = ce->ce_flags & ~CE_NAMEMASK;
flags |= (ce_namelen(ce) >= CE_NAMEMASK ? CE_NAMEMASK : ce_namelen(ce));
@@ -2730,7 +2730,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)
if (n != the_hash_algo->rawsz)
goto out;
- if (!hasheq(istate->oid.hash, hash))
+ if (!hasheq(istate->oid.hash, hash, the_repository->hash_algo))
goto out;
close(fd);
@@ -3603,7 +3603,7 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size)
src_offset += extsize;
}
the_hash_algo->final_fn(hash, &c);
- if (!hasheq(hash, (const unsigned char *)index))
+ if (!hasheq(hash, (const unsigned char *)index, the_repository->hash_algo))
return 0;
/* Validate that the extension offsets returned us back to the eoie extension. */
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 03/21] hash: require hash algorithm in `oidread()` and `oidclr()`
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 01/21] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 02/21] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
@ 2024-06-11 11:57 ` Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 04/21] global: ensure that object IDs are always padded Patrick Steinhardt
` (20 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:57 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 48416 bytes --]
Both `oidread()` and `oidclr()` use `the_repository` to derive the hash
function that shall be used. Require callers to pass in the hash
algorithm to get rid of this implicit dependency.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
blame.c | 2 +-
builtin/am.c | 8 +++----
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 39 +++++++++++++++++---------------
builtin/fetch-pack.c | 4 ++--
builtin/index-pack.c | 5 ++--
builtin/log.c | 2 +-
builtin/merge.c | 4 ++--
builtin/notes.c | 2 +-
builtin/pack-objects.c | 3 ++-
builtin/pack-redundant.c | 2 +-
builtin/patch-id.c | 6 ++---
builtin/pull.c | 6 ++---
builtin/receive-pack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rm.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-objects.c | 6 ++---
builtin/update-ref.c | 8 +++----
cache-tree.c | 3 ++-
commit-graph.c | 17 +++++++++-----
diff-lib.c | 4 ++--
diff.c | 6 ++---
dir.c | 6 ++---
hash-ll.h | 14 ++++++++++++
hash.h | 17 --------------
http-push.c | 2 +-
http-walker.c | 2 +-
match-trees.c | 2 +-
midx.c | 3 ++-
notes-merge.c | 6 ++---
notes.c | 8 +++----
object-file-convert.c | 2 +-
object-file.c | 4 ++--
packfile.c | 10 ++++----
read-cache.c | 8 ++++---
refs.c | 6 ++---
refs/files-backend.c | 6 ++---
refs/packed-backend.c | 6 ++---
refs/reftable-backend.c | 37 ++++++++++++++++++------------
remote.c | 8 +++----
resolve-undo.c | 3 ++-
sequencer.c | 4 ++--
split-index.c | 2 +-
submodule-config.c | 2 +-
t/helper/test-submodule-config.c | 2 +-
tree-walk.c | 4 ++--
48 files changed, 163 insertions(+), 140 deletions(-)
diff --git a/apply.c b/apply.c
index 901b67e625..528939abb6 100644
--- a/apply.c
+++ b/apply.c
@@ -3680,7 +3680,7 @@ static int try_threeway(struct apply_state *state,
if (status) {
patch->conflicted_threeway = 1;
if (patch->is_new)
- oidclr(&patch->threeway_stage[0]);
+ oidclr(&patch->threeway_stage[0], the_repository->hash_algo);
else
oidcpy(&patch->threeway_stage[0], &pre_oid);
oidcpy(&patch->threeway_stage[1], &our_oid);
diff --git a/blame.c b/blame.c
index 33586b9777..a80f5e2e61 100644
--- a/blame.c
+++ b/blame.c
@@ -1246,7 +1246,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
goto error_out;
return 0;
error_out:
- oidclr(&origin->blob_oid);
+ oidclr(&origin->blob_oid, the_repository->hash_algo);
origin->mode = S_IFINVALID;
return -1;
}
diff --git a/builtin/am.c b/builtin/am.c
index 36839029d2..45c305ec86 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -408,7 +408,7 @@ static void am_load(struct am_state *state)
read_commit_msg(state);
if (read_state_file(&sb, state, "original-commit", 1) < 0)
- oidclr(&state->orig_commit);
+ oidclr(&state->orig_commit, the_repository->hash_algo);
else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
die(_("could not parse %s"), am_path(state, "original-commit"));
@@ -1121,7 +1121,7 @@ static void am_next(struct am_state *state)
unlink(am_path(state, "author-script"));
unlink(am_path(state, "final-commit"));
- oidclr(&state->orig_commit);
+ oidclr(&state->orig_commit, the_repository->hash_algo);
unlink(am_path(state, "original-commit"));
refs_delete_ref(get_main_ref_store(the_repository), NULL,
"REBASE_HEAD", NULL, REF_NO_DEREF);
@@ -2151,11 +2151,11 @@ static int safe_to_abort(const struct am_state *state)
if (get_oid_hex(sb.buf, &abort_safety))
die(_("could not parse %s"), am_path(state, "abort-safety"));
} else
- oidclr(&abort_safety);
+ oidclr(&abort_safety, the_repository->hash_algo);
strbuf_release(&sb);
if (repo_get_oid(the_repository, "HEAD", &head))
- oidclr(&head);
+ oidclr(&head, the_repository->hash_algo);
if (oideq(&head, &abort_safety))
return 1;
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 4693d18cc9..4b6e8c6832 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -415,7 +415,7 @@ static char *generate_fake_oid(void)
struct object_id oid;
char *hex = xmallocz(GIT_MAX_HEXSZ);
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
put_be32(oid.hash + hashsz - 4, counter++);
return oid_to_hex_r(hex, &oid);
}
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index d1c0243d04..12543488f3 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1279,8 +1279,10 @@ static void load_tree(struct tree_entry *root)
e->versions[0].mode = e->versions[1].mode;
e->name = to_atom(c, strlen(c));
c += e->name->str_len + 1;
- oidread(&e->versions[0].oid, (unsigned char *)c);
- oidread(&e->versions[1].oid, (unsigned char *)c);
+ oidread(&e->versions[0].oid, (unsigned char *)c,
+ the_repository->hash_algo);
+ oidread(&e->versions[1].oid, (unsigned char *)c,
+ the_repository->hash_algo);
c += the_hash_algo->rawsz;
}
free(buf);
@@ -1386,7 +1388,7 @@ static void tree_content_replace(
{
if (!S_ISDIR(mode))
die("Root cannot be a non-directory");
- oidclr(&root->versions[0].oid);
+ oidclr(&root->versions[0].oid, the_repository->hash_algo);
oidcpy(&root->versions[1].oid, oid);
if (root->tree)
release_tree_content_recursive(root->tree);
@@ -1445,7 +1447,7 @@ static int tree_content_set(
if (S_ISDIR(e->versions[0].mode))
e->versions[0].mode |= NO_DELTA;
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
if (!S_ISDIR(e->versions[1].mode)) {
@@ -1455,7 +1457,7 @@ static int tree_content_set(
if (!e->tree)
load_tree(e);
if (tree_content_set(e, slash1 + 1, oid, mode, subtree)) {
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
return 0;
@@ -1467,7 +1469,7 @@ static int tree_content_set(
e = new_tree_entry();
e->name = to_atom(p, n);
e->versions[0].mode = 0;
- oidclr(&e->versions[0].oid);
+ oidclr(&e->versions[0].oid, the_repository->hash_algo);
t->entries[t->entry_count++] = e;
if (*slash1) {
e->tree = new_tree_content(8);
@@ -1478,7 +1480,7 @@ static int tree_content_set(
e->versions[1].mode = mode;
oidcpy(&e->versions[1].oid, oid);
}
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
@@ -1523,7 +1525,8 @@ static int tree_content_remove(
if (tree_content_remove(e, slash1 + 1, backup_leaf, 0)) {
for (n = 0; n < e->tree->entry_count; n++) {
if (e->tree->entries[n]->versions[1].mode) {
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid,
+ the_repository->hash_algo);
return 1;
}
}
@@ -1542,8 +1545,8 @@ static int tree_content_remove(
release_tree_content_recursive(e->tree);
e->tree = NULL;
e->versions[1].mode = 0;
- oidclr(&e->versions[1].oid);
- oidclr(&root->versions[1].oid);
+ oidclr(&e->versions[1].oid, the_repository->hash_algo);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
@@ -1609,7 +1612,7 @@ static int update_branch(struct branch *b)
return 0;
}
if (refs_read_ref(get_main_ref_store(the_repository), b->name, &old_oid))
- oidclr(&old_oid);
+ oidclr(&old_oid, the_repository->hash_algo);
if (!force_update && !is_null_oid(&old_oid)) {
struct commit *old_cmit, *new_cmit;
int ret;
@@ -2550,8 +2553,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
static void file_change_deleteall(struct branch *b)
{
release_tree_content_recursive(b->branch_tree.tree);
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
load_tree(&b->branch_tree);
b->num_notes = 0;
}
@@ -2570,8 +2573,8 @@ static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
static void parse_from_existing(struct branch *b)
{
if (is_null_oid(&b->oid)) {
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
} else {
unsigned long size;
char *buf;
@@ -2894,9 +2897,9 @@ static void parse_reset_branch(const char *arg)
b = lookup_branch(arg);
if (b) {
- oidclr(&b->oid);
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
if (b->branch_tree.tree) {
release_tree_content_recursive(b->branch_tree.tree);
b->branch_tree.tree = NULL;
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 44c05ee86c..af329e8d5c 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -29,11 +29,11 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
; /* <oid>, leave oid as name */
} else {
/* <ref>, clear cruft from oid */
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
}
} else {
/* <ref>, clear cruft from get_oid_hex */
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
}
ref = alloc_ref(name);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index ea727fba16..fd968d673d 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -528,7 +528,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
switch (obj->type) {
case OBJ_REF_DELTA:
- oidread(ref_oid, fill(the_hash_algo->rawsz));
+ oidread(ref_oid, fill(the_hash_algo->rawsz),
+ the_repository->hash_algo);
use(the_hash_algo->rawsz);
break;
case OBJ_OFS_DELTA:
@@ -1372,7 +1373,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
obj[1].idx.offset += write_compressed(f, buf, size);
obj[0].idx.crc32 = crc32_end(f);
hashflush(f);
- oidread(&obj->idx.oid, sha1);
+ oidread(&obj->idx.oid, sha1, the_repository->hash_algo);
return obj;
}
diff --git a/builtin/log.c b/builtin/log.c
index 78a247d8a9..ccbda8a005 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1938,7 +1938,7 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
free(bases->patch_id);
bases->nr_patch_id = 0;
bases->alloc_patch_id = 0;
- oidclr(&bases->base_commit);
+ oidclr(&bases->base_commit, the_repository->hash_algo);
}
static const char *diff_title(struct strbuf *sb,
diff --git a/builtin/merge.c b/builtin/merge.c
index daed2d4e1e..abe66311c7 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -494,7 +494,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_branchname(&bname, remote, 0);
remote = bname.buf;
- oidclr(&branch_head);
+ oidclr(&branch_head, the_repository->hash_algo);
remote_head = get_merge_parent(remote);
if (!remote_head)
die(_("'%s' does not point to a commit"), remote);
@@ -1690,7 +1690,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* index and working tree polluted.
*/
if (save_state(&stash))
- oidclr(&stash);
+ oidclr(&stash, the_repository->hash_algo);
for (i = 0; i < use_strategies_nr; i++) {
int ret, cnt;
diff --git a/builtin/notes.c b/builtin/notes.c
index 7f80b3449b..d9c356e354 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -828,7 +828,7 @@ static int merge_commit(struct notes_merge_options *o)
if (partial->parents)
oidcpy(&parent_oid, &partial->parents->item->object.oid);
else
- oidclr(&parent_oid);
+ oidclr(&parent_oid, the_repository->hash_algo);
CALLOC_ARRAY(t, 1);
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 638f5c57f0..2b00983a99 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2078,7 +2078,8 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
oidread(&base_ref,
use_pack(p, &w_curs,
entry->in_pack_offset + used,
- NULL));
+ NULL),
+ the_repository->hash_algo);
have_base = 1;
}
entry->in_pack_header_size = used + the_hash_algo->rawsz;
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 103c11b9d3..dd9bf35f5b 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -100,7 +100,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
const unsigned char *oid)
{
struct llist_item *new_item = llist_item_get();
- oidread(&new_item->oid, oid);
+ oidread(&new_item->oid, oid, the_repository->hash_algo);
new_item->next = NULL;
if (after) {
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 583099cacf..d790ae6354 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -70,7 +70,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
git_hash_ctx ctx;
the_hash_algo->init_fn(&ctx);
- oidclr(result);
+ oidclr(result, the_repository->hash_algo);
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
char *line = line_buf->buf;
@@ -166,7 +166,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
}
if (!found_next)
- oidclr(next_oid);
+ oidclr(next_oid, the_repository->hash_algo);
flush_one_hunk(result, &ctx);
@@ -179,7 +179,7 @@ static void generate_id_list(int stable, int verbatim)
int patchlen;
struct strbuf line_buf = STRBUF_INIT;
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
while (!feof(stdin)) {
patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim);
flush_current_id(patchlen, &oid, &result);
diff --git a/builtin/pull.c b/builtin/pull.c
index d622202bce..2a73e673f3 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -1038,7 +1038,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
die_conclude_merge();
if (repo_get_oid(the_repository, "HEAD", &orig_head))
- oidclr(&orig_head);
+ oidclr(&orig_head, the_repository->hash_algo);
if (opt_rebase) {
if (opt_autostash == -1)
@@ -1053,7 +1053,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
_("Please commit or stash them."), 1, 0);
if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
- oidclr(&rebase_fork_point);
+ oidclr(&rebase_fork_point, the_repository->hash_algo);
}
if (run_fetch(repo, refspecs))
@@ -1063,7 +1063,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
return 0;
if (repo_get_oid(the_repository, "HEAD", &curr_head))
- oidclr(&curr_head);
+ oidclr(&curr_head, the_repository->hash_algo);
if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
!oideq(&orig_head, &curr_head)) {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 01c1f04ece..aa5ba27d17 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -741,7 +741,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
already_done = 1;
if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
&push_cert_oid))
- oidclr(&push_cert_oid);
+ oidclr(&push_cert_oid, the_repository->hash_algo);
memset(&sigcheck, '\0', sizeof(sigcheck));
diff --git a/builtin/replace.c b/builtin/replace.c
index ce9f6974d2..1ef833c07f 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -167,7 +167,7 @@ static int check_ref_valid(struct object_id *object,
return error(_("'%s' is not a valid ref name"), ref->buf);
if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev))
- oidclr(prev);
+ oidclr(prev, the_repository->hash_algo);
else if (!force)
return error(_("replace ref '%s' already exists"), ref->buf);
return 0;
diff --git a/builtin/rm.c b/builtin/rm.c
index d195c16e74..0e79cbab62 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -377,7 +377,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (!force) {
struct object_id oid;
if (repo_get_oid(the_repository, "HEAD", &oid))
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
if (check_local_mod(&oid, index_only))
exit(1);
}
diff --git a/builtin/tag.c b/builtin/tag.c
index 6e2c0cf342..a1fb218512 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -650,7 +650,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die(_("'%s' is not a valid tag name."), tag);
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
- oidclr(&prev);
+ oidclr(&prev, the_repository->hash_algo);
else if (!force)
die(_("tag '%s' already exists"), tag);
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 0855572c27..08fa2a7a74 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -439,7 +439,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
struct object_id base_oid;
if (type == OBJ_REF_DELTA) {
- oidread(&base_oid, fill(the_hash_algo->rawsz));
+ oidread(&base_oid, fill(the_hash_algo->rawsz), the_repository->hash_algo);
use(the_hash_algo->rawsz);
delta_data = get_data(delta_size);
if (!delta_data)
@@ -451,7 +451,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
return; /* we are done */
else {
/* cannot resolve yet --- queue it */
- oidclr(&obj_list[nr].oid);
+ oidclr(&obj_list[nr].oid, the_repository->hash_algo);
add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
return;
}
@@ -500,7 +500,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
* The delta base object is itself a delta that
* has not been resolved yet.
*/
- oidclr(&obj_list[nr].oid);
+ oidclr(&obj_list[nr].oid, the_repository->hash_algo);
add_delta_to_list(nr, null_oid(), base_offset,
delta_data, delta_size);
return;
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 6cda1c08aa..f8a5b087f8 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -122,7 +122,7 @@ static int parse_next_oid(const char **next, const char *end,
goto invalid;
} else {
/* Without -z, an empty value means all zeros: */
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
}
} else {
/* With -z, read the next NUL-terminated line */
@@ -142,7 +142,7 @@ static int parse_next_oid(const char **next, const char *end,
/* With -z, treat an empty value as all zeros: */
warning("%s %s: missing <new-oid>, treating as zero",
command, refname);
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
} else {
/*
* With -z, an empty non-required value means
@@ -291,7 +291,7 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
if (parse_next_oid(&next, end, &old_oid, "verify", refname,
PARSE_SHA1_OLD))
- oidclr(&old_oid);
+ oidclr(&old_oid, the_repository->hash_algo);
if (*next != line_termination)
die("verify %s: extra input: %s", refname, next);
@@ -564,7 +564,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
* The empty string implies that the reference
* must not already exist:
*/
- oidclr(&oldoid);
+ oidclr(&oldoid, the_repository->hash_algo);
else if (repo_get_oid(the_repository, oldval, &oldoid))
die("%s: not a valid old SHA1", oldval);
}
diff --git a/cache-tree.c b/cache-tree.c
index 387c0a3e5b..e4255c4d02 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -578,7 +578,8 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
if (0 <= it->entry_count) {
if (size < rawsz)
goto free_return;
- oidread(&it->oid, (const unsigned char *)buf);
+ oidread(&it->oid, (const unsigned char *)buf,
+ the_repository->hash_algo);
buf += rawsz;
size -= rawsz;
}
diff --git a/commit-graph.c b/commit-graph.c
index 3429156b28..e4eefd83bf 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -475,7 +475,8 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
FREE_AND_NULL(graph->bloom_filter_settings);
}
- oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len);
+ oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len,
+ the_repository->hash_algo);
free_chunkfile(cf);
return graph;
@@ -838,7 +839,8 @@ static void load_oid_from_graph(struct commit_graph *g,
lex_index = pos - g->num_commits_in_base;
- oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index));
+ oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index),
+ the_repository->hash_algo);
}
static struct commit_list **insert_parent_or_die(struct repository *r,
@@ -1080,7 +1082,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
commit_data = g->chunk_commit_data +
st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
- oidread(&oid, commit_data);
+ oidread(&oid, commit_data, r->hash_algo);
set_commit_tree(c, lookup_tree(r, &oid));
return c->maybe_tree;
@@ -2556,7 +2558,8 @@ int write_commit_graph(struct object_directory *odb,
struct commit_graph *g = ctx->r->objects->commit_graph;
for (i = 0; i < g->num_commits; i++) {
struct object_id oid;
- oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ r->hash_algo);
oid_array_append(&ctx->oids, &oid);
}
}
@@ -2675,7 +2678,8 @@ static int verify_one_commit_graph(struct repository *r,
for (i = 0; i < g->num_commits; i++) {
struct commit *graph_commit;
- oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ r->hash_algo);
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2719,7 +2723,8 @@ static int verify_one_commit_graph(struct repository *r,
timestamp_t generation;
display_progress(progress, ++(*seen));
- oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ the_repository->hash_algo);
graph_commit = lookup_commit(r, &cur_oid);
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
diff --git a/diff-lib.c b/diff-lib.c
index 5a5a50c5a1..3fb8d79fef 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
dpath->next = NULL;
memcpy(dpath->path, ce->name, path_len);
dpath->path[path_len] = '\0';
- oidclr(&dpath->oid);
+ oidclr(&dpath->oid, the_repository->hash_algo);
memset(&(dpath->parent[0]), 0,
sizeof(struct combine_diff_parent)*5);
@@ -412,7 +412,7 @@ static int show_modified(struct rev_info *revs,
memcpy(p->path, new_entry->name, pathlen);
p->path[pathlen] = 0;
p->mode = mode;
- oidclr(&p->oid);
+ oidclr(&p->oid, the_repository->hash_algo);
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
p->parent[0].status = DIFF_STATUS_MODIFIED;
p->parent[0].mode = new_entry->ce_mode;
diff --git a/diff.c b/diff.c
index e70301df76..60d1f7be81 100644
--- a/diff.c
+++ b/diff.c
@@ -4567,7 +4567,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
if (!one->oid_valid) {
struct stat st;
if (one->is_stdin) {
- oidclr(&one->oid);
+ oidclr(&one->oid, the_repository->hash_algo);
return;
}
if (lstat(one->path, &st) < 0)
@@ -4577,7 +4577,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
}
}
else
- oidclr(&one->oid);
+ oidclr(&one->oid, the_repository->hash_algo);
}
static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
@@ -6404,7 +6404,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
the_hash_algo->init_fn(&ctx);
memset(&data, 0, sizeof(struct patch_id_t));
data.ctx = &ctx;
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
for (i = 0; i < q->nr; i++) {
xpparam_t xpp;
diff --git a/dir.c b/dir.c
index f6066cc01d..9f9c1f3822 100644
--- a/dir.c
+++ b/dir.c
@@ -1655,7 +1655,7 @@ static void prep_exclude(struct dir_struct *dir,
}
/* Try to read per-directory file */
- oidclr(&oid_stat.oid);
+ oidclr(&oid_stat.oid, the_repository->hash_algo);
oid_stat.valid = 0;
if (dir->exclude_per_dir &&
/*
@@ -3762,7 +3762,7 @@ static void read_oid(size_t pos, void *cb)
rd->data = rd->end + 1;
return;
}
- oidread(&ud->exclude_oid, rd->data);
+ oidread(&ud->exclude_oid, rd->data, the_repository->hash_algo);
rd->data += the_hash_algo->rawsz;
}
@@ -3770,7 +3770,7 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
const unsigned char *sha1)
{
stat_data_from_disk(&oid_stat->stat, data);
- oidread(&oid_stat->oid, sha1);
+ oidread(&oid_stat->oid, sha1, the_repository->hash_algo);
oid_stat->valid = 1;
}
diff --git a/hash-ll.h b/hash-ll.h
index fabdd8ecc7..dbb96369fc 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -284,6 +284,20 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src)
dst->algo = src->algo;
}
+static inline void oidread(struct object_id *oid, const unsigned char *hash,
+ const struct git_hash_algo *algop)
+{
+ memcpy(oid->hash, hash, algop->rawsz);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline void oidclr(struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
static inline struct object_id *oiddup(const struct object_id *src)
{
struct object_id *dst = xmalloc(sizeof(struct object_id));
diff --git a/hash.h b/hash.h
index 714938e2eb..43623a0c86 100644
--- a/hash.h
+++ b/hash.h
@@ -47,23 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
dst->algo = src->algo;
}
-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_algop(struct object_id *oid, const unsigned char *hash, const struct git_hash_algo *algop)
-{
- memcpy(oid->hash, hash, algop->rawsz);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline void oidread(struct object_id *oid, const unsigned char *hash)
-{
- oidread_algop(oid, hash, the_hash_algo);
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
diff --git a/http-push.c b/http-push.c
index 1fe51226fd..86de238b84 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1552,7 +1552,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
free(url);
FREE_AND_NULL(*symref);
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
if (buffer.len == 0)
return;
diff --git a/http-walker.c b/http-walker.c
index cf7f8c82bc..b7110b6f82 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -152,7 +152,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
newreq = xmalloc(sizeof(*newreq));
newreq->walker = walker;
- oidread(&newreq->oid, sha1);
+ oidread(&newreq->oid, sha1, the_repository->hash_algo);
newreq->repo = data->alt;
newreq->state = WAITING;
newreq->req = NULL;
diff --git a/match-trees.c b/match-trees.c
index 849b391d3d..50c42e2061 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -229,7 +229,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
oid_to_hex(oid1));
if (*subpath) {
struct object_id tree_oid;
- oidread(&tree_oid, rewrite_here);
+ oidread(&tree_oid, rewrite_here, the_repository->hash_algo);
status = splice_tree(&tree_oid, subpath, oid2, &subtree);
if (status)
return status;
diff --git a/midx.c b/midx.c
index bc4797196f..1e75f1a7eb 100644
--- a/midx.c
+++ b/midx.c
@@ -304,7 +304,8 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
if (n >= m->num_objects)
return NULL;
- oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
+ oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
+ the_repository->hash_algo);
return oid;
}
diff --git a/notes-merge.c b/notes-merge.c
index 6a9a139b12..801941c2d1 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -240,7 +240,7 @@ static void diff_tree_local(struct notes_merge_options *o,
* (will be overwritten by following addition)
*/
if (oideq(&mp->local, &uninitialized))
- oidclr(&mp->local);
+ oidclr(&mp->local, the_repository->hash_algo);
} else if (is_null_oid(&p->one->oid)) { /* addition */
/*
* Either this is a true addition (1), or it is part
@@ -556,7 +556,7 @@ int notes_merge(struct notes_merge_options *o,
assert(o->local_ref && o->remote_ref);
assert(!strcmp(o->local_ref, local_tree->ref));
- oidclr(result_oid);
+ oidclr(result_oid, the_repository->hash_algo);
trace_printf("notes_merge(o->local_ref = %s, o->remote_ref = %s)\n",
o->local_ref, o->remote_ref);
@@ -579,7 +579,7 @@ int notes_merge(struct notes_merge_options *o,
* unborn ref, perform the merge using an empty notes tree.
*/
if (!check_refname_format(o->remote_ref, 0)) {
- oidclr(&remote_oid);
+ oidclr(&remote_oid, the_repository->hash_algo);
remote = NULL;
} else {
die("Failed to resolve remote notes ref '%s'",
diff --git a/notes.c b/notes.c
index 5296fd863f..3a8da92fb9 100644
--- a/notes.c
+++ b/notes.c
@@ -353,7 +353,7 @@ static void add_non_note(struct notes_tree *t, char *path,
n->next = NULL;
n->path = path;
n->mode = mode;
- oidread(&n->oid, sha1);
+ oidread(&n->oid, sha1, the_repository->hash_algo);
t->prev_non_note = n;
if (!t->first_non_note) {
@@ -1036,7 +1036,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid));
- oidclr(&root_tree.key_oid);
+ oidclr(&root_tree.key_oid, the_repository->hash_algo);
oidcpy(&root_tree.val_oid, &oid);
load_subtree(t, &root_tree, t->root, 0);
}
@@ -1146,8 +1146,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
if (!t)
t = &default_notes_tree;
assert(t->initialized);
- oidread(&l.key_oid, object_sha1);
- oidclr(&l.val_oid);
+ oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
+ oidclr(&l.val_oid, the_repository->hash_algo);
note_tree_remove(t, t->root, 0, &l);
if (is_null_oid(&l.val_oid)) /* no note was removed */
return 1;
diff --git a/object-file-convert.c b/object-file-convert.c
index 4f6189095b..f684038f7f 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -56,7 +56,7 @@ static int decode_tree_entry_raw(struct object_id *oid, const char **path,
return -1;
*len = strlen(*path) + 1;
- oidread_algop(oid, (const unsigned char *)*path + *len, algo);
+ oidread(oid, (const unsigned char *)*path + *len, algo);
return 0;
}
diff --git a/object-file.c b/object-file.c
index a40300ce4a..c161e3e2a5 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1446,7 +1446,7 @@ static int loose_object_info(struct repository *r,
int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
/*
* If we don't care about type or size, then we don't
@@ -1580,7 +1580,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
diff --git a/packfile.c b/packfile.c
index 9156e9122c..ec7312cd20 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1251,7 +1251,7 @@ static int get_delta_base_oid(struct packed_git *p,
{
if (type == OBJ_REF_DELTA) {
unsigned char *base = use_pack(p, w_curs, curpos, NULL);
- oidread(oid, base);
+ oidread(oid, base, the_repository->hash_algo);
return 0;
} else if (type == OBJ_OFS_DELTA) {
uint32_t base_pos;
@@ -1593,7 +1593,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
goto out;
}
} else
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
}
oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :
@@ -1917,10 +1917,12 @@ int nth_packed_object_id(struct object_id *oid,
return -1;
index += 4 * 256;
if (p->index_version == 1) {
- oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4));
+ oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4),
+ the_repository->hash_algo);
} else {
index += 8;
- oidread(oid, index + st_mult(hashsz, n));
+ oidread(oid, index + st_mult(hashsz, n),
+ the_repository->hash_algo);
}
return 0;
}
diff --git a/read-cache.c b/read-cache.c
index 2642ac9558..836f1db721 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1728,7 +1728,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
end = (unsigned char *)hdr + size;
start = end - the_hash_algo->rawsz;
- oidread(&oid, start);
+ oidread(&oid, start, the_repository->hash_algo);
if (oideq(&oid, null_oid()))
return 0;
@@ -1876,7 +1876,8 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
ce->ce_flags = flags & ~CE_NAMEMASK;
ce->ce_namelen = len;
ce->index = 0;
- oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data));
+ oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data),
+ the_repository->hash_algo);
if (expand_name_field) {
if (copy_len)
@@ -2249,7 +2250,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
if (verify_hdr(hdr, mmap_size) < 0)
goto unmap;
- oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
+ oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz,
+ the_repository->hash_algo);
istate->version = ntohl(hdr->hdr_version);
istate->cache_nr = ntohl(hdr->hdr_entries);
istate->cache_alloc = alloc_nr(istate->cache_nr);
diff --git a/refs.c b/refs.c
index 1304d3dd87..6e7caefdcf 100644
--- a/refs.c
+++ b/refs.c
@@ -1822,7 +1822,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
failure_errno != ENOTDIR)
return NULL;
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
if (*flags & REF_BAD_NAME)
*flags |= REF_ISBROKEN;
return refname;
@@ -1832,7 +1832,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
if (!(read_flags & REF_ISSYMREF)) {
if (*flags & REF_BAD_NAME) {
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
*flags |= REF_ISBROKEN;
}
return refname;
@@ -1840,7 +1840,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
refname = sb_refname.buf;
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
return refname;
}
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4519b46171..b484b5880d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -246,7 +246,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
&oid, &flag)) {
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
flag |= REF_ISBROKEN;
} else if (is_null_oid(&oid)) {
/*
@@ -263,7 +263,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
if (!refname_is_safe(refname))
die("loose refname is dangerous: %s", refname);
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
flag |= REF_BAD_NAME | REF_ISBROKEN;
}
add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));
@@ -1150,7 +1150,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
&lock->old_oid, NULL))
- oidclr(&lock->old_oid);
+ oidclr(&lock->old_oid, the_repository->hash_algo);
goto out;
error_return:
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index c4c1e36aa2..5ab1b21d10 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -894,7 +894,7 @@ static int next_record(struct packed_ref_iterator *iter)
if (!refname_is_safe(iter->base.refname))
die("packed refname is dangerous: %s",
iter->base.refname);
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
iter->base.flags |= REF_BAD_NAME | REF_ISBROKEN;
}
if (iter->snapshot->peeled == PEELED_FULLY ||
@@ -919,13 +919,13 @@ static int next_record(struct packed_ref_iterator *iter)
* we suppress it if the reference is broken:
*/
if ((iter->base.flags & REF_ISBROKEN)) {
- oidclr(&iter->peeled);
+ oidclr(&iter->peeled, the_repository->hash_algo);
iter->base.flags &= ~REF_KNOWS_PEELED;
} else {
iter->base.flags |= REF_KNOWS_PEELED;
}
} else {
- oidclr(&iter->peeled);
+ oidclr(&iter->peeled, the_repository->hash_algo);
}
return ITER_OK;
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 9886fc67a4..57df2aba66 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -217,7 +217,8 @@ static int read_ref_without_reload(struct reftable_stack *stack,
strbuf_addstr(referent, ref.value.symref);
*type |= REF_ISSYMREF;
} else if (reftable_ref_record_val1(&ref)) {
- oidread(oid, reftable_ref_record_val1(&ref));
+ oidread(oid, reftable_ref_record_val1(&ref),
+ the_repository->hash_algo);
} else {
/* We got a tombstone, which should not happen. */
BUG("unhandled reference value type %d", ref.value_type);
@@ -483,15 +484,17 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
switch (iter->ref.value_type) {
case REFTABLE_REF_VAL1:
- oidread(&iter->oid, iter->ref.value.val1);
+ oidread(&iter->oid, iter->ref.value.val1,
+ the_repository->hash_algo);
break;
case REFTABLE_REF_VAL2:
- oidread(&iter->oid, iter->ref.value.val2.value);
+ oidread(&iter->oid, iter->ref.value.val2.value,
+ the_repository->hash_algo);
break;
case REFTABLE_REF_SYMREF:
if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname,
RESOLVE_REF_READING, &iter->oid, &flags))
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
break;
default:
BUG("unhandled reference value type %d", iter->ref.value_type);
@@ -503,7 +506,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
if (check_refname_format(iter->ref.refname, REFNAME_ALLOW_ONELEVEL)) {
if (!refname_is_safe(iter->ref.refname))
die(_("refname is dangerous: %s"), iter->ref.refname);
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
flags |= REF_BAD_NAME | REF_ISBROKEN;
}
@@ -545,7 +548,8 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,
(struct reftable_ref_iterator *)ref_iterator;
if (iter->ref.value_type == REFTABLE_REF_VAL2) {
- oidread(peeled, iter->ref.value.val2.target_value);
+ oidread(peeled, iter->ref.value.val2.target_value,
+ the_repository->hash_algo);
return 0;
}
@@ -1776,8 +1780,8 @@ static int yield_log_record(struct reftable_log_record *log,
struct object_id old_oid, new_oid;
const char *full_committer;
- oidread(&old_oid, log->value.update.old_hash);
- oidread(&new_oid, log->value.update.new_hash);
+ oidread(&old_oid, log->value.update.old_hash, the_repository->hash_algo);
+ oidread(&new_oid, log->value.update.new_hash, the_repository->hash_algo);
/*
* When both the old object ID and the new object ID are null
@@ -2178,7 +2182,8 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
if (ret < 0)
goto done;
if (reftable_ref_record_val1(&ref_record))
- oidread(&oid, reftable_ref_record_val1(&ref_record));
+ oidread(&oid, reftable_ref_record_val1(&ref_record),
+ the_repository->hash_algo);
prepare_fn(refname, &oid, policy_cb_data);
while (1) {
@@ -2193,8 +2198,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
break;
}
- oidread(&old_oid, log.value.update.old_hash);
- oidread(&new_oid, log.value.update.new_hash);
+ oidread(&old_oid, log.value.update.old_hash,
+ the_repository->hash_algo);
+ oidread(&new_oid, log.value.update.new_hash,
+ the_repository->hash_algo);
/*
* Skip over the reflog existence marker. We will add it back
@@ -2225,8 +2232,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
struct object_id old_oid, new_oid;
*dest = logs[i];
- oidread(&old_oid, logs[i].value.update.old_hash);
- oidread(&new_oid, logs[i].value.update.new_hash);
+ oidread(&old_oid, logs[i].value.update.old_hash,
+ the_repository->hash_algo);
+ oidread(&new_oid, logs[i].value.update.new_hash,
+ the_repository->hash_algo);
if (should_prune_fn(&old_oid, &new_oid, logs[i].value.update.email,
(timestamp_t)logs[i].value.update.time,
@@ -2243,7 +2252,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
reftable_ref_record_val1(&ref_record))
- oidread(&arg.update_oid, last_hash);
+ oidread(&arg.update_oid, last_hash, the_repository->hash_algo);
arg.refs = refs;
arg.records = rewritten;
diff --git a/remote.c b/remote.c
index dcb5492c85..1064171085 100644
--- a/remote.c
+++ b/remote.c
@@ -1164,7 +1164,7 @@ static void tail_link_ref(struct ref *ref, struct ref ***tail)
static struct ref *alloc_delete_ref(void)
{
struct ref *ref = alloc_ref("(delete)");
- oidclr(&ref->new_oid);
+ oidclr(&ref->new_oid, the_repository->hash_algo);
return ref;
}
@@ -2531,7 +2531,7 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
if (!*colon)
entry->use_tracking = 1;
else if (!colon[1])
- oidclr(&entry->expect);
+ oidclr(&entry->expect, the_repository->hash_algo);
else if (repo_get_oid(the_repository, colon + 1, &entry->expect))
return error(_("cannot parse expected object name '%s'"),
colon + 1);
@@ -2733,7 +2733,7 @@ static void apply_cas(struct push_cas_option *cas,
else if (remote_tracking(remote, ref->name,
&ref->old_oid_expect,
&ref->tracking_ref))
- oidclr(&ref->old_oid_expect);
+ oidclr(&ref->old_oid_expect, the_repository->hash_algo);
else
ref->check_reachable = cas->use_force_if_includes;
return;
@@ -2747,7 +2747,7 @@ static void apply_cas(struct push_cas_option *cas,
if (remote_tracking(remote, ref->name,
&ref->old_oid_expect,
&ref->tracking_ref))
- oidclr(&ref->old_oid_expect);
+ oidclr(&ref->old_oid_expect, the_repository->hash_algo);
else
ref->check_reachable = cas->use_force_if_includes;
}
diff --git a/resolve-undo.c b/resolve-undo.c
index cd02dc9928..4e6f0e4676 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -93,7 +93,8 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
continue;
if (size < rawsz)
goto error;
- oidread(&ui->oid[i], (const unsigned char *)data);
+ oidread(&ui->oid[i], (const unsigned char *)data,
+ the_repository->hash_algo);
size -= rawsz;
data += rawsz;
}
diff --git a/sequencer.c b/sequencer.c
index 30513e87bf..68d62a12ff 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3334,12 +3334,12 @@ static int rollback_is_safe(void)
strbuf_release(&sb);
}
else if (errno == ENOENT)
- oidclr(&expected_head);
+ oidclr(&expected_head, the_repository->hash_algo);
else
die_errno(_("could not read '%s'"), git_path_abort_safety_file());
if (repo_get_oid(the_repository, "HEAD", &actual_head))
- oidclr(&actual_head);
+ oidclr(&actual_head, the_repository->hash_algo);
return oideq(&actual_head, &expected_head);
}
diff --git a/split-index.c b/split-index.c
index 8c38687c04..058a8f448e 100644
--- a/split-index.c
+++ b/split-index.c
@@ -29,7 +29,7 @@ int read_link_extension(struct index_state *istate,
if (sz < the_hash_algo->rawsz)
return error("corrupt link extension (too short)");
si = init_split_index(istate);
- oidread(&si->base_oid, data);
+ oidread(&si->base_oid, data, the_repository->hash_algo);
data += the_hash_algo->rawsz;
sz -= the_hash_algo->rawsz;
if (!sz)
diff --git a/submodule-config.c b/submodule-config.c
index ec45ea67b9..ad43a282da 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -682,7 +682,7 @@ static int gitmodule_oid_from_commit(const struct object_id *treeish_name,
int ret = 0;
if (is_null_oid(treeish_name)) {
- oidclr(gitmodules_oid);
+ oidclr(gitmodules_oid, the_repository->hash_algo);
return 1;
}
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 9df2f03ac8..4b809d9dca 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -44,7 +44,7 @@ int cmd__submodule_config(int argc, const char **argv)
path_or_name = arg[1];
if (commit[0] == '\0')
- oidclr(&commit_oid);
+ oidclr(&commit_oid, the_repository->hash_algo);
else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
die_usage(argc, argv, "Commit not found.");
diff --git a/tree-walk.c b/tree-walk.c
index 6565d9ad99..535a3a2539 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -38,8 +38,8 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
desc->entry.path = path;
desc->entry.mode = (desc->flags & TREE_DESC_RAW_MODES) ? mode : canon_mode(mode);
desc->entry.pathlen = len - 1;
- oidread_algop(&desc->entry.oid, (const unsigned char *)path + len,
- desc->algo);
+ oidread(&desc->entry.oid, (const unsigned char *)path + len,
+ desc->algo);
return 0;
}
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 04/21] global: ensure that object IDs are always padded
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (2 preceding siblings ...)
2024-06-11 11:57 ` [PATCH 03/21] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
@ 2024-06-11 11:57 ` Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 05/21] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
` (19 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:57 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 6452 bytes --]
The `oidcmp()` and `oideq()` functions only compare the prefix length as
specified by the given hash algorithm. This mandates that the object IDs
have a valid hash algorithm set, or otherwise we wouldn't be able to
figure out that prefix. As we do not have a hash algorithm in many
cases, for example when handling null object IDs, this assumption cannot
always be fulfilled. We thus have a fallback in place that instead uses
`the_repository` to derive the hash function. This implicit dependency
is hidden away from callers and can be quite surprising, especially in
contexts where there may be no repository.
In theory, we can adapt those functions to always memcmp(3P) the whole
length of their hash arrays. But there exist a couple of sites where we
populate `struct object_id`s such that only the prefix of its hash that
is actually used by the hash algorithm is populated. The remaining bytes
are left uninitialized. The fact that those bytes are uninitialized also
leads to warnings under Valgrind in some places where we copy those
bytes.
Refactor callsites where we populate object IDs to always initialize all
bytes. This also allows us to get rid of `oidcpy_with_padding()`, for
one because the input is now fully initialized, and because `oidcpy()`
will now always copy the whole hash array.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 2 ++
hash.h | 16 ----------------
hex.c | 6 +++++-
http-push.c | 1 +
notes.c | 2 ++
object-file.c | 2 ++
oidtree.c | 4 ++--
parallel-checkout.c | 8 +-------
8 files changed, 15 insertions(+), 26 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index dbb96369fc..b72f84f4ae 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -288,6 +288,8 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash,
const struct git_hash_algo *algop)
{
memcpy(oid->hash, hash, algop->rawsz);
+ if (algop->rawsz < GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
oid->algo = hash_algo_by_ptr(algop);
}
diff --git a/hash.h b/hash.h
index 43623a0c86..e43e3d8b5a 100644
--- a/hash.h
+++ b/hash.h
@@ -31,22 +31,6 @@ static inline int is_null_oid(const struct object_id *oid)
return oideq(oid, null_oid());
}
-/* 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;
-
- memcpy(dst->hash, src->hash, hashsz);
- memset(dst->hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
- dst->algo = src->algo;
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
diff --git a/hex.c b/hex.c
index d42262bdca..bc9e86a978 100644
--- a/hex.c
+++ b/hex.c
@@ -25,8 +25,12 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid,
const struct git_hash_algo *algop)
{
int ret = get_hash_hex_algop(hex, oid->hash, algop);
- if (!ret)
+ if (!ret) {
oid_set_algo(oid, algop);
+ if (algop->rawsz != GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0,
+ GIT_MAX_RAWSZ - algop->rawsz);
+ }
return ret;
}
diff --git a/http-push.c b/http-push.c
index 86de238b84..a97df4a1fb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1016,6 +1016,7 @@ 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)
{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
oid->algo = hash_algo_by_ptr(the_hash_algo);
if (strlen(path) != the_hash_algo->hexsz + 1)
diff --git a/notes.c b/notes.c
index 3a8da92fb9..afe2e2882e 100644
--- a/notes.c
+++ b/notes.c
@@ -427,6 +427,8 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
hashsz - prefix_len))
goto handle_non_note; /* entry.path is not a SHA1 */
+ memset(object_oid.hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
+
type = PTR_TYPE_NOTE;
} else if (path_len == 2) {
/* This is potentially an internal node */
diff --git a/object-file.c b/object-file.c
index c161e3e2a5..bb97f8a809 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2743,6 +2743,8 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
!hex_to_bytes(oid.hash + 1, de->d_name,
the_hash_algo->rawsz - 1)) {
oid_set_algo(&oid, the_hash_algo);
+ memset(oid.hash + the_hash_algo->rawsz, 0,
+ GIT_MAX_RAWSZ - the_hash_algo->rawsz);
if (obj_cb) {
r = obj_cb(&oid, path->buf, data);
if (r)
diff --git a/oidtree.c b/oidtree.c
index daef175dc7..92d03b52db 100644
--- a/oidtree.c
+++ b/oidtree.c
@@ -42,7 +42,7 @@ void oidtree_insert(struct oidtree *ot, const struct object_id *oid)
* Clear the padding and copy the result in separate steps to
* respect the 4-byte alignment needed by struct object_id.
*/
- oidcpy_with_padding(&k, oid);
+ oidcpy(&k, oid);
memcpy(on->k, &k, sizeof(k));
/*
@@ -60,7 +60,7 @@ int oidtree_contains(struct oidtree *ot, const struct object_id *oid)
struct object_id k;
size_t klen = sizeof(k);
- oidcpy_with_padding(&k, oid);
+ oidcpy(&k, oid);
if (oid->algo == GIT_HASH_UNKNOWN)
klen -= sizeof(oid->algo);
diff --git a/parallel-checkout.c b/parallel-checkout.c
index b5a714c711..08b960aac8 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -429,13 +429,7 @@ static void send_one_item(int fd, struct parallel_checkout_item *pc_item)
fixed_portion->ident = pc_item->ca.ident;
fixed_portion->name_len = name_len;
fixed_portion->working_tree_encoding_len = working_tree_encoding_len;
- /*
- * We pad the unused bytes in the hash array because, otherwise,
- * Valgrind would complain about passing uninitialized bytes to a
- * write() syscall. The warning doesn't represent any real risk here,
- * but it could hinder the detection of actual errors.
- */
- oidcpy_with_padding(&fixed_portion->oid, &pc_item->ce->oid);
+ oidcpy(&fixed_portion->oid, &pc_item->ce->oid);
variant = data + sizeof(*fixed_portion);
if (working_tree_encoding_len) {
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 05/21] hash: convert `oidcmp()` and `oideq()` to compare whole hash
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (3 preceding siblings ...)
2024-06-11 11:57 ` [PATCH 04/21] global: ensure that object IDs are always padded Patrick Steinhardt
@ 2024-06-11 11:57 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 06/21] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
` (18 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:57 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 6009 bytes --]
With the preceding commit, the hash array of object IDs is now fully
zero-padded even when the hash algorithm's output is smaller than the
array length. With that, we can now adapt both `oidcmp()` and `oideq()`
to unconditionally memcmp(3P) the whole array instead of depending on
the hash size.
While it may feel inefficient to compare unused bytes for e.g. SHA-1, in
practice the compiler should now be able to produce code that is better
optimized both because we have no branch anymore, but also because the
size to compare is now known at compile time. Goldbolt spits out the
following assembly on an x86_64 platform with GCC 14.1 for the old and
new implementations of `oidcmp()`:
oidcmp_old:
movsx rax, DWORD PTR [rdi+32]
test eax, eax
jne .L2
mov rax, QWORD PTR the_repository[rip]
cmp QWORD PTR [rax+16], 32
je .L6
.L4:
mov edx, 20
jmp memcmp
.L2:
lea rdx, [rax+rax*2]
lea rax, [rax+rdx*4]
lea rax, hash_algos[0+rax*8]
cmp QWORD PTR [rax+16], 32
jne .L4
.L6:
mov edx, 32
jmp memcmp
oidcmp_new:
mov edx, 32
jmp memcmp
The new implementation gets ridi of all the branches and effectively
only ends setting up `edx` for `memcmp()` and then calling it.
And for `oideq()`:
oideq_old:
movsx rcx, DWORD PTR [rdi+32]
mov rax, rdi
mov rdx, rsi
test ecx, ecx
jne .L2
mov rcx, QWORD PTR the_repository[rip]
cmp QWORD PTR [rcx+16], 32
mov rcx, QWORD PTR [rax]
je .L12
.L4:
mov rsi, QWORD PTR [rax+8]
xor rcx, QWORD PTR [rdx]
xor rsi, QWORD PTR [rdx+8]
or rcx, rsi
je .L13
.L8:
mov eax, 1
test eax, eax
sete al
movzx eax, al
ret
.L2:
lea rsi, [rcx+rcx*2]
lea rcx, [rcx+rsi*4]
lea rcx, hash_algos[0+rcx*8]
cmp QWORD PTR [rcx+16], 32
mov rcx, QWORD PTR [rax]
jne .L4
.L12:
mov rsi, QWORD PTR [rax+8]
xor rcx, QWORD PTR [rdx]
xor rsi, QWORD PTR [rdx+8]
or rcx, rsi
jne .L8
mov rcx, QWORD PTR [rax+16]
mov rax, QWORD PTR [rax+24]
xor rcx, QWORD PTR [rdx+16]
xor rax, QWORD PTR [rdx+24]
or rcx, rax
jne .L8
xor eax, eax
.L14:
test eax, eax
sete al
movzx eax, al
ret
.L13:
mov edi, DWORD PTR [rdx+16]
cmp DWORD PTR [rax+16], edi
jne .L8
xor eax, eax
jmp .L14
oideq_new:
mov rax, QWORD PTR [rdi]
mov rdx, QWORD PTR [rdi+8]
xor rax, QWORD PTR [rsi]
xor rdx, QWORD PTR [rsi+8]
or rax, rdx
je .L5
.L2:
mov eax, 1
xor eax, 1
ret
.L5:
mov rax, QWORD PTR [rdi+16]
mov rdx, QWORD PTR [rdi+24]
xor rax, QWORD PTR [rsi+16]
xor rdx, QWORD PTR [rsi+24]
or rax, rdx
jne .L2
xor eax, eax
xor eax, 1
ret
Interestingly, the compiler decides to split the comparisons into two so
that it first compares the lower half of the object ID for equality and
then the upper half. If the first check shows a difference, then we
wouldn't even end up comparing the second half.
In both cases, the new generated code is significantly shorter and has
way less branches. While I didn't benchmark the change, I'd be surprised
if the new code was slower.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 10 ++++++++++
hash.h | 20 --------------------
2 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index b72f84f4ae..b04fe12aef 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -278,6 +278,16 @@ static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algo
memset(hash, 0, algop->rawsz);
}
+static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
diff --git a/hash.h b/hash.h
index e43e3d8b5a..ddc2e5ca47 100644
--- a/hash.h
+++ b/hash.h
@@ -6,26 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-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(oid1->hash, oid2->hash, algop);
-}
-
-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(oid1->hash, oid2->hash, algop);
-}
-
static inline int is_null_oid(const struct object_id *oid)
{
return oideq(oid, null_oid());
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 06/21] hash: make `is_null_oid()` independent of `the_repository`
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (4 preceding siblings ...)
2024-06-11 11:57 ` [PATCH 05/21] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 07/21] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
` (17 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1496 bytes --]
The function `is_null_oid()` uses `oideq(oid, null_oid())` to check
whether a given object ID is the all-zero object ID. `null_oid()`
implicitly relies on `the_repository` though to return the correct null
object ID.
Get rid of this dependency by always comparing the complete hash array
for being all-zeroes. This is possible due to the refactoring of object
IDs so that their hash arrays are always fully initialized.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 6 ++++++
hash.h | 5 -----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index b04fe12aef..faf6c292d2 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -341,6 +341,12 @@ static inline unsigned int oidhash(const struct object_id *oid)
return hash;
}
+static inline int is_null_oid(const struct object_id *oid)
+{
+ static const unsigned char null_hash[GIT_MAX_RAWSZ];
+ return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
+}
+
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
diff --git a/hash.h b/hash.h
index ddc2e5ca47..84f2296cfb 100644
--- a/hash.h
+++ b/hash.h
@@ -6,11 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-static inline int is_null_oid(const struct object_id *oid)
-{
- return oideq(oid, null_oid());
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 07/21] hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (5 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 06/21] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 08/21] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
` (16 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 3968 bytes --]
Both functions `is_empty_{blob,tree}_oid()` use `the_repository` to
derive the hash function that shall be used. Require callers to pass in
the hash algorithm to get rid of this implicit dependency.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 4 +++-
cache-tree.c | 2 +-
diffcore-rename.c | 4 ++--
hash-ll.h | 12 ++++++++++++
hash.h | 10 ----------
read-cache.c | 2 +-
6 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 12543488f3..d21c4053a7 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2361,7 +2361,9 @@ static void file_change_m(const char *p, struct branch *b)
parse_path_eol(&path, p, "path");
/* Git does not track empty, non-toplevel directories. */
- if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *path.buf) {
+ if (S_ISDIR(mode) &&
+ is_empty_tree_oid(&oid, the_repository->hash_algo) &&
+ *path.buf) {
tree_content_remove(&b->branch_tree, path.buf, NULL, 0);
return;
}
diff --git a/cache-tree.c b/cache-tree.c
index e4255c4d02..3290a1b8dd 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -422,7 +422,7 @@ static int update_one(struct cache_tree *it,
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
- if (contains_ita && is_empty_tree_oid(oid))
+ if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo))
continue;
strbuf_grow(&buffer, entlen + 100);
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 5a6e2bcac7..5abb958651 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -1422,7 +1422,7 @@ void diffcore_rename_extended(struct diff_options *options,
strcmp(options->single_follow, p->two->path))
continue; /* not interested */
else if (!options->flags.rename_empty &&
- is_empty_blob_oid(&p->two->oid))
+ is_empty_blob_oid(&p->two->oid, the_repository->hash_algo))
continue;
else if (add_rename_dst(p) < 0) {
warning("skipping rename detection, detected"
@@ -1432,7 +1432,7 @@ void diffcore_rename_extended(struct diff_options *options,
}
}
else if (!options->flags.rename_empty &&
- is_empty_blob_oid(&p->one->oid))
+ is_empty_blob_oid(&p->one->oid, the_repository->hash_algo))
continue;
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
/*
diff --git a/hash-ll.h b/hash-ll.h
index faf6c292d2..1000a9af22 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -350,4 +350,16 @@ static inline int is_null_oid(const struct object_id *oid)
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
+static inline int is_empty_blob_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_blob);
+}
+
+static inline int is_empty_tree_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_tree);
+}
+
#endif
diff --git a/hash.h b/hash.h
index 84f2296cfb..39a0164be3 100644
--- a/hash.h
+++ b/hash.h
@@ -6,14 +6,4 @@
#define the_hash_algo the_repository->hash_algo
-static inline int is_empty_blob_oid(const struct object_id *oid)
-{
- return oideq(oid, the_hash_algo->empty_blob);
-}
-
-static inline int is_empty_tree_oid(const struct object_id *oid)
-{
- return oideq(oid, the_hash_algo->empty_tree);
-}
-
#endif
diff --git a/read-cache.c b/read-cache.c
index 836f1db721..085b22faf3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
/* Racily smudged entry? */
if (!ce->ce_stat_data.sd_size) {
- if (!is_empty_blob_oid(&ce->oid))
+ if (!is_empty_blob_oid(&ce->oid, the_repository->hash_algo))
changed |= DATA_CHANGED;
}
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 08/21] hash: require hash algorithm in `empty_tree_oid_hex()`
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (6 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 07/21] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 09/21] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (15 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 6668 bytes --]
The `empty_tree_oid_hex()` function use `the_repository` to derive the
hash function that shall be used. Require callers to pass in the hash
algorithm to get rid of this implicit dependency.
While at it, remove the unused `empty_blob_oid_hex()` function.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
add-interactive.c | 2 +-
add-patch.c | 2 +-
builtin/merge.c | 3 ++-
builtin/receive-pack.c | 2 +-
hash-ll.h | 3 +--
object-file.c | 10 ++--------
sequencer.c | 2 +-
submodule.c | 6 +++---
wt-status.c | 4 ++--
9 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/add-interactive.c b/add-interactive.c
index b5d6cd689a..a0961096cd 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
s.skip_unseen = filter && i;
opt.def = is_initial ?
- empty_tree_oid_hex() : oid_to_hex(&head_oid);
+ empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
repo_init_revisions(r, &rev, NULL);
setup_revisions(0, NULL, &rev, &opt);
diff --git a/add-patch.c b/add-patch.c
index 814de57c4a..86181770f2 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -420,7 +420,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
/* could be on an unborn branch */
!strcmp("HEAD", s->revision) &&
repo_get_oid(the_repository, "HEAD", &oid) ?
- empty_tree_oid_hex() : s->revision);
+ empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
}
color_arg_index = args.nr;
/* Use `--no-color` explicitly, just in case `diff.color = always`. */
diff --git a/builtin/merge.c b/builtin/merge.c
index abe66311c7..bb94b7df21 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -330,7 +330,8 @@ static void read_empty(const struct object_id *oid)
{
struct child_process cmd = CHILD_PROCESS_INIT;
- strvec_pushl(&cmd.args, "read-tree", "-m", "-u", empty_tree_oid_hex(),
+ strvec_pushl(&cmd.args, "read-tree", "-m", "-u",
+ empty_tree_oid_hex(the_repository->hash_algo),
oid_to_hex(oid), NULL);
cmd.git_cmd = 1;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index aa5ba27d17..41d5fb8e60 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1371,7 +1371,7 @@ static const char *push_to_deploy(unsigned char *sha1,
strvec_pushl(&child.args, "diff-index", "--quiet", "--cached",
"--ignore-submodules",
/* diff-index with either HEAD or an empty tree */
- head_has_history() ? "HEAD" : empty_tree_oid_hex(),
+ head_has_history() ? "HEAD" : empty_tree_oid_hex(the_repository->hash_algo),
"--", NULL);
strvec_pushv(&child.env, env->v);
child.no_stdin = 1;
diff --git a/hash-ll.h b/hash-ll.h
index 1000a9af22..3161c778b9 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -347,8 +347,7 @@ static inline int is_null_oid(const struct object_id *oid)
return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
}
-const char *empty_tree_oid_hex(void);
-const char *empty_blob_oid_hex(void);
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
static inline int is_empty_blob_oid(const struct object_id *oid,
const struct git_hash_algo *algop)
diff --git a/object-file.c b/object-file.c
index bb97f8a809..72318c8dd4 100644
--- a/object-file.c
+++ b/object-file.c
@@ -227,16 +227,10 @@ const struct object_id *null_oid(void)
return the_hash_algo->null_oid;
}
-const char *empty_tree_oid_hex(void)
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
{
static char buf[GIT_MAX_HEXSZ + 1];
- return oid_to_hex_r(buf, the_hash_algo->empty_tree);
-}
-
-const char *empty_blob_oid_hex(void)
-{
- static char buf[GIT_MAX_HEXSZ + 1];
- return oid_to_hex_r(buf, the_hash_algo->empty_blob);
+ return oid_to_hex_r(buf, algop->empty_tree);
}
int hash_algo_by_name(const char *name)
diff --git a/sequencer.c b/sequencer.c
index 68d62a12ff..823691e379 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
unborn = 1;
} else if (unborn)
oidcpy(&head, the_hash_algo->empty_tree);
- if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
+ if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
NULL, 0))
return error_dirty_index(r, opts);
}
diff --git a/submodule.c b/submodule.c
index 759cf1e1cd..caf3aa5600 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2119,7 +2119,7 @@ static void submodule_reset_index(const char *path, const char *super_prefix)
strvec_pushf(&cp.args, "--super-prefix=%s%s/",
(super_prefix ? super_prefix : ""), path);
- strvec_push(&cp.args, empty_tree_oid_hex());
+ strvec_push(&cp.args, empty_tree_oid_hex(the_repository->hash_algo));
if (run_command(&cp))
die(_("could not reset submodule index"));
@@ -2229,9 +2229,9 @@ int submodule_move_head(const char *path, const char *super_prefix,
strvec_push(&cp.args, "-m");
if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
- strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex());
+ strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex(the_repository->hash_algo));
- strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex());
+ strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex(the_repository->hash_algo));
if (run_command(&cp)) {
ret = error(_("Submodule '%s' could not be updated."), path);
diff --git a/wt-status.c b/wt-status.c
index ff4be071ca..5051f5e599 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -641,7 +641,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
repo_init_revisions(s->repo, &rev, NULL);
memset(&opt, 0, sizeof(opt));
- opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
+ opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.flags.override_submodule_config = 1;
@@ -1136,7 +1136,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
rev.diffopt.ita_invisible_in_index = 1;
memset(&opt, 0, sizeof(opt));
- opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
+ opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 09/21] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (7 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 08/21] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 10/21] refs: avoid include cycle with "repository.h" Patrick Steinhardt
` (14 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 54630 bytes --]
Use of the `the_repository` variable is deprecated nowadays, and we
slowly but steadily convert the codebase to not use it anymore. Instead,
callers should be passing down the repository to work on via parameters.
It is hard though to prove that a given code unit does not use this
variable anymore. The most trivial case, merely demonstrating that there
is no direct use of `the_repository`, is already a bit of a pain during
code reviews as the reviewer needs to manually verify claims made by the
patch author. The bigger problem though is that we have many interfaces
that implicitly rely on `the_repository`.
Introduce a new `USE_THE_REPOSITORY_VARIABLE` macro that allows code
units to opt into usage of `the_repository`. The intent of this macro is
to demonstrate that a certain code unit does not use this variable
anymore, and to keep it from new dependencies on it in future changes,
be it explicit or implicit
For now, the macro only guards `the_repository` itself as well as
`the_hash_algo`. There are many more known interfaces where we have an
implicit dependency on `the_repository`, but those are not guarded at
the current point in time. Over time though, we should start to add
guards as required (or even better, just remove them).
Define the macro as required in our code units. As expected, most of our
code still relies on the global variable. Nearly all of our builtins
rely on the variable as there is no way yet to pass `the_repository` to
their entry point. For now, declare the macro in "biultin.h" to keep the
required changes at least a little bit more contained.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
add-interactive.c | 2 ++
add-patch.c | 2 ++
apply.c | 2 ++
archive-tar.c | 3 +++
archive-zip.c | 3 +++
archive.c | 2 ++
attr.c | 2 ++
bisect.c | 2 ++
blame.c | 2 ++
branch.c | 2 ++
builtin.h | 8 ++++++++
builtin/blame.c | 2 +-
builtin/log.c | 2 +-
bulk-checkin.c | 3 +++
bundle-uri.c | 2 ++
bundle.c | 2 ++
cache-tree.c | 2 ++
checkout.c | 2 ++
chunk-format.c | 2 ++
combine-diff.c | 2 ++
commit-graph.c | 2 ++
commit-reach.c | 2 ++
commit.c | 2 ++
common-main.c | 2 ++
compat/win32/trace2_win32_process_info.c | 2 ++
config.c | 3 +++
connected.c | 2 ++
convert.c | 2 ++
csum-file.c | 3 +++
delta-islands.c | 2 ++
diagnose.c | 2 ++
diff-lib.c | 3 +++
diff.c | 3 +++
diffcore-break.c | 3 +++
diffcore-rename.c | 3 +++
dir.c | 3 +++
entry.c | 2 ++
environment.c | 3 +++
fetch-pack.c | 2 ++
fmt-merge-msg.c | 2 ++
fsck.c | 2 ++
fsmonitor-ipc.c | 2 ++
git.c | 2 ++
hash-lookup.c | 2 ++
hash.h | 4 +++-
help.c | 2 ++
hex.c | 2 ++
http-backend.c | 2 ++
http-push.c | 2 ++
http-walker.c | 2 ++
http.c | 2 ++
list-objects-filter-options.c | 2 ++
list-objects-filter.c | 2 ++
list-objects.c | 2 ++
log-tree.c | 2 ++
loose.c | 2 ++
ls-refs.c | 2 ++
mailmap.c | 2 ++
match-trees.c | 2 ++
merge-blobs.c | 2 ++
merge-ort.c | 2 ++
merge-recursive.c | 3 +++
merge.c | 2 ++
midx-write.c | 2 ++
midx.c | 2 ++
negotiator/default.c | 2 ++
negotiator/skipping.c | 2 ++
notes-cache.c | 2 ++
notes-merge.c | 2 ++
notes-utils.c | 2 ++
notes.c | 2 ++
object-file-convert.c | 2 ++
object-file.c | 3 +++
object-name.c | 2 ++
object.c | 2 ++
oid-array.c | 2 ++
oss-fuzz/fuzz-commit-graph.c | 2 ++
pack-bitmap-write.c | 2 ++
pack-bitmap.c | 2 ++
pack-check.c | 2 ++
pack-revindex.c | 2 ++
pack-write.c | 2 ++
packfile.c | 2 ++
parse-options-cb.c | 2 ++
path.c | 3 +++
pathspec.c | 2 ++
pretty.c | 2 ++
progress.c | 2 ++
promisor-remote.c | 2 ++
range-diff.c | 2 ++
reachable.c | 2 ++
read-cache.c | 3 +++
rebase-interactive.c | 2 ++
ref-filter.c | 2 ++
reflog-walk.c | 2 ++
reflog.c | 2 ++
refs.c | 2 ++
refs/files-backend.c | 2 ++
refs/packed-backend.c | 2 ++
refs/reftable-backend.c | 2 ++
refspec.c | 2 ++
remote-curl.c | 2 ++
remote.c | 2 ++
repository.h | 2 ++
rerere.c | 2 ++
reset.c | 2 ++
resolve-undo.c | 2 ++
revision.c | 2 ++
run-command.c | 2 ++
scalar.c | 2 ++
send-pack.c | 2 ++
sequencer.c | 2 ++
serve.c | 2 ++
server-info.c | 2 ++
setup.c | 2 ++
shallow.c | 2 ++
split-index.c | 2 ++
streaming.c | 3 +++
submodule-config.c | 2 ++
submodule.c | 2 ++
t/helper/test-bitmap.c | 2 ++
t/helper/test-bloom.c | 2 ++
t/helper/test-cache-tree.c | 2 ++
t/helper/test-dump-cache-tree.c | 2 ++
t/helper/test-dump-fsmonitor.c | 2 ++
t/helper/test-dump-split-index.c | 2 ++
t/helper/test-dump-untracked-cache.c | 2 ++
t/helper/test-example-decorate.c | 2 ++
t/helper/test-find-pack.c | 2 ++
t/helper/test-fsmonitor-client.c | 2 ++
t/helper/test-lazy-init-name-hash.c | 2 ++
t/helper/test-match-trees.c | 2 ++
t/helper/test-oidmap.c | 2 ++
t/helper/test-pack-mtimes.c | 2 ++
t/helper/test-reach.c | 2 ++
t/helper/test-read-cache.c | 2 ++
t/helper/test-read-graph.c | 2 ++
t/helper/test-read-midx.c | 2 ++
t/helper/test-ref-store.c | 2 ++
t/helper/test-repository.c | 2 ++
t/helper/test-revision-walking.c | 2 ++
t/helper/test-scrap-cache-tree.c | 2 ++
t/helper/test-submodule-config.c | 2 ++
t/helper/test-submodule-nested-repo-config.c | 2 ++
t/helper/test-submodule.c | 2 ++
t/helper/test-trace2.c | 2 ++
t/helper/test-write-cache.c | 2 ++
tag.c | 2 ++
tmp-objdir.c | 2 ++
transport-helper.c | 2 ++
transport.c | 2 ++
tree-walk.c | 2 ++
tree.c | 2 ++
unpack-trees.c | 2 ++
upload-pack.c | 2 ++
walker.c | 2 ++
worktree.c | 2 ++
wt-status.c | 2 ++
xdiff-interface.c | 2 ++
159 files changed, 339 insertions(+), 3 deletions(-)
diff --git a/add-interactive.c b/add-interactive.c
index a0961096cd..49042b3026 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "add-interactive.h"
#include "color.h"
diff --git a/add-patch.c b/add-patch.c
index 86181770f2..99e037c1e2 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "add-interactive.h"
#include "advice.h"
diff --git a/apply.c b/apply.c
index 528939abb6..ff939f908a 100644
--- a/apply.c
+++ b/apply.c
@@ -7,6 +7,8 @@
*
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
diff --git a/archive-tar.c b/archive-tar.c
index 8ae30125f8..e7b3489e1e 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2005, 2006 Rene Scharfe
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
diff --git a/archive-zip.c b/archive-zip.c
index fd1d3f816d..9f32730181 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2006 Rene Scharfe
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "archive.h"
diff --git a/archive.c b/archive.c
index 5287fcdd8e..7bd60d0632 100644
--- a/archive.c
+++ b/archive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/attr.c b/attr.c
index 300f994ba6..b5ed83c90e 100644
--- a/attr.c
+++ b/attr.c
@@ -6,6 +6,8 @@
* an insanely large number of attributes.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/bisect.c b/bisect.c
index 4ea703bec1..135f94ba09 100644
--- a/bisect.c
+++ b/bisect.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/blame.c b/blame.c
index a80f5e2e61..d403c46a35 100644
--- a/blame.c
+++ b/blame.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "refs.h"
#include "object-store-ll.h"
diff --git a/branch.c b/branch.c
index df5d24fec6..c887ea2151 100644
--- a/branch.c
+++ b/branch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/builtin.h b/builtin.h
index 7eda9b2486..14fa017160 100644
--- a/builtin.h
+++ b/builtin.h
@@ -1,6 +1,14 @@
#ifndef BUILTIN_H
#define BUILTIN_H
+/*
+ * TODO: Almost all of our builtins access `the_repository` by necessity
+ * because they do not get passed a pointer to it. We should adapt the function
+ * signature of those main functions to accept a `struct repository *` and then
+ * remove the macro here.
+ */
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
/*
diff --git a/builtin/blame.c b/builtin/blame.c
index e09ff0155a..de89fff3f8 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -5,7 +5,7 @@
* See COPYING for licensing conditions
*/
-#include "git-compat-util.h"
+#include "builtin.h"
#include "config.h"
#include "color.h"
#include "builtin.h"
diff --git a/builtin/log.c b/builtin/log.c
index ccbda8a005..00305bea51 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -4,7 +4,7 @@
* (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano
*/
-#include "git-compat-util.h"
+#include "builtin.h"
#include "abspath.h"
#include "config.h"
#include "environment.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index eb46b88637..da8673199b 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2011, Google Inc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bulk-checkin.h"
#include "environment.h"
diff --git a/bundle-uri.c b/bundle-uri.c
index 91b3319a5c..804fbcfbfa 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bundle-uri.h"
#include "bundle.h"
diff --git a/bundle.c b/bundle.c
index 95367c2d0a..82c285b905 100644
--- a/bundle.c
+++ b/bundle.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "lockfile.h"
#include "bundle.h"
diff --git a/cache-tree.c b/cache-tree.c
index 3290a1b8dd..50610c3f3c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/checkout.c b/checkout.c
index cfaea4bd10..0b1cf8b40b 100644
--- a/checkout.c
+++ b/checkout.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-name.h"
#include "remote.h"
diff --git a/chunk-format.c b/chunk-format.c
index cdc7f39b70..2dde24e6a3 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "chunk-format.h"
#include "csum-file.h"
diff --git a/combine-diff.c b/combine-diff.c
index 4960d904ac..829a44e416 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-store-ll.h"
#include "commit.h"
diff --git a/commit-graph.c b/commit-graph.c
index e4eefd83bf..b6bb9df0d0 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "csum-file.h"
diff --git a/commit-reach.c b/commit-reach.c
index 384aee1ab3..dabc2972e4 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "commit-graph.h"
diff --git a/commit.c b/commit.c
index 1d08951007..4956803e11 100644
--- a/commit.c
+++ b/commit.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"
diff --git a/common-main.c b/common-main.c
index b86f40600f..8e68ac9e42 100644
--- a/common-main.c
+++ b/common-main.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "exec-cmd.h"
#include "gettext.h"
diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
index 3ef0936f6f..f147da706a 100644
--- a/compat/win32/trace2_win32_process_info.c
+++ b/compat/win32/trace2_win32_process_info.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../../git-compat-util.h"
#include "../../json-writer.h"
#include "../../repository.h"
diff --git a/config.c b/config.c
index abce05b774..7951029644 100644
--- a/config.c
+++ b/config.c
@@ -5,6 +5,9 @@
* Copyright (C) Johannes Schindelin, 2005
*
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
diff --git a/connected.c b/connected.c
index 8f89376dbc..87cc4b57a1 100644
--- a/connected.c
+++ b/connected.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/convert.c b/convert.c
index f2b9f01354..d8737fe0f2 100644
--- a/convert.c
+++ b/convert.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/csum-file.c b/csum-file.c
index f4be0804b7..8abbf01325 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -7,6 +7,9 @@
* files. Useful when you write a file that you want to be
* able to verify hasn't been messed with afterwards.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "progress.h"
#include "csum-file.h"
diff --git a/delta-islands.c b/delta-islands.c
index 89d51b72e3..ffe1ca2814 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object.h"
#include "commit.h"
diff --git a/diagnose.c b/diagnose.c
index 4d096c857f..cc2d535b60 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diagnose.h"
#include "compat/disk.h"
diff --git a/diff-lib.c b/diff-lib.c
index 3fb8d79fef..b0d0f711e8 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "diff.h"
diff --git a/diff.c b/diff.c
index 60d1f7be81..d4579d5f76 100644
--- a/diff.c
+++ b/diff.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
diff --git a/diffcore-break.c b/diffcore-break.c
index 49ba38aa7c..831b66b5c3 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diffcore.h"
#include "hash.h"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 5abb958651..ae504007cf 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -2,6 +2,9 @@
*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diff.h"
#include "diffcore.h"
diff --git a/dir.c b/dir.c
index 9f9c1f3822..99688792e3 100644
--- a/dir.c
+++ b/dir.c
@@ -5,6 +5,9 @@
* Copyright (C) Linus Torvalds, 2005-2006
* Junio Hamano, 2005-2006
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/entry.c b/entry.c
index b8c257f6f9..fe1f74d140 100644
--- a/entry.c
+++ b/entry.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-store-ll.h"
#include "dir.h"
diff --git a/environment.c b/environment.c
index 701d515135..5cea2c9f54 100644
--- a/environment.c
+++ b/environment.c
@@ -7,6 +7,9 @@
* even if you might want to know where the git directory etc
* are.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "branch.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index eba9e420ea..e6e14b3874 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 7d144b803a..b8bca89c0c 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/fsck.c b/fsck.c
index dd0a33028e..432996cbb6 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "date.h"
#include "dir.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 45471b5b74..f1b1631111 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "simple-ipc.h"
diff --git a/git.c b/git.c
index 683bb69194..e35af9b0e5 100644
--- a/git.c
+++ b/git.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "builtin.h"
#include "config.h"
#include "environment.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index 9aa6b82eb7..5f808caa51 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "hash-lookup.h"
diff --git a/hash.h b/hash.h
index 39a0164be3..cb85d26a2f 100644
--- a/hash.h
+++ b/hash.h
@@ -4,6 +4,8 @@
#include "hash-ll.h"
#include "repository.h"
-#define the_hash_algo the_repository->hash_algo
+#ifdef USE_THE_REPOSITORY_VARIABLE
+# define the_hash_algo the_repository->hash_algo
+#endif
#endif
diff --git a/help.c b/help.c
index 1d057aa607..10fdb1a03d 100644
--- a/help.c
+++ b/help.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "builtin.h"
diff --git a/hex.c b/hex.c
index bc9e86a978..5ca78a7744 100644
--- a/hex.c
+++ b/hex.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "hex.h"
diff --git a/http-backend.c b/http-backend.c
index 5b65287ac9..7c0b3be968 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/http-push.c b/http-push.c
index a97df4a1fb..7315a694aa 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/http-walker.c b/http-walker.c
index b7110b6f82..e417a7f51c 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "hex.h"
diff --git a/http.c b/http.c
index 67cc47d28f..6536816e81 100644
--- a/http.c
+++ b/http.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "git-curl-compat.h"
#include "hex.h"
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index c5f363ca6f..00611107d2 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 4346f8da45..49e2fa6f97 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "gettext.h"
diff --git a/list-objects.c b/list-objects.c
index 11ad8be411..985d008799 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"
diff --git a/log-tree.c b/log-tree.c
index 41416de4e3..223a4d9463 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit-reach.h"
#include "config.h"
diff --git a/loose.c b/loose.c
index f6faa6216a..a8bf772172 100644
--- a/loose.c
+++ b/loose.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
diff --git a/ls-refs.c b/ls-refs.c
index 398afe4ce3..2dd925b43d 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/mailmap.c b/mailmap.c
index b2efe29b3d..534a3eb4f0 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "string-list.h"
diff --git a/match-trees.c b/match-trees.c
index 50c42e2061..f17c74d483 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "match-trees.h"
diff --git a/merge-blobs.c b/merge-blobs.c
index 2f659fd014..0ad0390fea 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-ll.h"
#include "blob.h"
diff --git a/merge-ort.c b/merge-ort.c
index eaede6cead..691db9050e 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -14,6 +14,8 @@
* "cale", "peedy", or "ins" instead of "ort"?)
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-ort.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 8ff29ed09e..46ee364af7 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3,6 +3,9 @@
* Fredrik Kuivinen.
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-recursive.h"
diff --git a/merge.c b/merge.c
index 752a937fa9..fe3efa4b24 100644
--- a/merge.c
+++ b/merge.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/midx-write.c b/midx-write.c
index 55a6b63bac..9a194e8aac 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/midx.c b/midx.c
index 1e75f1a7eb..3992b05465 100644
--- a/midx.c
+++ b/midx.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "dir.h"
diff --git a/negotiator/default.c b/negotiator/default.c
index 518b3c43b2..e3fa5c3324 100644
--- a/negotiator/default.c
+++ b/negotiator/default.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "default.h"
#include "../commit.h"
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
index b7e008c2fd..f109928ad0 100644
--- a/negotiator/skipping.c
+++ b/negotiator/skipping.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "skipping.h"
#include "../commit.h"
diff --git a/notes-cache.c b/notes-cache.c
index 038db01ca0..ecfdf6e43b 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-store-ll.h"
diff --git a/notes-merge.c b/notes-merge.c
index 801941c2d1..d95e683414 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "commit.h"
diff --git a/notes-utils.c b/notes-utils.c
index e33aa86c4b..bca71274be 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/notes.c b/notes.c
index afe2e2882e..b6a13d0980 100644
--- a/notes.c
+++ b/notes.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/object-file-convert.c b/object-file-convert.c
index f684038f7f..958f61f094 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "strbuf.h"
diff --git a/object-file.c b/object-file.c
index 72318c8dd4..a6555ed68c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -6,6 +6,9 @@
* This handles basic git object files - packing, unpacking,
* creation etc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/object-name.c b/object-name.c
index 523af6f64f..d7509514bc 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-name.h"
#include "advice.h"
diff --git a/object.c b/object.c
index 93b5d97fdb..0c0fcb76c0 100644
--- a/object.c
+++ b/object.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/oid-array.c b/oid-array.c
index 1f36651754..9cac974395 100644
--- a/oid-array.c
+++ b/oid-array.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "oid-array.h"
#include "hash-lookup.h"
diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c
index 75e668a057..951c9c082f 100644
--- a/oss-fuzz/fuzz-commit-graph.c
+++ b/oss-fuzz/fuzz-commit-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit-graph.h"
#include "repository.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 59d2e3a387..37a8ad0fb3 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 184d28f05c..7eafdce4ee 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "gettext.h"
diff --git a/pack-check.c b/pack-check.c
index 288f5a3479..d78289da3c 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index fc63aa76a2..de922b47d2 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
diff --git a/pack-write.c b/pack-write.c
index eef625fa5b..d07f03d0ab 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/packfile.c b/packfile.c
index ec7312cd20..813584646f 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/parse-options-cb.c b/parse-options-cb.c
index d99d688d3c..3fb7ce68ca 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "parse-options.h"
#include "branch.h"
diff --git a/path.c b/path.c
index adfb3d3eb7..19f7684f38 100644
--- a/path.c
+++ b/path.c
@@ -1,6 +1,9 @@
/*
* Utilities for paths and pathnames
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
diff --git a/pathspec.c b/pathspec.c
index 2133b9fe60..fe1f0f41af 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "parse.h"
diff --git a/pretty.c b/pretty.c
index 22a81506b7..2c14a88abc 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/progress.c b/progress.c
index c83cb60bf1..0d44c18edc 100644
--- a/progress.c
+++ b/progress.c
@@ -9,6 +9,8 @@
*/
#define GIT_TEST_PROGRESS_ONLY
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "pager.h"
#include "progress.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 2ca7c2ae48..317e1b127f 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/range-diff.c b/range-diff.c
index c45b6d849c..5f01605550 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/reachable.c b/reachable.c
index 1224b30008..46613a6bb6 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/read-cache.c b/read-cache.c
index 085b22faf3..48bf24f87c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,6 +3,9 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bulk-checkin.h"
#include "config.h"
diff --git a/rebase-interactive.c b/rebase-interactive.c
index c343e16fcd..e93b385523 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "editor.h"
diff --git a/ref-filter.c b/ref-filter.c
index f7fb0c7e0e..8c5e673fc0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/reflog-walk.c b/reflog-walk.c
index 5f09552c5c..c7070b13b0 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "refs.h"
diff --git a/reflog.c b/reflog.c
index 3c80950186..5ca944529b 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "object-store-ll.h"
diff --git a/refs.c b/refs.c
index 6e7caefdcf..727ed6c1d6 100644
--- a/refs.c
+++ b/refs.c
@@ -2,6 +2,8 @@
* The backend-independent part of the reference module.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index b484b5880d..35931bc71e 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../copy.h"
#include "../environment.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 5ab1b21d10..a0666407cd 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../config.h"
#include "../dir.h"
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 57df2aba66..6e34eb2188 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../abspath.h"
#include "../chdir-notify.h"
diff --git a/refspec.c b/refspec.c
index d60932f4de..c2e3e24351 100644
--- a/refspec.c
+++ b/refspec.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/remote-curl.c b/remote-curl.c
index 6008d7e87c..1930f83cc7 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "git-curl-compat.h"
#include "config.h"
diff --git a/remote.c b/remote.c
index 1064171085..5fab7f0970 100644
--- a/remote.c
+++ b/remote.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/repository.h b/repository.h
index a35cd77c35..29727edec6 100644
--- a/repository.h
+++ b/repository.h
@@ -197,7 +197,9 @@ struct repository {
unsigned different_commondir:1;
};
+#ifdef USE_THE_REPOSITORY_VARIABLE
extern struct repository *the_repository;
+#endif
/*
* Define a custom repository layout. Any field can be NULL, which
diff --git a/rerere.c b/rerere.c
index c7e1f8fd25..597256fa5b 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/reset.c b/reset.c
index 937f11c0f4..9550dea03d 100644
--- a/reset.c
+++ b/reset.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "cache-tree.h"
#include "gettext.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 4e6f0e4676..8c9911affb 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "hash.h"
diff --git a/revision.c b/revision.c
index 7ddf0f151a..40da255953 100644
--- a/revision.c
+++ b/revision.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/run-command.c b/run-command.c
index 1b821042b4..1f25263d6d 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "run-command.h"
#include "environment.h"
diff --git a/scalar.c b/scalar.c
index 331b91dbdb..a1cb4b45b5 100644
--- a/scalar.c
+++ b/scalar.c
@@ -2,6 +2,8 @@
* The Scalar command-line interface.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "gettext.h"
diff --git a/send-pack.c b/send-pack.c
index 37f59d4f66..b42e6986df 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/sequencer.c b/sequencer.c
index 823691e379..8083fe20bf 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
diff --git a/serve.c b/serve.c
index aa651b73e9..33608ea4d5 100644
--- a/serve.c
+++ b/serve.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
diff --git a/server-info.c b/server-info.c
index 6feaa457c5..97e839c33d 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "environment.h"
diff --git a/setup.c b/setup.c
index 03386dc5ce..58b012f063 100644
--- a/setup.c
+++ b/setup.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "copy.h"
diff --git a/shallow.c b/shallow.c
index a0b181ba8a..31a6ca40fe 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "repository.h"
diff --git a/split-index.c b/split-index.c
index 058a8f448e..120c8190b1 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/streaming.c b/streaming.c
index 10adf625b2..38839511af 100644
--- a/streaming.c
+++ b/streaming.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2011, Google Inc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "convert.h"
#include "environment.h"
diff --git a/submodule-config.c b/submodule-config.c
index ad43a282da..9b0bb0b9f4 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "environment.h"
diff --git a/submodule.c b/submodule.c
index caf3aa5600..ab99a30253 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index af43ee1cb5..1f18d57007 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "git-compat-util.h"
#include "pack-bitmap.h"
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index 1281e66876..f7f9b62002 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "bloom.h"
#include "hex.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index dc89ecfd71..5cdef3ebef 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "gettext.h"
#include "hex.h"
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 02b0b46c3f..3f0c7d0ed0 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hash.h"
#include "hex.h"
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 4f215fea02..1b7f37a84f 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "read-cache-ll.h"
#include "repository.h"
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index f472691a3c..a6720faf9c 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index 9ff67c3967..4f010d5324 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "dir.h"
#include "hex.h"
diff --git a/t/helper/test-example-decorate.c b/t/helper/test-example-decorate.c
index 8f59f6be4c..e8a8a5dc26 100644
--- a/t/helper/test-example-decorate.c
+++ b/t/helper/test-example-decorate.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "git-compat-util.h"
#include "object.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index e8bd793e58..14b2b0c12c 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "object-name.h"
#include "object-store.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 8280984d08..02bfe92e8d 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -3,6 +3,8 @@
* a `git fsmonitor--daemon` daemon.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "parse-options.h"
#include "fsmonitor-ipc.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 5f33bb7b8f..40f5df4412 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "environment.h"
#include "name-hash.h"
diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c
index d0db5ff26f..e0e2048320 100644
--- a/t/helper/test-match-trees.c
+++ b/t/helper/test-match-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "match-trees.h"
diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c
index bd30244a54..c03cfa5ecf 100644
--- a/t/helper/test-oidmap.c
+++ b/t/helper/test-oidmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "object-name.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 67a964ef90..f8f9afbb5b 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 1ba226f1f9..5dd374379c 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit.h"
#include "commit-reach.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index e803c43ece..d285c656bd 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "config.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8c7a83f578..d9e980d04c 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 4acae41bb9..83effc2b5f 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "midx.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index ad24300170..637b8b294e 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "refs.h"
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 0c7c5aa4dd..c6a074df3d 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit-graph.h"
#include "commit.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index f346951bc2..071f5bd1e2 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -8,6 +8,8 @@
* published by the Free Software Foundation.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit.h"
#include "diff.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 737cbe475b..64fff6e9e3 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "lockfile.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 4b809d9dca..cbe93f2f9e 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "config.h"
#include "hash.h"
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index ecd40ded99..6ca069ce63 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index 7197969a08..22e518d229 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "test-tool-utils.h"
#include "parse-options.h"
diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c
index 1adac29a57..cd955ec63e 100644
--- a/t/helper/test-trace2.c
+++ b/t/helper/test-trace2.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "strvec.h"
#include "run-command.h"
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index 7e3da380a9..b37dd2c5d6 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "lockfile.h"
#include "read-cache-ll.h"
diff --git a/tag.c b/tag.c
index 52bbe50819..d24170e340 100644
--- a/tag.c
+++ b/tag.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "tag.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 3509258be5..a8e4553f27 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tmp-objdir.h"
#include "abspath.h"
diff --git a/transport-helper.c b/transport-helper.c
index 9820947ab2..09b3560ffd 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "transport.h"
#include "quote.h"
diff --git a/transport.c b/transport.c
index 83ddea8fbc..b9c8827ed9 100644
--- a/transport.c
+++ b/transport.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/tree-walk.c b/tree-walk.c
index 535a3a2539..a033397965 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tree-walk.h"
#include "dir.h"
diff --git a/tree.c b/tree.c
index 7973d3f9a8..ad86ad1ba9 100644
--- a/tree.c
+++ b/tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "tree.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 304ea2ed86..7dc884fafd 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "strvec.h"
diff --git a/upload-pack.c b/upload-pack.c
index b726f7a57d..0052c6a4dc 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/walker.c b/walker.c
index 946d86b04e..0fafdc97cf 100644
--- a/walker.c
+++ b/walker.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/worktree.c b/worktree.c
index 70844d023a..f3c4c8ec54 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
diff --git a/wt-status.c b/wt-status.c
index 5051f5e599..8815df419e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "wt-status.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 16ed8ac492..d5dc88661e 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "config.h"
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 10/21] refs: avoid include cycle with "repository.h"
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (8 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 09/21] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 11/21] hash-ll: merge with "hash.h" Patrick Steinhardt
` (13 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1797 bytes --]
There is an include cycle between "refs.h" and "repository.h" via
"commit.h", "object.h" and "hash.h". This has the effect that several
definitions of structs and enums will not be visible once we merge
"hash-ll.h" back into "hash.h" in the next commit.
The only reason that "repository.h" includes "refs.h" is the definition
of `enum ref_storage_format`. Move it into "repository.h" and have
"refs.h" include "repository.h" instead to fix the cycle.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
refs.h | 8 +-------
repository.h | 7 ++++++-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/refs.h b/refs.h
index 76d25df4de..a9716e5d25 100644
--- a/refs.h
+++ b/refs.h
@@ -2,21 +2,15 @@
#define REFS_H
#include "commit.h"
+#include "repository.h"
struct object_id;
struct ref_store;
-struct repository;
struct strbuf;
struct string_list;
struct string_list_item;
struct worktree;
-enum ref_storage_format {
- REF_STORAGE_FORMAT_UNKNOWN,
- REF_STORAGE_FORMAT_FILES,
- REF_STORAGE_FORMAT_REFTABLE,
-};
-
enum ref_storage_format ref_storage_format_by_name(const char *name);
const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_format);
diff --git a/repository.h b/repository.h
index 29727edec6..6ce6826c26 100644
--- a/repository.h
+++ b/repository.h
@@ -1,7 +1,6 @@
#ifndef REPOSITORY_H
#define REPOSITORY_H
-#include "refs.h"
#include "strmap.h"
struct config_set;
@@ -27,6 +26,12 @@ enum fetch_negotiation_setting {
FETCH_NEGOTIATION_NOOP,
};
+enum ref_storage_format {
+ REF_STORAGE_FORMAT_UNKNOWN,
+ REF_STORAGE_FORMAT_FILES,
+ REF_STORAGE_FORMAT_REFTABLE,
+};
+
struct repo_settings {
int initialized;
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 11/21] hash-ll: merge with "hash.h"
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (9 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 10/21] refs: avoid include cycle with "repository.h" Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 12/21] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
` (12 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 36432 bytes --]
The "hash-ll.h" header was introduced via d1cbe1e6d8 (hash-ll.h: split
out of hash.h to remove dependency on repository.h, 2023-04-22) to make
explicit the split between hash-related functions that rely on the
global `the_repository`, and those that don't. This split is no longer
necessary now that we we have removed the reliance on `the_repository`.
Merge "hash-ll.h" back into "hash.h". This causes some code units to not
include "repository.h" anymore, which requires us to add some forward
declarations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.h | 2 +-
bloom.c | 1 +
checkout.h | 2 +-
chunk-format.h | 2 +-
commit-graph.h | 2 +
compat/sha1-chunked.c | 2 +-
convert.h | 2 +-
csum-file.h | 2 +-
diff.h | 2 +-
diffcore.h | 2 +-
dir.h | 2 +-
hash-ll.h | 364 -------------------------------------
hash.h | 362 +++++++++++++++++++++++++++++++++++-
hex.h | 2 +-
loose.h | 2 +
merge-ort.h | 2 +-
object-file-convert.c | 2 +-
object.h | 2 +-
oidmap.h | 2 +-
oidtree.h | 2 +-
packfile.h | 2 +
protocol-caps.c | 2 +-
read-cache-ll.h | 2 +-
refs/ref-cache.h | 2 +-
reftable/dump.c | 2 +-
reftable/reftable-record.h | 2 +-
reftable/system.h | 2 +-
remote.h | 2 +-
reset.h | 2 +-
resolve-undo.h | 2 +-
serve.c | 2 +-
split-index.h | 2 +-
t/helper/test-hash-speed.c | 2 +-
t/helper/test-sha1.c | 2 +-
t/helper/test-sha256.c | 2 +-
tree-diff.c | 1 +
tree-walk.h | 2 +-
xdiff-interface.h | 2 +-
38 files changed, 399 insertions(+), 397 deletions(-)
delete mode 100644 hash-ll.h
diff --git a/apply.h b/apply.h
index 7cd38b1443..b9f18ce87d 100644
--- a/apply.h
+++ b/apply.h
@@ -1,7 +1,7 @@
#ifndef APPLY_H
#define APPLY_H
-#include "hash-ll.h"
+#include "hash.h"
#include "lockfile.h"
#include "string-list.h"
#include "strmap.h"
diff --git a/bloom.c b/bloom.c
index e529f7605c..bbf146fc30 100644
--- a/bloom.c
+++ b/bloom.c
@@ -6,6 +6,7 @@
#include "commit-graph.h"
#include "commit.h"
#include "commit-slab.h"
+#include "repository.h"
define_commit_slab(bloom_filter_slab, struct bloom_filter);
diff --git a/checkout.h b/checkout.h
index ba15a13fb3..55920e7aeb 100644
--- a/checkout.h
+++ b/checkout.h
@@ -1,7 +1,7 @@
#ifndef CHECKOUT_H
#define CHECKOUT_H
-#include "hash-ll.h"
+#include "hash.h"
/*
* Check if the branch name uniquely matches a branch name on a remote
diff --git a/chunk-format.h b/chunk-format.h
index 14b76180ef..212a0a6af1 100644
--- a/chunk-format.h
+++ b/chunk-format.h
@@ -1,7 +1,7 @@
#ifndef CHUNK_FORMAT_H
#define CHUNK_FORMAT_H
-#include "hash-ll.h"
+#include "hash.h"
struct hashfile;
struct chunkfile;
diff --git a/commit-graph.h b/commit-graph.h
index e519cb81cb..6781940195 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -122,6 +122,8 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
struct commit_graph *read_commit_graph_one(struct repository *r,
struct object_directory *odb);
+struct repo_settings;
+
/*
* Callers should initialize the repo_settings with prepare_repo_settings()
* prior to calling parse_commit_graph().
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index a4a6f930d7..0446f9983f 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "hash-ll.h"
+#include "hash.h"
int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
{
diff --git a/convert.h b/convert.h
index d925589444..0a6e4086b8 100644
--- a/convert.h
+++ b/convert.h
@@ -4,7 +4,7 @@
#ifndef CONVERT_H
#define CONVERT_H
-#include "hash-ll.h"
+#include "hash.h"
#include "string-list.h"
struct index_state;
diff --git a/csum-file.h b/csum-file.h
index bc5bec27ac..566e05cbd2 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -1,7 +1,7 @@
#ifndef CSUM_FILE_H
#define CSUM_FILE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "write-or-die.h"
struct progress;
diff --git a/diff.h b/diff.h
index 66bd8aeb29..9901c8ca8c 100644
--- a/diff.h
+++ b/diff.h
@@ -4,7 +4,7 @@
#ifndef DIFF_H
#define DIFF_H
-#include "hash-ll.h"
+#include "hash.h"
#include "pathspec.h"
#include "strbuf.h"
diff --git a/diffcore.h b/diffcore.h
index 5ffe4ec788..1701ed50b9 100644
--- a/diffcore.h
+++ b/diffcore.h
@@ -4,7 +4,7 @@
#ifndef DIFFCORE_H
#define DIFFCORE_H
-#include "hash-ll.h"
+#include "hash.h"
struct diff_options;
struct mem_pool;
diff --git a/dir.h b/dir.h
index b9e8e96128..c9b0123e05 100644
--- a/dir.h
+++ b/dir.h
@@ -1,7 +1,7 @@
#ifndef DIR_H
#define DIR_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "pathspec.h"
#include "statinfo.h"
diff --git a/hash-ll.h b/hash-ll.h
deleted file mode 100644
index 3161c778b9..0000000000
--- a/hash-ll.h
+++ /dev/null
@@ -1,364 +0,0 @@
-#ifndef HASH_LL_H
-#define HASH_LL_H
-
-#if defined(SHA1_APPLE)
-#include <CommonCrypto/CommonDigest.h>
-#elif defined(SHA1_OPENSSL)
-# include <openssl/sha.h>
-# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
-# define SHA1_NEEDS_CLONE_HELPER
-# include "sha1/openssl.h"
-# endif
-#elif defined(SHA1_DC)
-#include "sha1dc_git.h"
-#else /* SHA1_BLK */
-#include "block-sha1/sha1.h"
-#endif
-
-#if defined(SHA256_NETTLE)
-#include "sha256/nettle.h"
-#elif defined(SHA256_GCRYPT)
-#define SHA256_NEEDS_CLONE_HELPER
-#include "sha256/gcrypt.h"
-#elif defined(SHA256_OPENSSL)
-# include <openssl/sha.h>
-# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
-# define SHA256_NEEDS_CLONE_HELPER
-# include "sha256/openssl.h"
-# endif
-#else
-#include "sha256/block/sha256.h"
-#endif
-
-#ifndef platform_SHA_CTX
-/*
- * platform's underlying implementation of SHA-1; could be OpenSSL,
- * blk_SHA, Apple CommonCrypto, etc... Note that the relevant
- * SHA-1 header may have already defined platform_SHA_CTX for our
- * own implementations like block-sha1, so we list
- * the default for OpenSSL compatible SHA-1 implementations here.
- */
-#define platform_SHA_CTX SHA_CTX
-#define platform_SHA1_Init SHA1_Init
-#define platform_SHA1_Update SHA1_Update
-#define platform_SHA1_Final SHA1_Final
-#endif
-
-#define git_SHA_CTX platform_SHA_CTX
-#define git_SHA1_Init platform_SHA1_Init
-#define git_SHA1_Update platform_SHA1_Update
-#define git_SHA1_Final platform_SHA1_Final
-
-#ifdef platform_SHA1_Clone
-#define git_SHA1_Clone platform_SHA1_Clone
-#endif
-
-#ifndef platform_SHA256_CTX
-#define platform_SHA256_CTX SHA256_CTX
-#define platform_SHA256_Init SHA256_Init
-#define platform_SHA256_Update SHA256_Update
-#define platform_SHA256_Final SHA256_Final
-#endif
-
-#define git_SHA256_CTX platform_SHA256_CTX
-#define git_SHA256_Init platform_SHA256_Init
-#define git_SHA256_Update platform_SHA256_Update
-#define git_SHA256_Final platform_SHA256_Final
-
-#ifdef platform_SHA256_Clone
-#define git_SHA256_Clone platform_SHA256_Clone
-#endif
-
-#ifdef SHA1_MAX_BLOCK_SIZE
-#include "compat/sha1-chunked.h"
-#undef git_SHA1_Update
-#define git_SHA1_Update git_SHA1_Update_Chunked
-#endif
-
-#ifndef SHA1_NEEDS_CLONE_HELPER
-static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
-{
- memcpy(dst, src, sizeof(*dst));
-}
-#endif
-
-#ifndef SHA256_NEEDS_CLONE_HELPER
-static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
-{
- memcpy(dst, src, sizeof(*dst));
-}
-#endif
-
-/*
- * Note that these constants are suitable for indexing the hash_algos array and
- * comparing against each other, but are otherwise arbitrary, so they should not
- * be exposed to the user or serialized to disk. To know whether a
- * git_hash_algo struct points to some usable hash function, test the format_id
- * field for being non-zero. Use the name field for user-visible situations and
- * the format_id field for fixed-length fields on disk.
- */
-/* An unknown hash function. */
-#define GIT_HASH_UNKNOWN 0
-/* SHA-1 */
-#define GIT_HASH_SHA1 1
-/* SHA-256 */
-#define GIT_HASH_SHA256 2
-/* Number of algorithms supported (including unknown). */
-#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
-
-/* "sha1", big-endian */
-#define GIT_SHA1_FORMAT_ID 0x73686131
-
-/* The length in bytes and in hex digits of an object name (SHA-1 value). */
-#define GIT_SHA1_RAWSZ 20
-#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
-/* The block size of SHA-1. */
-#define GIT_SHA1_BLKSZ 64
-
-/* "s256", big-endian */
-#define GIT_SHA256_FORMAT_ID 0x73323536
-
-/* The length in bytes and in hex digits of an object name (SHA-256 value). */
-#define GIT_SHA256_RAWSZ 32
-#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
-/* The block size of SHA-256. */
-#define GIT_SHA256_BLKSZ 64
-
-/* The length in byte and in hex digits of the largest possible hash value. */
-#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
-#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
-/* The largest possible block size for any supported hash. */
-#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
-
-struct object_id {
- unsigned char hash[GIT_MAX_RAWSZ];
- int algo; /* XXX requires 4-byte alignment */
-};
-
-#define GET_OID_QUIETLY 01
-#define GET_OID_COMMIT 02
-#define GET_OID_COMMITTISH 04
-#define GET_OID_TREE 010
-#define GET_OID_TREEISH 020
-#define GET_OID_BLOB 040
-#define GET_OID_FOLLOW_SYMLINKS 0100
-#define GET_OID_RECORD_PATH 0200
-#define GET_OID_ONLY_TO_DIE 04000
-#define GET_OID_REQUIRE_PATH 010000
-#define GET_OID_HASH_ANY 020000
-
-#define GET_OID_DISAMBIGUATORS \
- (GET_OID_COMMIT | GET_OID_COMMITTISH | \
- GET_OID_TREE | GET_OID_TREEISH | \
- GET_OID_BLOB)
-
-enum get_oid_result {
- FOUND = 0,
- MISSING_OBJECT = -1, /* The requested object is missing */
- SHORT_NAME_AMBIGUOUS = -2,
- /* The following only apply when symlinks are followed */
- DANGLING_SYMLINK = -4, /*
- * The initial symlink is there, but
- * (transitively) points to a missing
- * in-tree file
- */
- SYMLINK_LOOP = -5,
- NOT_DIR = -6, /*
- * Somewhere along the symlink chain, a path is
- * requested which contains a file as a
- * non-final element.
- */
-};
-
-/* A suitably aligned type for stack allocations of hash contexts. */
-union git_hash_ctx {
- git_SHA_CTX sha1;
- git_SHA256_CTX sha256;
-};
-typedef union git_hash_ctx git_hash_ctx;
-
-typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
-typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src);
-typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
-typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
-typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx);
-
-struct git_hash_algo {
- /*
- * The name of the algorithm, as appears in the config file and in
- * messages.
- */
- const char *name;
-
- /* A four-byte version identifier, used in pack indices. */
- uint32_t format_id;
-
- /* The length of the hash in binary. */
- size_t rawsz;
-
- /* The length of the hash in hex characters. */
- size_t hexsz;
-
- /* The block size of the hash. */
- size_t blksz;
-
- /* The hash initialization function. */
- git_hash_init_fn init_fn;
-
- /* The hash context cloning function. */
- git_hash_clone_fn clone_fn;
-
- /* The hash update function. */
- git_hash_update_fn update_fn;
-
- /* The hash finalization function. */
- git_hash_final_fn final_fn;
-
- /* The hash finalization function for object IDs. */
- git_hash_final_oid_fn final_oid_fn;
-
- /* The OID of the empty tree. */
- const struct object_id *empty_tree;
-
- /* The OID of the empty blob. */
- const struct object_id *empty_blob;
-
- /* The all-zeros OID. */
- const struct object_id *null_oid;
-};
-extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
-
-/*
- * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
- * the name doesn't match a known algorithm.
- */
-int hash_algo_by_name(const char *name);
-/* Identical, except based on the format ID. */
-int hash_algo_by_id(uint32_t format_id);
-/* Identical, except based on the length. */
-int hash_algo_by_length(int len);
-/* Identical, except for a pointer to struct git_hash_algo. */
-static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
-{
- return p - hash_algos;
-}
-
-const struct object_id *null_oid(void);
-
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
-{
- /*
- * Teach the compiler that there are only two possibilities of hash size
- * here, so that it can optimize for this case as much as possible.
- */
- if (algop->rawsz == GIT_MAX_RAWSZ)
- return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
- return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
-}
-
-static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
-{
- /*
- * We write this here instead of deferring to hashcmp so that the
- * compiler can properly inline it and avoid calling memcmp.
- */
- if (algop->rawsz == GIT_MAX_RAWSZ)
- return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
- return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
-}
-
-static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
- const struct git_hash_algo *algop)
-{
- memcpy(sha_dst, sha_src, algop->rawsz);
-}
-
-static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
-{
- memset(hash, 0, algop->rawsz);
-}
-
-static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
-{
- return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
-}
-
-static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
-{
- return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
-}
-
-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;
-}
-
-static inline void oidread(struct object_id *oid, const unsigned char *hash,
- const struct git_hash_algo *algop)
-{
- memcpy(oid->hash, hash, algop->rawsz);
- if (algop->rawsz < GIT_MAX_RAWSZ)
- memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline void oidclr(struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- memset(oid->hash, 0, GIT_MAX_RAWSZ);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline struct object_id *oiddup(const struct object_id *src)
-{
- struct object_id *dst = xmalloc(sizeof(struct object_id));
- oidcpy(dst, src);
- return dst;
-}
-
-static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
-{
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-/*
- * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
- * for use in hash tables. Cryptographic hashes are supposed to have
- * uniform distribution, so in contrast to `memhash()`, this just copies
- * the first `sizeof(int)` bytes without shuffling any bits. Note that
- * the results will be different on big-endian and little-endian
- * platforms, so they should not be stored or transferred over the net.
- */
-static inline unsigned int oidhash(const struct object_id *oid)
-{
- /*
- * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
- * platforms that don't support unaligned reads.
- */
- unsigned int hash;
- memcpy(&hash, oid->hash, sizeof(hash));
- return hash;
-}
-
-static inline int is_null_oid(const struct object_id *oid)
-{
- static const unsigned char null_hash[GIT_MAX_RAWSZ];
- return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
-}
-
-const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
-
-static inline int is_empty_blob_oid(const struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- return oideq(oid, algop->empty_blob);
-}
-
-static inline int is_empty_tree_oid(const struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- return oideq(oid, algop->empty_tree);
-}
-
-#endif
diff --git a/hash.h b/hash.h
index cb85d26a2f..72ffbc862e 100644
--- a/hash.h
+++ b/hash.h
@@ -1,11 +1,369 @@
#ifndef HASH_H
#define HASH_H
-#include "hash-ll.h"
-#include "repository.h"
+#if defined(SHA1_APPLE)
+#include <CommonCrypto/CommonDigest.h>
+#elif defined(SHA1_OPENSSL)
+# include <openssl/sha.h>
+# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
+# define SHA1_NEEDS_CLONE_HELPER
+# include "sha1/openssl.h"
+# endif
+#elif defined(SHA1_DC)
+#include "sha1dc_git.h"
+#else /* SHA1_BLK */
+#include "block-sha1/sha1.h"
+#endif
+
+#if defined(SHA256_NETTLE)
+#include "sha256/nettle.h"
+#elif defined(SHA256_GCRYPT)
+#define SHA256_NEEDS_CLONE_HELPER
+#include "sha256/gcrypt.h"
+#elif defined(SHA256_OPENSSL)
+# include <openssl/sha.h>
+# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
+# define SHA256_NEEDS_CLONE_HELPER
+# include "sha256/openssl.h"
+# endif
+#else
+#include "sha256/block/sha256.h"
+#endif
+
+#ifndef platform_SHA_CTX
+/*
+ * platform's underlying implementation of SHA-1; could be OpenSSL,
+ * blk_SHA, Apple CommonCrypto, etc... Note that the relevant
+ * SHA-1 header may have already defined platform_SHA_CTX for our
+ * own implementations like block-sha1, so we list
+ * the default for OpenSSL compatible SHA-1 implementations here.
+ */
+#define platform_SHA_CTX SHA_CTX
+#define platform_SHA1_Init SHA1_Init
+#define platform_SHA1_Update SHA1_Update
+#define platform_SHA1_Final SHA1_Final
+#endif
+
+#define git_SHA_CTX platform_SHA_CTX
+#define git_SHA1_Init platform_SHA1_Init
+#define git_SHA1_Update platform_SHA1_Update
+#define git_SHA1_Final platform_SHA1_Final
+
+#ifdef platform_SHA1_Clone
+#define git_SHA1_Clone platform_SHA1_Clone
+#endif
+
+#ifndef platform_SHA256_CTX
+#define platform_SHA256_CTX SHA256_CTX
+#define platform_SHA256_Init SHA256_Init
+#define platform_SHA256_Update SHA256_Update
+#define platform_SHA256_Final SHA256_Final
+#endif
+
+#define git_SHA256_CTX platform_SHA256_CTX
+#define git_SHA256_Init platform_SHA256_Init
+#define git_SHA256_Update platform_SHA256_Update
+#define git_SHA256_Final platform_SHA256_Final
+
+#ifdef platform_SHA256_Clone
+#define git_SHA256_Clone platform_SHA256_Clone
+#endif
+
+#ifdef SHA1_MAX_BLOCK_SIZE
+#include "compat/sha1-chunked.h"
+#undef git_SHA1_Update
+#define git_SHA1_Update git_SHA1_Update_Chunked
+#endif
+
+#ifndef SHA1_NEEDS_CLONE_HELPER
+static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
+{
+ memcpy(dst, src, sizeof(*dst));
+}
+#endif
+
+#ifndef SHA256_NEEDS_CLONE_HELPER
+static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
+{
+ memcpy(dst, src, sizeof(*dst));
+}
+#endif
+
+/*
+ * Note that these constants are suitable for indexing the hash_algos array and
+ * comparing against each other, but are otherwise arbitrary, so they should not
+ * be exposed to the user or serialized to disk. To know whether a
+ * git_hash_algo struct points to some usable hash function, test the format_id
+ * field for being non-zero. Use the name field for user-visible situations and
+ * the format_id field for fixed-length fields on disk.
+ */
+/* An unknown hash function. */
+#define GIT_HASH_UNKNOWN 0
+/* SHA-1 */
+#define GIT_HASH_SHA1 1
+/* SHA-256 */
+#define GIT_HASH_SHA256 2
+/* Number of algorithms supported (including unknown). */
+#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
+
+/* "sha1", big-endian */
+#define GIT_SHA1_FORMAT_ID 0x73686131
+
+/* The length in bytes and in hex digits of an object name (SHA-1 value). */
+#define GIT_SHA1_RAWSZ 20
+#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
+/* The block size of SHA-1. */
+#define GIT_SHA1_BLKSZ 64
+
+/* "s256", big-endian */
+#define GIT_SHA256_FORMAT_ID 0x73323536
+
+/* The length in bytes and in hex digits of an object name (SHA-256 value). */
+#define GIT_SHA256_RAWSZ 32
+#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
+/* The block size of SHA-256. */
+#define GIT_SHA256_BLKSZ 64
+
+/* The length in byte and in hex digits of the largest possible hash value. */
+#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
+#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
+/* The largest possible block size for any supported hash. */
+#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
+
+struct object_id {
+ unsigned char hash[GIT_MAX_RAWSZ];
+ int algo; /* XXX requires 4-byte alignment */
+};
+
+#define GET_OID_QUIETLY 01
+#define GET_OID_COMMIT 02
+#define GET_OID_COMMITTISH 04
+#define GET_OID_TREE 010
+#define GET_OID_TREEISH 020
+#define GET_OID_BLOB 040
+#define GET_OID_FOLLOW_SYMLINKS 0100
+#define GET_OID_RECORD_PATH 0200
+#define GET_OID_ONLY_TO_DIE 04000
+#define GET_OID_REQUIRE_PATH 010000
+#define GET_OID_HASH_ANY 020000
+
+#define GET_OID_DISAMBIGUATORS \
+ (GET_OID_COMMIT | GET_OID_COMMITTISH | \
+ GET_OID_TREE | GET_OID_TREEISH | \
+ GET_OID_BLOB)
+
+enum get_oid_result {
+ FOUND = 0,
+ MISSING_OBJECT = -1, /* The requested object is missing */
+ SHORT_NAME_AMBIGUOUS = -2,
+ /* The following only apply when symlinks are followed */
+ DANGLING_SYMLINK = -4, /*
+ * The initial symlink is there, but
+ * (transitively) points to a missing
+ * in-tree file
+ */
+ SYMLINK_LOOP = -5,
+ NOT_DIR = -6, /*
+ * Somewhere along the symlink chain, a path is
+ * requested which contains a file as a
+ * non-final element.
+ */
+};
#ifdef USE_THE_REPOSITORY_VARIABLE
+# include "repository.h"
# define the_hash_algo the_repository->hash_algo
#endif
+/* A suitably aligned type for stack allocations of hash contexts. */
+union git_hash_ctx {
+ git_SHA_CTX sha1;
+ git_SHA256_CTX sha256;
+};
+typedef union git_hash_ctx git_hash_ctx;
+
+typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
+typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src);
+typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
+typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
+typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx);
+
+struct git_hash_algo {
+ /*
+ * The name of the algorithm, as appears in the config file and in
+ * messages.
+ */
+ const char *name;
+
+ /* A four-byte version identifier, used in pack indices. */
+ uint32_t format_id;
+
+ /* The length of the hash in binary. */
+ size_t rawsz;
+
+ /* The length of the hash in hex characters. */
+ size_t hexsz;
+
+ /* The block size of the hash. */
+ size_t blksz;
+
+ /* The hash initialization function. */
+ git_hash_init_fn init_fn;
+
+ /* The hash context cloning function. */
+ git_hash_clone_fn clone_fn;
+
+ /* The hash update function. */
+ git_hash_update_fn update_fn;
+
+ /* The hash finalization function. */
+ git_hash_final_fn final_fn;
+
+ /* The hash finalization function for object IDs. */
+ git_hash_final_oid_fn final_oid_fn;
+
+ /* The OID of the empty tree. */
+ const struct object_id *empty_tree;
+
+ /* The OID of the empty blob. */
+ const struct object_id *empty_blob;
+
+ /* The all-zeros OID. */
+ const struct object_id *null_oid;
+};
+extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
+
+/*
+ * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
+ * the name doesn't match a known algorithm.
+ */
+int hash_algo_by_name(const char *name);
+/* Identical, except based on the format ID. */
+int hash_algo_by_id(uint32_t format_id);
+/* Identical, except based on the length. */
+int hash_algo_by_length(int len);
+/* Identical, except for a pointer to struct git_hash_algo. */
+static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
+{
+ return p - hash_algos;
+}
+
+const struct object_id *null_oid(void);
+
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+{
+ /*
+ * Teach the compiler that there are only two possibilities of hash size
+ * here, so that it can optimize for this case as much as possible.
+ */
+ if (algop->rawsz == GIT_MAX_RAWSZ)
+ return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
+ return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+}
+
+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+{
+ /*
+ * We write this here instead of deferring to hashcmp so that the
+ * compiler can properly inline it and avoid calling memcmp.
+ */
+ if (algop->rawsz == GIT_MAX_RAWSZ)
+ return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
+ return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+}
+
+static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
+ const struct git_hash_algo *algop)
+{
+ memcpy(sha_dst, sha_src, algop->rawsz);
+}
+
+static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
+{
+ memset(hash, 0, algop->rawsz);
+}
+
+static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+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;
+}
+
+static inline void oidread(struct object_id *oid, const unsigned char *hash,
+ const struct git_hash_algo *algop)
+{
+ memcpy(oid->hash, hash, algop->rawsz);
+ if (algop->rawsz < GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline void oidclr(struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline struct object_id *oiddup(const struct object_id *src)
+{
+ struct object_id *dst = xmalloc(sizeof(struct object_id));
+ oidcpy(dst, src);
+ return dst;
+}
+
+static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
+{
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+/*
+ * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
+ * for use in hash tables. Cryptographic hashes are supposed to have
+ * uniform distribution, so in contrast to `memhash()`, this just copies
+ * the first `sizeof(int)` bytes without shuffling any bits. Note that
+ * the results will be different on big-endian and little-endian
+ * platforms, so they should not be stored or transferred over the net.
+ */
+static inline unsigned int oidhash(const struct object_id *oid)
+{
+ /*
+ * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
+ * platforms that don't support unaligned reads.
+ */
+ unsigned int hash;
+ memcpy(&hash, oid->hash, sizeof(hash));
+ return hash;
+}
+
+static inline int is_null_oid(const struct object_id *oid)
+{
+ static const unsigned char null_hash[GIT_MAX_RAWSZ];
+ return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
+}
+
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
+
+static inline int is_empty_blob_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_blob);
+}
+
+static inline int is_empty_tree_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_tree);
+}
+
#endif
diff --git a/hex.h b/hex.h
index e0b83f776f..9809667f33 100644
--- a/hex.h
+++ b/hex.h
@@ -1,7 +1,7 @@
#ifndef HEX_H
#define HEX_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hex-ll.h"
/*
diff --git a/loose.h b/loose.h
index 2c2957072c..28512306e5 100644
--- a/loose.h
+++ b/loose.h
@@ -3,6 +3,8 @@
#include "khash.h"
+struct repository;
+
struct loose_object_map {
kh_oid_map_t *to_compat;
kh_oid_map_t *to_storage;
diff --git a/merge-ort.h b/merge-ort.h
index ce56ec1a78..a994c9a5fc 100644
--- a/merge-ort.h
+++ b/merge-ort.h
@@ -2,7 +2,7 @@
#define MERGE_ORT_H
#include "merge-recursive.h"
-#include "hash-ll.h"
+#include "hash.h"
struct commit;
struct tree;
diff --git a/object-file-convert.c b/object-file-convert.c
index 958f61f094..3887d6d57b 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -5,7 +5,7 @@
#include "strbuf.h"
#include "hex.h"
#include "repository.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "hash.h"
#include "object.h"
#include "loose.h"
diff --git a/object.h b/object.h
index 73b4ec3904..9fa42d51d9 100644
--- a/object.h
+++ b/object.h
@@ -1,7 +1,7 @@
#ifndef OBJECT_H
#define OBJECT_H
-#include "hash-ll.h"
+#include "hash.h"
struct buffer_slab;
struct repository;
diff --git a/oidmap.h b/oidmap.h
index 05c673eb7c..fad412827a 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -1,7 +1,7 @@
#ifndef OIDMAP_H
#define OIDMAP_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
/*
diff --git a/oidtree.h b/oidtree.h
index 55c83513fd..77898f510a 100644
--- a/oidtree.h
+++ b/oidtree.h
@@ -2,7 +2,7 @@
#define OIDTREE_H
#include "cbtree.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "mem-pool.h"
struct oidtree {
diff --git a/packfile.h b/packfile.h
index 28c8fd3e39..eb18ec15db 100644
--- a/packfile.h
+++ b/packfile.h
@@ -101,6 +101,8 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
+struct raw_object_store;
+
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
diff --git a/protocol-caps.c b/protocol-caps.c
index 75f4cbb0a7..fe8d1d5c63 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -3,7 +3,7 @@
#include "gettext.h"
#include "hex.h"
#include "pkt-line.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "hex.h"
#include "object.h"
#include "object-store-ll.h"
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 09414afd04..e0e39607ef 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -1,7 +1,7 @@
#ifndef READ_CACHE_LL_H
#define READ_CACHE_LL_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "statinfo.h"
diff --git a/refs/ref-cache.h b/refs/ref-cache.h
index 95c76e27c8..31ebe24f6c 100644
--- a/refs/ref-cache.h
+++ b/refs/ref-cache.h
@@ -1,7 +1,7 @@
#ifndef REFS_REF_CACHE_H
#define REFS_REF_CACHE_H
-#include "hash-ll.h"
+#include "hash.h"
struct ref_dir;
struct ref_store;
diff --git a/reftable/dump.c b/reftable/dump.c
index 41abbb8ecf..dd65d9e8bb 100644
--- a/reftable/dump.c
+++ b/reftable/dump.c
@@ -7,7 +7,7 @@ license that can be found in the LICENSE file or at
*/
#include "git-compat-util.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "reftable-blocksource.h"
#include "reftable-error.h"
diff --git a/reftable/reftable-record.h b/reftable/reftable-record.h
index 2a2943cd13..ff486eb1f7 100644
--- a/reftable/reftable-record.h
+++ b/reftable/reftable-record.h
@@ -9,7 +9,7 @@ license that can be found in the LICENSE file or at
#ifndef REFTABLE_RECORD_H
#define REFTABLE_RECORD_H
-#include "hash-ll.h"
+#include "hash.h"
#include <stdint.h>
/*
diff --git a/reftable/system.h b/reftable/system.h
index 5d8b6dede5..d0cabd5d17 100644
--- a/reftable/system.h
+++ b/reftable/system.h
@@ -15,7 +15,7 @@ license that can be found in the LICENSE file or at
#include "lockfile.h"
#include "strbuf.h"
#include "tempfile.h"
-#include "hash-ll.h" /* hash ID, sizes.*/
+#include "hash.h" /* hash ID, sizes.*/
#include "dir.h" /* remove_dir_recursively, for tests.*/
int hash_size(uint32_t id);
diff --git a/remote.h b/remote.h
index e8c6655e42..7d04e1be1b 100644
--- a/remote.h
+++ b/remote.h
@@ -1,7 +1,7 @@
#ifndef REMOTE_H
#define REMOTE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "refspec.h"
diff --git a/reset.h b/reset.h
index 10708d8ddc..a28f81829d 100644
--- a/reset.h
+++ b/reset.h
@@ -1,7 +1,7 @@
#ifndef RESET_H
#define RESET_H
-#include "hash-ll.h"
+#include "hash.h"
#include "repository.h"
#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
diff --git a/resolve-undo.h b/resolve-undo.h
index f3f8462751..89a3227262 100644
--- a/resolve-undo.h
+++ b/resolve-undo.h
@@ -6,7 +6,7 @@ struct index_state;
struct pathspec;
struct string_list;
-#include "hash-ll.h"
+#include "hash.h"
struct resolve_undo_info {
unsigned int mode[3];
diff --git a/serve.c b/serve.c
index 33608ea4d5..884cd84ca8 100644
--- a/serve.c
+++ b/serve.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "pkt-line.h"
#include "version.h"
#include "ls-refs.h"
diff --git a/split-index.h b/split-index.h
index 15a29cd08c..1a153f47ba 100644
--- a/split-index.h
+++ b/split-index.h
@@ -1,7 +1,7 @@
#ifndef SPLIT_INDEX_H
#define SPLIT_INDEX_H
-#include "hash-ll.h"
+#include "hash.h"
struct index_state;
struct strbuf;
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index b235da594f..7de822af51 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
#define NUM_SECONDS 3
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index dcb7f6c003..e60d000c03 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
int cmd__sha1(int ac, const char **av)
{
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 08cf149001..2fb20438f3 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
int cmd__sha256(int ac, const char **av)
{
diff --git a/tree-diff.c b/tree-diff.c
index 46107772d1..9252481df3 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -8,6 +8,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "environment.h"
+#include "repository.h"
/*
* Some mode bits are also used internally for computations.
diff --git a/tree-walk.h b/tree-walk.h
index 0b1067fbc5..aaea689f9a 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -1,7 +1,7 @@
#ifndef TREE_WALK_H
#define TREE_WALK_H
-#include "hash-ll.h"
+#include "hash.h"
struct index_state;
struct repository;
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 38537169b7..1ed430b622 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -1,7 +1,7 @@
#ifndef XDIFF_INTERFACE_H
#define XDIFF_INTERFACE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "xdiff/xdiff.h"
/*
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 12/21] http-fetch: don't crash when parsing packfile without a repo
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (10 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 11/21] hash-ll: merge with "hash.h" Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 13/21] oidset: pass hash algorithm when parsing file Patrick Steinhardt
` (11 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 3160 bytes --]
The git-http-fetch(1) command accepts a `--packfile=` option, which
allows the user to specify that it shall fetch a specific packfile,
only. The parameter here is the hash of the packfile, which is specific
to the object hash used by the repository. This requirement is implicit
though via our use of `parse_oid_hex()`, which internally uses
`the_repository`.
The git-http-fetch(1) command allows for there to be no repository
though, which only exists such that we can show usage via the "-h"
option. In that case though, starting with c8aed5e8da (repository: stop
setting SHA1 as the default object hash, 2024-05-07), `the_repository`
does not have its object hash initialized anymore and thus we would
crash when trying to parse the object ID outside of a repository.
Fix this issue by dying immediately when we see a "--packfile="
parameter when outside a Git repository. This is not a functional
regression as we would die later on with the same error anyway.
Add a test to detect the segfault. We use the "nongit" function to do
so, which we need to allow-list in `test_must_fail ()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
http-fetch.c | 8 +++++++-
t/t5550-http-fetch-dumb.sh | 6 ++++++
t/test-lib-functions.sh | 5 +++++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/http-fetch.c b/http-fetch.c
index bec94988bb..d460bb1837 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
@@ -127,8 +129,12 @@ int cmd_main(int argc, const char **argv)
} else if (skip_prefix(argv[arg], "--packfile=", &p)) {
const char *end;
+ if (nongit)
+ die(_("not a git repository"));
+
packfile = 1;
- if (parse_oid_hex(p, &packfile_hash, &end) || *end)
+ if (parse_oid_hex_algop(p, &packfile_hash, &end,
+ the_repository->hash_algo) || *end)
die(_("argument to --packfile must be a valid hash (got '%s')"), p);
} else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
strvec_push(&index_pack_args, p);
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index 5f16cbc58d..ea8e48f627 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -25,6 +25,12 @@ test_expect_success 'setup repository' '
git commit -m two
'
+test_expect_success 'packfile without repository does not crash' '
+ echo "fatal: not a git repository" >expect &&
+ test_must_fail nongit git http-fetch --packfile=abc 2>err &&
+ test_cmp expect err
+'
+
setup_post_update_server_info_hook () {
test_hook --setup -C "$1" post-update <<-\EOF &&
exec git update-server-info
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 862d80c974..34bc7d7da4 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1096,6 +1096,11 @@ test_must_fail_acceptable () {
done
fi
+ if test "$1" = "nongit"
+ then
+ shift
+ fi
+
case "$1" in
git|__git*|scalar|test-tool|test_terminal)
return 0
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 13/21] oidset: pass hash algorithm when parsing file
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (11 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 12/21] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 14/21] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
` (10 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 3242 bytes --]
The `oidset_parse_file_carefully()` function implicitly depends on
`the_repository` when parsing object IDs. Fix this by having callers
pass in the hash algorithm to use.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/blame.c | 1 +
fsck.c | 3 ++-
oidset.c | 8 +++++---
oidset.h | 4 +++-
4 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index de89fff3f8..18f1a3cea0 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -852,6 +852,7 @@ static void build_ignorelist(struct blame_scoreboard *sb,
oidset_clear(&sb->ignore_list);
else
oidset_parse_file_carefully(&sb->ignore_list, i->string,
+ the_repository->hash_algo,
peel_to_commit_oid, sb);
}
for_each_string_list_item(i, ignore_rev_list) {
diff --git a/fsck.c b/fsck.c
index 432996cbb6..304f4a17ec 100644
--- a/fsck.c
+++ b/fsck.c
@@ -205,7 +205,8 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
if (!strcmp(buf, "skiplist")) {
if (equal == len)
die("skiplist requires a path");
- oidset_parse_file(&options->skiplist, buf + equal + 1);
+ oidset_parse_file(&options->skiplist, buf + equal + 1,
+ the_repository->hash_algo);
buf += len + 1;
continue;
}
diff --git a/oidset.c b/oidset.c
index 91d1385910..8d36aef8dc 100644
--- a/oidset.c
+++ b/oidset.c
@@ -48,12 +48,14 @@ void oidset_clear(struct oidset *set)
oidset_init(set, 0);
}
-void oidset_parse_file(struct oidset *set, const char *path)
+void oidset_parse_file(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop)
{
- oidset_parse_file_carefully(set, path, NULL, NULL);
+ oidset_parse_file_carefully(set, path, algop, NULL, NULL);
}
void oidset_parse_file_carefully(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop,
oidset_parse_tweak_fn fn, void *cbdata)
{
FILE *fp;
@@ -79,7 +81,7 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,
if (!sb.len)
continue;
- if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
+ if (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\0')
die("invalid object name: %s", sb.buf);
if (fn && fn(&oid, cbdata))
continue;
diff --git a/oidset.h b/oidset.h
index 262f4256d6..0106b6f278 100644
--- a/oidset.h
+++ b/oidset.h
@@ -80,7 +80,8 @@ void oidset_clear(struct oidset *set);
* are allowed. Leading whitespace and empty or white-space only lines are
* ignored.
*/
-void oidset_parse_file(struct oidset *set, const char *path);
+void oidset_parse_file(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop);
/*
* Similar to the above, but with a callback which can (1) return non-zero to
@@ -89,6 +90,7 @@ void oidset_parse_file(struct oidset *set, const char *path);
*/
typedef int (*oidset_parse_tweak_fn)(struct object_id *, void *);
void oidset_parse_file_carefully(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop,
oidset_parse_tweak_fn fn, void *cbdata);
struct oidset_iter {
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 14/21] protocol-caps: use hash algorithm from passed-in repository
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (12 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 13/21] oidset: pass hash algorithm when parsing file Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 15/21] replace-object: " Patrick Steinhardt
` (9 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]
In `send_info()`, we pass in a repository but then use `get_oid_hex()`
to parse passed-in object IDs, which implicitly uses `the_repository`.
Fix this by using the hash algorithm from the passed-in repository
instead.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
protocol-caps.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/protocol-caps.c b/protocol-caps.c
index fe8d1d5c63..855f279c2f 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -7,6 +7,7 @@
#include "hex.h"
#include "object.h"
#include "object-store-ll.h"
+#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
@@ -52,7 +53,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
struct object_id oid;
unsigned long object_size;
- if (get_oid_hex(oid_str, &oid) < 0) {
+ if (get_oid_hex_algop(oid_str, &oid, r->hash_algo) < 0) {
packet_writer_error(
writer,
"object-info: protocol error, expected to get oid, not '%s'",
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 15/21] replace-object: use hash algorithm from passed-in repository
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (13 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 14/21] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 16/21] compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC Patrick Steinhardt
` (8 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 939 bytes --]
In `register_replace_ref()`, we pass in a repository but then use
`get_oid_hex()` to parse passed-in object IDs, which implicitly uses
`the_repository`. Fix this by using the hash algorithm from the
passed-in repository instead.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
replace-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/replace-object.c b/replace-object.c
index 73f5acbcd9..59252d565e 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -20,7 +20,7 @@ static int register_replace_ref(const char *refname,
const char *hash = slash ? slash + 1 : refname;
struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj));
- if (get_oid_hex(hash, &repl_obj->original.oid)) {
+ if (get_oid_hex_algop(hash, &repl_obj->original.oid, r->hash_algo)) {
free(repl_obj);
warning(_("bad replace ref name: %s"), refname);
return 0;
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 16/21] compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (14 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 15/21] replace-object: " Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 23:16 ` brian m. carlson
2024-06-11 11:58 ` [PATCH 17/21] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
` (7 subsequent siblings)
23 siblings, 1 reply; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1756 bytes --]
The IPC socket used by the fsmonitor on Darwin is usually contained in
the Git repository itself. When the repository is hosted on a networked
filesystem though, we instead create the socket path in the user's home
directory or the socket directory. In that case, we derive the path by
hashing the repository path.
The hashing implicitly depends on `the_repository` though via
`hash_to_hex()`. For one, this is wrong because we really should be
using the passed-in repository. But arguably, it is not sensible to
derive the path hash from the repository's object hash in the first
place -- they don't have anything to do with each other, and a
repository that is hosted in the same path should always derive the same
IPC socket path.
Fix this by unconditionally using SHA1 to derive the path.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
compat/fsmonitor/fsm-ipc-darwin.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 6f3a95410c..b4d21d6dc2 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -41,9 +41,10 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
/* Create the socket file in either socketDir or $HOME */
if (sock_dir && *sock_dir) {
strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s",
- sock_dir, hash_to_hex(hash));
+ sock_dir, hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
} else {
- strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash));
+ strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s",
+ hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
}
free(sock_dir);
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 17/21] t/helper: use correct object hash in partial-clone helper
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (15 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 16/21] compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 18/21] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
` (6 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]
The `object_info()` function of the partial-clone helper is responsible
for checking the object ID of a repository other than `the_repository`.
We use `parse_oid_hex()` in this function though, which means that we
still depend on `the_repository->hash_algo`.
Fix this by using the object hash of the function-local repository.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-partial-clone.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 910a128614..0ead529167 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -21,7 +21,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
if (repo_init(&r, gitdir, NULL))
die("could not init repo");
- if (parse_oid_hex(oid_hex, &oid, &p))
+ if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
if (oid_object_info_extended(&r, &oid, &oi, 0))
die("could not obtain object info");
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 18/21] t/helper: fix segfault in "oid-array" command without repository
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (16 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 17/21] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
@ 2024-06-11 11:58 ` Patrick Steinhardt
2024-06-11 13:23 ` Ghanshyam Thakkar
2024-06-11 11:59 ` [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree" Patrick Steinhardt
` (5 subsequent siblings)
23 siblings, 1 reply; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 2118 bytes --]
The "oid-array" test helper can supposedly work without a Git
repository, but will in fact crash because `the_repository->hash_algo`
is not initialized. This is because `oid_pos()`, which is used by
`oid_array_lookup()`, depends on `the_hash_algo->rawsz`.
Ideally, we'd adapt `oid_pos()` to not depend on `the_hash_algo`
anymore. That is a bigger untertaking though, so instead we fall back to
SHA1 when there is no repository.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-oid-array.c | 4 ++++
t/t0064-oid-array.sh | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c
index aafe398ef0..076b849cbf 100644
--- a/t/helper/test-oid-array.c
+++ b/t/helper/test-oid-array.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "oid-array.h"
@@ -17,6 +19,8 @@ int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
int nongit_ok;
setup_git_directory_gently(&nongit_ok);
+ if (nongit_ok)
+ repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
while (strbuf_getline(&line, stdin) != EOF) {
const char *arg;
diff --git a/t/t0064-oid-array.sh b/t/t0064-oid-array.sh
index 88c89e8f48..de74b692d0 100755
--- a/t/t0064-oid-array.sh
+++ b/t/t0064-oid-array.sh
@@ -15,6 +15,24 @@ echoid () {
done
}
+test_expect_success 'without repository' '
+ cat >expect <<-EOF &&
+ 4444444444444444444444444444444444444444
+ 5555555555555555555555555555555555555555
+ 8888888888888888888888888888888888888888
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ EOF
+ cat >input <<-EOF &&
+ append 4444444444444444444444444444444444444444
+ append 5555555555555555555555555555555555555555
+ append 8888888888888888888888888888888888888888
+ append aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ for_each_unique
+ EOF
+ nongit test-tool oid-array <input >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'ordered enumeration' '
echoid "" 44 55 88 aa >expect &&
{
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree"
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (17 preceding siblings ...)
2024-06-11 11:58 ` [PATCH 18/21] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
@ 2024-06-11 11:59 ` Patrick Steinhardt
2024-06-11 12:57 ` Ghanshyam Thakkar
2024-06-11 23:17 ` brian m. carlson
2024-06-11 11:59 ` [PATCH 20/21] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
` (4 subsequent siblings)
23 siblings, 2 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:59 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1835 bytes --]
The "oidtree" test helper sets up a Git repository, but this is really
only used such that `get_oid_hex()` can parse both SHA1 and SHA256
object hashes. The `struct oidtree` interface itself does not care at
all about the object hash of `the_repository`, and always asserts that
inserted object IDs have their hash algorithm set.
Stop initializing the repository and instead use `get_oid_hex_any()` to
parse object IDs for the "contains" action, like we already do when
parsing the "insert" action.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-oidtree.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c
index c7a1d4c642..04ec24cc84 100644
--- a/t/helper/test-oidtree.c
+++ b/t/helper/test-oidtree.c
@@ -1,7 +1,6 @@
#include "test-tool.h"
#include "hex.h"
#include "oidtree.h"
-#include "setup.h"
#include "strbuf.h"
static enum cb_next print_oid(const struct object_id *oid, void *data UNUSED)
@@ -14,11 +13,9 @@ int cmd__oidtree(int argc UNUSED, const char **argv UNUSED)
{
struct oidtree ot;
struct strbuf line = STRBUF_INIT;
- int nongit_ok;
int algo = GIT_HASH_UNKNOWN;
oidtree_init(&ot);
- setup_git_directory_gently(&nongit_ok);
while (strbuf_getline(&line, stdin) != EOF) {
const char *arg;
@@ -30,7 +27,7 @@ int cmd__oidtree(int argc UNUSED, const char **argv UNUSED)
algo = oid.algo;
oidtree_insert(&ot, &oid);
} else if (skip_prefix(line.buf, "contains ", &arg)) {
- if (get_oid_hex(arg, &oid))
+ if (get_oid_hex_any(arg, &oid) == GIT_HASH_UNKNOWN)
die("contains not a hexadecimal oid: %s", arg);
printf("%d\n", oidtree_contains(&ot, &oid));
} else if (skip_prefix(line.buf, "each ", &arg)) {
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 20/21] t/helper: remove dependency on `the_repository` in "proc-receive"
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (18 preceding siblings ...)
2024-06-11 11:59 ` [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree" Patrick Steinhardt
@ 2024-06-11 11:59 ` Patrick Steinhardt
2024-06-11 11:59 ` [PATCH 21/21] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
` (3 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:59 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 2061 bytes --]
The "proc-receive" test helper implicitly relies on `the_repository` via
`parse_oid_hex()`. This isn't necessary though, and in fact the whole
command does not depend on `the_repository` at all.
Stop setting up `the_repository` and use `parse_oid_hex_any()` to parse
object IDs.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-proc-receive.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index f30022d222..29361c7aab 100644
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -3,8 +3,8 @@
#include "hex.h"
#include "parse-options.h"
#include "pkt-line.h"
-#include "setup.h"
#include "sigchain.h"
+#include "string-list.h"
static const char *proc_receive_usage[] = {
"test-tool proc-receive [<options>]",
@@ -92,9 +92,9 @@ static void proc_receive_read_commands(struct packet_reader *reader,
if (die_read_commands)
die("die with the --die-read-commands option");
- if (parse_oid_hex(reader->line, &old_oid, &p) ||
+ if (parse_oid_hex_any(reader->line, &old_oid, &p) == GIT_HASH_UNKNOWN ||
*p++ != ' ' ||
- parse_oid_hex(p, &new_oid, &p) ||
+ parse_oid_hex_any(p, &new_oid, &p) == GIT_HASH_UNKNOWN ||
*p++ != ' ')
die("protocol error: expected 'old new ref', got '%s'",
reader->line);
@@ -128,7 +128,6 @@ static void proc_receive_read_push_options(struct packet_reader *reader,
int cmd__proc_receive(int argc, const char **argv)
{
- int nongit_ok = 0;
struct packet_reader reader;
struct command *commands = NULL;
struct string_list push_options = STRING_LIST_INIT_DUP;
@@ -154,8 +153,6 @@ int cmd__proc_receive(int argc, const char **argv)
OPT_END()
};
- setup_git_directory_gently(&nongit_ok);
-
argc = parse_options(argc, argv, "test-tools", options, proc_receive_usage, 0);
if (argc > 0)
usage_msg_opt("Too many arguments.", proc_receive_usage, options);
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH 21/21] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (19 preceding siblings ...)
2024-06-11 11:59 ` [PATCH 20/21] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
@ 2024-06-11 11:59 ` Patrick Steinhardt
2024-06-11 23:24 ` [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro brian m. carlson
` (2 subsequent siblings)
23 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-11 11:59 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 2848 bytes --]
Guard declarations of functions that implicitly use `the_repository`
with `USE_THE_REPOSITORY_VARIABLE` such that callers don't accidentally
rely on that global variable.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hex.h | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/hex.h b/hex.h
index 9809667f33..e9ccb54065 100644
--- a/hex.h
+++ b/hex.h
@@ -13,10 +13,6 @@
* input, so it is safe to pass this function an arbitrary
* null-terminated string.
*/
-int get_hash_hex(const char *hex, unsigned char *hash);
-int get_oid_hex(const char *hex, struct object_id *oid);
-
-/* Like get_oid_hex, but for an arbitrary hash algorithm. */
int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop);
/*
@@ -35,7 +31,6 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_h
char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *);
char *oid_to_hex_r(char *out, const struct object_id *oid);
char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */
-char *hash_to_hex(const unsigned char *hash); /* same static buffer */
char *oid_to_hex(const struct object_id *oid); /* same static buffer */
/*
@@ -45,13 +40,9 @@ char *oid_to_hex(const struct object_id *oid); /* same static buffer */
* other invalid character. end is only updated on success; otherwise, it is
* unmodified.
*/
-int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
-
-/* Like parse_oid_hex, but for an arbitrary hash algorithm. */
int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end,
const struct git_hash_algo *algo);
-
/*
* These functions work like get_oid_hex and parse_oid_hex, but they will parse
* a hex value for any algorithm. The algorithm is detected based on the length
@@ -61,4 +52,19 @@ int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end
int get_oid_hex_any(const char *hex, struct object_id *oid);
int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end);
-#endif
+#ifdef USE_THE_REPOSITORY_VARIABLE
+
+/* Like get_oid_hex_algop, but for `the_hash_algo`. */
+int get_hash_hex(const char *hex, unsigned char *hash);
+int get_oid_hex(const char *hex, struct object_id *oid);
+
+/* Like parse_oid_hex_algop, but uses `the_hash_algo`. */
+int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
+
+/*
+ * Same as `hash_to_hex_algop()`, but uses `the_hash_algo`.
+ */
+char *hash_to_hex(const unsigned char *hash);
+
+#endif /* USE_THE_REPOSITORY_VARIABLE */
+#endif /* HEX_H */
--
2.45.2.436.gcd77e87115.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* Re: [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree"
2024-06-11 11:59 ` [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree" Patrick Steinhardt
@ 2024-06-11 12:57 ` Ghanshyam Thakkar
2024-06-12 7:38 ` Patrick Steinhardt
2024-06-11 23:17 ` brian m. carlson
1 sibling, 1 reply; 94+ messages in thread
From: Ghanshyam Thakkar @ 2024-06-11 12:57 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
On Tue, 11 Jun 2024, Patrick Steinhardt <ps@pks.im> wrote:
> The "oidtree" test helper sets up a Git repository, but this is really
> only used such that `get_oid_hex()` can parse both SHA1 and SHA256
> object hashes. The `struct oidtree` interface itself does not care at
> all about the object hash of `the_repository`, and always asserts that
> inserted object IDs have their hash algorithm set.
>
> Stop initializing the repository and instead use `get_oid_hex_any()` to
> parse object IDs for the "contains" action, like we already do when
> parsing the "insert" action.
I think the motive of this patch is already achieved in
'gt/unit-test-oidtree'[1], if this is to be merged after that.
Thanks.
[1]: https://github.com/git/git/commit/79d9e08db3a08c5a06e2633a39cd38b980e654f4
mailing list: https://lore.kernel.org/git/20240608165731.29467-1-shyamthakkar001@gmail.com/
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> t/helper/test-oidtree.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c
> index c7a1d4c642..04ec24cc84 100644
> --- a/t/helper/test-oidtree.c
> +++ b/t/helper/test-oidtree.c
> @@ -1,7 +1,6 @@
> #include "test-tool.h"
> #include "hex.h"
> #include "oidtree.h"
> -#include "setup.h"
> #include "strbuf.h"
>
> static enum cb_next print_oid(const struct object_id *oid, void *data UNUSED)
> @@ -14,11 +13,9 @@ int cmd__oidtree(int argc UNUSED, const char **argv UNUSED)
> {
> struct oidtree ot;
> struct strbuf line = STRBUF_INIT;
> - int nongit_ok;
> int algo = GIT_HASH_UNKNOWN;
>
> oidtree_init(&ot);
> - setup_git_directory_gently(&nongit_ok);
>
> while (strbuf_getline(&line, stdin) != EOF) {
> const char *arg;
> @@ -30,7 +27,7 @@ int cmd__oidtree(int argc UNUSED, const char **argv UNUSED)
> algo = oid.algo;
> oidtree_insert(&ot, &oid);
> } else if (skip_prefix(line.buf, "contains ", &arg)) {
> - if (get_oid_hex(arg, &oid))
> + if (get_oid_hex_any(arg, &oid) == GIT_HASH_UNKNOWN)
> die("contains not a hexadecimal oid: %s", arg);
> printf("%d\n", oidtree_contains(&ot, &oid));
> } else if (skip_prefix(line.buf, "each ", &arg)) {
> --
> 2.45.2.436.gcd77e87115.dirty
>
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 18/21] t/helper: fix segfault in "oid-array" command without repository
2024-06-11 11:58 ` [PATCH 18/21] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
@ 2024-06-11 13:23 ` Ghanshyam Thakkar
0 siblings, 0 replies; 94+ messages in thread
From: Ghanshyam Thakkar @ 2024-06-11 13:23 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
On Tue, 11 Jun 2024, Patrick Steinhardt <ps@pks.im> wrote:
> The "oid-array" test helper can supposedly work without a Git
> repository, but will in fact crash because `the_repository->hash_algo`
> is not initialized. This is because `oid_pos()`, which is used by
> `oid_array_lookup()`, depends on `the_hash_algo->rawsz`.
>
> Ideally, we'd adapt `oid_pos()` to not depend on `the_hash_algo`
> anymore. That is a bigger untertaking though, so instead we fall back to
> SHA1 when there is no repository.
Thanks for working on this. This would make t-oid-array migration
smoother.
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> t/helper/test-oid-array.c | 4 ++++
> t/t0064-oid-array.sh | 18 ++++++++++++++++++
> 2 files changed, 22 insertions(+)
>
> diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c
> index aafe398ef0..076b849cbf 100644
> --- a/t/helper/test-oid-array.c
> +++ b/t/helper/test-oid-array.c
> @@ -1,3 +1,5 @@
> +#define USE_THE_REPOSITORY_VARIABLE
> +
> #include "test-tool.h"
> #include "hex.h"
> #include "oid-array.h"
> @@ -17,6 +19,8 @@ int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
> int nongit_ok;
>
> setup_git_directory_gently(&nongit_ok);
> + if (nongit_ok)
> + repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
Ideally we would want to test with both SHA1 and SHA256 without the
repo, but it is not a necessity for this patch as it would get solved
when we migrate to the unit testing framework.
> while (strbuf_getline(&line, stdin) != EOF) {
> const char *arg;
> diff --git a/t/t0064-oid-array.sh b/t/t0064-oid-array.sh
> index 88c89e8f48..de74b692d0 100755
> --- a/t/t0064-oid-array.sh
> +++ b/t/t0064-oid-array.sh
> @@ -15,6 +15,24 @@ echoid () {
> done
> }
>
> +test_expect_success 'without repository' '
> + cat >expect <<-EOF &&
> + 4444444444444444444444444444444444444444
> + 5555555555555555555555555555555555555555
> + 8888888888888888888888888888888888888888
> + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> + EOF
> + cat >input <<-EOF &&
> + append 4444444444444444444444444444444444444444
> + append 5555555555555555555555555555555555555555
> + append 8888888888888888888888888888888888888888
> + append aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> + for_each_unique
> + EOF
> + nongit test-tool oid-array <input >actual &&
> + test_cmp expect actual
> +'
> +
> test_expect_success 'ordered enumeration' '
> echoid "" 44 55 88 aa >expect &&
> {
> --
> 2.45.2.436.gcd77e87115.dirty
>
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 16/21] compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC
2024-06-11 11:58 ` [PATCH 16/21] compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC Patrick Steinhardt
@ 2024-06-11 23:16 ` brian m. carlson
2024-06-12 7:38 ` Patrick Steinhardt
0 siblings, 1 reply; 94+ messages in thread
From: brian m. carlson @ 2024-06-11 23:16 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1345 bytes --]
On 2024-06-11 at 11:58:47, Patrick Steinhardt wrote:
> The IPC socket used by the fsmonitor on Darwin is usually contained in
> the Git repository itself. When the repository is hosted on a networked
> filesystem though, we instead create the socket path in the user's home
> directory or the socket directory. In that case, we derive the path by
> hashing the repository path.
>
> The hashing implicitly depends on `the_repository` though via
> `hash_to_hex()`. For one, this is wrong because we really should be
> using the passed-in repository. But arguably, it is not sensible to
> derive the path hash from the repository's object hash in the first
> place -- they don't have anything to do with each other, and a
> repository that is hosted in the same path should always derive the same
> IPC socket path.
>
> Fix this by unconditionally using SHA1 to derive the path.
Let's instead use SHA-256 to derive the path. I can imagine that there
might be a time when some users would like to drop support for SHA-1
altogether (for FIPS compliance reasons, say) and we'll make our lives a
lot easier if we avoid more uses of SHA-1.
It is also typically faster when compiled appropriately, although the
amount of data we're processing is very small.
--
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree"
2024-06-11 11:59 ` [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree" Patrick Steinhardt
2024-06-11 12:57 ` Ghanshyam Thakkar
@ 2024-06-11 23:17 ` brian m. carlson
2024-06-12 7:38 ` Patrick Steinhardt
1 sibling, 1 reply; 94+ messages in thread
From: brian m. carlson @ 2024-06-11 23:17 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]
On 2024-06-11 at 11:59:01, Patrick Steinhardt wrote:
> diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c
> index c7a1d4c642..04ec24cc84 100644
> --- a/t/helper/test-oidtree.c
> +++ b/t/helper/test-oidtree.c
> @@ -1,7 +1,6 @@
> #include "test-tool.h"
> #include "hex.h"
> #include "oidtree.h"
> -#include "setup.h"
> #include "strbuf.h"
>
> static enum cb_next print_oid(const struct object_id *oid, void *data UNUSED)
> @@ -14,11 +13,9 @@ int cmd__oidtree(int argc UNUSED, const char **argv UNUSED)
> {
> struct oidtree ot;
> struct strbuf line = STRBUF_INIT;
> - int nongit_ok;
> int algo = GIT_HASH_UNKNOWN;
>
> oidtree_init(&ot);
> - setup_git_directory_gently(&nongit_ok);
>
> while (strbuf_getline(&line, stdin) != EOF) {
> const char *arg;
> @@ -30,7 +27,7 @@ int cmd__oidtree(int argc UNUSED, const char **argv UNUSED)
> algo = oid.algo;
> oidtree_insert(&ot, &oid);
> } else if (skip_prefix(line.buf, "contains ", &arg)) {
> - if (get_oid_hex(arg, &oid))
> + if (get_oid_hex_any(arg, &oid) == GIT_HASH_UNKNOWN)
> die("contains not a hexadecimal oid: %s", arg);
This is not a problem in your code, but this might read more naturally
as "does not contain a hexadecimal oid" or "contains no hexadecimal
oid".
--
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (20 preceding siblings ...)
2024-06-11 11:59 ` [PATCH 21/21] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
@ 2024-06-11 23:24 ` brian m. carlson
2024-06-12 7:37 ` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
23 siblings, 1 reply; 94+ messages in thread
From: brian m. carlson @ 2024-06-11 23:24 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1959 bytes --]
On 2024-06-11 at 11:57:33, Patrick Steinhardt wrote:
> Hi,
>
> use of the `the_repository` variable is nowadays considered to be
> deprecated, and over time we want to convert our codebase to stop using
> it in favor of explicitly passing down the repository to functions via
> parameters. This effort faces some important problems though.
>
> - It is hard to prove that a certain code unit does not use
> `the_repository` anymore when sending patch series. The reviewer has
> no way to verify that it's not used anymore without reading through
> the code itself.
>
> - It is easy to sneak in new usages of `the_repository` by accident
> into a code unit that is already `the_repository`-clean.
>
> - There are many functions which implicitly use `the_repository`,
> which is really hard to spot.
>
> This patch series aims to address those problems by introducing a new
> `USE_THE_REPOSITORY_VARIABLE` macro. When unset, then the declarations
> of `the_repository`, `the_hash_algo` and some functions that implicitly
> depend on them will be hidden away. This makes it trivial to demonstrate
> that a code unit is `the_repository`-free by removing the definition of
> any such macro.
Overall, I left a few comments, but I think this definitely moves us in
the right direction and I'm glad to see it. This obviously improves the
experience with libification and unit testing in a lot of ways, which is
good.
My only caution is that using the *_any functions will cause us a world
of pain if we ever adopt another 256-bit hash function, since it will be
ambiguous which algorithm is to be used. That's why, traditionally, we
haven't assumed a hash algorithm based on the object ID length. I don't
think the amount of uses we have is excessive, even with your changes,
but we'll need to be mindful of that going forward.
--
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-11 23:24 ` [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro brian m. carlson
@ 2024-06-12 7:37 ` Patrick Steinhardt
2024-06-12 10:12 ` Ghanshyam Thakkar
0 siblings, 1 reply; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-12 7:37 UTC (permalink / raw)
To: brian m. carlson, git
[-- Attachment #1: Type: text/plain, Size: 2760 bytes --]
On Tue, Jun 11, 2024 at 11:24:30PM +0000, brian m. carlson wrote:
> On 2024-06-11 at 11:57:33, Patrick Steinhardt wrote:
> > Hi,
> >
> > use of the `the_repository` variable is nowadays considered to be
> > deprecated, and over time we want to convert our codebase to stop using
> > it in favor of explicitly passing down the repository to functions via
> > parameters. This effort faces some important problems though.
> >
> > - It is hard to prove that a certain code unit does not use
> > `the_repository` anymore when sending patch series. The reviewer has
> > no way to verify that it's not used anymore without reading through
> > the code itself.
> >
> > - It is easy to sneak in new usages of `the_repository` by accident
> > into a code unit that is already `the_repository`-clean.
> >
> > - There are many functions which implicitly use `the_repository`,
> > which is really hard to spot.
> >
> > This patch series aims to address those problems by introducing a new
> > `USE_THE_REPOSITORY_VARIABLE` macro. When unset, then the declarations
> > of `the_repository`, `the_hash_algo` and some functions that implicitly
> > depend on them will be hidden away. This makes it trivial to demonstrate
> > that a code unit is `the_repository`-free by removing the definition of
> > any such macro.
>
> Overall, I left a few comments, but I think this definitely moves us in
> the right direction and I'm glad to see it. This obviously improves the
> experience with libification and unit testing in a lot of ways, which is
> good.
>
> My only caution is that using the *_any functions will cause us a world
> of pain if we ever adopt another 256-bit hash function, since it will be
> ambiguous which algorithm is to be used. That's why, traditionally, we
> haven't assumed a hash algorithm based on the object ID length. I don't
> think the amount of uses we have is excessive, even with your changes,
> but we'll need to be mindful of that going forward.
The only cases where I add new calls to `_any()` are in test helpers:
- "t/helper/test-oidtree.c". This one is getting converted to a unit
test by Ghanshyam, so I'll leave it to him to improve this.
- "t/helper/test-proc-receive.c". Here we don't care about the actual
algorithm, the only thing we care about is that we can correctly
parse them and then eventually emit them via `oid_to_hex()` again.
So even if we introduce a second hash function with the same length
this code would continue to work alright.
So I think it should be fine in the context of this series. But the
remark is certainly valid and something we should be cautious about
going forward.
Thanks!
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 16/21] compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC
2024-06-11 23:16 ` brian m. carlson
@ 2024-06-12 7:38 ` Patrick Steinhardt
0 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-12 7:38 UTC (permalink / raw)
To: brian m. carlson, git
[-- Attachment #1: Type: text/plain, Size: 2097 bytes --]
On Tue, Jun 11, 2024 at 11:16:03PM +0000, brian m. carlson wrote:
> On 2024-06-11 at 11:58:47, Patrick Steinhardt wrote:
> > The IPC socket used by the fsmonitor on Darwin is usually contained in
> > the Git repository itself. When the repository is hosted on a networked
> > filesystem though, we instead create the socket path in the user's home
> > directory or the socket directory. In that case, we derive the path by
> > hashing the repository path.
> >
> > The hashing implicitly depends on `the_repository` though via
> > `hash_to_hex()`. For one, this is wrong because we really should be
> > using the passed-in repository. But arguably, it is not sensible to
> > derive the path hash from the repository's object hash in the first
> > place -- they don't have anything to do with each other, and a
> > repository that is hosted in the same path should always derive the same
> > IPC socket path.
> >
> > Fix this by unconditionally using SHA1 to derive the path.
>
> Let's instead use SHA-256 to derive the path. I can imagine that there
> might be a time when some users would like to drop support for SHA-1
> altogether (for FIPS compliance reasons, say) and we'll make our lives a
> lot easier if we avoid more uses of SHA-1.
>
> It is also typically faster when compiled appropriately, although the
> amount of data we're processing is very small.
I only now realize that this actually a bug. The hash is already getting
computed as SHA1 unconditionally like this:
git_SHA1_Init(&sha1ctx);
git_SHA1_Update(&sha1ctx, r->worktree, strlen(r->worktree));
git_SHA1_Final(hash, &sha1ctx);
And then we used to pass the computed hash to `hash_to_hex()`, which is
of course the wrong thing to do in a SHA256 repository because we would
end up printing `GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ` uninitialized bytes.
I agree that we want to convert this to SHA256 eventually. But I'd say
we should keep such a backwards-incompatible change out of this patch
series and handle it as a follow-up.
I'll rephrase the commit message though.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree"
2024-06-11 12:57 ` Ghanshyam Thakkar
@ 2024-06-12 7:38 ` Patrick Steinhardt
0 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-12 7:38 UTC (permalink / raw)
To: Ghanshyam Thakkar; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1129 bytes --]
On Tue, Jun 11, 2024 at 06:27:51PM +0530, Ghanshyam Thakkar wrote:
> On Tue, 11 Jun 2024, Patrick Steinhardt <ps@pks.im> wrote:
> > The "oidtree" test helper sets up a Git repository, but this is really
> > only used such that `get_oid_hex()` can parse both SHA1 and SHA256
> > object hashes. The `struct oidtree` interface itself does not care at
> > all about the object hash of `the_repository`, and always asserts that
> > inserted object IDs have their hash algorithm set.
> >
> > Stop initializing the repository and instead use `get_oid_hex_any()` to
> > parse object IDs for the "contains" action, like we already do when
> > parsing the "insert" action.
>
> I think the motive of this patch is already achieved in
> 'gt/unit-test-oidtree'[1], if this is to be merged after that.
>
> Thanks.
>
> [1]: https://github.com/git/git/commit/79d9e08db3a08c5a06e2633a39cd38b980e654f4
> mailing list: https://lore.kernel.org/git/20240608165731.29467-1-shyamthakkar001@gmail.com/
Okay. I'll make sure to evict this patch once your patch series gets
merged down to "next". Thanks for the hint.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree"
2024-06-11 23:17 ` brian m. carlson
@ 2024-06-12 7:38 ` Patrick Steinhardt
0 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-12 7:38 UTC (permalink / raw)
To: brian m. carlson, git
[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]
On Tue, Jun 11, 2024 at 11:17:57PM +0000, brian m. carlson wrote:
> On 2024-06-11 at 11:59:01, Patrick Steinhardt wrote:
> > diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c
> > index c7a1d4c642..04ec24cc84 100644
> > --- a/t/helper/test-oidtree.c
> > +++ b/t/helper/test-oidtree.c
> > @@ -30,7 +27,7 @@ int cmd__oidtree(int argc UNUSED, const char **argv UNUSED)
> > algo = oid.algo;
> > oidtree_insert(&ot, &oid);
> > } else if (skip_prefix(line.buf, "contains ", &arg)) {
> > - if (get_oid_hex(arg, &oid))
> > + if (get_oid_hex_any(arg, &oid) == GIT_HASH_UNKNOWN)
> > die("contains not a hexadecimal oid: %s", arg);
>
> This is not a problem in your code, but this might read more naturally
> as "does not contain a hexadecimal oid" or "contains no hexadecimal
> oid".
True. I'll leave this as-is though given that Ghanshyam is already busy
converting this test to be a unit test anyway, so I don't want to make
his life harder here.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-12 7:37 ` Patrick Steinhardt
@ 2024-06-12 10:12 ` Ghanshyam Thakkar
0 siblings, 0 replies; 94+ messages in thread
From: Ghanshyam Thakkar @ 2024-06-12 10:12 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: brian m. carlson, git
On Wed, 12 Jun 2024, Patrick Steinhardt <ps@pks.im> wrote:
> On Tue, Jun 11, 2024 at 11:24:30PM +0000, brian m. carlson wrote:
> > On 2024-06-11 at 11:57:33, Patrick Steinhardt wrote:
> > > Hi,
> > >
> > > use of the `the_repository` variable is nowadays considered to be
> > > deprecated, and over time we want to convert our codebase to stop using
> > > it in favor of explicitly passing down the repository to functions via
> > > parameters. This effort faces some important problems though.
> > >
> > > - It is hard to prove that a certain code unit does not use
> > > `the_repository` anymore when sending patch series. The reviewer has
> > > no way to verify that it's not used anymore without reading through
> > > the code itself.
> > >
> > > - It is easy to sneak in new usages of `the_repository` by accident
> > > into a code unit that is already `the_repository`-clean.
> > >
> > > - There are many functions which implicitly use `the_repository`,
> > > which is really hard to spot.
> > >
> > > This patch series aims to address those problems by introducing a new
> > > `USE_THE_REPOSITORY_VARIABLE` macro. When unset, then the declarations
> > > of `the_repository`, `the_hash_algo` and some functions that implicitly
> > > depend on them will be hidden away. This makes it trivial to demonstrate
> > > that a code unit is `the_repository`-free by removing the definition of
> > > any such macro.
> >
> > Overall, I left a few comments, but I think this definitely moves us in
> > the right direction and I'm glad to see it. This obviously improves the
> > experience with libification and unit testing in a lot of ways, which is
> > good.
> >
> > My only caution is that using the *_any functions will cause us a world
> > of pain if we ever adopt another 256-bit hash function, since it will be
> > ambiguous which algorithm is to be used. That's why, traditionally, we
> > haven't assumed a hash algorithm based on the object ID length. I don't
> > think the amount of uses we have is excessive, even with your changes,
> > but we'll need to be mindful of that going forward.
>
> The only cases where I add new calls to `_any()` are in test helpers:
>
> - "t/helper/test-oidtree.c". This one is getting converted to a unit
> test by Ghanshyam, so I'll leave it to him to improve this.
Yeah, I don't use '_any()', and explicitly give algo using '_algop()'.
link:https://lore.kernel.org/git/20240608165731.29467-1-shyamthakkar001@gmail.com/
Thanks.
> - "t/helper/test-proc-receive.c". Here we don't care about the actual
> algorithm, the only thing we care about is that we can correctly
> parse them and then eventually emit them via `oid_to_hex()` again.
> So even if we introduce a second hash function with the same length
> this code would continue to work alright.
>
> So I think it should be fine in the context of this series. But the
> remark is certainly valid and something we should be cautious about
> going forward.
>
> Thanks!
>
> Patrick
^ permalink raw reply [flat|nested] 94+ messages in thread
* [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (21 preceding siblings ...)
2024-06-11 23:24 ` [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro brian m. carlson
@ 2024-06-13 6:13 ` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
` (20 more replies)
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
23 siblings, 21 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:13 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 20271 bytes --]
Hi,
this is the second version of my patch series that introduce a new
`USE_THE_REPOSITORY_VARIABLE` macro. If undefined, then declarations
like `the_repository`, `the_hash_algo` and a subset of functions that
implicitly depend on either of these are hidden away. This is a step
towards fully deprecating and getting rid of this global state.
Changes compared to v1:
- Pull in gt/unit-test-oidtree at ed54840872 (t/: migrate
helper/test-oidtree.c to unit-tests/t-oidtree.c, 2024-06-08) as a
new dependency. I mostly did it because it makes commit 19
redundant, so I've it.
- As the base commit had to be rebuilt anyway I rebased on top of
d63586cb31 (The thirteenth batch, 2024-06-12).
- Rewrote the commit message of patch 16 to explain that this is
actually a bug that is getting fixed.
Thanks!
Patrick
Patrick Steinhardt (20):
hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
hash: require hash algorithm in `hasheq()`, `hashcmp()` and
`hashclr()`
hash: require hash algorithm in `oidread()` and `oidclr()`
global: ensure that object IDs are always padded
hash: convert `oidcmp()` and `oideq()` to compare whole hash
hash: make `is_null_oid()` independent of `the_repository`
hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
hash: require hash algorithm in `empty_tree_oid_hex()`
global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
refs: avoid include cycle with "repository.h"
hash-ll: merge with "hash.h"
http-fetch: don't crash when parsing packfile without a repo
oidset: pass hash algorithm when parsing file
protocol-caps: use hash algorithm from passed-in repository
replace-object: use hash algorithm from passed-in repository
compat/fsmonitor: fix socket path in networked SHA256 repos
t/helper: use correct object hash in partial-clone helper
t/helper: fix segfault in "oid-array" command without repository
t/helper: remove dependency on `the_repository` in "proc-receive"
hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
add-interactive.c | 4 +-
add-patch.c | 4 +-
apply.c | 4 +-
apply.h | 2 +-
archive-tar.c | 3 +
archive-zip.c | 3 +
archive.c | 2 +
attr.c | 2 +
bisect.c | 2 +
blame.c | 4 +-
bloom.c | 1 +
branch.c | 2 +
builtin.h | 8 +
builtin/am.c | 8 +-
builtin/blame.c | 3 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 43 ++-
builtin/fetch-pack.c | 4 +-
builtin/index-pack.c | 11 +-
builtin/log.c | 4 +-
builtin/merge.c | 7 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 3 +-
builtin/pack-redundant.c | 10 +-
builtin/patch-id.c | 6 +-
builtin/pull.c | 6 +-
builtin/receive-pack.c | 4 +-
builtin/replace.c | 2 +-
builtin/rm.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-objects.c | 9 +-
builtin/update-ref.c | 8 +-
bulk-checkin.c | 3 +
bundle-uri.c | 2 +
bundle.c | 2 +
cache-tree.c | 7 +-
checkout.c | 2 +
checkout.h | 2 +-
chunk-format.c | 2 +
chunk-format.h | 2 +-
combine-diff.c | 2 +
commit-graph.c | 22 +-
commit-graph.h | 2 +
commit-reach.c | 2 +
commit.c | 2 +
common-main.c | 2 +
compat/fsmonitor/fsm-ipc-darwin.c | 7 +-
compat/sha1-chunked.c | 2 +-
compat/win32/trace2_win32_process_info.c | 2 +
config.c | 3 +
connected.c | 2 +
convert.c | 2 +
convert.h | 2 +-
csum-file.c | 9 +-
csum-file.h | 2 +-
delta-islands.c | 2 +
diagnose.c | 2 +
diff-lib.c | 7 +-
diff.c | 9 +-
diff.h | 2 +-
diffcore-break.c | 3 +
diffcore-rename.c | 7 +-
diffcore.h | 2 +-
dir.c | 9 +-
dir.h | 2 +-
entry.c | 2 +
environment.c | 3 +
fetch-pack.c | 2 +
fmt-merge-msg.c | 2 +
fsck.c | 5 +-
fsmonitor-ipc.c | 2 +
git.c | 2 +
hash-ll.h | 310 ----------------
hash-lookup.c | 5 +-
hash.h | 366 ++++++++++++++++---
help.c | 2 +
hex.c | 8 +-
hex.h | 28 +-
http-backend.c | 2 +
http-fetch.c | 8 +-
http-push.c | 5 +-
http-walker.c | 6 +-
http.c | 2 +
list-objects-filter-options.c | 2 +
list-objects-filter.c | 2 +
list-objects.c | 2 +
log-tree.c | 2 +
loose.c | 2 +
loose.h | 2 +
ls-refs.c | 2 +
mailmap.c | 2 +
match-trees.c | 6 +-
merge-blobs.c | 2 +
merge-ort.c | 2 +
merge-ort.h | 2 +-
merge-recursive.c | 3 +
merge.c | 2 +
midx-write.c | 2 +
midx.c | 5 +-
negotiator/default.c | 2 +
negotiator/skipping.c | 2 +
notes-cache.c | 2 +
notes-merge.c | 8 +-
notes-utils.c | 2 +
notes.c | 14 +-
object-file-convert.c | 6 +-
object-file.c | 19 +-
object-name.c | 2 +
object.c | 2 +
object.h | 2 +-
oid-array.c | 2 +
oidmap.h | 2 +-
oidset.c | 8 +-
oidset.h | 4 +-
oidtree.c | 4 +-
oidtree.h | 2 +-
oss-fuzz/fuzz-commit-graph.c | 2 +
pack-bitmap-write.c | 6 +-
pack-bitmap.c | 5 +-
pack-check.c | 7 +-
pack-revindex.c | 2 +
pack-write.c | 5 +-
packfile.c | 20 +-
packfile.h | 2 +
parallel-checkout.c | 8 +-
parse-options-cb.c | 2 +
path.c | 3 +
pathspec.c | 2 +
pretty.c | 2 +
progress.c | 2 +
promisor-remote.c | 2 +
protocol-caps.c | 5 +-
range-diff.c | 2 +
reachable.c | 2 +
read-cache-ll.h | 2 +-
read-cache.c | 21 +-
rebase-interactive.c | 2 +
ref-filter.c | 2 +
reflog-walk.c | 2 +
reflog.c | 2 +
refs.c | 8 +-
refs.h | 8 +-
refs/files-backend.c | 8 +-
refs/packed-backend.c | 8 +-
refs/ref-cache.h | 2 +-
refs/reftable-backend.c | 39 +-
refspec.c | 2 +
reftable/dump.c | 2 +-
reftable/reftable-record.h | 2 +-
reftable/system.h | 2 +-
remote-curl.c | 2 +
remote.c | 10 +-
remote.h | 2 +-
replace-object.c | 2 +-
repository.h | 9 +-
rerere.c | 2 +
reset.c | 2 +
reset.h | 2 +-
resolve-undo.c | 5 +-
resolve-undo.h | 2 +-
revision.c | 2 +
run-command.c | 2 +
scalar.c | 2 +
send-pack.c | 2 +
sequencer.c | 8 +-
serve.c | 4 +-
server-info.c | 2 +
setup.c | 2 +
shallow.c | 2 +
split-index.c | 4 +-
split-index.h | 2 +-
streaming.c | 3 +
submodule-config.c | 4 +-
submodule.c | 8 +-
t/helper/test-bitmap.c | 2 +
t/helper/test-bloom.c | 2 +
t/helper/test-cache-tree.c | 2 +
t/helper/test-dump-cache-tree.c | 2 +
t/helper/test-dump-fsmonitor.c | 2 +
t/helper/test-dump-split-index.c | 2 +
t/helper/test-dump-untracked-cache.c | 2 +
t/helper/test-find-pack.c | 2 +
t/helper/test-fsmonitor-client.c | 2 +
t/helper/test-hash-speed.c | 2 +-
t/helper/test-lazy-init-name-hash.c | 2 +
t/helper/test-match-trees.c | 2 +
t/helper/test-oid-array.c | 4 +
t/helper/test-oidmap.c | 2 +
t/helper/test-pack-mtimes.c | 2 +
t/helper/test-partial-clone.c | 2 +-
t/helper/test-proc-receive.c | 9 +-
t/helper/test-reach.c | 2 +
t/helper/test-read-cache.c | 2 +
t/helper/test-read-graph.c | 2 +
t/helper/test-read-midx.c | 2 +
t/helper/test-ref-store.c | 2 +
t/helper/test-repository.c | 2 +
t/helper/test-revision-walking.c | 2 +
t/helper/test-scrap-cache-tree.c | 2 +
t/helper/test-sha1.c | 2 +-
t/helper/test-sha256.c | 2 +-
t/helper/test-submodule-config.c | 4 +-
t/helper/test-submodule-nested-repo-config.c | 2 +
t/helper/test-submodule.c | 2 +
t/helper/test-trace2.c | 2 +
t/helper/test-write-cache.c | 2 +
t/t0064-oid-array.sh | 18 +
t/t5550-http-fetch-dumb.sh | 6 +
t/test-lib-functions.sh | 5 +
t/unit-tests/lib-oid.h | 2 +-
t/unit-tests/t-example-decorate.c | 2 +
tag.c | 2 +
tmp-objdir.c | 2 +
transport-helper.c | 2 +
transport.c | 2 +
tree-diff.c | 1 +
tree-walk.c | 6 +-
tree-walk.h | 2 +-
tree.c | 2 +
unpack-trees.c | 2 +
upload-pack.c | 2 +
walker.c | 2 +
worktree.c | 2 +
wt-status.c | 6 +-
xdiff-interface.c | 2 +
xdiff-interface.h | 2 +-
226 files changed, 994 insertions(+), 617 deletions(-)
delete mode 100644 hash-ll.h
Range-diff against v1:
1: f839013744 = 1: d2154e8c45 hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
2: 687ad9fc02 = 2: aa468c3d88 hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()`
3: 346ca76a7c = 3: 403ea4485b hash: require hash algorithm in `oidread()` and `oidclr()`
4: 3ff28f313b = 4: fa263d6b07 global: ensure that object IDs are always padded
5: e2a0f2125d = 5: a7df209bda hash: convert `oidcmp()` and `oideq()` to compare whole hash
6: 3b6ce3b26c = 6: 9058837c93 hash: make `is_null_oid()` independent of `the_repository`
7: 82a391acac = 7: d26584dc8f hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
8: 3f091dd94a = 8: 4858cca25f hash: require hash algorithm in `empty_tree_oid_hex()`
9: 479bebdf53 ! 9: cb3694ad0e global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
@@ t/helper/test-dump-untracked-cache.c
#include "dir.h"
#include "hex.h"
- ## t/helper/test-example-decorate.c ##
-@@
-+#define USE_THE_REPOSITORY_VARIABLE
-+
- #include "test-tool.h"
- #include "git-compat-util.h"
- #include "object.h"
-
## t/helper/test-find-pack.c ##
@@
+#define USE_THE_REPOSITORY_VARIABLE
@@ t/helper/test-write-cache.c
#include "lockfile.h"
#include "read-cache-ll.h"
+ ## t/unit-tests/t-example-decorate.c ##
+@@
++#define USE_THE_REPOSITORY_VARIABLE
++
+ #include "test-lib.h"
+ #include "object.h"
+ #include "decorate.h"
+
## tag.c ##
@@
+#define USE_THE_REPOSITORY_VARIABLE
10: 7e718c967a = 10: 4492548209 refs: avoid include cycle with "repository.h"
11: fb7544181a ! 11: f3cbc4b9f9 hash-ll: merge with "hash.h"
@@ t/helper/test-sha256.c
int cmd__sha256(int ac, const char **av)
{
+ ## t/unit-tests/lib-oid.h ##
+@@
+ #ifndef LIB_OID_H
+ #define LIB_OID_H
+
+-#include "hash-ll.h"
++#include "hash.h"
+
+ /*
+ * Convert arbitrary hex string to object_id.
+
## tree-diff.c ##
@@
#include "tree.h"
12: b47fa99f3d = 12: 9178098dd7 http-fetch: don't crash when parsing packfile without a repo
13: 95d9b5fa3e = 13: 0b4436c32b oidset: pass hash algorithm when parsing file
14: c877d48f7d = 14: c7abfbc489 protocol-caps: use hash algorithm from passed-in repository
15: ca5f4056fb = 15: 9ae4fdb8f1 replace-object: use hash algorithm from passed-in repository
16: d4e87f9d6b ! 16: 3ceb726655 compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC
@@ Metadata
Author: Patrick Steinhardt <ps@pks.im>
## Commit message ##
- compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC
+ compat/fsmonitor: fix socket path in networked SHA256 repos
The IPC socket used by the fsmonitor on Darwin is usually contained in
the Git repository itself. When the repository is hosted on a networked
@@ Commit message
directory or the socket directory. In that case, we derive the path by
hashing the repository path.
- The hashing implicitly depends on `the_repository` though via
- `hash_to_hex()`. For one, this is wrong because we really should be
- using the passed-in repository. But arguably, it is not sensible to
- derive the path hash from the repository's object hash in the first
- place -- they don't have anything to do with each other, and a
- repository that is hosted in the same path should always derive the same
- IPC socket path.
+ But while we always use SHA1 to hash the repository path, we then end up
+ using `hash_to_hex()` to append the computed hash to the socket path.
+ This is wrong because `hash_to_hex()` uses the hash algorithm configured
+ in `the_repository`, which may not be SHA1. The consequence is that we
+ may append uninitialized bytes to the path when operating in a SHA256
+ repository.
- Fix this by unconditionally using SHA1 to derive the path.
+ Fix this bug by using `hash_to_hex_algop()` with SHA1.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
## compat/fsmonitor/fsm-ipc-darwin.c ##
+@@ compat/fsmonitor/fsm-ipc-darwin.c: const char *fsmonitor_ipc__get_path(struct repository *r)
+ git_SHA_CTX sha1ctx;
+ char *sock_dir = NULL;
+ struct strbuf ipc_file = STRBUF_INIT;
+- unsigned char hash[GIT_MAX_RAWSZ];
++ unsigned char hash[GIT_SHA1_RAWSZ];
+
+ if (!r)
+ BUG("No repository passed into fsmonitor_ipc__get_path");
@@ compat/fsmonitor/fsm-ipc-darwin.c: const char *fsmonitor_ipc__get_path(struct repository *r)
/* Create the socket file in either socketDir or $HOME */
if (sock_dir && *sock_dir) {
17: 5310883469 = 17: 74e5489bd0 t/helper: use correct object hash in partial-clone helper
18: 2774b8500f = 18: 470aea1fc8 t/helper: fix segfault in "oid-array" command without repository
19: 339d668da8 < -: ---------- t/helper: remove dependency on `the_repository` in "oidtree"
20: 97fa3051fa = 19: 1f0682fc7d t/helper: remove dependency on `the_repository` in "proc-receive"
21: 92c7f542d2 = 20: 16fb86c2b2 hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* [PATCH v2 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
@ 2024-06-13 6:13 ` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
` (19 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:13 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]
The functions `is_empty_{blob,tree}_sha1()` are mostly unused, except
for a single callsite in "read-cache.c". Most callsites have long since
been converted to use the equivalents that accept a `struct object_id`
instead of a string.
Adapt the remaining callsite and drop those functions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash.h | 10 ----------
read-cache.c | 2 +-
2 files changed, 1 insertion(+), 11 deletions(-)
diff --git a/hash.h b/hash.h
index e064807c17..a1161e1b22 100644
--- a/hash.h
+++ b/hash.h
@@ -84,21 +84,11 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash)
oidread_algop(oid, hash, the_hash_algo);
}
-static inline int is_empty_blob_sha1(const unsigned char *sha1)
-{
- return hasheq(sha1, the_hash_algo->empty_blob->hash);
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
}
-static inline int is_empty_tree_sha1(const unsigned char *sha1)
-{
- return hasheq(sha1, the_hash_algo->empty_tree->hash);
-}
-
static inline int is_empty_tree_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_tree);
diff --git a/read-cache.c b/read-cache.c
index 447109aa76..10e002ce6d 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
/* Racily smudged entry? */
if (!ce->ce_stat_data.sd_size) {
- if (!is_empty_blob_sha1(ce->oid.hash))
+ if (!is_empty_blob_oid(&ce->oid))
changed |= DATA_CHANGED;
}
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()`
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
@ 2024-06-13 6:13 ` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 03/20] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
` (18 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:13 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 17356 bytes --]
Many of our hash functions have two variants, one receiving a `struct
git_hash_algo` and one that derives it via `the_repository`. Adapt all
of those functions to always require the hash algorithm as input and
drop the variants that do not accept one.
As those functions are now independent of `the_repository`, we can move
them from "hash.h" to "hash-ll.h".
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/index-pack.c | 6 +++---
builtin/pack-redundant.c | 8 +++++---
builtin/unpack-objects.c | 3 ++-
commit-graph.c | 3 ++-
csum-file.c | 6 +++---
hash-ll.h | 15 +++++++++++++--
hash-lookup.c | 3 ++-
hash.h | 24 ++----------------------
http-walker.c | 2 +-
match-trees.c | 2 +-
notes.c | 2 +-
pack-bitmap-write.c | 4 ++--
pack-bitmap.c | 3 ++-
pack-check.c | 5 +++--
pack-write.c | 3 ++-
packfile.c | 8 ++++----
read-cache.c | 8 ++++----
17 files changed, 52 insertions(+), 53 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 856428fef9..ea727fba16 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1204,7 +1204,7 @@ static void parse_pack_objects(unsigned char *hash)
the_hash_algo->init_fn(&tmp_ctx);
the_hash_algo->clone_fn(&tmp_ctx, &input_ctx);
the_hash_algo->final_fn(hash, &tmp_ctx);
- if (!hasheq(fill(the_hash_algo->rawsz), hash))
+ if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo))
die(_("pack is corrupted (SHA1 mismatch)"));
use(the_hash_algo->rawsz);
@@ -1307,11 +1307,11 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
stop_progress_msg(&progress, msg.buf);
strbuf_release(&msg);
finalize_hashfile(f, tail_hash, FSYNC_COMPONENT_PACK, 0);
- hashcpy(read_hash, pack_hash);
+ hashcpy(read_hash, pack_hash, the_repository->hash_algo);
fixup_pack_header_footer(output_fd, pack_hash,
curr_pack, nr_objects,
read_hash, consumed_bytes-the_hash_algo->rawsz);
- if (!hasheq(read_hash, tail_hash))
+ if (!hasheq(read_hash, tail_hash, the_repository->hash_algo))
die(_("Unexpected tail checksum for %s "
"(disk corruption?)"), curr_pack);
}
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 4c735ba069..103c11b9d3 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -155,7 +155,7 @@ static inline struct llist_item * llist_sorted_remove(struct llist *list, const
l = (hint == NULL) ? list->front : hint;
prev = NULL;
while (l) {
- const int cmp = hashcmp(l->oid.hash, oid);
+ const int cmp = hashcmp(l->oid.hash, oid, the_repository->hash_algo);
if (cmp > 0) /* not in list, since sorted */
return prev;
if (!cmp) { /* found */
@@ -258,7 +258,8 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
while (p1_off < p1->pack->num_objects * p1_step &&
p2_off < p2->pack->num_objects * p2_step)
{
- const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
+ const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off,
+ the_repository->hash_algo);
/* cmp ~ p1 - p2 */
if (cmp == 0) {
p1_hint = llist_sorted_remove(p1->unique_objects,
@@ -296,7 +297,8 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
while (p1_off < p1->num_objects * p1_step &&
p2_off < p2->num_objects * p2_step)
{
- int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
+ int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off,
+ the_repository->hash_algo);
/* cmp ~ p1 - p2 */
if (cmp == 0) {
ret++;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f1c85a00ae..0855572c27 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -674,7 +674,8 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
if (fsck_finish(&fsck_options))
die(_("fsck error in pack objects"));
}
- if (!hasheq(fill(the_hash_algo->rawsz), oid.hash))
+ if (!hasheq(fill(the_hash_algo->rawsz), oid.hash,
+ the_repository->hash_algo))
die("final sha1 did not match");
use(the_hash_algo->rawsz);
diff --git a/commit-graph.c b/commit-graph.c
index e5dd3553df..3429156b28 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -565,7 +565,8 @@ static int add_graph_to_chain(struct commit_graph *g,
if (!cur_g ||
!oideq(&oids[n], &cur_g->oid) ||
- !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n))) {
+ !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n),
+ the_repository->hash_algo)) {
warning(_("commit-graph chain does not match"));
return 0;
}
diff --git a/csum-file.c b/csum-file.c
index 870748e016..f4be0804b7 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -68,12 +68,12 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
hashflush(f);
if (f->skip_hash)
- hashclr(f->buffer);
+ hashclr(f->buffer, the_repository->hash_algo);
else
the_hash_algo->final_fn(f->buffer, &f->ctx);
if (result)
- hashcpy(result, f->buffer);
+ hashcpy(result, f->buffer, the_repository->hash_algo);
if (flags & CSUM_HASH_IN_STREAM)
flush(f, f->buffer, the_hash_algo->rawsz);
if (flags & CSUM_FSYNC)
@@ -237,5 +237,5 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
the_hash_algo->update_fn(&ctx, data, data_len);
the_hash_algo->final_fn(got, &ctx);
- return hasheq(got, data + data_len);
+ return hasheq(got, data + data_len, the_repository->hash_algo);
}
diff --git a/hash-ll.h b/hash-ll.h
index 2cfde63ae1..fabdd8ecc7 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -245,7 +245,7 @@ static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
const struct object_id *null_oid(void);
-static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* Teach the compiler that there are only two possibilities of hash size
@@ -256,7 +256,7 @@ static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *
return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
-static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* We write this here instead of deferring to hashcmp so that the
@@ -267,6 +267,17 @@ static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *s
return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
+static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
+ const struct git_hash_algo *algop)
+{
+ memcpy(sha_dst, sha_src, algop->rawsz);
+}
+
+static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
+{
+ memset(hash, 0, algop->rawsz);
+}
+
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
diff --git a/hash-lookup.c b/hash-lookup.c
index 9f0f95e2b9..9aa6b82eb7 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -112,7 +112,8 @@ int bsearch_hash(const unsigned char *hash, const uint32_t *fanout_nbo,
while (lo < hi) {
unsigned mi = lo + (hi - lo) / 2;
- int cmp = hashcmp(table + mi * stride, hash);
+ int cmp = hashcmp(table + mi * stride, hash,
+ the_repository->hash_algo);
if (!cmp) {
if (result)
diff --git a/hash.h b/hash.h
index a1161e1b22..714938e2eb 100644
--- a/hash.h
+++ b/hash.h
@@ -6,11 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
-{
- return hashcmp_algop(sha1, sha2, the_hash_algo);
-}
-
static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
{
const struct git_hash_algo *algop;
@@ -18,12 +13,7 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o
algop = the_hash_algo;
else
algop = &hash_algos[oid1->algo];
- return hashcmp_algop(oid1->hash, oid2->hash, algop);
-}
-
-static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
-{
- return hasheq_algop(sha1, sha2, the_hash_algo);
+ return hashcmp(oid1->hash, oid2->hash, algop);
}
static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
@@ -33,7 +23,7 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi
algop = the_hash_algo;
else
algop = &hash_algos[oid1->algo];
- return hasheq_algop(oid1->hash, oid2->hash, algop);
+ return hasheq(oid1->hash, oid2->hash, algop);
}
static inline int is_null_oid(const struct object_id *oid)
@@ -41,11 +31,6 @@ static inline int is_null_oid(const struct object_id *oid)
return oideq(oid, null_oid());
}
-static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
-{
- memcpy(sha_dst, sha_src, the_hash_algo->rawsz);
-}
-
/* 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)
@@ -62,11 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
dst->algo = src->algo;
}
-static inline void hashclr(unsigned char *hash)
-{
- memset(hash, 0, the_hash_algo->rawsz);
-}
-
static inline void oidclr(struct object_id *oid)
{
memset(oid->hash, 0, GIT_MAX_RAWSZ);
diff --git a/http-walker.c b/http-walker.c
index b395ef1327..cf7f8c82bc 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -485,7 +485,7 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
list_for_each(pos, head) {
obj_req = list_entry(pos, struct object_request, node);
- if (hasheq(obj_req->oid.hash, hash))
+ if (hasheq(obj_req->oid.hash, hash, the_repository->hash_algo))
break;
}
if (!obj_req)
diff --git a/match-trees.c b/match-trees.c
index 3412b6a140..849b391d3d 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -237,7 +237,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
} else {
rewrite_with = oid2;
}
- hashcpy(rewrite_here, rewrite_with->hash);
+ hashcpy(rewrite_here, rewrite_with->hash, the_repository->hash_algo);
status = write_object_file(buf, sz, OBJ_TREE, result);
free(buf);
return status;
diff --git a/notes.c b/notes.c
index 53ca25c814..5296fd863f 100644
--- a/notes.c
+++ b/notes.c
@@ -149,7 +149,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
void **p = note_tree_search(t, &tree, &n, key_sha1);
if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
- if (hasheq(key_sha1, l->key_oid.hash))
+ if (hasheq(key_sha1, l->key_oid.hash, the_repository->hash_algo))
return l;
}
return NULL;
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 6cae670412..59d2e3a387 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -790,7 +790,7 @@ static void write_hash_cache(struct hashfile *f,
void bitmap_writer_set_checksum(struct bitmap_writer *writer,
const unsigned char *sha1)
{
- hashcpy(writer->pack_checksum, sha1);
+ hashcpy(writer->pack_checksum, sha1, the_repository->hash_algo);
}
void bitmap_writer_finish(struct bitmap_writer *writer,
@@ -816,7 +816,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
header.version = htons(default_version);
header.options = htons(flags | options);
header.entry_count = htonl(writer->selected_nr);
- hashcpy(header.checksum, writer->pack_checksum);
+ hashcpy(header.checksum, writer->pack_checksum, the_repository->hash_algo);
hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz);
dump_bitmap(f, writer->commits);
diff --git a/pack-bitmap.c b/pack-bitmap.c
index fe8e8a51d3..184d28f05c 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -367,7 +367,8 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
if (load_bitmap_header(bitmap_git) < 0)
goto cleanup;
- if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum)) {
+ if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum,
+ the_repository->hash_algo)) {
error(_("checksum doesn't match in MIDX and bitmap"));
goto cleanup;
}
diff --git a/pack-check.c b/pack-check.c
index 25104d5b14..288f5a3479 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -78,10 +78,11 @@ static int verify_packfile(struct repository *r,
} while (offset < pack_sig_ofs);
r->hash_algo->final_fn(hash, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
- if (!hasheq(hash, pack_sig))
+ if (!hasheq(hash, pack_sig, r->hash_algo))
err = error("%s pack checksum mismatch",
p->pack_name);
- if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig))
+ if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig,
+ r->hash_algo))
err = error("%s pack checksum does not match its index",
p->pack_name);
unuse_pack(w_curs);
diff --git a/pack-write.c b/pack-write.c
index 80ecfa544c..eef625fa5b 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -428,7 +428,8 @@ void fixup_pack_header_footer(int pack_fd,
if (partial_pack_offset == 0) {
unsigned char hash[GIT_MAX_RAWSZ];
the_hash_algo->final_fn(hash, &old_hash_ctx);
- if (!hasheq(hash, partial_pack_hash))
+ if (!hasheq(hash, partial_pack_hash,
+ the_repository->hash_algo))
die("Unexpected checksum for %s "
"(disk corruption?)", pack_name);
/*
diff --git a/packfile.c b/packfile.c
index d4df7fdeea..9156e9122c 100644
--- a/packfile.c
+++ b/packfile.c
@@ -242,7 +242,7 @@ struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
struct packed_git *p = alloc_packed_git(alloc);
memcpy(p->pack_name, path, alloc); /* includes NUL */
- hashcpy(p->hash, sha1);
+ hashcpy(p->hash, sha1, the_repository->hash_algo);
if (check_packed_git_idx(idx_path, p)) {
free(p);
return NULL;
@@ -596,7 +596,7 @@ static int open_packed_git_1(struct packed_git *p)
if (read_result != hashsz)
return error("packfile %s signature is unavailable", p->pack_name);
idx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;
- if (!hasheq(hash, idx_hash))
+ if (!hasheq(hash, idx_hash, the_repository->hash_algo))
return error("packfile %s does not match index", p->pack_name);
return 0;
}
@@ -751,7 +751,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
p->mtime = st.st_mtime;
if (path_len < the_hash_algo->hexsz ||
get_hash_hex(path + path_len - the_hash_algo->hexsz, p->hash))
- hashclr(p->hash);
+ hashclr(p->hash, the_repository->hash_algo);
return p;
}
@@ -1971,7 +1971,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
return 0;
}
- hashcpy(oid.hash, sha1);
+ hashcpy(oid.hash, sha1, the_repository->hash_algo);
if (bsearch_pack(&oid, p, &result))
return nth_packed_object_offset(p, result);
return 0;
diff --git a/read-cache.c b/read-cache.c
index 10e002ce6d..2642ac9558 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1735,7 +1735,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
the_hash_algo->final_fn(hash, &c);
- if (!hasheq(hash, start))
+ if (!hasheq(hash, start, the_repository->hash_algo))
return error(_("bad index file sha1 signature"));
return 0;
}
@@ -2641,7 +2641,7 @@ static void copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,
ondisk->uid = htonl(ce->ce_stat_data.sd_uid);
ondisk->gid = htonl(ce->ce_stat_data.sd_gid);
ondisk->size = htonl(ce->ce_stat_data.sd_size);
- hashcpy(ondisk->data, ce->oid.hash);
+ hashcpy(ondisk->data, ce->oid.hash, the_repository->hash_algo);
flags = ce->ce_flags & ~CE_NAMEMASK;
flags |= (ce_namelen(ce) >= CE_NAMEMASK ? CE_NAMEMASK : ce_namelen(ce));
@@ -2730,7 +2730,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)
if (n != the_hash_algo->rawsz)
goto out;
- if (!hasheq(istate->oid.hash, hash))
+ if (!hasheq(istate->oid.hash, hash, the_repository->hash_algo))
goto out;
close(fd);
@@ -3603,7 +3603,7 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size)
src_offset += extsize;
}
the_hash_algo->final_fn(hash, &c);
- if (!hasheq(hash, (const unsigned char *)index))
+ if (!hasheq(hash, (const unsigned char *)index, the_repository->hash_algo))
return 0;
/* Validate that the extension offsets returned us back to the eoie extension. */
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 03/20] hash: require hash algorithm in `oidread()` and `oidclr()`
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
@ 2024-06-13 6:13 ` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 04/20] global: ensure that object IDs are always padded Patrick Steinhardt
` (17 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:13 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 48416 bytes --]
Both `oidread()` and `oidclr()` use `the_repository` to derive the hash
function that shall be used. Require callers to pass in the hash
algorithm to get rid of this implicit dependency.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
blame.c | 2 +-
builtin/am.c | 8 +++----
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 39 +++++++++++++++++---------------
builtin/fetch-pack.c | 4 ++--
builtin/index-pack.c | 5 ++--
builtin/log.c | 2 +-
builtin/merge.c | 4 ++--
builtin/notes.c | 2 +-
builtin/pack-objects.c | 3 ++-
builtin/pack-redundant.c | 2 +-
builtin/patch-id.c | 6 ++---
builtin/pull.c | 6 ++---
builtin/receive-pack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rm.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-objects.c | 6 ++---
builtin/update-ref.c | 8 +++----
cache-tree.c | 3 ++-
commit-graph.c | 17 +++++++++-----
diff-lib.c | 4 ++--
diff.c | 6 ++---
dir.c | 6 ++---
hash-ll.h | 14 ++++++++++++
hash.h | 17 --------------
http-push.c | 2 +-
http-walker.c | 2 +-
match-trees.c | 2 +-
midx.c | 3 ++-
notes-merge.c | 6 ++---
notes.c | 8 +++----
object-file-convert.c | 2 +-
object-file.c | 4 ++--
packfile.c | 10 ++++----
read-cache.c | 8 ++++---
refs.c | 6 ++---
refs/files-backend.c | 6 ++---
refs/packed-backend.c | 6 ++---
refs/reftable-backend.c | 37 ++++++++++++++++++------------
remote.c | 8 +++----
resolve-undo.c | 3 ++-
sequencer.c | 4 ++--
split-index.c | 2 +-
submodule-config.c | 2 +-
t/helper/test-submodule-config.c | 2 +-
tree-walk.c | 4 ++--
48 files changed, 163 insertions(+), 140 deletions(-)
diff --git a/apply.c b/apply.c
index 901b67e625..528939abb6 100644
--- a/apply.c
+++ b/apply.c
@@ -3680,7 +3680,7 @@ static int try_threeway(struct apply_state *state,
if (status) {
patch->conflicted_threeway = 1;
if (patch->is_new)
- oidclr(&patch->threeway_stage[0]);
+ oidclr(&patch->threeway_stage[0], the_repository->hash_algo);
else
oidcpy(&patch->threeway_stage[0], &pre_oid);
oidcpy(&patch->threeway_stage[1], &our_oid);
diff --git a/blame.c b/blame.c
index 33586b9777..a80f5e2e61 100644
--- a/blame.c
+++ b/blame.c
@@ -1246,7 +1246,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
goto error_out;
return 0;
error_out:
- oidclr(&origin->blob_oid);
+ oidclr(&origin->blob_oid, the_repository->hash_algo);
origin->mode = S_IFINVALID;
return -1;
}
diff --git a/builtin/am.c b/builtin/am.c
index 36839029d2..45c305ec86 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -408,7 +408,7 @@ static void am_load(struct am_state *state)
read_commit_msg(state);
if (read_state_file(&sb, state, "original-commit", 1) < 0)
- oidclr(&state->orig_commit);
+ oidclr(&state->orig_commit, the_repository->hash_algo);
else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
die(_("could not parse %s"), am_path(state, "original-commit"));
@@ -1121,7 +1121,7 @@ static void am_next(struct am_state *state)
unlink(am_path(state, "author-script"));
unlink(am_path(state, "final-commit"));
- oidclr(&state->orig_commit);
+ oidclr(&state->orig_commit, the_repository->hash_algo);
unlink(am_path(state, "original-commit"));
refs_delete_ref(get_main_ref_store(the_repository), NULL,
"REBASE_HEAD", NULL, REF_NO_DEREF);
@@ -2151,11 +2151,11 @@ static int safe_to_abort(const struct am_state *state)
if (get_oid_hex(sb.buf, &abort_safety))
die(_("could not parse %s"), am_path(state, "abort-safety"));
} else
- oidclr(&abort_safety);
+ oidclr(&abort_safety, the_repository->hash_algo);
strbuf_release(&sb);
if (repo_get_oid(the_repository, "HEAD", &head))
- oidclr(&head);
+ oidclr(&head, the_repository->hash_algo);
if (oideq(&head, &abort_safety))
return 1;
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 4693d18cc9..4b6e8c6832 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -415,7 +415,7 @@ static char *generate_fake_oid(void)
struct object_id oid;
char *hex = xmallocz(GIT_MAX_HEXSZ);
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
put_be32(oid.hash + hashsz - 4, counter++);
return oid_to_hex_r(hex, &oid);
}
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index d1c0243d04..12543488f3 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1279,8 +1279,10 @@ static void load_tree(struct tree_entry *root)
e->versions[0].mode = e->versions[1].mode;
e->name = to_atom(c, strlen(c));
c += e->name->str_len + 1;
- oidread(&e->versions[0].oid, (unsigned char *)c);
- oidread(&e->versions[1].oid, (unsigned char *)c);
+ oidread(&e->versions[0].oid, (unsigned char *)c,
+ the_repository->hash_algo);
+ oidread(&e->versions[1].oid, (unsigned char *)c,
+ the_repository->hash_algo);
c += the_hash_algo->rawsz;
}
free(buf);
@@ -1386,7 +1388,7 @@ static void tree_content_replace(
{
if (!S_ISDIR(mode))
die("Root cannot be a non-directory");
- oidclr(&root->versions[0].oid);
+ oidclr(&root->versions[0].oid, the_repository->hash_algo);
oidcpy(&root->versions[1].oid, oid);
if (root->tree)
release_tree_content_recursive(root->tree);
@@ -1445,7 +1447,7 @@ static int tree_content_set(
if (S_ISDIR(e->versions[0].mode))
e->versions[0].mode |= NO_DELTA;
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
if (!S_ISDIR(e->versions[1].mode)) {
@@ -1455,7 +1457,7 @@ static int tree_content_set(
if (!e->tree)
load_tree(e);
if (tree_content_set(e, slash1 + 1, oid, mode, subtree)) {
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
return 0;
@@ -1467,7 +1469,7 @@ static int tree_content_set(
e = new_tree_entry();
e->name = to_atom(p, n);
e->versions[0].mode = 0;
- oidclr(&e->versions[0].oid);
+ oidclr(&e->versions[0].oid, the_repository->hash_algo);
t->entries[t->entry_count++] = e;
if (*slash1) {
e->tree = new_tree_content(8);
@@ -1478,7 +1480,7 @@ static int tree_content_set(
e->versions[1].mode = mode;
oidcpy(&e->versions[1].oid, oid);
}
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
@@ -1523,7 +1525,8 @@ static int tree_content_remove(
if (tree_content_remove(e, slash1 + 1, backup_leaf, 0)) {
for (n = 0; n < e->tree->entry_count; n++) {
if (e->tree->entries[n]->versions[1].mode) {
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid,
+ the_repository->hash_algo);
return 1;
}
}
@@ -1542,8 +1545,8 @@ static int tree_content_remove(
release_tree_content_recursive(e->tree);
e->tree = NULL;
e->versions[1].mode = 0;
- oidclr(&e->versions[1].oid);
- oidclr(&root->versions[1].oid);
+ oidclr(&e->versions[1].oid, the_repository->hash_algo);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
@@ -1609,7 +1612,7 @@ static int update_branch(struct branch *b)
return 0;
}
if (refs_read_ref(get_main_ref_store(the_repository), b->name, &old_oid))
- oidclr(&old_oid);
+ oidclr(&old_oid, the_repository->hash_algo);
if (!force_update && !is_null_oid(&old_oid)) {
struct commit *old_cmit, *new_cmit;
int ret;
@@ -2550,8 +2553,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
static void file_change_deleteall(struct branch *b)
{
release_tree_content_recursive(b->branch_tree.tree);
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
load_tree(&b->branch_tree);
b->num_notes = 0;
}
@@ -2570,8 +2573,8 @@ static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
static void parse_from_existing(struct branch *b)
{
if (is_null_oid(&b->oid)) {
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
} else {
unsigned long size;
char *buf;
@@ -2894,9 +2897,9 @@ static void parse_reset_branch(const char *arg)
b = lookup_branch(arg);
if (b) {
- oidclr(&b->oid);
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
if (b->branch_tree.tree) {
release_tree_content_recursive(b->branch_tree.tree);
b->branch_tree.tree = NULL;
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 44c05ee86c..af329e8d5c 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -29,11 +29,11 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
; /* <oid>, leave oid as name */
} else {
/* <ref>, clear cruft from oid */
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
}
} else {
/* <ref>, clear cruft from get_oid_hex */
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
}
ref = alloc_ref(name);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index ea727fba16..fd968d673d 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -528,7 +528,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
switch (obj->type) {
case OBJ_REF_DELTA:
- oidread(ref_oid, fill(the_hash_algo->rawsz));
+ oidread(ref_oid, fill(the_hash_algo->rawsz),
+ the_repository->hash_algo);
use(the_hash_algo->rawsz);
break;
case OBJ_OFS_DELTA:
@@ -1372,7 +1373,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
obj[1].idx.offset += write_compressed(f, buf, size);
obj[0].idx.crc32 = crc32_end(f);
hashflush(f);
- oidread(&obj->idx.oid, sha1);
+ oidread(&obj->idx.oid, sha1, the_repository->hash_algo);
return obj;
}
diff --git a/builtin/log.c b/builtin/log.c
index 78a247d8a9..ccbda8a005 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1938,7 +1938,7 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
free(bases->patch_id);
bases->nr_patch_id = 0;
bases->alloc_patch_id = 0;
- oidclr(&bases->base_commit);
+ oidclr(&bases->base_commit, the_repository->hash_algo);
}
static const char *diff_title(struct strbuf *sb,
diff --git a/builtin/merge.c b/builtin/merge.c
index daed2d4e1e..abe66311c7 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -494,7 +494,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_branchname(&bname, remote, 0);
remote = bname.buf;
- oidclr(&branch_head);
+ oidclr(&branch_head, the_repository->hash_algo);
remote_head = get_merge_parent(remote);
if (!remote_head)
die(_("'%s' does not point to a commit"), remote);
@@ -1690,7 +1690,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* index and working tree polluted.
*/
if (save_state(&stash))
- oidclr(&stash);
+ oidclr(&stash, the_repository->hash_algo);
for (i = 0; i < use_strategies_nr; i++) {
int ret, cnt;
diff --git a/builtin/notes.c b/builtin/notes.c
index 7f80b3449b..d9c356e354 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -828,7 +828,7 @@ static int merge_commit(struct notes_merge_options *o)
if (partial->parents)
oidcpy(&parent_oid, &partial->parents->item->object.oid);
else
- oidclr(&parent_oid);
+ oidclr(&parent_oid, the_repository->hash_algo);
CALLOC_ARRAY(t, 1);
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 638f5c57f0..2b00983a99 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2078,7 +2078,8 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
oidread(&base_ref,
use_pack(p, &w_curs,
entry->in_pack_offset + used,
- NULL));
+ NULL),
+ the_repository->hash_algo);
have_base = 1;
}
entry->in_pack_header_size = used + the_hash_algo->rawsz;
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 103c11b9d3..dd9bf35f5b 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -100,7 +100,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
const unsigned char *oid)
{
struct llist_item *new_item = llist_item_get();
- oidread(&new_item->oid, oid);
+ oidread(&new_item->oid, oid, the_repository->hash_algo);
new_item->next = NULL;
if (after) {
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 583099cacf..d790ae6354 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -70,7 +70,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
git_hash_ctx ctx;
the_hash_algo->init_fn(&ctx);
- oidclr(result);
+ oidclr(result, the_repository->hash_algo);
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
char *line = line_buf->buf;
@@ -166,7 +166,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
}
if (!found_next)
- oidclr(next_oid);
+ oidclr(next_oid, the_repository->hash_algo);
flush_one_hunk(result, &ctx);
@@ -179,7 +179,7 @@ static void generate_id_list(int stable, int verbatim)
int patchlen;
struct strbuf line_buf = STRBUF_INIT;
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
while (!feof(stdin)) {
patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim);
flush_current_id(patchlen, &oid, &result);
diff --git a/builtin/pull.c b/builtin/pull.c
index d622202bce..2a73e673f3 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -1038,7 +1038,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
die_conclude_merge();
if (repo_get_oid(the_repository, "HEAD", &orig_head))
- oidclr(&orig_head);
+ oidclr(&orig_head, the_repository->hash_algo);
if (opt_rebase) {
if (opt_autostash == -1)
@@ -1053,7 +1053,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
_("Please commit or stash them."), 1, 0);
if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
- oidclr(&rebase_fork_point);
+ oidclr(&rebase_fork_point, the_repository->hash_algo);
}
if (run_fetch(repo, refspecs))
@@ -1063,7 +1063,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
return 0;
if (repo_get_oid(the_repository, "HEAD", &curr_head))
- oidclr(&curr_head);
+ oidclr(&curr_head, the_repository->hash_algo);
if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
!oideq(&orig_head, &curr_head)) {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 01c1f04ece..aa5ba27d17 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -741,7 +741,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
already_done = 1;
if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
&push_cert_oid))
- oidclr(&push_cert_oid);
+ oidclr(&push_cert_oid, the_repository->hash_algo);
memset(&sigcheck, '\0', sizeof(sigcheck));
diff --git a/builtin/replace.c b/builtin/replace.c
index ce9f6974d2..1ef833c07f 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -167,7 +167,7 @@ static int check_ref_valid(struct object_id *object,
return error(_("'%s' is not a valid ref name"), ref->buf);
if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev))
- oidclr(prev);
+ oidclr(prev, the_repository->hash_algo);
else if (!force)
return error(_("replace ref '%s' already exists"), ref->buf);
return 0;
diff --git a/builtin/rm.c b/builtin/rm.c
index d195c16e74..0e79cbab62 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -377,7 +377,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (!force) {
struct object_id oid;
if (repo_get_oid(the_repository, "HEAD", &oid))
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
if (check_local_mod(&oid, index_only))
exit(1);
}
diff --git a/builtin/tag.c b/builtin/tag.c
index 6e2c0cf342..a1fb218512 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -650,7 +650,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die(_("'%s' is not a valid tag name."), tag);
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
- oidclr(&prev);
+ oidclr(&prev, the_repository->hash_algo);
else if (!force)
die(_("tag '%s' already exists"), tag);
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 0855572c27..08fa2a7a74 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -439,7 +439,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
struct object_id base_oid;
if (type == OBJ_REF_DELTA) {
- oidread(&base_oid, fill(the_hash_algo->rawsz));
+ oidread(&base_oid, fill(the_hash_algo->rawsz), the_repository->hash_algo);
use(the_hash_algo->rawsz);
delta_data = get_data(delta_size);
if (!delta_data)
@@ -451,7 +451,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
return; /* we are done */
else {
/* cannot resolve yet --- queue it */
- oidclr(&obj_list[nr].oid);
+ oidclr(&obj_list[nr].oid, the_repository->hash_algo);
add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
return;
}
@@ -500,7 +500,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
* The delta base object is itself a delta that
* has not been resolved yet.
*/
- oidclr(&obj_list[nr].oid);
+ oidclr(&obj_list[nr].oid, the_repository->hash_algo);
add_delta_to_list(nr, null_oid(), base_offset,
delta_data, delta_size);
return;
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 6cda1c08aa..f8a5b087f8 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -122,7 +122,7 @@ static int parse_next_oid(const char **next, const char *end,
goto invalid;
} else {
/* Without -z, an empty value means all zeros: */
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
}
} else {
/* With -z, read the next NUL-terminated line */
@@ -142,7 +142,7 @@ static int parse_next_oid(const char **next, const char *end,
/* With -z, treat an empty value as all zeros: */
warning("%s %s: missing <new-oid>, treating as zero",
command, refname);
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
} else {
/*
* With -z, an empty non-required value means
@@ -291,7 +291,7 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
if (parse_next_oid(&next, end, &old_oid, "verify", refname,
PARSE_SHA1_OLD))
- oidclr(&old_oid);
+ oidclr(&old_oid, the_repository->hash_algo);
if (*next != line_termination)
die("verify %s: extra input: %s", refname, next);
@@ -564,7 +564,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
* The empty string implies that the reference
* must not already exist:
*/
- oidclr(&oldoid);
+ oidclr(&oldoid, the_repository->hash_algo);
else if (repo_get_oid(the_repository, oldval, &oldoid))
die("%s: not a valid old SHA1", oldval);
}
diff --git a/cache-tree.c b/cache-tree.c
index 387c0a3e5b..e4255c4d02 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -578,7 +578,8 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
if (0 <= it->entry_count) {
if (size < rawsz)
goto free_return;
- oidread(&it->oid, (const unsigned char *)buf);
+ oidread(&it->oid, (const unsigned char *)buf,
+ the_repository->hash_algo);
buf += rawsz;
size -= rawsz;
}
diff --git a/commit-graph.c b/commit-graph.c
index 3429156b28..e4eefd83bf 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -475,7 +475,8 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
FREE_AND_NULL(graph->bloom_filter_settings);
}
- oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len);
+ oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len,
+ the_repository->hash_algo);
free_chunkfile(cf);
return graph;
@@ -838,7 +839,8 @@ static void load_oid_from_graph(struct commit_graph *g,
lex_index = pos - g->num_commits_in_base;
- oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index));
+ oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index),
+ the_repository->hash_algo);
}
static struct commit_list **insert_parent_or_die(struct repository *r,
@@ -1080,7 +1082,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
commit_data = g->chunk_commit_data +
st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
- oidread(&oid, commit_data);
+ oidread(&oid, commit_data, r->hash_algo);
set_commit_tree(c, lookup_tree(r, &oid));
return c->maybe_tree;
@@ -2556,7 +2558,8 @@ int write_commit_graph(struct object_directory *odb,
struct commit_graph *g = ctx->r->objects->commit_graph;
for (i = 0; i < g->num_commits; i++) {
struct object_id oid;
- oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ r->hash_algo);
oid_array_append(&ctx->oids, &oid);
}
}
@@ -2675,7 +2678,8 @@ static int verify_one_commit_graph(struct repository *r,
for (i = 0; i < g->num_commits; i++) {
struct commit *graph_commit;
- oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ r->hash_algo);
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2719,7 +2723,8 @@ static int verify_one_commit_graph(struct repository *r,
timestamp_t generation;
display_progress(progress, ++(*seen));
- oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ the_repository->hash_algo);
graph_commit = lookup_commit(r, &cur_oid);
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
diff --git a/diff-lib.c b/diff-lib.c
index 5a5a50c5a1..3fb8d79fef 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
dpath->next = NULL;
memcpy(dpath->path, ce->name, path_len);
dpath->path[path_len] = '\0';
- oidclr(&dpath->oid);
+ oidclr(&dpath->oid, the_repository->hash_algo);
memset(&(dpath->parent[0]), 0,
sizeof(struct combine_diff_parent)*5);
@@ -412,7 +412,7 @@ static int show_modified(struct rev_info *revs,
memcpy(p->path, new_entry->name, pathlen);
p->path[pathlen] = 0;
p->mode = mode;
- oidclr(&p->oid);
+ oidclr(&p->oid, the_repository->hash_algo);
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
p->parent[0].status = DIFF_STATUS_MODIFIED;
p->parent[0].mode = new_entry->ce_mode;
diff --git a/diff.c b/diff.c
index e70301df76..60d1f7be81 100644
--- a/diff.c
+++ b/diff.c
@@ -4567,7 +4567,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
if (!one->oid_valid) {
struct stat st;
if (one->is_stdin) {
- oidclr(&one->oid);
+ oidclr(&one->oid, the_repository->hash_algo);
return;
}
if (lstat(one->path, &st) < 0)
@@ -4577,7 +4577,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
}
}
else
- oidclr(&one->oid);
+ oidclr(&one->oid, the_repository->hash_algo);
}
static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
@@ -6404,7 +6404,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
the_hash_algo->init_fn(&ctx);
memset(&data, 0, sizeof(struct patch_id_t));
data.ctx = &ctx;
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
for (i = 0; i < q->nr; i++) {
xpparam_t xpp;
diff --git a/dir.c b/dir.c
index 45be4ad261..5de421c29c 100644
--- a/dir.c
+++ b/dir.c
@@ -1687,7 +1687,7 @@ static void prep_exclude(struct dir_struct *dir,
}
/* Try to read per-directory file */
- oidclr(&oid_stat.oid);
+ oidclr(&oid_stat.oid, the_repository->hash_algo);
oid_stat.valid = 0;
if (dir->exclude_per_dir &&
/*
@@ -3794,7 +3794,7 @@ static void read_oid(size_t pos, void *cb)
rd->data = rd->end + 1;
return;
}
- oidread(&ud->exclude_oid, rd->data);
+ oidread(&ud->exclude_oid, rd->data, the_repository->hash_algo);
rd->data += the_hash_algo->rawsz;
}
@@ -3802,7 +3802,7 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
const unsigned char *sha1)
{
stat_data_from_disk(&oid_stat->stat, data);
- oidread(&oid_stat->oid, sha1);
+ oidread(&oid_stat->oid, sha1, the_repository->hash_algo);
oid_stat->valid = 1;
}
diff --git a/hash-ll.h b/hash-ll.h
index fabdd8ecc7..dbb96369fc 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -284,6 +284,20 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src)
dst->algo = src->algo;
}
+static inline void oidread(struct object_id *oid, const unsigned char *hash,
+ const struct git_hash_algo *algop)
+{
+ memcpy(oid->hash, hash, algop->rawsz);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline void oidclr(struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
static inline struct object_id *oiddup(const struct object_id *src)
{
struct object_id *dst = xmalloc(sizeof(struct object_id));
diff --git a/hash.h b/hash.h
index 714938e2eb..43623a0c86 100644
--- a/hash.h
+++ b/hash.h
@@ -47,23 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
dst->algo = src->algo;
}
-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_algop(struct object_id *oid, const unsigned char *hash, const struct git_hash_algo *algop)
-{
- memcpy(oid->hash, hash, algop->rawsz);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline void oidread(struct object_id *oid, const unsigned char *hash)
-{
- oidread_algop(oid, hash, the_hash_algo);
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
diff --git a/http-push.c b/http-push.c
index 1fe51226fd..86de238b84 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1552,7 +1552,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
free(url);
FREE_AND_NULL(*symref);
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
if (buffer.len == 0)
return;
diff --git a/http-walker.c b/http-walker.c
index cf7f8c82bc..b7110b6f82 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -152,7 +152,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
newreq = xmalloc(sizeof(*newreq));
newreq->walker = walker;
- oidread(&newreq->oid, sha1);
+ oidread(&newreq->oid, sha1, the_repository->hash_algo);
newreq->repo = data->alt;
newreq->state = WAITING;
newreq->req = NULL;
diff --git a/match-trees.c b/match-trees.c
index 849b391d3d..50c42e2061 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -229,7 +229,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
oid_to_hex(oid1));
if (*subpath) {
struct object_id tree_oid;
- oidread(&tree_oid, rewrite_here);
+ oidread(&tree_oid, rewrite_here, the_repository->hash_algo);
status = splice_tree(&tree_oid, subpath, oid2, &subtree);
if (status)
return status;
diff --git a/midx.c b/midx.c
index bc4797196f..1e75f1a7eb 100644
--- a/midx.c
+++ b/midx.c
@@ -304,7 +304,8 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
if (n >= m->num_objects)
return NULL;
- oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
+ oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
+ the_repository->hash_algo);
return oid;
}
diff --git a/notes-merge.c b/notes-merge.c
index 6a9a139b12..801941c2d1 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -240,7 +240,7 @@ static void diff_tree_local(struct notes_merge_options *o,
* (will be overwritten by following addition)
*/
if (oideq(&mp->local, &uninitialized))
- oidclr(&mp->local);
+ oidclr(&mp->local, the_repository->hash_algo);
} else if (is_null_oid(&p->one->oid)) { /* addition */
/*
* Either this is a true addition (1), or it is part
@@ -556,7 +556,7 @@ int notes_merge(struct notes_merge_options *o,
assert(o->local_ref && o->remote_ref);
assert(!strcmp(o->local_ref, local_tree->ref));
- oidclr(result_oid);
+ oidclr(result_oid, the_repository->hash_algo);
trace_printf("notes_merge(o->local_ref = %s, o->remote_ref = %s)\n",
o->local_ref, o->remote_ref);
@@ -579,7 +579,7 @@ int notes_merge(struct notes_merge_options *o,
* unborn ref, perform the merge using an empty notes tree.
*/
if (!check_refname_format(o->remote_ref, 0)) {
- oidclr(&remote_oid);
+ oidclr(&remote_oid, the_repository->hash_algo);
remote = NULL;
} else {
die("Failed to resolve remote notes ref '%s'",
diff --git a/notes.c b/notes.c
index 5296fd863f..3a8da92fb9 100644
--- a/notes.c
+++ b/notes.c
@@ -353,7 +353,7 @@ static void add_non_note(struct notes_tree *t, char *path,
n->next = NULL;
n->path = path;
n->mode = mode;
- oidread(&n->oid, sha1);
+ oidread(&n->oid, sha1, the_repository->hash_algo);
t->prev_non_note = n;
if (!t->first_non_note) {
@@ -1036,7 +1036,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid));
- oidclr(&root_tree.key_oid);
+ oidclr(&root_tree.key_oid, the_repository->hash_algo);
oidcpy(&root_tree.val_oid, &oid);
load_subtree(t, &root_tree, t->root, 0);
}
@@ -1146,8 +1146,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
if (!t)
t = &default_notes_tree;
assert(t->initialized);
- oidread(&l.key_oid, object_sha1);
- oidclr(&l.val_oid);
+ oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
+ oidclr(&l.val_oid, the_repository->hash_algo);
note_tree_remove(t, t->root, 0, &l);
if (is_null_oid(&l.val_oid)) /* no note was removed */
return 1;
diff --git a/object-file-convert.c b/object-file-convert.c
index 4f6189095b..f684038f7f 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -56,7 +56,7 @@ static int decode_tree_entry_raw(struct object_id *oid, const char **path,
return -1;
*len = strlen(*path) + 1;
- oidread_algop(oid, (const unsigned char *)*path + *len, algo);
+ oidread(oid, (const unsigned char *)*path + *len, algo);
return 0;
}
diff --git a/object-file.c b/object-file.c
index a40300ce4a..c161e3e2a5 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1446,7 +1446,7 @@ static int loose_object_info(struct repository *r,
int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
/*
* If we don't care about type or size, then we don't
@@ -1580,7 +1580,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
diff --git a/packfile.c b/packfile.c
index 9156e9122c..ec7312cd20 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1251,7 +1251,7 @@ static int get_delta_base_oid(struct packed_git *p,
{
if (type == OBJ_REF_DELTA) {
unsigned char *base = use_pack(p, w_curs, curpos, NULL);
- oidread(oid, base);
+ oidread(oid, base, the_repository->hash_algo);
return 0;
} else if (type == OBJ_OFS_DELTA) {
uint32_t base_pos;
@@ -1593,7 +1593,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
goto out;
}
} else
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
}
oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :
@@ -1917,10 +1917,12 @@ int nth_packed_object_id(struct object_id *oid,
return -1;
index += 4 * 256;
if (p->index_version == 1) {
- oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4));
+ oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4),
+ the_repository->hash_algo);
} else {
index += 8;
- oidread(oid, index + st_mult(hashsz, n));
+ oidread(oid, index + st_mult(hashsz, n),
+ the_repository->hash_algo);
}
return 0;
}
diff --git a/read-cache.c b/read-cache.c
index 2642ac9558..836f1db721 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1728,7 +1728,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
end = (unsigned char *)hdr + size;
start = end - the_hash_algo->rawsz;
- oidread(&oid, start);
+ oidread(&oid, start, the_repository->hash_algo);
if (oideq(&oid, null_oid()))
return 0;
@@ -1876,7 +1876,8 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
ce->ce_flags = flags & ~CE_NAMEMASK;
ce->ce_namelen = len;
ce->index = 0;
- oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data));
+ oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data),
+ the_repository->hash_algo);
if (expand_name_field) {
if (copy_len)
@@ -2249,7 +2250,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
if (verify_hdr(hdr, mmap_size) < 0)
goto unmap;
- oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
+ oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz,
+ the_repository->hash_algo);
istate->version = ntohl(hdr->hdr_version);
istate->cache_nr = ntohl(hdr->hdr_entries);
istate->cache_alloc = alloc_nr(istate->cache_nr);
diff --git a/refs.c b/refs.c
index 1304d3dd87..6e7caefdcf 100644
--- a/refs.c
+++ b/refs.c
@@ -1822,7 +1822,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
failure_errno != ENOTDIR)
return NULL;
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
if (*flags & REF_BAD_NAME)
*flags |= REF_ISBROKEN;
return refname;
@@ -1832,7 +1832,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
if (!(read_flags & REF_ISSYMREF)) {
if (*flags & REF_BAD_NAME) {
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
*flags |= REF_ISBROKEN;
}
return refname;
@@ -1840,7 +1840,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
refname = sb_refname.buf;
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
return refname;
}
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4519b46171..b484b5880d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -246,7 +246,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
&oid, &flag)) {
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
flag |= REF_ISBROKEN;
} else if (is_null_oid(&oid)) {
/*
@@ -263,7 +263,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
if (!refname_is_safe(refname))
die("loose refname is dangerous: %s", refname);
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
flag |= REF_BAD_NAME | REF_ISBROKEN;
}
add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));
@@ -1150,7 +1150,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
&lock->old_oid, NULL))
- oidclr(&lock->old_oid);
+ oidclr(&lock->old_oid, the_repository->hash_algo);
goto out;
error_return:
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index c4c1e36aa2..5ab1b21d10 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -894,7 +894,7 @@ static int next_record(struct packed_ref_iterator *iter)
if (!refname_is_safe(iter->base.refname))
die("packed refname is dangerous: %s",
iter->base.refname);
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
iter->base.flags |= REF_BAD_NAME | REF_ISBROKEN;
}
if (iter->snapshot->peeled == PEELED_FULLY ||
@@ -919,13 +919,13 @@ static int next_record(struct packed_ref_iterator *iter)
* we suppress it if the reference is broken:
*/
if ((iter->base.flags & REF_ISBROKEN)) {
- oidclr(&iter->peeled);
+ oidclr(&iter->peeled, the_repository->hash_algo);
iter->base.flags &= ~REF_KNOWS_PEELED;
} else {
iter->base.flags |= REF_KNOWS_PEELED;
}
} else {
- oidclr(&iter->peeled);
+ oidclr(&iter->peeled, the_repository->hash_algo);
}
return ITER_OK;
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 9886fc67a4..57df2aba66 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -217,7 +217,8 @@ static int read_ref_without_reload(struct reftable_stack *stack,
strbuf_addstr(referent, ref.value.symref);
*type |= REF_ISSYMREF;
} else if (reftable_ref_record_val1(&ref)) {
- oidread(oid, reftable_ref_record_val1(&ref));
+ oidread(oid, reftable_ref_record_val1(&ref),
+ the_repository->hash_algo);
} else {
/* We got a tombstone, which should not happen. */
BUG("unhandled reference value type %d", ref.value_type);
@@ -483,15 +484,17 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
switch (iter->ref.value_type) {
case REFTABLE_REF_VAL1:
- oidread(&iter->oid, iter->ref.value.val1);
+ oidread(&iter->oid, iter->ref.value.val1,
+ the_repository->hash_algo);
break;
case REFTABLE_REF_VAL2:
- oidread(&iter->oid, iter->ref.value.val2.value);
+ oidread(&iter->oid, iter->ref.value.val2.value,
+ the_repository->hash_algo);
break;
case REFTABLE_REF_SYMREF:
if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname,
RESOLVE_REF_READING, &iter->oid, &flags))
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
break;
default:
BUG("unhandled reference value type %d", iter->ref.value_type);
@@ -503,7 +506,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
if (check_refname_format(iter->ref.refname, REFNAME_ALLOW_ONELEVEL)) {
if (!refname_is_safe(iter->ref.refname))
die(_("refname is dangerous: %s"), iter->ref.refname);
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
flags |= REF_BAD_NAME | REF_ISBROKEN;
}
@@ -545,7 +548,8 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,
(struct reftable_ref_iterator *)ref_iterator;
if (iter->ref.value_type == REFTABLE_REF_VAL2) {
- oidread(peeled, iter->ref.value.val2.target_value);
+ oidread(peeled, iter->ref.value.val2.target_value,
+ the_repository->hash_algo);
return 0;
}
@@ -1776,8 +1780,8 @@ static int yield_log_record(struct reftable_log_record *log,
struct object_id old_oid, new_oid;
const char *full_committer;
- oidread(&old_oid, log->value.update.old_hash);
- oidread(&new_oid, log->value.update.new_hash);
+ oidread(&old_oid, log->value.update.old_hash, the_repository->hash_algo);
+ oidread(&new_oid, log->value.update.new_hash, the_repository->hash_algo);
/*
* When both the old object ID and the new object ID are null
@@ -2178,7 +2182,8 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
if (ret < 0)
goto done;
if (reftable_ref_record_val1(&ref_record))
- oidread(&oid, reftable_ref_record_val1(&ref_record));
+ oidread(&oid, reftable_ref_record_val1(&ref_record),
+ the_repository->hash_algo);
prepare_fn(refname, &oid, policy_cb_data);
while (1) {
@@ -2193,8 +2198,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
break;
}
- oidread(&old_oid, log.value.update.old_hash);
- oidread(&new_oid, log.value.update.new_hash);
+ oidread(&old_oid, log.value.update.old_hash,
+ the_repository->hash_algo);
+ oidread(&new_oid, log.value.update.new_hash,
+ the_repository->hash_algo);
/*
* Skip over the reflog existence marker. We will add it back
@@ -2225,8 +2232,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
struct object_id old_oid, new_oid;
*dest = logs[i];
- oidread(&old_oid, logs[i].value.update.old_hash);
- oidread(&new_oid, logs[i].value.update.new_hash);
+ oidread(&old_oid, logs[i].value.update.old_hash,
+ the_repository->hash_algo);
+ oidread(&new_oid, logs[i].value.update.new_hash,
+ the_repository->hash_algo);
if (should_prune_fn(&old_oid, &new_oid, logs[i].value.update.email,
(timestamp_t)logs[i].value.update.time,
@@ -2243,7 +2252,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
reftable_ref_record_val1(&ref_record))
- oidread(&arg.update_oid, last_hash);
+ oidread(&arg.update_oid, last_hash, the_repository->hash_algo);
arg.refs = refs;
arg.records = rewritten;
diff --git a/remote.c b/remote.c
index dcb5492c85..1064171085 100644
--- a/remote.c
+++ b/remote.c
@@ -1164,7 +1164,7 @@ static void tail_link_ref(struct ref *ref, struct ref ***tail)
static struct ref *alloc_delete_ref(void)
{
struct ref *ref = alloc_ref("(delete)");
- oidclr(&ref->new_oid);
+ oidclr(&ref->new_oid, the_repository->hash_algo);
return ref;
}
@@ -2531,7 +2531,7 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
if (!*colon)
entry->use_tracking = 1;
else if (!colon[1])
- oidclr(&entry->expect);
+ oidclr(&entry->expect, the_repository->hash_algo);
else if (repo_get_oid(the_repository, colon + 1, &entry->expect))
return error(_("cannot parse expected object name '%s'"),
colon + 1);
@@ -2733,7 +2733,7 @@ static void apply_cas(struct push_cas_option *cas,
else if (remote_tracking(remote, ref->name,
&ref->old_oid_expect,
&ref->tracking_ref))
- oidclr(&ref->old_oid_expect);
+ oidclr(&ref->old_oid_expect, the_repository->hash_algo);
else
ref->check_reachable = cas->use_force_if_includes;
return;
@@ -2747,7 +2747,7 @@ static void apply_cas(struct push_cas_option *cas,
if (remote_tracking(remote, ref->name,
&ref->old_oid_expect,
&ref->tracking_ref))
- oidclr(&ref->old_oid_expect);
+ oidclr(&ref->old_oid_expect, the_repository->hash_algo);
else
ref->check_reachable = cas->use_force_if_includes;
}
diff --git a/resolve-undo.c b/resolve-undo.c
index cd02dc9928..4e6f0e4676 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -93,7 +93,8 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
continue;
if (size < rawsz)
goto error;
- oidread(&ui->oid[i], (const unsigned char *)data);
+ oidread(&ui->oid[i], (const unsigned char *)data,
+ the_repository->hash_algo);
size -= rawsz;
data += rawsz;
}
diff --git a/sequencer.c b/sequencer.c
index 30513e87bf..68d62a12ff 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3334,12 +3334,12 @@ static int rollback_is_safe(void)
strbuf_release(&sb);
}
else if (errno == ENOENT)
- oidclr(&expected_head);
+ oidclr(&expected_head, the_repository->hash_algo);
else
die_errno(_("could not read '%s'"), git_path_abort_safety_file());
if (repo_get_oid(the_repository, "HEAD", &actual_head))
- oidclr(&actual_head);
+ oidclr(&actual_head, the_repository->hash_algo);
return oideq(&actual_head, &expected_head);
}
diff --git a/split-index.c b/split-index.c
index 8c38687c04..058a8f448e 100644
--- a/split-index.c
+++ b/split-index.c
@@ -29,7 +29,7 @@ int read_link_extension(struct index_state *istate,
if (sz < the_hash_algo->rawsz)
return error("corrupt link extension (too short)");
si = init_split_index(istate);
- oidread(&si->base_oid, data);
+ oidread(&si->base_oid, data, the_repository->hash_algo);
data += the_hash_algo->rawsz;
sz -= the_hash_algo->rawsz;
if (!sz)
diff --git a/submodule-config.c b/submodule-config.c
index ec45ea67b9..ad43a282da 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -682,7 +682,7 @@ static int gitmodule_oid_from_commit(const struct object_id *treeish_name,
int ret = 0;
if (is_null_oid(treeish_name)) {
- oidclr(gitmodules_oid);
+ oidclr(gitmodules_oid, the_repository->hash_algo);
return 1;
}
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 9df2f03ac8..4b809d9dca 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -44,7 +44,7 @@ int cmd__submodule_config(int argc, const char **argv)
path_or_name = arg[1];
if (commit[0] == '\0')
- oidclr(&commit_oid);
+ oidclr(&commit_oid, the_repository->hash_algo);
else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
die_usage(argc, argv, "Commit not found.");
diff --git a/tree-walk.c b/tree-walk.c
index 6565d9ad99..535a3a2539 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -38,8 +38,8 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
desc->entry.path = path;
desc->entry.mode = (desc->flags & TREE_DESC_RAW_MODES) ? mode : canon_mode(mode);
desc->entry.pathlen = len - 1;
- oidread_algop(&desc->entry.oid, (const unsigned char *)path + len,
- desc->algo);
+ oidread(&desc->entry.oid, (const unsigned char *)path + len,
+ desc->algo);
return 0;
}
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 04/20] global: ensure that object IDs are always padded
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (2 preceding siblings ...)
2024-06-13 6:13 ` [PATCH v2 03/20] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
@ 2024-06-13 6:13 ` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
` (16 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:13 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 6452 bytes --]
The `oidcmp()` and `oideq()` functions only compare the prefix length as
specified by the given hash algorithm. This mandates that the object IDs
have a valid hash algorithm set, or otherwise we wouldn't be able to
figure out that prefix. As we do not have a hash algorithm in many
cases, for example when handling null object IDs, this assumption cannot
always be fulfilled. We thus have a fallback in place that instead uses
`the_repository` to derive the hash function. This implicit dependency
is hidden away from callers and can be quite surprising, especially in
contexts where there may be no repository.
In theory, we can adapt those functions to always memcmp(3P) the whole
length of their hash arrays. But there exist a couple of sites where we
populate `struct object_id`s such that only the prefix of its hash that
is actually used by the hash algorithm is populated. The remaining bytes
are left uninitialized. The fact that those bytes are uninitialized also
leads to warnings under Valgrind in some places where we copy those
bytes.
Refactor callsites where we populate object IDs to always initialize all
bytes. This also allows us to get rid of `oidcpy_with_padding()`, for
one because the input is now fully initialized, and because `oidcpy()`
will now always copy the whole hash array.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 2 ++
hash.h | 16 ----------------
hex.c | 6 +++++-
http-push.c | 1 +
notes.c | 2 ++
object-file.c | 2 ++
oidtree.c | 4 ++--
parallel-checkout.c | 8 +-------
8 files changed, 15 insertions(+), 26 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index dbb96369fc..b72f84f4ae 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -288,6 +288,8 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash,
const struct git_hash_algo *algop)
{
memcpy(oid->hash, hash, algop->rawsz);
+ if (algop->rawsz < GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
oid->algo = hash_algo_by_ptr(algop);
}
diff --git a/hash.h b/hash.h
index 43623a0c86..e43e3d8b5a 100644
--- a/hash.h
+++ b/hash.h
@@ -31,22 +31,6 @@ static inline int is_null_oid(const struct object_id *oid)
return oideq(oid, null_oid());
}
-/* 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;
-
- memcpy(dst->hash, src->hash, hashsz);
- memset(dst->hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
- dst->algo = src->algo;
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
diff --git a/hex.c b/hex.c
index d42262bdca..bc9e86a978 100644
--- a/hex.c
+++ b/hex.c
@@ -25,8 +25,12 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid,
const struct git_hash_algo *algop)
{
int ret = get_hash_hex_algop(hex, oid->hash, algop);
- if (!ret)
+ if (!ret) {
oid_set_algo(oid, algop);
+ if (algop->rawsz != GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0,
+ GIT_MAX_RAWSZ - algop->rawsz);
+ }
return ret;
}
diff --git a/http-push.c b/http-push.c
index 86de238b84..a97df4a1fb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1016,6 +1016,7 @@ 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)
{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
oid->algo = hash_algo_by_ptr(the_hash_algo);
if (strlen(path) != the_hash_algo->hexsz + 1)
diff --git a/notes.c b/notes.c
index 3a8da92fb9..afe2e2882e 100644
--- a/notes.c
+++ b/notes.c
@@ -427,6 +427,8 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
hashsz - prefix_len))
goto handle_non_note; /* entry.path is not a SHA1 */
+ memset(object_oid.hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
+
type = PTR_TYPE_NOTE;
} else if (path_len == 2) {
/* This is potentially an internal node */
diff --git a/object-file.c b/object-file.c
index c161e3e2a5..bb97f8a809 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2743,6 +2743,8 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
!hex_to_bytes(oid.hash + 1, de->d_name,
the_hash_algo->rawsz - 1)) {
oid_set_algo(&oid, the_hash_algo);
+ memset(oid.hash + the_hash_algo->rawsz, 0,
+ GIT_MAX_RAWSZ - the_hash_algo->rawsz);
if (obj_cb) {
r = obj_cb(&oid, path->buf, data);
if (r)
diff --git a/oidtree.c b/oidtree.c
index daef175dc7..92d03b52db 100644
--- a/oidtree.c
+++ b/oidtree.c
@@ -42,7 +42,7 @@ void oidtree_insert(struct oidtree *ot, const struct object_id *oid)
* Clear the padding and copy the result in separate steps to
* respect the 4-byte alignment needed by struct object_id.
*/
- oidcpy_with_padding(&k, oid);
+ oidcpy(&k, oid);
memcpy(on->k, &k, sizeof(k));
/*
@@ -60,7 +60,7 @@ int oidtree_contains(struct oidtree *ot, const struct object_id *oid)
struct object_id k;
size_t klen = sizeof(k);
- oidcpy_with_padding(&k, oid);
+ oidcpy(&k, oid);
if (oid->algo == GIT_HASH_UNKNOWN)
klen -= sizeof(oid->algo);
diff --git a/parallel-checkout.c b/parallel-checkout.c
index b5a714c711..08b960aac8 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -429,13 +429,7 @@ static void send_one_item(int fd, struct parallel_checkout_item *pc_item)
fixed_portion->ident = pc_item->ca.ident;
fixed_portion->name_len = name_len;
fixed_portion->working_tree_encoding_len = working_tree_encoding_len;
- /*
- * We pad the unused bytes in the hash array because, otherwise,
- * Valgrind would complain about passing uninitialized bytes to a
- * write() syscall. The warning doesn't represent any real risk here,
- * but it could hinder the detection of actual errors.
- */
- oidcpy_with_padding(&fixed_portion->oid, &pc_item->ce->oid);
+ oidcpy(&fixed_portion->oid, &pc_item->ce->oid);
variant = data + sizeof(*fixed_portion);
if (working_tree_encoding_len) {
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (3 preceding siblings ...)
2024-06-13 6:13 ` [PATCH v2 04/20] global: ensure that object IDs are always padded Patrick Steinhardt
@ 2024-06-13 6:13 ` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 06/20] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
` (15 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:13 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 6009 bytes --]
With the preceding commit, the hash array of object IDs is now fully
zero-padded even when the hash algorithm's output is smaller than the
array length. With that, we can now adapt both `oidcmp()` and `oideq()`
to unconditionally memcmp(3P) the whole array instead of depending on
the hash size.
While it may feel inefficient to compare unused bytes for e.g. SHA-1, in
practice the compiler should now be able to produce code that is better
optimized both because we have no branch anymore, but also because the
size to compare is now known at compile time. Goldbolt spits out the
following assembly on an x86_64 platform with GCC 14.1 for the old and
new implementations of `oidcmp()`:
oidcmp_old:
movsx rax, DWORD PTR [rdi+32]
test eax, eax
jne .L2
mov rax, QWORD PTR the_repository[rip]
cmp QWORD PTR [rax+16], 32
je .L6
.L4:
mov edx, 20
jmp memcmp
.L2:
lea rdx, [rax+rax*2]
lea rax, [rax+rdx*4]
lea rax, hash_algos[0+rax*8]
cmp QWORD PTR [rax+16], 32
jne .L4
.L6:
mov edx, 32
jmp memcmp
oidcmp_new:
mov edx, 32
jmp memcmp
The new implementation gets ridi of all the branches and effectively
only ends setting up `edx` for `memcmp()` and then calling it.
And for `oideq()`:
oideq_old:
movsx rcx, DWORD PTR [rdi+32]
mov rax, rdi
mov rdx, rsi
test ecx, ecx
jne .L2
mov rcx, QWORD PTR the_repository[rip]
cmp QWORD PTR [rcx+16], 32
mov rcx, QWORD PTR [rax]
je .L12
.L4:
mov rsi, QWORD PTR [rax+8]
xor rcx, QWORD PTR [rdx]
xor rsi, QWORD PTR [rdx+8]
or rcx, rsi
je .L13
.L8:
mov eax, 1
test eax, eax
sete al
movzx eax, al
ret
.L2:
lea rsi, [rcx+rcx*2]
lea rcx, [rcx+rsi*4]
lea rcx, hash_algos[0+rcx*8]
cmp QWORD PTR [rcx+16], 32
mov rcx, QWORD PTR [rax]
jne .L4
.L12:
mov rsi, QWORD PTR [rax+8]
xor rcx, QWORD PTR [rdx]
xor rsi, QWORD PTR [rdx+8]
or rcx, rsi
jne .L8
mov rcx, QWORD PTR [rax+16]
mov rax, QWORD PTR [rax+24]
xor rcx, QWORD PTR [rdx+16]
xor rax, QWORD PTR [rdx+24]
or rcx, rax
jne .L8
xor eax, eax
.L14:
test eax, eax
sete al
movzx eax, al
ret
.L13:
mov edi, DWORD PTR [rdx+16]
cmp DWORD PTR [rax+16], edi
jne .L8
xor eax, eax
jmp .L14
oideq_new:
mov rax, QWORD PTR [rdi]
mov rdx, QWORD PTR [rdi+8]
xor rax, QWORD PTR [rsi]
xor rdx, QWORD PTR [rsi+8]
or rax, rdx
je .L5
.L2:
mov eax, 1
xor eax, 1
ret
.L5:
mov rax, QWORD PTR [rdi+16]
mov rdx, QWORD PTR [rdi+24]
xor rax, QWORD PTR [rsi+16]
xor rdx, QWORD PTR [rsi+24]
or rax, rdx
jne .L2
xor eax, eax
xor eax, 1
ret
Interestingly, the compiler decides to split the comparisons into two so
that it first compares the lower half of the object ID for equality and
then the upper half. If the first check shows a difference, then we
wouldn't even end up comparing the second half.
In both cases, the new generated code is significantly shorter and has
way less branches. While I didn't benchmark the change, I'd be surprised
if the new code was slower.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 10 ++++++++++
hash.h | 20 --------------------
2 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index b72f84f4ae..b04fe12aef 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -278,6 +278,16 @@ static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algo
memset(hash, 0, algop->rawsz);
}
+static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
diff --git a/hash.h b/hash.h
index e43e3d8b5a..ddc2e5ca47 100644
--- a/hash.h
+++ b/hash.h
@@ -6,26 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-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(oid1->hash, oid2->hash, algop);
-}
-
-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(oid1->hash, oid2->hash, algop);
-}
-
static inline int is_null_oid(const struct object_id *oid)
{
return oideq(oid, null_oid());
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 06/20] hash: make `is_null_oid()` independent of `the_repository`
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (4 preceding siblings ...)
2024-06-13 6:13 ` [PATCH v2 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
@ 2024-06-13 6:13 ` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
` (14 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:13 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 1496 bytes --]
The function `is_null_oid()` uses `oideq(oid, null_oid())` to check
whether a given object ID is the all-zero object ID. `null_oid()`
implicitly relies on `the_repository` though to return the correct null
object ID.
Get rid of this dependency by always comparing the complete hash array
for being all-zeroes. This is possible due to the refactoring of object
IDs so that their hash arrays are always fully initialized.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 6 ++++++
hash.h | 5 -----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index b04fe12aef..faf6c292d2 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -341,6 +341,12 @@ static inline unsigned int oidhash(const struct object_id *oid)
return hash;
}
+static inline int is_null_oid(const struct object_id *oid)
+{
+ static const unsigned char null_hash[GIT_MAX_RAWSZ];
+ return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
+}
+
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
diff --git a/hash.h b/hash.h
index ddc2e5ca47..84f2296cfb 100644
--- a/hash.h
+++ b/hash.h
@@ -6,11 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-static inline int is_null_oid(const struct object_id *oid)
-{
- return oideq(oid, null_oid());
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (5 preceding siblings ...)
2024-06-13 6:13 ` [PATCH v2 06/20] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
@ 2024-06-13 6:13 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
` (13 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:13 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 3968 bytes --]
Both functions `is_empty_{blob,tree}_oid()` use `the_repository` to
derive the hash function that shall be used. Require callers to pass in
the hash algorithm to get rid of this implicit dependency.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 4 +++-
cache-tree.c | 2 +-
diffcore-rename.c | 4 ++--
hash-ll.h | 12 ++++++++++++
hash.h | 10 ----------
read-cache.c | 2 +-
6 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 12543488f3..d21c4053a7 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2361,7 +2361,9 @@ static void file_change_m(const char *p, struct branch *b)
parse_path_eol(&path, p, "path");
/* Git does not track empty, non-toplevel directories. */
- if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *path.buf) {
+ if (S_ISDIR(mode) &&
+ is_empty_tree_oid(&oid, the_repository->hash_algo) &&
+ *path.buf) {
tree_content_remove(&b->branch_tree, path.buf, NULL, 0);
return;
}
diff --git a/cache-tree.c b/cache-tree.c
index e4255c4d02..3290a1b8dd 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -422,7 +422,7 @@ static int update_one(struct cache_tree *it,
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
- if (contains_ita && is_empty_tree_oid(oid))
+ if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo))
continue;
strbuf_grow(&buffer, entlen + 100);
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 5a6e2bcac7..5abb958651 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -1422,7 +1422,7 @@ void diffcore_rename_extended(struct diff_options *options,
strcmp(options->single_follow, p->two->path))
continue; /* not interested */
else if (!options->flags.rename_empty &&
- is_empty_blob_oid(&p->two->oid))
+ is_empty_blob_oid(&p->two->oid, the_repository->hash_algo))
continue;
else if (add_rename_dst(p) < 0) {
warning("skipping rename detection, detected"
@@ -1432,7 +1432,7 @@ void diffcore_rename_extended(struct diff_options *options,
}
}
else if (!options->flags.rename_empty &&
- is_empty_blob_oid(&p->one->oid))
+ is_empty_blob_oid(&p->one->oid, the_repository->hash_algo))
continue;
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
/*
diff --git a/hash-ll.h b/hash-ll.h
index faf6c292d2..1000a9af22 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -350,4 +350,16 @@ static inline int is_null_oid(const struct object_id *oid)
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
+static inline int is_empty_blob_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_blob);
+}
+
+static inline int is_empty_tree_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_tree);
+}
+
#endif
diff --git a/hash.h b/hash.h
index 84f2296cfb..39a0164be3 100644
--- a/hash.h
+++ b/hash.h
@@ -6,14 +6,4 @@
#define the_hash_algo the_repository->hash_algo
-static inline int is_empty_blob_oid(const struct object_id *oid)
-{
- return oideq(oid, the_hash_algo->empty_blob);
-}
-
-static inline int is_empty_tree_oid(const struct object_id *oid)
-{
- return oideq(oid, the_hash_algo->empty_tree);
-}
-
#endif
diff --git a/read-cache.c b/read-cache.c
index 836f1db721..085b22faf3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
/* Racily smudged entry? */
if (!ce->ce_stat_data.sd_size) {
- if (!is_empty_blob_oid(&ce->oid))
+ if (!is_empty_blob_oid(&ce->oid, the_repository->hash_algo))
changed |= DATA_CHANGED;
}
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()`
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (6 preceding siblings ...)
2024-06-13 6:13 ` [PATCH v2 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 10:01 ` Phillip Wood
2024-06-13 6:14 ` [PATCH v2 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (12 subsequent siblings)
20 siblings, 1 reply; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 6668 bytes --]
The `empty_tree_oid_hex()` function use `the_repository` to derive the
hash function that shall be used. Require callers to pass in the hash
algorithm to get rid of this implicit dependency.
While at it, remove the unused `empty_blob_oid_hex()` function.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
add-interactive.c | 2 +-
add-patch.c | 2 +-
builtin/merge.c | 3 ++-
builtin/receive-pack.c | 2 +-
hash-ll.h | 3 +--
object-file.c | 10 ++--------
sequencer.c | 2 +-
submodule.c | 6 +++---
wt-status.c | 4 ++--
9 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/add-interactive.c b/add-interactive.c
index b5d6cd689a..a0961096cd 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
s.skip_unseen = filter && i;
opt.def = is_initial ?
- empty_tree_oid_hex() : oid_to_hex(&head_oid);
+ empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
repo_init_revisions(r, &rev, NULL);
setup_revisions(0, NULL, &rev, &opt);
diff --git a/add-patch.c b/add-patch.c
index 814de57c4a..86181770f2 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -420,7 +420,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
/* could be on an unborn branch */
!strcmp("HEAD", s->revision) &&
repo_get_oid(the_repository, "HEAD", &oid) ?
- empty_tree_oid_hex() : s->revision);
+ empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
}
color_arg_index = args.nr;
/* Use `--no-color` explicitly, just in case `diff.color = always`. */
diff --git a/builtin/merge.c b/builtin/merge.c
index abe66311c7..bb94b7df21 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -330,7 +330,8 @@ static void read_empty(const struct object_id *oid)
{
struct child_process cmd = CHILD_PROCESS_INIT;
- strvec_pushl(&cmd.args, "read-tree", "-m", "-u", empty_tree_oid_hex(),
+ strvec_pushl(&cmd.args, "read-tree", "-m", "-u",
+ empty_tree_oid_hex(the_repository->hash_algo),
oid_to_hex(oid), NULL);
cmd.git_cmd = 1;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index aa5ba27d17..41d5fb8e60 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1371,7 +1371,7 @@ static const char *push_to_deploy(unsigned char *sha1,
strvec_pushl(&child.args, "diff-index", "--quiet", "--cached",
"--ignore-submodules",
/* diff-index with either HEAD or an empty tree */
- head_has_history() ? "HEAD" : empty_tree_oid_hex(),
+ head_has_history() ? "HEAD" : empty_tree_oid_hex(the_repository->hash_algo),
"--", NULL);
strvec_pushv(&child.env, env->v);
child.no_stdin = 1;
diff --git a/hash-ll.h b/hash-ll.h
index 1000a9af22..3161c778b9 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -347,8 +347,7 @@ static inline int is_null_oid(const struct object_id *oid)
return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
}
-const char *empty_tree_oid_hex(void);
-const char *empty_blob_oid_hex(void);
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
static inline int is_empty_blob_oid(const struct object_id *oid,
const struct git_hash_algo *algop)
diff --git a/object-file.c b/object-file.c
index bb97f8a809..72318c8dd4 100644
--- a/object-file.c
+++ b/object-file.c
@@ -227,16 +227,10 @@ const struct object_id *null_oid(void)
return the_hash_algo->null_oid;
}
-const char *empty_tree_oid_hex(void)
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
{
static char buf[GIT_MAX_HEXSZ + 1];
- return oid_to_hex_r(buf, the_hash_algo->empty_tree);
-}
-
-const char *empty_blob_oid_hex(void)
-{
- static char buf[GIT_MAX_HEXSZ + 1];
- return oid_to_hex_r(buf, the_hash_algo->empty_blob);
+ return oid_to_hex_r(buf, algop->empty_tree);
}
int hash_algo_by_name(const char *name)
diff --git a/sequencer.c b/sequencer.c
index 68d62a12ff..823691e379 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
unborn = 1;
} else if (unborn)
oidcpy(&head, the_hash_algo->empty_tree);
- if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
+ if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
NULL, 0))
return error_dirty_index(r, opts);
}
diff --git a/submodule.c b/submodule.c
index 759cf1e1cd..caf3aa5600 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2119,7 +2119,7 @@ static void submodule_reset_index(const char *path, const char *super_prefix)
strvec_pushf(&cp.args, "--super-prefix=%s%s/",
(super_prefix ? super_prefix : ""), path);
- strvec_push(&cp.args, empty_tree_oid_hex());
+ strvec_push(&cp.args, empty_tree_oid_hex(the_repository->hash_algo));
if (run_command(&cp))
die(_("could not reset submodule index"));
@@ -2229,9 +2229,9 @@ int submodule_move_head(const char *path, const char *super_prefix,
strvec_push(&cp.args, "-m");
if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
- strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex());
+ strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex(the_repository->hash_algo));
- strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex());
+ strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex(the_repository->hash_algo));
if (run_command(&cp)) {
ret = error(_("Submodule '%s' could not be updated."), path);
diff --git a/wt-status.c b/wt-status.c
index ff4be071ca..5051f5e599 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -641,7 +641,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
repo_init_revisions(s->repo, &rev, NULL);
memset(&opt, 0, sizeof(opt));
- opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
+ opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.flags.override_submodule_config = 1;
@@ -1136,7 +1136,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
rev.diffopt.ita_invisible_in_index = 1;
memset(&opt, 0, sizeof(opt));
- opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
+ opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (7 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 10/20] refs: avoid include cycle with "repository.h" Patrick Steinhardt
` (11 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 54626 bytes --]
Use of the `the_repository` variable is deprecated nowadays, and we
slowly but steadily convert the codebase to not use it anymore. Instead,
callers should be passing down the repository to work on via parameters.
It is hard though to prove that a given code unit does not use this
variable anymore. The most trivial case, merely demonstrating that there
is no direct use of `the_repository`, is already a bit of a pain during
code reviews as the reviewer needs to manually verify claims made by the
patch author. The bigger problem though is that we have many interfaces
that implicitly rely on `the_repository`.
Introduce a new `USE_THE_REPOSITORY_VARIABLE` macro that allows code
units to opt into usage of `the_repository`. The intent of this macro is
to demonstrate that a certain code unit does not use this variable
anymore, and to keep it from new dependencies on it in future changes,
be it explicit or implicit
For now, the macro only guards `the_repository` itself as well as
`the_hash_algo`. There are many more known interfaces where we have an
implicit dependency on `the_repository`, but those are not guarded at
the current point in time. Over time though, we should start to add
guards as required (or even better, just remove them).
Define the macro as required in our code units. As expected, most of our
code still relies on the global variable. Nearly all of our builtins
rely on the variable as there is no way yet to pass `the_repository` to
their entry point. For now, declare the macro in "biultin.h" to keep the
required changes at least a little bit more contained.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
add-interactive.c | 2 ++
add-patch.c | 2 ++
apply.c | 2 ++
archive-tar.c | 3 +++
archive-zip.c | 3 +++
archive.c | 2 ++
attr.c | 2 ++
bisect.c | 2 ++
blame.c | 2 ++
branch.c | 2 ++
builtin.h | 8 ++++++++
builtin/blame.c | 2 +-
builtin/log.c | 2 +-
bulk-checkin.c | 3 +++
bundle-uri.c | 2 ++
bundle.c | 2 ++
cache-tree.c | 2 ++
checkout.c | 2 ++
chunk-format.c | 2 ++
combine-diff.c | 2 ++
commit-graph.c | 2 ++
commit-reach.c | 2 ++
commit.c | 2 ++
common-main.c | 2 ++
compat/win32/trace2_win32_process_info.c | 2 ++
config.c | 3 +++
connected.c | 2 ++
convert.c | 2 ++
csum-file.c | 3 +++
delta-islands.c | 2 ++
diagnose.c | 2 ++
diff-lib.c | 3 +++
diff.c | 3 +++
diffcore-break.c | 3 +++
diffcore-rename.c | 3 +++
dir.c | 3 +++
entry.c | 2 ++
environment.c | 3 +++
fetch-pack.c | 2 ++
fmt-merge-msg.c | 2 ++
fsck.c | 2 ++
fsmonitor-ipc.c | 2 ++
git.c | 2 ++
hash-lookup.c | 2 ++
hash.h | 4 +++-
help.c | 2 ++
hex.c | 2 ++
http-backend.c | 2 ++
http-push.c | 2 ++
http-walker.c | 2 ++
http.c | 2 ++
list-objects-filter-options.c | 2 ++
list-objects-filter.c | 2 ++
list-objects.c | 2 ++
log-tree.c | 2 ++
loose.c | 2 ++
ls-refs.c | 2 ++
mailmap.c | 2 ++
match-trees.c | 2 ++
merge-blobs.c | 2 ++
merge-ort.c | 2 ++
merge-recursive.c | 3 +++
merge.c | 2 ++
midx-write.c | 2 ++
midx.c | 2 ++
negotiator/default.c | 2 ++
negotiator/skipping.c | 2 ++
notes-cache.c | 2 ++
notes-merge.c | 2 ++
notes-utils.c | 2 ++
notes.c | 2 ++
object-file-convert.c | 2 ++
object-file.c | 3 +++
object-name.c | 2 ++
object.c | 2 ++
oid-array.c | 2 ++
oss-fuzz/fuzz-commit-graph.c | 2 ++
pack-bitmap-write.c | 2 ++
pack-bitmap.c | 2 ++
pack-check.c | 2 ++
pack-revindex.c | 2 ++
pack-write.c | 2 ++
packfile.c | 2 ++
parse-options-cb.c | 2 ++
path.c | 3 +++
pathspec.c | 2 ++
pretty.c | 2 ++
progress.c | 2 ++
promisor-remote.c | 2 ++
range-diff.c | 2 ++
reachable.c | 2 ++
read-cache.c | 3 +++
rebase-interactive.c | 2 ++
ref-filter.c | 2 ++
reflog-walk.c | 2 ++
reflog.c | 2 ++
refs.c | 2 ++
refs/files-backend.c | 2 ++
refs/packed-backend.c | 2 ++
refs/reftable-backend.c | 2 ++
refspec.c | 2 ++
remote-curl.c | 2 ++
remote.c | 2 ++
repository.h | 2 ++
rerere.c | 2 ++
reset.c | 2 ++
resolve-undo.c | 2 ++
revision.c | 2 ++
run-command.c | 2 ++
scalar.c | 2 ++
send-pack.c | 2 ++
sequencer.c | 2 ++
serve.c | 2 ++
server-info.c | 2 ++
setup.c | 2 ++
shallow.c | 2 ++
split-index.c | 2 ++
streaming.c | 3 +++
submodule-config.c | 2 ++
submodule.c | 2 ++
t/helper/test-bitmap.c | 2 ++
t/helper/test-bloom.c | 2 ++
t/helper/test-cache-tree.c | 2 ++
t/helper/test-dump-cache-tree.c | 2 ++
t/helper/test-dump-fsmonitor.c | 2 ++
t/helper/test-dump-split-index.c | 2 ++
t/helper/test-dump-untracked-cache.c | 2 ++
t/helper/test-find-pack.c | 2 ++
t/helper/test-fsmonitor-client.c | 2 ++
t/helper/test-lazy-init-name-hash.c | 2 ++
t/helper/test-match-trees.c | 2 ++
t/helper/test-oidmap.c | 2 ++
t/helper/test-pack-mtimes.c | 2 ++
t/helper/test-reach.c | 2 ++
t/helper/test-read-cache.c | 2 ++
t/helper/test-read-graph.c | 2 ++
t/helper/test-read-midx.c | 2 ++
t/helper/test-ref-store.c | 2 ++
t/helper/test-repository.c | 2 ++
t/helper/test-revision-walking.c | 2 ++
t/helper/test-scrap-cache-tree.c | 2 ++
t/helper/test-submodule-config.c | 2 ++
t/helper/test-submodule-nested-repo-config.c | 2 ++
t/helper/test-submodule.c | 2 ++
t/helper/test-trace2.c | 2 ++
t/helper/test-write-cache.c | 2 ++
t/unit-tests/t-example-decorate.c | 2 ++
tag.c | 2 ++
tmp-objdir.c | 2 ++
transport-helper.c | 2 ++
transport.c | 2 ++
tree-walk.c | 2 ++
tree.c | 2 ++
unpack-trees.c | 2 ++
upload-pack.c | 2 ++
walker.c | 2 ++
worktree.c | 2 ++
wt-status.c | 2 ++
xdiff-interface.c | 2 ++
159 files changed, 339 insertions(+), 3 deletions(-)
diff --git a/add-interactive.c b/add-interactive.c
index a0961096cd..49042b3026 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "add-interactive.h"
#include "color.h"
diff --git a/add-patch.c b/add-patch.c
index 86181770f2..99e037c1e2 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "add-interactive.h"
#include "advice.h"
diff --git a/apply.c b/apply.c
index 528939abb6..ff939f908a 100644
--- a/apply.c
+++ b/apply.c
@@ -7,6 +7,8 @@
*
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
diff --git a/archive-tar.c b/archive-tar.c
index 8ae30125f8..e7b3489e1e 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2005, 2006 Rene Scharfe
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
diff --git a/archive-zip.c b/archive-zip.c
index fd1d3f816d..9f32730181 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2006 Rene Scharfe
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "archive.h"
diff --git a/archive.c b/archive.c
index 5287fcdd8e..7bd60d0632 100644
--- a/archive.c
+++ b/archive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/attr.c b/attr.c
index 300f994ba6..b5ed83c90e 100644
--- a/attr.c
+++ b/attr.c
@@ -6,6 +6,8 @@
* an insanely large number of attributes.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/bisect.c b/bisect.c
index 4ea703bec1..135f94ba09 100644
--- a/bisect.c
+++ b/bisect.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/blame.c b/blame.c
index a80f5e2e61..d403c46a35 100644
--- a/blame.c
+++ b/blame.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "refs.h"
#include "object-store-ll.h"
diff --git a/branch.c b/branch.c
index df5d24fec6..c887ea2151 100644
--- a/branch.c
+++ b/branch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/builtin.h b/builtin.h
index 7eda9b2486..14fa017160 100644
--- a/builtin.h
+++ b/builtin.h
@@ -1,6 +1,14 @@
#ifndef BUILTIN_H
#define BUILTIN_H
+/*
+ * TODO: Almost all of our builtins access `the_repository` by necessity
+ * because they do not get passed a pointer to it. We should adapt the function
+ * signature of those main functions to accept a `struct repository *` and then
+ * remove the macro here.
+ */
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
/*
diff --git a/builtin/blame.c b/builtin/blame.c
index e09ff0155a..de89fff3f8 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -5,7 +5,7 @@
* See COPYING for licensing conditions
*/
-#include "git-compat-util.h"
+#include "builtin.h"
#include "config.h"
#include "color.h"
#include "builtin.h"
diff --git a/builtin/log.c b/builtin/log.c
index ccbda8a005..00305bea51 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -4,7 +4,7 @@
* (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano
*/
-#include "git-compat-util.h"
+#include "builtin.h"
#include "abspath.h"
#include "config.h"
#include "environment.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index eb46b88637..da8673199b 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2011, Google Inc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bulk-checkin.h"
#include "environment.h"
diff --git a/bundle-uri.c b/bundle-uri.c
index 91b3319a5c..804fbcfbfa 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bundle-uri.h"
#include "bundle.h"
diff --git a/bundle.c b/bundle.c
index 95367c2d0a..82c285b905 100644
--- a/bundle.c
+++ b/bundle.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "lockfile.h"
#include "bundle.h"
diff --git a/cache-tree.c b/cache-tree.c
index 3290a1b8dd..50610c3f3c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/checkout.c b/checkout.c
index cfaea4bd10..0b1cf8b40b 100644
--- a/checkout.c
+++ b/checkout.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-name.h"
#include "remote.h"
diff --git a/chunk-format.c b/chunk-format.c
index cdc7f39b70..2dde24e6a3 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "chunk-format.h"
#include "csum-file.h"
diff --git a/combine-diff.c b/combine-diff.c
index 4960d904ac..829a44e416 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-store-ll.h"
#include "commit.h"
diff --git a/commit-graph.c b/commit-graph.c
index e4eefd83bf..b6bb9df0d0 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "csum-file.h"
diff --git a/commit-reach.c b/commit-reach.c
index 384aee1ab3..dabc2972e4 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "commit-graph.h"
diff --git a/commit.c b/commit.c
index 1d08951007..4956803e11 100644
--- a/commit.c
+++ b/commit.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"
diff --git a/common-main.c b/common-main.c
index b86f40600f..8e68ac9e42 100644
--- a/common-main.c
+++ b/common-main.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "exec-cmd.h"
#include "gettext.h"
diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
index 3ef0936f6f..f147da706a 100644
--- a/compat/win32/trace2_win32_process_info.c
+++ b/compat/win32/trace2_win32_process_info.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../../git-compat-util.h"
#include "../../json-writer.h"
#include "../../repository.h"
diff --git a/config.c b/config.c
index abce05b774..7951029644 100644
--- a/config.c
+++ b/config.c
@@ -5,6 +5,9 @@
* Copyright (C) Johannes Schindelin, 2005
*
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
diff --git a/connected.c b/connected.c
index 8f89376dbc..87cc4b57a1 100644
--- a/connected.c
+++ b/connected.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/convert.c b/convert.c
index f2b9f01354..d8737fe0f2 100644
--- a/convert.c
+++ b/convert.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/csum-file.c b/csum-file.c
index f4be0804b7..8abbf01325 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -7,6 +7,9 @@
* files. Useful when you write a file that you want to be
* able to verify hasn't been messed with afterwards.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "progress.h"
#include "csum-file.h"
diff --git a/delta-islands.c b/delta-islands.c
index 89d51b72e3..ffe1ca2814 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object.h"
#include "commit.h"
diff --git a/diagnose.c b/diagnose.c
index 4d096c857f..cc2d535b60 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diagnose.h"
#include "compat/disk.h"
diff --git a/diff-lib.c b/diff-lib.c
index 3fb8d79fef..b0d0f711e8 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "diff.h"
diff --git a/diff.c b/diff.c
index 60d1f7be81..d4579d5f76 100644
--- a/diff.c
+++ b/diff.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
diff --git a/diffcore-break.c b/diffcore-break.c
index 49ba38aa7c..831b66b5c3 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diffcore.h"
#include "hash.h"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 5abb958651..ae504007cf 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -2,6 +2,9 @@
*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diff.h"
#include "diffcore.h"
diff --git a/dir.c b/dir.c
index 5de421c29c..b7a6625ebd 100644
--- a/dir.c
+++ b/dir.c
@@ -5,6 +5,9 @@
* Copyright (C) Linus Torvalds, 2005-2006
* Junio Hamano, 2005-2006
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/entry.c b/entry.c
index b8c257f6f9..fe1f74d140 100644
--- a/entry.c
+++ b/entry.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-store-ll.h"
#include "dir.h"
diff --git a/environment.c b/environment.c
index 701d515135..5cea2c9f54 100644
--- a/environment.c
+++ b/environment.c
@@ -7,6 +7,9 @@
* even if you might want to know where the git directory etc
* are.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "branch.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index eba9e420ea..e6e14b3874 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 7d144b803a..b8bca89c0c 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/fsck.c b/fsck.c
index dd0a33028e..432996cbb6 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "date.h"
#include "dir.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 45471b5b74..f1b1631111 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "simple-ipc.h"
diff --git a/git.c b/git.c
index 683bb69194..e35af9b0e5 100644
--- a/git.c
+++ b/git.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "builtin.h"
#include "config.h"
#include "environment.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index 9aa6b82eb7..5f808caa51 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "hash-lookup.h"
diff --git a/hash.h b/hash.h
index 39a0164be3..cb85d26a2f 100644
--- a/hash.h
+++ b/hash.h
@@ -4,6 +4,8 @@
#include "hash-ll.h"
#include "repository.h"
-#define the_hash_algo the_repository->hash_algo
+#ifdef USE_THE_REPOSITORY_VARIABLE
+# define the_hash_algo the_repository->hash_algo
+#endif
#endif
diff --git a/help.c b/help.c
index 1d057aa607..10fdb1a03d 100644
--- a/help.c
+++ b/help.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "builtin.h"
diff --git a/hex.c b/hex.c
index bc9e86a978..5ca78a7744 100644
--- a/hex.c
+++ b/hex.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "hex.h"
diff --git a/http-backend.c b/http-backend.c
index 5b65287ac9..7c0b3be968 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/http-push.c b/http-push.c
index a97df4a1fb..7315a694aa 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/http-walker.c b/http-walker.c
index b7110b6f82..e417a7f51c 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "hex.h"
diff --git a/http.c b/http.c
index 67cc47d28f..6536816e81 100644
--- a/http.c
+++ b/http.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "git-curl-compat.h"
#include "hex.h"
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index c5f363ca6f..00611107d2 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 4346f8da45..49e2fa6f97 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "gettext.h"
diff --git a/list-objects.c b/list-objects.c
index 11ad8be411..985d008799 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"
diff --git a/log-tree.c b/log-tree.c
index 41416de4e3..223a4d9463 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit-reach.h"
#include "config.h"
diff --git a/loose.c b/loose.c
index f6faa6216a..a8bf772172 100644
--- a/loose.c
+++ b/loose.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
diff --git a/ls-refs.c b/ls-refs.c
index 398afe4ce3..2dd925b43d 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/mailmap.c b/mailmap.c
index b2efe29b3d..534a3eb4f0 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "string-list.h"
diff --git a/match-trees.c b/match-trees.c
index 50c42e2061..f17c74d483 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "match-trees.h"
diff --git a/merge-blobs.c b/merge-blobs.c
index 2f659fd014..0ad0390fea 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-ll.h"
#include "blob.h"
diff --git a/merge-ort.c b/merge-ort.c
index eaede6cead..691db9050e 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -14,6 +14,8 @@
* "cale", "peedy", or "ins" instead of "ort"?)
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-ort.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 8ff29ed09e..46ee364af7 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3,6 +3,9 @@
* Fredrik Kuivinen.
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-recursive.h"
diff --git a/merge.c b/merge.c
index 752a937fa9..fe3efa4b24 100644
--- a/merge.c
+++ b/merge.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/midx-write.c b/midx-write.c
index 55a6b63bac..9a194e8aac 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/midx.c b/midx.c
index 1e75f1a7eb..3992b05465 100644
--- a/midx.c
+++ b/midx.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "dir.h"
diff --git a/negotiator/default.c b/negotiator/default.c
index 518b3c43b2..e3fa5c3324 100644
--- a/negotiator/default.c
+++ b/negotiator/default.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "default.h"
#include "../commit.h"
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
index b7e008c2fd..f109928ad0 100644
--- a/negotiator/skipping.c
+++ b/negotiator/skipping.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "skipping.h"
#include "../commit.h"
diff --git a/notes-cache.c b/notes-cache.c
index 038db01ca0..ecfdf6e43b 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-store-ll.h"
diff --git a/notes-merge.c b/notes-merge.c
index 801941c2d1..d95e683414 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "commit.h"
diff --git a/notes-utils.c b/notes-utils.c
index e33aa86c4b..bca71274be 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/notes.c b/notes.c
index afe2e2882e..b6a13d0980 100644
--- a/notes.c
+++ b/notes.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/object-file-convert.c b/object-file-convert.c
index f684038f7f..958f61f094 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "strbuf.h"
diff --git a/object-file.c b/object-file.c
index 72318c8dd4..a6555ed68c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -6,6 +6,9 @@
* This handles basic git object files - packing, unpacking,
* creation etc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/object-name.c b/object-name.c
index 523af6f64f..d7509514bc 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-name.h"
#include "advice.h"
diff --git a/object.c b/object.c
index 93b5d97fdb..0c0fcb76c0 100644
--- a/object.c
+++ b/object.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/oid-array.c b/oid-array.c
index 1f36651754..9cac974395 100644
--- a/oid-array.c
+++ b/oid-array.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "oid-array.h"
#include "hash-lookup.h"
diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c
index 75e668a057..951c9c082f 100644
--- a/oss-fuzz/fuzz-commit-graph.c
+++ b/oss-fuzz/fuzz-commit-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit-graph.h"
#include "repository.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 59d2e3a387..37a8ad0fb3 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 184d28f05c..7eafdce4ee 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "gettext.h"
diff --git a/pack-check.c b/pack-check.c
index 288f5a3479..d78289da3c 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index fc63aa76a2..de922b47d2 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
diff --git a/pack-write.c b/pack-write.c
index eef625fa5b..d07f03d0ab 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/packfile.c b/packfile.c
index ec7312cd20..813584646f 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/parse-options-cb.c b/parse-options-cb.c
index d99d688d3c..3fb7ce68ca 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "parse-options.h"
#include "branch.h"
diff --git a/path.c b/path.c
index adfb3d3eb7..19f7684f38 100644
--- a/path.c
+++ b/path.c
@@ -1,6 +1,9 @@
/*
* Utilities for paths and pathnames
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
diff --git a/pathspec.c b/pathspec.c
index 2133b9fe60..fe1f0f41af 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "parse.h"
diff --git a/pretty.c b/pretty.c
index 22a81506b7..2c14a88abc 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/progress.c b/progress.c
index c83cb60bf1..0d44c18edc 100644
--- a/progress.c
+++ b/progress.c
@@ -9,6 +9,8 @@
*/
#define GIT_TEST_PROGRESS_ONLY
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "pager.h"
#include "progress.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 2ca7c2ae48..317e1b127f 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/range-diff.c b/range-diff.c
index c45b6d849c..5f01605550 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/reachable.c b/reachable.c
index 1224b30008..46613a6bb6 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/read-cache.c b/read-cache.c
index 085b22faf3..48bf24f87c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,6 +3,9 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bulk-checkin.h"
#include "config.h"
diff --git a/rebase-interactive.c b/rebase-interactive.c
index c343e16fcd..e93b385523 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "editor.h"
diff --git a/ref-filter.c b/ref-filter.c
index f7fb0c7e0e..8c5e673fc0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/reflog-walk.c b/reflog-walk.c
index 5f09552c5c..c7070b13b0 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "refs.h"
diff --git a/reflog.c b/reflog.c
index 3c80950186..5ca944529b 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "object-store-ll.h"
diff --git a/refs.c b/refs.c
index 6e7caefdcf..727ed6c1d6 100644
--- a/refs.c
+++ b/refs.c
@@ -2,6 +2,8 @@
* The backend-independent part of the reference module.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index b484b5880d..35931bc71e 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../copy.h"
#include "../environment.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 5ab1b21d10..a0666407cd 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../config.h"
#include "../dir.h"
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 57df2aba66..6e34eb2188 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../abspath.h"
#include "../chdir-notify.h"
diff --git a/refspec.c b/refspec.c
index d60932f4de..c2e3e24351 100644
--- a/refspec.c
+++ b/refspec.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/remote-curl.c b/remote-curl.c
index 6008d7e87c..1930f83cc7 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "git-curl-compat.h"
#include "config.h"
diff --git a/remote.c b/remote.c
index 1064171085..5fab7f0970 100644
--- a/remote.c
+++ b/remote.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/repository.h b/repository.h
index a35cd77c35..29727edec6 100644
--- a/repository.h
+++ b/repository.h
@@ -197,7 +197,9 @@ struct repository {
unsigned different_commondir:1;
};
+#ifdef USE_THE_REPOSITORY_VARIABLE
extern struct repository *the_repository;
+#endif
/*
* Define a custom repository layout. Any field can be NULL, which
diff --git a/rerere.c b/rerere.c
index c7e1f8fd25..597256fa5b 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/reset.c b/reset.c
index 937f11c0f4..9550dea03d 100644
--- a/reset.c
+++ b/reset.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "cache-tree.h"
#include "gettext.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 4e6f0e4676..8c9911affb 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "hash.h"
diff --git a/revision.c b/revision.c
index 7ddf0f151a..40da255953 100644
--- a/revision.c
+++ b/revision.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/run-command.c b/run-command.c
index 31b20123d8..f5fde92b7c 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "run-command.h"
#include "environment.h"
diff --git a/scalar.c b/scalar.c
index 331b91dbdb..a1cb4b45b5 100644
--- a/scalar.c
+++ b/scalar.c
@@ -2,6 +2,8 @@
* The Scalar command-line interface.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "gettext.h"
diff --git a/send-pack.c b/send-pack.c
index 37f59d4f66..b42e6986df 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/sequencer.c b/sequencer.c
index 823691e379..8083fe20bf 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
diff --git a/serve.c b/serve.c
index aa651b73e9..33608ea4d5 100644
--- a/serve.c
+++ b/serve.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
diff --git a/server-info.c b/server-info.c
index 6feaa457c5..97e839c33d 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "environment.h"
diff --git a/setup.c b/setup.c
index 20f380825b..7e1169eb86 100644
--- a/setup.c
+++ b/setup.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "copy.h"
diff --git a/shallow.c b/shallow.c
index a0b181ba8a..31a6ca40fe 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "repository.h"
diff --git a/split-index.c b/split-index.c
index 058a8f448e..120c8190b1 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/streaming.c b/streaming.c
index 10adf625b2..38839511af 100644
--- a/streaming.c
+++ b/streaming.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2011, Google Inc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "convert.h"
#include "environment.h"
diff --git a/submodule-config.c b/submodule-config.c
index ad43a282da..9b0bb0b9f4 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "environment.h"
diff --git a/submodule.c b/submodule.c
index caf3aa5600..ab99a30253 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index af43ee1cb5..1f18d57007 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "git-compat-util.h"
#include "pack-bitmap.h"
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index 1281e66876..f7f9b62002 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "bloom.h"
#include "hex.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index dc89ecfd71..5cdef3ebef 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "gettext.h"
#include "hex.h"
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 02b0b46c3f..3f0c7d0ed0 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hash.h"
#include "hex.h"
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 4f215fea02..1b7f37a84f 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "read-cache-ll.h"
#include "repository.h"
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index f472691a3c..a6720faf9c 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index 9ff67c3967..4f010d5324 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "dir.h"
#include "hex.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index e8bd793e58..14b2b0c12c 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "object-name.h"
#include "object-store.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 8280984d08..02bfe92e8d 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -3,6 +3,8 @@
* a `git fsmonitor--daemon` daemon.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "parse-options.h"
#include "fsmonitor-ipc.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 5f33bb7b8f..40f5df4412 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "environment.h"
#include "name-hash.h"
diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c
index d0db5ff26f..e0e2048320 100644
--- a/t/helper/test-match-trees.c
+++ b/t/helper/test-match-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "match-trees.h"
diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c
index bd30244a54..c03cfa5ecf 100644
--- a/t/helper/test-oidmap.c
+++ b/t/helper/test-oidmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "object-name.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 67a964ef90..f8f9afbb5b 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 1ba226f1f9..5dd374379c 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit.h"
#include "commit-reach.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index e803c43ece..d285c656bd 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "config.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8c7a83f578..d9e980d04c 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 4acae41bb9..83effc2b5f 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "midx.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index ad24300170..637b8b294e 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "refs.h"
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 0c7c5aa4dd..c6a074df3d 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit-graph.h"
#include "commit.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index f346951bc2..071f5bd1e2 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -8,6 +8,8 @@
* published by the Free Software Foundation.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit.h"
#include "diff.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 737cbe475b..64fff6e9e3 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "lockfile.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 4b809d9dca..cbe93f2f9e 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "config.h"
#include "hash.h"
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index ecd40ded99..6ca069ce63 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index 7197969a08..22e518d229 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "test-tool-utils.h"
#include "parse-options.h"
diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c
index 1adac29a57..cd955ec63e 100644
--- a/t/helper/test-trace2.c
+++ b/t/helper/test-trace2.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "strvec.h"
#include "run-command.h"
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index 7e3da380a9..b37dd2c5d6 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "lockfile.h"
#include "read-cache-ll.h"
diff --git a/t/unit-tests/t-example-decorate.c b/t/unit-tests/t-example-decorate.c
index 3c856a8cf2..a4a75db735 100644
--- a/t/unit-tests/t-example-decorate.c
+++ b/t/unit-tests/t-example-decorate.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-lib.h"
#include "object.h"
#include "decorate.h"
diff --git a/tag.c b/tag.c
index 52bbe50819..d24170e340 100644
--- a/tag.c
+++ b/tag.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "tag.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 3509258be5..a8e4553f27 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tmp-objdir.h"
#include "abspath.h"
diff --git a/transport-helper.c b/transport-helper.c
index 9820947ab2..09b3560ffd 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "transport.h"
#include "quote.h"
diff --git a/transport.c b/transport.c
index 83ddea8fbc..b9c8827ed9 100644
--- a/transport.c
+++ b/transport.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/tree-walk.c b/tree-walk.c
index 535a3a2539..a033397965 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tree-walk.h"
#include "dir.h"
diff --git a/tree.c b/tree.c
index 7973d3f9a8..ad86ad1ba9 100644
--- a/tree.c
+++ b/tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "tree.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 304ea2ed86..7dc884fafd 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "strvec.h"
diff --git a/upload-pack.c b/upload-pack.c
index b726f7a57d..0052c6a4dc 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/walker.c b/walker.c
index 946d86b04e..0fafdc97cf 100644
--- a/walker.c
+++ b/walker.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/worktree.c b/worktree.c
index 70844d023a..f3c4c8ec54 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
diff --git a/wt-status.c b/wt-status.c
index 5051f5e599..8815df419e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "wt-status.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 16ed8ac492..d5dc88661e 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "config.h"
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 10/20] refs: avoid include cycle with "repository.h"
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (8 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 11/20] hash-ll: merge with "hash.h" Patrick Steinhardt
` (10 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 1797 bytes --]
There is an include cycle between "refs.h" and "repository.h" via
"commit.h", "object.h" and "hash.h". This has the effect that several
definitions of structs and enums will not be visible once we merge
"hash-ll.h" back into "hash.h" in the next commit.
The only reason that "repository.h" includes "refs.h" is the definition
of `enum ref_storage_format`. Move it into "repository.h" and have
"refs.h" include "repository.h" instead to fix the cycle.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
refs.h | 8 +-------
repository.h | 7 ++++++-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/refs.h b/refs.h
index 76d25df4de..a9716e5d25 100644
--- a/refs.h
+++ b/refs.h
@@ -2,21 +2,15 @@
#define REFS_H
#include "commit.h"
+#include "repository.h"
struct object_id;
struct ref_store;
-struct repository;
struct strbuf;
struct string_list;
struct string_list_item;
struct worktree;
-enum ref_storage_format {
- REF_STORAGE_FORMAT_UNKNOWN,
- REF_STORAGE_FORMAT_FILES,
- REF_STORAGE_FORMAT_REFTABLE,
-};
-
enum ref_storage_format ref_storage_format_by_name(const char *name);
const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_format);
diff --git a/repository.h b/repository.h
index 29727edec6..6ce6826c26 100644
--- a/repository.h
+++ b/repository.h
@@ -1,7 +1,6 @@
#ifndef REPOSITORY_H
#define REPOSITORY_H
-#include "refs.h"
#include "strmap.h"
struct config_set;
@@ -27,6 +26,12 @@ enum fetch_negotiation_setting {
FETCH_NEGOTIATION_NOOP,
};
+enum ref_storage_format {
+ REF_STORAGE_FORMAT_UNKNOWN,
+ REF_STORAGE_FORMAT_FILES,
+ REF_STORAGE_FORMAT_REFTABLE,
+};
+
struct repo_settings {
int initialized;
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 11/20] hash-ll: merge with "hash.h"
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (9 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 10/20] refs: avoid include cycle with "repository.h" Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 12/20] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
` (9 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 36788 bytes --]
The "hash-ll.h" header was introduced via d1cbe1e6d8 (hash-ll.h: split
out of hash.h to remove dependency on repository.h, 2023-04-22) to make
explicit the split between hash-related functions that rely on the
global `the_repository`, and those that don't. This split is no longer
necessary now that we we have removed the reliance on `the_repository`.
Merge "hash-ll.h" back into "hash.h". This causes some code units to not
include "repository.h" anymore, which requires us to add some forward
declarations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.h | 2 +-
bloom.c | 1 +
checkout.h | 2 +-
chunk-format.h | 2 +-
commit-graph.h | 2 +
compat/sha1-chunked.c | 2 +-
convert.h | 2 +-
csum-file.h | 2 +-
diff.h | 2 +-
diffcore.h | 2 +-
dir.h | 2 +-
hash-ll.h | 364 -------------------------------------
hash.h | 362 +++++++++++++++++++++++++++++++++++-
hex.h | 2 +-
loose.h | 2 +
merge-ort.h | 2 +-
object-file-convert.c | 2 +-
object.h | 2 +-
oidmap.h | 2 +-
oidtree.h | 2 +-
packfile.h | 2 +
protocol-caps.c | 2 +-
read-cache-ll.h | 2 +-
refs/ref-cache.h | 2 +-
reftable/dump.c | 2 +-
reftable/reftable-record.h | 2 +-
reftable/system.h | 2 +-
remote.h | 2 +-
reset.h | 2 +-
resolve-undo.h | 2 +-
serve.c | 2 +-
split-index.h | 2 +-
t/helper/test-hash-speed.c | 2 +-
t/helper/test-sha1.c | 2 +-
t/helper/test-sha256.c | 2 +-
t/unit-tests/lib-oid.h | 2 +-
tree-diff.c | 1 +
tree-walk.h | 2 +-
xdiff-interface.h | 2 +-
39 files changed, 400 insertions(+), 398 deletions(-)
delete mode 100644 hash-ll.h
diff --git a/apply.h b/apply.h
index 7cd38b1443..b9f18ce87d 100644
--- a/apply.h
+++ b/apply.h
@@ -1,7 +1,7 @@
#ifndef APPLY_H
#define APPLY_H
-#include "hash-ll.h"
+#include "hash.h"
#include "lockfile.h"
#include "string-list.h"
#include "strmap.h"
diff --git a/bloom.c b/bloom.c
index e529f7605c..bbf146fc30 100644
--- a/bloom.c
+++ b/bloom.c
@@ -6,6 +6,7 @@
#include "commit-graph.h"
#include "commit.h"
#include "commit-slab.h"
+#include "repository.h"
define_commit_slab(bloom_filter_slab, struct bloom_filter);
diff --git a/checkout.h b/checkout.h
index ba15a13fb3..55920e7aeb 100644
--- a/checkout.h
+++ b/checkout.h
@@ -1,7 +1,7 @@
#ifndef CHECKOUT_H
#define CHECKOUT_H
-#include "hash-ll.h"
+#include "hash.h"
/*
* Check if the branch name uniquely matches a branch name on a remote
diff --git a/chunk-format.h b/chunk-format.h
index 14b76180ef..212a0a6af1 100644
--- a/chunk-format.h
+++ b/chunk-format.h
@@ -1,7 +1,7 @@
#ifndef CHUNK_FORMAT_H
#define CHUNK_FORMAT_H
-#include "hash-ll.h"
+#include "hash.h"
struct hashfile;
struct chunkfile;
diff --git a/commit-graph.h b/commit-graph.h
index e519cb81cb..6781940195 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -122,6 +122,8 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
struct commit_graph *read_commit_graph_one(struct repository *r,
struct object_directory *odb);
+struct repo_settings;
+
/*
* Callers should initialize the repo_settings with prepare_repo_settings()
* prior to calling parse_commit_graph().
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index a4a6f930d7..0446f9983f 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "hash-ll.h"
+#include "hash.h"
int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
{
diff --git a/convert.h b/convert.h
index d925589444..0a6e4086b8 100644
--- a/convert.h
+++ b/convert.h
@@ -4,7 +4,7 @@
#ifndef CONVERT_H
#define CONVERT_H
-#include "hash-ll.h"
+#include "hash.h"
#include "string-list.h"
struct index_state;
diff --git a/csum-file.h b/csum-file.h
index bc5bec27ac..566e05cbd2 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -1,7 +1,7 @@
#ifndef CSUM_FILE_H
#define CSUM_FILE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "write-or-die.h"
struct progress;
diff --git a/diff.h b/diff.h
index 66bd8aeb29..9901c8ca8c 100644
--- a/diff.h
+++ b/diff.h
@@ -4,7 +4,7 @@
#ifndef DIFF_H
#define DIFF_H
-#include "hash-ll.h"
+#include "hash.h"
#include "pathspec.h"
#include "strbuf.h"
diff --git a/diffcore.h b/diffcore.h
index 5ffe4ec788..1701ed50b9 100644
--- a/diffcore.h
+++ b/diffcore.h
@@ -4,7 +4,7 @@
#ifndef DIFFCORE_H
#define DIFFCORE_H
-#include "hash-ll.h"
+#include "hash.h"
struct diff_options;
struct mem_pool;
diff --git a/dir.h b/dir.h
index 1398a53fb4..69a76d8bdd 100644
--- a/dir.h
+++ b/dir.h
@@ -1,7 +1,7 @@
#ifndef DIR_H
#define DIR_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "pathspec.h"
#include "statinfo.h"
diff --git a/hash-ll.h b/hash-ll.h
deleted file mode 100644
index 3161c778b9..0000000000
--- a/hash-ll.h
+++ /dev/null
@@ -1,364 +0,0 @@
-#ifndef HASH_LL_H
-#define HASH_LL_H
-
-#if defined(SHA1_APPLE)
-#include <CommonCrypto/CommonDigest.h>
-#elif defined(SHA1_OPENSSL)
-# include <openssl/sha.h>
-# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
-# define SHA1_NEEDS_CLONE_HELPER
-# include "sha1/openssl.h"
-# endif
-#elif defined(SHA1_DC)
-#include "sha1dc_git.h"
-#else /* SHA1_BLK */
-#include "block-sha1/sha1.h"
-#endif
-
-#if defined(SHA256_NETTLE)
-#include "sha256/nettle.h"
-#elif defined(SHA256_GCRYPT)
-#define SHA256_NEEDS_CLONE_HELPER
-#include "sha256/gcrypt.h"
-#elif defined(SHA256_OPENSSL)
-# include <openssl/sha.h>
-# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
-# define SHA256_NEEDS_CLONE_HELPER
-# include "sha256/openssl.h"
-# endif
-#else
-#include "sha256/block/sha256.h"
-#endif
-
-#ifndef platform_SHA_CTX
-/*
- * platform's underlying implementation of SHA-1; could be OpenSSL,
- * blk_SHA, Apple CommonCrypto, etc... Note that the relevant
- * SHA-1 header may have already defined platform_SHA_CTX for our
- * own implementations like block-sha1, so we list
- * the default for OpenSSL compatible SHA-1 implementations here.
- */
-#define platform_SHA_CTX SHA_CTX
-#define platform_SHA1_Init SHA1_Init
-#define platform_SHA1_Update SHA1_Update
-#define platform_SHA1_Final SHA1_Final
-#endif
-
-#define git_SHA_CTX platform_SHA_CTX
-#define git_SHA1_Init platform_SHA1_Init
-#define git_SHA1_Update platform_SHA1_Update
-#define git_SHA1_Final platform_SHA1_Final
-
-#ifdef platform_SHA1_Clone
-#define git_SHA1_Clone platform_SHA1_Clone
-#endif
-
-#ifndef platform_SHA256_CTX
-#define platform_SHA256_CTX SHA256_CTX
-#define platform_SHA256_Init SHA256_Init
-#define platform_SHA256_Update SHA256_Update
-#define platform_SHA256_Final SHA256_Final
-#endif
-
-#define git_SHA256_CTX platform_SHA256_CTX
-#define git_SHA256_Init platform_SHA256_Init
-#define git_SHA256_Update platform_SHA256_Update
-#define git_SHA256_Final platform_SHA256_Final
-
-#ifdef platform_SHA256_Clone
-#define git_SHA256_Clone platform_SHA256_Clone
-#endif
-
-#ifdef SHA1_MAX_BLOCK_SIZE
-#include "compat/sha1-chunked.h"
-#undef git_SHA1_Update
-#define git_SHA1_Update git_SHA1_Update_Chunked
-#endif
-
-#ifndef SHA1_NEEDS_CLONE_HELPER
-static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
-{
- memcpy(dst, src, sizeof(*dst));
-}
-#endif
-
-#ifndef SHA256_NEEDS_CLONE_HELPER
-static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
-{
- memcpy(dst, src, sizeof(*dst));
-}
-#endif
-
-/*
- * Note that these constants are suitable for indexing the hash_algos array and
- * comparing against each other, but are otherwise arbitrary, so they should not
- * be exposed to the user or serialized to disk. To know whether a
- * git_hash_algo struct points to some usable hash function, test the format_id
- * field for being non-zero. Use the name field for user-visible situations and
- * the format_id field for fixed-length fields on disk.
- */
-/* An unknown hash function. */
-#define GIT_HASH_UNKNOWN 0
-/* SHA-1 */
-#define GIT_HASH_SHA1 1
-/* SHA-256 */
-#define GIT_HASH_SHA256 2
-/* Number of algorithms supported (including unknown). */
-#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
-
-/* "sha1", big-endian */
-#define GIT_SHA1_FORMAT_ID 0x73686131
-
-/* The length in bytes and in hex digits of an object name (SHA-1 value). */
-#define GIT_SHA1_RAWSZ 20
-#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
-/* The block size of SHA-1. */
-#define GIT_SHA1_BLKSZ 64
-
-/* "s256", big-endian */
-#define GIT_SHA256_FORMAT_ID 0x73323536
-
-/* The length in bytes and in hex digits of an object name (SHA-256 value). */
-#define GIT_SHA256_RAWSZ 32
-#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
-/* The block size of SHA-256. */
-#define GIT_SHA256_BLKSZ 64
-
-/* The length in byte and in hex digits of the largest possible hash value. */
-#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
-#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
-/* The largest possible block size for any supported hash. */
-#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
-
-struct object_id {
- unsigned char hash[GIT_MAX_RAWSZ];
- int algo; /* XXX requires 4-byte alignment */
-};
-
-#define GET_OID_QUIETLY 01
-#define GET_OID_COMMIT 02
-#define GET_OID_COMMITTISH 04
-#define GET_OID_TREE 010
-#define GET_OID_TREEISH 020
-#define GET_OID_BLOB 040
-#define GET_OID_FOLLOW_SYMLINKS 0100
-#define GET_OID_RECORD_PATH 0200
-#define GET_OID_ONLY_TO_DIE 04000
-#define GET_OID_REQUIRE_PATH 010000
-#define GET_OID_HASH_ANY 020000
-
-#define GET_OID_DISAMBIGUATORS \
- (GET_OID_COMMIT | GET_OID_COMMITTISH | \
- GET_OID_TREE | GET_OID_TREEISH | \
- GET_OID_BLOB)
-
-enum get_oid_result {
- FOUND = 0,
- MISSING_OBJECT = -1, /* The requested object is missing */
- SHORT_NAME_AMBIGUOUS = -2,
- /* The following only apply when symlinks are followed */
- DANGLING_SYMLINK = -4, /*
- * The initial symlink is there, but
- * (transitively) points to a missing
- * in-tree file
- */
- SYMLINK_LOOP = -5,
- NOT_DIR = -6, /*
- * Somewhere along the symlink chain, a path is
- * requested which contains a file as a
- * non-final element.
- */
-};
-
-/* A suitably aligned type for stack allocations of hash contexts. */
-union git_hash_ctx {
- git_SHA_CTX sha1;
- git_SHA256_CTX sha256;
-};
-typedef union git_hash_ctx git_hash_ctx;
-
-typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
-typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src);
-typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
-typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
-typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx);
-
-struct git_hash_algo {
- /*
- * The name of the algorithm, as appears in the config file and in
- * messages.
- */
- const char *name;
-
- /* A four-byte version identifier, used in pack indices. */
- uint32_t format_id;
-
- /* The length of the hash in binary. */
- size_t rawsz;
-
- /* The length of the hash in hex characters. */
- size_t hexsz;
-
- /* The block size of the hash. */
- size_t blksz;
-
- /* The hash initialization function. */
- git_hash_init_fn init_fn;
-
- /* The hash context cloning function. */
- git_hash_clone_fn clone_fn;
-
- /* The hash update function. */
- git_hash_update_fn update_fn;
-
- /* The hash finalization function. */
- git_hash_final_fn final_fn;
-
- /* The hash finalization function for object IDs. */
- git_hash_final_oid_fn final_oid_fn;
-
- /* The OID of the empty tree. */
- const struct object_id *empty_tree;
-
- /* The OID of the empty blob. */
- const struct object_id *empty_blob;
-
- /* The all-zeros OID. */
- const struct object_id *null_oid;
-};
-extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
-
-/*
- * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
- * the name doesn't match a known algorithm.
- */
-int hash_algo_by_name(const char *name);
-/* Identical, except based on the format ID. */
-int hash_algo_by_id(uint32_t format_id);
-/* Identical, except based on the length. */
-int hash_algo_by_length(int len);
-/* Identical, except for a pointer to struct git_hash_algo. */
-static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
-{
- return p - hash_algos;
-}
-
-const struct object_id *null_oid(void);
-
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
-{
- /*
- * Teach the compiler that there are only two possibilities of hash size
- * here, so that it can optimize for this case as much as possible.
- */
- if (algop->rawsz == GIT_MAX_RAWSZ)
- return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
- return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
-}
-
-static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
-{
- /*
- * We write this here instead of deferring to hashcmp so that the
- * compiler can properly inline it and avoid calling memcmp.
- */
- if (algop->rawsz == GIT_MAX_RAWSZ)
- return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
- return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
-}
-
-static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
- const struct git_hash_algo *algop)
-{
- memcpy(sha_dst, sha_src, algop->rawsz);
-}
-
-static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
-{
- memset(hash, 0, algop->rawsz);
-}
-
-static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
-{
- return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
-}
-
-static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
-{
- return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
-}
-
-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;
-}
-
-static inline void oidread(struct object_id *oid, const unsigned char *hash,
- const struct git_hash_algo *algop)
-{
- memcpy(oid->hash, hash, algop->rawsz);
- if (algop->rawsz < GIT_MAX_RAWSZ)
- memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline void oidclr(struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- memset(oid->hash, 0, GIT_MAX_RAWSZ);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline struct object_id *oiddup(const struct object_id *src)
-{
- struct object_id *dst = xmalloc(sizeof(struct object_id));
- oidcpy(dst, src);
- return dst;
-}
-
-static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
-{
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-/*
- * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
- * for use in hash tables. Cryptographic hashes are supposed to have
- * uniform distribution, so in contrast to `memhash()`, this just copies
- * the first `sizeof(int)` bytes without shuffling any bits. Note that
- * the results will be different on big-endian and little-endian
- * platforms, so they should not be stored or transferred over the net.
- */
-static inline unsigned int oidhash(const struct object_id *oid)
-{
- /*
- * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
- * platforms that don't support unaligned reads.
- */
- unsigned int hash;
- memcpy(&hash, oid->hash, sizeof(hash));
- return hash;
-}
-
-static inline int is_null_oid(const struct object_id *oid)
-{
- static const unsigned char null_hash[GIT_MAX_RAWSZ];
- return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
-}
-
-const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
-
-static inline int is_empty_blob_oid(const struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- return oideq(oid, algop->empty_blob);
-}
-
-static inline int is_empty_tree_oid(const struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- return oideq(oid, algop->empty_tree);
-}
-
-#endif
diff --git a/hash.h b/hash.h
index cb85d26a2f..72ffbc862e 100644
--- a/hash.h
+++ b/hash.h
@@ -1,11 +1,369 @@
#ifndef HASH_H
#define HASH_H
-#include "hash-ll.h"
-#include "repository.h"
+#if defined(SHA1_APPLE)
+#include <CommonCrypto/CommonDigest.h>
+#elif defined(SHA1_OPENSSL)
+# include <openssl/sha.h>
+# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
+# define SHA1_NEEDS_CLONE_HELPER
+# include "sha1/openssl.h"
+# endif
+#elif defined(SHA1_DC)
+#include "sha1dc_git.h"
+#else /* SHA1_BLK */
+#include "block-sha1/sha1.h"
+#endif
+
+#if defined(SHA256_NETTLE)
+#include "sha256/nettle.h"
+#elif defined(SHA256_GCRYPT)
+#define SHA256_NEEDS_CLONE_HELPER
+#include "sha256/gcrypt.h"
+#elif defined(SHA256_OPENSSL)
+# include <openssl/sha.h>
+# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
+# define SHA256_NEEDS_CLONE_HELPER
+# include "sha256/openssl.h"
+# endif
+#else
+#include "sha256/block/sha256.h"
+#endif
+
+#ifndef platform_SHA_CTX
+/*
+ * platform's underlying implementation of SHA-1; could be OpenSSL,
+ * blk_SHA, Apple CommonCrypto, etc... Note that the relevant
+ * SHA-1 header may have already defined platform_SHA_CTX for our
+ * own implementations like block-sha1, so we list
+ * the default for OpenSSL compatible SHA-1 implementations here.
+ */
+#define platform_SHA_CTX SHA_CTX
+#define platform_SHA1_Init SHA1_Init
+#define platform_SHA1_Update SHA1_Update
+#define platform_SHA1_Final SHA1_Final
+#endif
+
+#define git_SHA_CTX platform_SHA_CTX
+#define git_SHA1_Init platform_SHA1_Init
+#define git_SHA1_Update platform_SHA1_Update
+#define git_SHA1_Final platform_SHA1_Final
+
+#ifdef platform_SHA1_Clone
+#define git_SHA1_Clone platform_SHA1_Clone
+#endif
+
+#ifndef platform_SHA256_CTX
+#define platform_SHA256_CTX SHA256_CTX
+#define platform_SHA256_Init SHA256_Init
+#define platform_SHA256_Update SHA256_Update
+#define platform_SHA256_Final SHA256_Final
+#endif
+
+#define git_SHA256_CTX platform_SHA256_CTX
+#define git_SHA256_Init platform_SHA256_Init
+#define git_SHA256_Update platform_SHA256_Update
+#define git_SHA256_Final platform_SHA256_Final
+
+#ifdef platform_SHA256_Clone
+#define git_SHA256_Clone platform_SHA256_Clone
+#endif
+
+#ifdef SHA1_MAX_BLOCK_SIZE
+#include "compat/sha1-chunked.h"
+#undef git_SHA1_Update
+#define git_SHA1_Update git_SHA1_Update_Chunked
+#endif
+
+#ifndef SHA1_NEEDS_CLONE_HELPER
+static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
+{
+ memcpy(dst, src, sizeof(*dst));
+}
+#endif
+
+#ifndef SHA256_NEEDS_CLONE_HELPER
+static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
+{
+ memcpy(dst, src, sizeof(*dst));
+}
+#endif
+
+/*
+ * Note that these constants are suitable for indexing the hash_algos array and
+ * comparing against each other, but are otherwise arbitrary, so they should not
+ * be exposed to the user or serialized to disk. To know whether a
+ * git_hash_algo struct points to some usable hash function, test the format_id
+ * field for being non-zero. Use the name field for user-visible situations and
+ * the format_id field for fixed-length fields on disk.
+ */
+/* An unknown hash function. */
+#define GIT_HASH_UNKNOWN 0
+/* SHA-1 */
+#define GIT_HASH_SHA1 1
+/* SHA-256 */
+#define GIT_HASH_SHA256 2
+/* Number of algorithms supported (including unknown). */
+#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
+
+/* "sha1", big-endian */
+#define GIT_SHA1_FORMAT_ID 0x73686131
+
+/* The length in bytes and in hex digits of an object name (SHA-1 value). */
+#define GIT_SHA1_RAWSZ 20
+#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
+/* The block size of SHA-1. */
+#define GIT_SHA1_BLKSZ 64
+
+/* "s256", big-endian */
+#define GIT_SHA256_FORMAT_ID 0x73323536
+
+/* The length in bytes and in hex digits of an object name (SHA-256 value). */
+#define GIT_SHA256_RAWSZ 32
+#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
+/* The block size of SHA-256. */
+#define GIT_SHA256_BLKSZ 64
+
+/* The length in byte and in hex digits of the largest possible hash value. */
+#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
+#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
+/* The largest possible block size for any supported hash. */
+#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
+
+struct object_id {
+ unsigned char hash[GIT_MAX_RAWSZ];
+ int algo; /* XXX requires 4-byte alignment */
+};
+
+#define GET_OID_QUIETLY 01
+#define GET_OID_COMMIT 02
+#define GET_OID_COMMITTISH 04
+#define GET_OID_TREE 010
+#define GET_OID_TREEISH 020
+#define GET_OID_BLOB 040
+#define GET_OID_FOLLOW_SYMLINKS 0100
+#define GET_OID_RECORD_PATH 0200
+#define GET_OID_ONLY_TO_DIE 04000
+#define GET_OID_REQUIRE_PATH 010000
+#define GET_OID_HASH_ANY 020000
+
+#define GET_OID_DISAMBIGUATORS \
+ (GET_OID_COMMIT | GET_OID_COMMITTISH | \
+ GET_OID_TREE | GET_OID_TREEISH | \
+ GET_OID_BLOB)
+
+enum get_oid_result {
+ FOUND = 0,
+ MISSING_OBJECT = -1, /* The requested object is missing */
+ SHORT_NAME_AMBIGUOUS = -2,
+ /* The following only apply when symlinks are followed */
+ DANGLING_SYMLINK = -4, /*
+ * The initial symlink is there, but
+ * (transitively) points to a missing
+ * in-tree file
+ */
+ SYMLINK_LOOP = -5,
+ NOT_DIR = -6, /*
+ * Somewhere along the symlink chain, a path is
+ * requested which contains a file as a
+ * non-final element.
+ */
+};
#ifdef USE_THE_REPOSITORY_VARIABLE
+# include "repository.h"
# define the_hash_algo the_repository->hash_algo
#endif
+/* A suitably aligned type for stack allocations of hash contexts. */
+union git_hash_ctx {
+ git_SHA_CTX sha1;
+ git_SHA256_CTX sha256;
+};
+typedef union git_hash_ctx git_hash_ctx;
+
+typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
+typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src);
+typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
+typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
+typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx);
+
+struct git_hash_algo {
+ /*
+ * The name of the algorithm, as appears in the config file and in
+ * messages.
+ */
+ const char *name;
+
+ /* A four-byte version identifier, used in pack indices. */
+ uint32_t format_id;
+
+ /* The length of the hash in binary. */
+ size_t rawsz;
+
+ /* The length of the hash in hex characters. */
+ size_t hexsz;
+
+ /* The block size of the hash. */
+ size_t blksz;
+
+ /* The hash initialization function. */
+ git_hash_init_fn init_fn;
+
+ /* The hash context cloning function. */
+ git_hash_clone_fn clone_fn;
+
+ /* The hash update function. */
+ git_hash_update_fn update_fn;
+
+ /* The hash finalization function. */
+ git_hash_final_fn final_fn;
+
+ /* The hash finalization function for object IDs. */
+ git_hash_final_oid_fn final_oid_fn;
+
+ /* The OID of the empty tree. */
+ const struct object_id *empty_tree;
+
+ /* The OID of the empty blob. */
+ const struct object_id *empty_blob;
+
+ /* The all-zeros OID. */
+ const struct object_id *null_oid;
+};
+extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
+
+/*
+ * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
+ * the name doesn't match a known algorithm.
+ */
+int hash_algo_by_name(const char *name);
+/* Identical, except based on the format ID. */
+int hash_algo_by_id(uint32_t format_id);
+/* Identical, except based on the length. */
+int hash_algo_by_length(int len);
+/* Identical, except for a pointer to struct git_hash_algo. */
+static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
+{
+ return p - hash_algos;
+}
+
+const struct object_id *null_oid(void);
+
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+{
+ /*
+ * Teach the compiler that there are only two possibilities of hash size
+ * here, so that it can optimize for this case as much as possible.
+ */
+ if (algop->rawsz == GIT_MAX_RAWSZ)
+ return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
+ return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+}
+
+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+{
+ /*
+ * We write this here instead of deferring to hashcmp so that the
+ * compiler can properly inline it and avoid calling memcmp.
+ */
+ if (algop->rawsz == GIT_MAX_RAWSZ)
+ return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
+ return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+}
+
+static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
+ const struct git_hash_algo *algop)
+{
+ memcpy(sha_dst, sha_src, algop->rawsz);
+}
+
+static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
+{
+ memset(hash, 0, algop->rawsz);
+}
+
+static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+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;
+}
+
+static inline void oidread(struct object_id *oid, const unsigned char *hash,
+ const struct git_hash_algo *algop)
+{
+ memcpy(oid->hash, hash, algop->rawsz);
+ if (algop->rawsz < GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline void oidclr(struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline struct object_id *oiddup(const struct object_id *src)
+{
+ struct object_id *dst = xmalloc(sizeof(struct object_id));
+ oidcpy(dst, src);
+ return dst;
+}
+
+static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
+{
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+/*
+ * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
+ * for use in hash tables. Cryptographic hashes are supposed to have
+ * uniform distribution, so in contrast to `memhash()`, this just copies
+ * the first `sizeof(int)` bytes without shuffling any bits. Note that
+ * the results will be different on big-endian and little-endian
+ * platforms, so they should not be stored or transferred over the net.
+ */
+static inline unsigned int oidhash(const struct object_id *oid)
+{
+ /*
+ * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
+ * platforms that don't support unaligned reads.
+ */
+ unsigned int hash;
+ memcpy(&hash, oid->hash, sizeof(hash));
+ return hash;
+}
+
+static inline int is_null_oid(const struct object_id *oid)
+{
+ static const unsigned char null_hash[GIT_MAX_RAWSZ];
+ return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
+}
+
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
+
+static inline int is_empty_blob_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_blob);
+}
+
+static inline int is_empty_tree_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_tree);
+}
+
#endif
diff --git a/hex.h b/hex.h
index e0b83f776f..9809667f33 100644
--- a/hex.h
+++ b/hex.h
@@ -1,7 +1,7 @@
#ifndef HEX_H
#define HEX_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hex-ll.h"
/*
diff --git a/loose.h b/loose.h
index 2c2957072c..28512306e5 100644
--- a/loose.h
+++ b/loose.h
@@ -3,6 +3,8 @@
#include "khash.h"
+struct repository;
+
struct loose_object_map {
kh_oid_map_t *to_compat;
kh_oid_map_t *to_storage;
diff --git a/merge-ort.h b/merge-ort.h
index ce56ec1a78..a994c9a5fc 100644
--- a/merge-ort.h
+++ b/merge-ort.h
@@ -2,7 +2,7 @@
#define MERGE_ORT_H
#include "merge-recursive.h"
-#include "hash-ll.h"
+#include "hash.h"
struct commit;
struct tree;
diff --git a/object-file-convert.c b/object-file-convert.c
index 958f61f094..3887d6d57b 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -5,7 +5,7 @@
#include "strbuf.h"
#include "hex.h"
#include "repository.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "hash.h"
#include "object.h"
#include "loose.h"
diff --git a/object.h b/object.h
index 73b4ec3904..9fa42d51d9 100644
--- a/object.h
+++ b/object.h
@@ -1,7 +1,7 @@
#ifndef OBJECT_H
#define OBJECT_H
-#include "hash-ll.h"
+#include "hash.h"
struct buffer_slab;
struct repository;
diff --git a/oidmap.h b/oidmap.h
index 05c673eb7c..fad412827a 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -1,7 +1,7 @@
#ifndef OIDMAP_H
#define OIDMAP_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
/*
diff --git a/oidtree.h b/oidtree.h
index 55c83513fd..77898f510a 100644
--- a/oidtree.h
+++ b/oidtree.h
@@ -2,7 +2,7 @@
#define OIDTREE_H
#include "cbtree.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "mem-pool.h"
struct oidtree {
diff --git a/packfile.h b/packfile.h
index 28c8fd3e39..eb18ec15db 100644
--- a/packfile.h
+++ b/packfile.h
@@ -101,6 +101,8 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
+struct raw_object_store;
+
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
diff --git a/protocol-caps.c b/protocol-caps.c
index 75f4cbb0a7..fe8d1d5c63 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -3,7 +3,7 @@
#include "gettext.h"
#include "hex.h"
#include "pkt-line.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "hex.h"
#include "object.h"
#include "object-store-ll.h"
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 09414afd04..e0e39607ef 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -1,7 +1,7 @@
#ifndef READ_CACHE_LL_H
#define READ_CACHE_LL_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "statinfo.h"
diff --git a/refs/ref-cache.h b/refs/ref-cache.h
index 95c76e27c8..31ebe24f6c 100644
--- a/refs/ref-cache.h
+++ b/refs/ref-cache.h
@@ -1,7 +1,7 @@
#ifndef REFS_REF_CACHE_H
#define REFS_REF_CACHE_H
-#include "hash-ll.h"
+#include "hash.h"
struct ref_dir;
struct ref_store;
diff --git a/reftable/dump.c b/reftable/dump.c
index 41abbb8ecf..dd65d9e8bb 100644
--- a/reftable/dump.c
+++ b/reftable/dump.c
@@ -7,7 +7,7 @@ license that can be found in the LICENSE file or at
*/
#include "git-compat-util.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "reftable-blocksource.h"
#include "reftable-error.h"
diff --git a/reftable/reftable-record.h b/reftable/reftable-record.h
index 2a2943cd13..ff486eb1f7 100644
--- a/reftable/reftable-record.h
+++ b/reftable/reftable-record.h
@@ -9,7 +9,7 @@ license that can be found in the LICENSE file or at
#ifndef REFTABLE_RECORD_H
#define REFTABLE_RECORD_H
-#include "hash-ll.h"
+#include "hash.h"
#include <stdint.h>
/*
diff --git a/reftable/system.h b/reftable/system.h
index 5d8b6dede5..d0cabd5d17 100644
--- a/reftable/system.h
+++ b/reftable/system.h
@@ -15,7 +15,7 @@ license that can be found in the LICENSE file or at
#include "lockfile.h"
#include "strbuf.h"
#include "tempfile.h"
-#include "hash-ll.h" /* hash ID, sizes.*/
+#include "hash.h" /* hash ID, sizes.*/
#include "dir.h" /* remove_dir_recursively, for tests.*/
int hash_size(uint32_t id);
diff --git a/remote.h b/remote.h
index e8c6655e42..7d04e1be1b 100644
--- a/remote.h
+++ b/remote.h
@@ -1,7 +1,7 @@
#ifndef REMOTE_H
#define REMOTE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "refspec.h"
diff --git a/reset.h b/reset.h
index 10708d8ddc..a28f81829d 100644
--- a/reset.h
+++ b/reset.h
@@ -1,7 +1,7 @@
#ifndef RESET_H
#define RESET_H
-#include "hash-ll.h"
+#include "hash.h"
#include "repository.h"
#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
diff --git a/resolve-undo.h b/resolve-undo.h
index f3f8462751..89a3227262 100644
--- a/resolve-undo.h
+++ b/resolve-undo.h
@@ -6,7 +6,7 @@ struct index_state;
struct pathspec;
struct string_list;
-#include "hash-ll.h"
+#include "hash.h"
struct resolve_undo_info {
unsigned int mode[3];
diff --git a/serve.c b/serve.c
index 33608ea4d5..884cd84ca8 100644
--- a/serve.c
+++ b/serve.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "pkt-line.h"
#include "version.h"
#include "ls-refs.h"
diff --git a/split-index.h b/split-index.h
index 15a29cd08c..1a153f47ba 100644
--- a/split-index.h
+++ b/split-index.h
@@ -1,7 +1,7 @@
#ifndef SPLIT_INDEX_H
#define SPLIT_INDEX_H
-#include "hash-ll.h"
+#include "hash.h"
struct index_state;
struct strbuf;
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index b235da594f..7de822af51 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
#define NUM_SECONDS 3
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index dcb7f6c003..e60d000c03 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
int cmd__sha1(int ac, const char **av)
{
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 08cf149001..2fb20438f3 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
int cmd__sha256(int ac, const char **av)
{
diff --git a/t/unit-tests/lib-oid.h b/t/unit-tests/lib-oid.h
index bfde639190..8d2acca768 100644
--- a/t/unit-tests/lib-oid.h
+++ b/t/unit-tests/lib-oid.h
@@ -1,7 +1,7 @@
#ifndef LIB_OID_H
#define LIB_OID_H
-#include "hash-ll.h"
+#include "hash.h"
/*
* Convert arbitrary hex string to object_id.
diff --git a/tree-diff.c b/tree-diff.c
index 46107772d1..9252481df3 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -8,6 +8,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "environment.h"
+#include "repository.h"
/*
* Some mode bits are also used internally for computations.
diff --git a/tree-walk.h b/tree-walk.h
index 0b1067fbc5..aaea689f9a 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -1,7 +1,7 @@
#ifndef TREE_WALK_H
#define TREE_WALK_H
-#include "hash-ll.h"
+#include "hash.h"
struct index_state;
struct repository;
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 38537169b7..1ed430b622 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -1,7 +1,7 @@
#ifndef XDIFF_INTERFACE_H
#define XDIFF_INTERFACE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "xdiff/xdiff.h"
/*
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 12/20] http-fetch: don't crash when parsing packfile without a repo
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (10 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 11/20] hash-ll: merge with "hash.h" Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 13/20] oidset: pass hash algorithm when parsing file Patrick Steinhardt
` (8 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 3160 bytes --]
The git-http-fetch(1) command accepts a `--packfile=` option, which
allows the user to specify that it shall fetch a specific packfile,
only. The parameter here is the hash of the packfile, which is specific
to the object hash used by the repository. This requirement is implicit
though via our use of `parse_oid_hex()`, which internally uses
`the_repository`.
The git-http-fetch(1) command allows for there to be no repository
though, which only exists such that we can show usage via the "-h"
option. In that case though, starting with c8aed5e8da (repository: stop
setting SHA1 as the default object hash, 2024-05-07), `the_repository`
does not have its object hash initialized anymore and thus we would
crash when trying to parse the object ID outside of a repository.
Fix this issue by dying immediately when we see a "--packfile="
parameter when outside a Git repository. This is not a functional
regression as we would die later on with the same error anyway.
Add a test to detect the segfault. We use the "nongit" function to do
so, which we need to allow-list in `test_must_fail ()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
http-fetch.c | 8 +++++++-
t/t5550-http-fetch-dumb.sh | 6 ++++++
t/test-lib-functions.sh | 5 +++++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/http-fetch.c b/http-fetch.c
index bec94988bb..d460bb1837 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
@@ -127,8 +129,12 @@ int cmd_main(int argc, const char **argv)
} else if (skip_prefix(argv[arg], "--packfile=", &p)) {
const char *end;
+ if (nongit)
+ die(_("not a git repository"));
+
packfile = 1;
- if (parse_oid_hex(p, &packfile_hash, &end) || *end)
+ if (parse_oid_hex_algop(p, &packfile_hash, &end,
+ the_repository->hash_algo) || *end)
die(_("argument to --packfile must be a valid hash (got '%s')"), p);
} else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
strvec_push(&index_pack_args, p);
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index 5f16cbc58d..ea8e48f627 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -25,6 +25,12 @@ test_expect_success 'setup repository' '
git commit -m two
'
+test_expect_success 'packfile without repository does not crash' '
+ echo "fatal: not a git repository" >expect &&
+ test_must_fail nongit git http-fetch --packfile=abc 2>err &&
+ test_cmp expect err
+'
+
setup_post_update_server_info_hook () {
test_hook --setup -C "$1" post-update <<-\EOF &&
exec git update-server-info
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 862d80c974..34bc7d7da4 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1096,6 +1096,11 @@ test_must_fail_acceptable () {
done
fi
+ if test "$1" = "nongit"
+ then
+ shift
+ fi
+
case "$1" in
git|__git*|scalar|test-tool|test_terminal)
return 0
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 13/20] oidset: pass hash algorithm when parsing file
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (11 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 12/20] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 14/20] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
` (7 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 3242 bytes --]
The `oidset_parse_file_carefully()` function implicitly depends on
`the_repository` when parsing object IDs. Fix this by having callers
pass in the hash algorithm to use.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/blame.c | 1 +
fsck.c | 3 ++-
oidset.c | 8 +++++---
oidset.h | 4 +++-
4 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index de89fff3f8..18f1a3cea0 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -852,6 +852,7 @@ static void build_ignorelist(struct blame_scoreboard *sb,
oidset_clear(&sb->ignore_list);
else
oidset_parse_file_carefully(&sb->ignore_list, i->string,
+ the_repository->hash_algo,
peel_to_commit_oid, sb);
}
for_each_string_list_item(i, ignore_rev_list) {
diff --git a/fsck.c b/fsck.c
index 432996cbb6..304f4a17ec 100644
--- a/fsck.c
+++ b/fsck.c
@@ -205,7 +205,8 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
if (!strcmp(buf, "skiplist")) {
if (equal == len)
die("skiplist requires a path");
- oidset_parse_file(&options->skiplist, buf + equal + 1);
+ oidset_parse_file(&options->skiplist, buf + equal + 1,
+ the_repository->hash_algo);
buf += len + 1;
continue;
}
diff --git a/oidset.c b/oidset.c
index 91d1385910..8d36aef8dc 100644
--- a/oidset.c
+++ b/oidset.c
@@ -48,12 +48,14 @@ void oidset_clear(struct oidset *set)
oidset_init(set, 0);
}
-void oidset_parse_file(struct oidset *set, const char *path)
+void oidset_parse_file(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop)
{
- oidset_parse_file_carefully(set, path, NULL, NULL);
+ oidset_parse_file_carefully(set, path, algop, NULL, NULL);
}
void oidset_parse_file_carefully(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop,
oidset_parse_tweak_fn fn, void *cbdata)
{
FILE *fp;
@@ -79,7 +81,7 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,
if (!sb.len)
continue;
- if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
+ if (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\0')
die("invalid object name: %s", sb.buf);
if (fn && fn(&oid, cbdata))
continue;
diff --git a/oidset.h b/oidset.h
index 262f4256d6..0106b6f278 100644
--- a/oidset.h
+++ b/oidset.h
@@ -80,7 +80,8 @@ void oidset_clear(struct oidset *set);
* are allowed. Leading whitespace and empty or white-space only lines are
* ignored.
*/
-void oidset_parse_file(struct oidset *set, const char *path);
+void oidset_parse_file(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop);
/*
* Similar to the above, but with a callback which can (1) return non-zero to
@@ -89,6 +90,7 @@ void oidset_parse_file(struct oidset *set, const char *path);
*/
typedef int (*oidset_parse_tweak_fn)(struct object_id *, void *);
void oidset_parse_file_carefully(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop,
oidset_parse_tweak_fn fn, void *cbdata);
struct oidset_iter {
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 14/20] protocol-caps: use hash algorithm from passed-in repository
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (12 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 13/20] oidset: pass hash algorithm when parsing file Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 15/20] replace-object: " Patrick Steinhardt
` (6 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]
In `send_info()`, we pass in a repository but then use `get_oid_hex()`
to parse passed-in object IDs, which implicitly uses `the_repository`.
Fix this by using the hash algorithm from the passed-in repository
instead.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
protocol-caps.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/protocol-caps.c b/protocol-caps.c
index fe8d1d5c63..855f279c2f 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -7,6 +7,7 @@
#include "hex.h"
#include "object.h"
#include "object-store-ll.h"
+#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
@@ -52,7 +53,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
struct object_id oid;
unsigned long object_size;
- if (get_oid_hex(oid_str, &oid) < 0) {
+ if (get_oid_hex_algop(oid_str, &oid, r->hash_algo) < 0) {
packet_writer_error(
writer,
"object-info: protocol error, expected to get oid, not '%s'",
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 15/20] replace-object: use hash algorithm from passed-in repository
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (13 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 14/20] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos Patrick Steinhardt
` (5 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 939 bytes --]
In `register_replace_ref()`, we pass in a repository but then use
`get_oid_hex()` to parse passed-in object IDs, which implicitly uses
`the_repository`. Fix this by using the hash algorithm from the
passed-in repository instead.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
replace-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/replace-object.c b/replace-object.c
index 73f5acbcd9..59252d565e 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -20,7 +20,7 @@ static int register_replace_ref(const char *refname,
const char *hash = slash ? slash + 1 : refname;
struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj));
- if (get_oid_hex(hash, &repl_obj->original.oid)) {
+ if (get_oid_hex_algop(hash, &repl_obj->original.oid, r->hash_algo)) {
free(repl_obj);
warning(_("bad replace ref name: %s"), refname);
return 0;
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (14 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 15/20] replace-object: " Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 17/20] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
` (4 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 2024 bytes --]
The IPC socket used by the fsmonitor on Darwin is usually contained in
the Git repository itself. When the repository is hosted on a networked
filesystem though, we instead create the socket path in the user's home
directory or the socket directory. In that case, we derive the path by
hashing the repository path.
But while we always use SHA1 to hash the repository path, we then end up
using `hash_to_hex()` to append the computed hash to the socket path.
This is wrong because `hash_to_hex()` uses the hash algorithm configured
in `the_repository`, which may not be SHA1. The consequence is that we
may append uninitialized bytes to the path when operating in a SHA256
repository.
Fix this bug by using `hash_to_hex_algop()` with SHA1.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
compat/fsmonitor/fsm-ipc-darwin.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 6f3a95410c..52f4f29720 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -17,7 +17,7 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
git_SHA_CTX sha1ctx;
char *sock_dir = NULL;
struct strbuf ipc_file = STRBUF_INIT;
- unsigned char hash[GIT_MAX_RAWSZ];
+ unsigned char hash[GIT_SHA1_RAWSZ];
if (!r)
BUG("No repository passed into fsmonitor_ipc__get_path");
@@ -41,9 +41,10 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
/* Create the socket file in either socketDir or $HOME */
if (sock_dir && *sock_dir) {
strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s",
- sock_dir, hash_to_hex(hash));
+ sock_dir, hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
} else {
- strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash));
+ strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s",
+ hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
}
free(sock_dir);
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 17/20] t/helper: use correct object hash in partial-clone helper
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (15 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 18/20] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
` (3 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]
The `object_info()` function of the partial-clone helper is responsible
for checking the object ID of a repository other than `the_repository`.
We use `parse_oid_hex()` in this function though, which means that we
still depend on `the_repository->hash_algo`.
Fix this by using the object hash of the function-local repository.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-partial-clone.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 910a128614..0ead529167 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -21,7 +21,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
if (repo_init(&r, gitdir, NULL))
die("could not init repo");
- if (parse_oid_hex(oid_hex, &oid, &p))
+ if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
if (oid_object_info_extended(&r, &oid, &oi, 0))
die("could not obtain object info");
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 18/20] t/helper: fix segfault in "oid-array" command without repository
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (16 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 17/20] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 19/20] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
` (2 subsequent siblings)
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 2118 bytes --]
The "oid-array" test helper can supposedly work without a Git
repository, but will in fact crash because `the_repository->hash_algo`
is not initialized. This is because `oid_pos()`, which is used by
`oid_array_lookup()`, depends on `the_hash_algo->rawsz`.
Ideally, we'd adapt `oid_pos()` to not depend on `the_hash_algo`
anymore. That is a bigger untertaking though, so instead we fall back to
SHA1 when there is no repository.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-oid-array.c | 4 ++++
t/t0064-oid-array.sh | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c
index aafe398ef0..076b849cbf 100644
--- a/t/helper/test-oid-array.c
+++ b/t/helper/test-oid-array.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "oid-array.h"
@@ -17,6 +19,8 @@ int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
int nongit_ok;
setup_git_directory_gently(&nongit_ok);
+ if (nongit_ok)
+ repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
while (strbuf_getline(&line, stdin) != EOF) {
const char *arg;
diff --git a/t/t0064-oid-array.sh b/t/t0064-oid-array.sh
index 88c89e8f48..de74b692d0 100755
--- a/t/t0064-oid-array.sh
+++ b/t/t0064-oid-array.sh
@@ -15,6 +15,24 @@ echoid () {
done
}
+test_expect_success 'without repository' '
+ cat >expect <<-EOF &&
+ 4444444444444444444444444444444444444444
+ 5555555555555555555555555555555555555555
+ 8888888888888888888888888888888888888888
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ EOF
+ cat >input <<-EOF &&
+ append 4444444444444444444444444444444444444444
+ append 5555555555555555555555555555555555555555
+ append 8888888888888888888888888888888888888888
+ append aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ for_each_unique
+ EOF
+ nongit test-tool oid-array <input >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'ordered enumeration' '
echoid "" 44 55 88 aa >expect &&
{
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 19/20] t/helper: remove dependency on `the_repository` in "proc-receive"
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (17 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 18/20] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2024-06-13 18:01 ` [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Junio C Hamano
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 2061 bytes --]
The "proc-receive" test helper implicitly relies on `the_repository` via
`parse_oid_hex()`. This isn't necessary though, and in fact the whole
command does not depend on `the_repository` at all.
Stop setting up `the_repository` and use `parse_oid_hex_any()` to parse
object IDs.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-proc-receive.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index f30022d222..29361c7aab 100644
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -3,8 +3,8 @@
#include "hex.h"
#include "parse-options.h"
#include "pkt-line.h"
-#include "setup.h"
#include "sigchain.h"
+#include "string-list.h"
static const char *proc_receive_usage[] = {
"test-tool proc-receive [<options>]",
@@ -92,9 +92,9 @@ static void proc_receive_read_commands(struct packet_reader *reader,
if (die_read_commands)
die("die with the --die-read-commands option");
- if (parse_oid_hex(reader->line, &old_oid, &p) ||
+ if (parse_oid_hex_any(reader->line, &old_oid, &p) == GIT_HASH_UNKNOWN ||
*p++ != ' ' ||
- parse_oid_hex(p, &new_oid, &p) ||
+ parse_oid_hex_any(p, &new_oid, &p) == GIT_HASH_UNKNOWN ||
*p++ != ' ')
die("protocol error: expected 'old new ref', got '%s'",
reader->line);
@@ -128,7 +128,6 @@ static void proc_receive_read_push_options(struct packet_reader *reader,
int cmd__proc_receive(int argc, const char **argv)
{
- int nongit_ok = 0;
struct packet_reader reader;
struct command *commands = NULL;
struct string_list push_options = STRING_LIST_INIT_DUP;
@@ -154,8 +153,6 @@ int cmd__proc_receive(int argc, const char **argv)
OPT_END()
};
- setup_git_directory_gently(&nongit_ok);
-
argc = parse_options(argc, argv, "test-tools", options, proc_receive_usage, 0);
if (argc > 0)
usage_msg_opt("Too many arguments.", proc_receive_usage, options);
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v2 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (18 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 19/20] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
@ 2024-06-13 6:14 ` Patrick Steinhardt
2024-06-13 18:01 ` [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Junio C Hamano
20 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-13 6:14 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 2848 bytes --]
Guard declarations of functions that implicitly use `the_repository`
with `USE_THE_REPOSITORY_VARIABLE` such that callers don't accidentally
rely on that global variable.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hex.h | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/hex.h b/hex.h
index 9809667f33..e9ccb54065 100644
--- a/hex.h
+++ b/hex.h
@@ -13,10 +13,6 @@
* input, so it is safe to pass this function an arbitrary
* null-terminated string.
*/
-int get_hash_hex(const char *hex, unsigned char *hash);
-int get_oid_hex(const char *hex, struct object_id *oid);
-
-/* Like get_oid_hex, but for an arbitrary hash algorithm. */
int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop);
/*
@@ -35,7 +31,6 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_h
char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *);
char *oid_to_hex_r(char *out, const struct object_id *oid);
char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */
-char *hash_to_hex(const unsigned char *hash); /* same static buffer */
char *oid_to_hex(const struct object_id *oid); /* same static buffer */
/*
@@ -45,13 +40,9 @@ char *oid_to_hex(const struct object_id *oid); /* same static buffer */
* other invalid character. end is only updated on success; otherwise, it is
* unmodified.
*/
-int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
-
-/* Like parse_oid_hex, but for an arbitrary hash algorithm. */
int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end,
const struct git_hash_algo *algo);
-
/*
* These functions work like get_oid_hex and parse_oid_hex, but they will parse
* a hex value for any algorithm. The algorithm is detected based on the length
@@ -61,4 +52,19 @@ int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end
int get_oid_hex_any(const char *hex, struct object_id *oid);
int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end);
-#endif
+#ifdef USE_THE_REPOSITORY_VARIABLE
+
+/* Like get_oid_hex_algop, but for `the_hash_algo`. */
+int get_hash_hex(const char *hex, unsigned char *hash);
+int get_oid_hex(const char *hex, struct object_id *oid);
+
+/* Like parse_oid_hex_algop, but uses `the_hash_algo`. */
+int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
+
+/*
+ * Same as `hash_to_hex_algop()`, but uses `the_hash_algo`.
+ */
+char *hash_to_hex(const unsigned char *hash);
+
+#endif /* USE_THE_REPOSITORY_VARIABLE */
+#endif /* HEX_H */
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* Re: [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()`
2024-06-13 6:14 ` [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
@ 2024-06-13 10:01 ` Phillip Wood
2024-06-13 15:39 ` Junio C Hamano
0 siblings, 1 reply; 94+ messages in thread
From: Phillip Wood @ 2024-06-13 10:01 UTC (permalink / raw)
To: Patrick Steinhardt, git; +Cc: Ghanshyam Thakkar, brian m. carlson
On 13/06/2024 07:14, Patrick Steinhardt wrote:
> The `empty_tree_oid_hex()` function use `the_repository` to derive the
> hash function that shall be used. Require callers to pass in the hash
> algorithm to get rid of this implicit dependency.
Many of these call sites already have a repository instance available so
don't need to use "the_repository". I haven't checked but with these
changes it might be possible to remove some of these files from the next
patch.
I've only really looked at this patch in this series as I was just
checking for changes to the sequencer code. As for the series as a whole
I think adding USE_THE_REPOSITORY_VARIABLE is a good direction.
> While at it, remove the unused `empty_blob_oid_hex()` function.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> add-interactive.c | 2 +-
> add-patch.c | 2 +-
> builtin/merge.c | 3 ++-
> builtin/receive-pack.c | 2 +-
> hash-ll.h | 3 +--
> object-file.c | 10 ++--------
> sequencer.c | 2 +-
> submodule.c | 6 +++---
> wt-status.c | 4 ++--
> 9 files changed, 14 insertions(+), 20 deletions(-)
>
> diff --git a/add-interactive.c b/add-interactive.c
> index b5d6cd689a..a0961096cd 100644
> --- a/add-interactive.c
> +++ b/add-interactive.c
> @@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
> s.skip_unseen = filter && i;
>
> opt.def = is_initial ?
> - empty_tree_oid_hex() : oid_to_hex(&head_oid);
> + empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
The hunk fragment shows that we already have a struct repository
instance in this function which we should use instead of "the_repository"
> diff --git a/add-patch.c b/add-patch.c
> index 814de57c4a..86181770f2 100644
> --- a/add-patch.c
> +++ b/add-patch.c
> @@ -420,7 +420,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
> /* could be on an unborn branch */
> !strcmp("HEAD", s->revision) &&
> repo_get_oid(the_repository, "HEAD", &oid) ?
> - empty_tree_oid_hex() : s->revision);
> + empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
It's not obvious from this hunk but there is a repository instance in
"s->s->r" which we should use instead of "the_repository"
> diff --git a/sequencer.c b/sequencer.c
> index 68d62a12ff..823691e379 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
> unborn = 1;
> } else if (unborn)
> oidcpy(&head, the_hash_algo->empty_tree);
> - if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
> + if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
The hunk fragment shows that we already have a struct repository
instance in "r" which we should use instead of "the_repository" here.
> diff --git a/wt-status.c b/wt-status.c
> index ff4be071ca..5051f5e599 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -641,7 +641,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
>
> repo_init_revisions(s->repo, &rev, NULL);
> memset(&opt, 0, sizeof(opt));
> - opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
> + opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
The context line above shows us that we have a repository instance
available so we should use "s->repo" instead of "the_repository"
> @@ -1136,7 +1136,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
> rev.diffopt.ita_invisible_in_index = 1;
>
> memset(&opt, 0, sizeof(opt));
> - opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
> + opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
We should use "s->repo" here as well
Best Wishes
Phillip
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()`
2024-06-13 10:01 ` Phillip Wood
@ 2024-06-13 15:39 ` Junio C Hamano
2024-06-14 5:23 ` Patrick Steinhardt
0 siblings, 1 reply; 94+ messages in thread
From: Junio C Hamano @ 2024-06-13 15:39 UTC (permalink / raw)
To: Phillip Wood; +Cc: Patrick Steinhardt, git, Ghanshyam Thakkar, brian m. carlson
Phillip Wood <phillip.wood123@gmail.com> writes:
>> diff --git a/add-interactive.c b/add-interactive.c
>> index b5d6cd689a..a0961096cd 100644
>> --- a/add-interactive.c
>> +++ b/add-interactive.c
>> @@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
>> s.skip_unseen = filter && i;
>> opt.def = is_initial ?
>> - empty_tree_oid_hex() : oid_to_hex(&head_oid);
>> + empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
>
> The hunk fragment shows that we already have a struct repository
> instance in this function which we should use instead of
> "the_repository"
As an internal helper function in add-interactive.c, all of whose
callers deal with "struct add_i_state *", it probably should not
even take "struct repository *" as a parameter. The state knows
what repository we are working with.
>> diff --git a/add-patch.c b/add-patch.c
>> index 814de57c4a..86181770f2 100644
>> --- a/add-patch.c
>> +++ b/add-patch.c
>> @@ -420,7 +420,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
>> /* could be on an unborn branch */
>> !strcmp("HEAD", s->revision) &&
>> repo_get_oid(the_repository, "HEAD", &oid) ?
>> - empty_tree_oid_hex() : s->revision);
>> + empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
>
> It's not obvious from this hunk but there is a repository instance in
> "s->s->r" which we should use instead of "the_repository"
I agree it is the same issue.
Just like a previous effort, making a "faithful" conversion from the
original that used the_repository implicitly by explicitly passing
the_repository in one patch, and then making semantics corrections
of the original (if we were ever working on a repository in s->r
that is different from the_repository, the existing code is already
buggy) in a separate patch, is a reasonable approach to limit the
cognitive load while reviewing the first step, I would say.
> diff --git a/sequencer.c b/sequencer.c
>> index 68d62a12ff..823691e379 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
>> unborn = 1;
>> } else if (unborn)
>> oidcpy(&head, the_hash_algo->empty_tree);
>> - if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
>> + if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
>
> The hunk fragment shows that we already have a struct repository
> instance in "r" which we should use instead of "the_repository" here.
Yes, but the same "it is better to make a faithful conversion first,
corrections separately in a later step" would apply.
As the sequencer machinery is inherently stateful, I wonder if we
should pass around not "repository" but a sequencer state object
that may have a pointer to a repository in use. But that of course
belongs to the latter, i.e., "making corrections", theme.
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
` (19 preceding siblings ...)
2024-06-13 6:14 ` [PATCH v2 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
@ 2024-06-13 18:01 ` Junio C Hamano
2024-06-13 18:48 ` Junio C Hamano
20 siblings, 1 reply; 94+ messages in thread
From: Junio C Hamano @ 2024-06-13 18:01 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Ghanshyam Thakkar, brian m. carlson
Patrick Steinhardt <ps@pks.im> writes:
> this is the second version of my patch series that introduce a new
> `USE_THE_REPOSITORY_VARIABLE` macro. If undefined, then declarations
> like `the_repository`, `the_hash_algo` and a subset of functions that
> implicitly depend on either of these are hidden away.
;-)
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-13 18:01 ` [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Junio C Hamano
@ 2024-06-13 18:48 ` Junio C Hamano
2024-06-13 23:14 ` Ramsay Jones
0 siblings, 1 reply; 94+ messages in thread
From: Junio C Hamano @ 2024-06-13 18:48 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Ghanshyam Thakkar, brian m. carlson
Junio C Hamano <gitster@pobox.com> writes:
> Patrick Steinhardt <ps@pks.im> writes:
>
>> this is the second version of my patch series that introduce a new
>> `USE_THE_REPOSITORY_VARIABLE` macro. If undefined, then declarations
>> like `the_repository`, `the_hash_algo` and a subset of functions that
>> implicitly depend on either of these are hidden away.
>
> ;-)
Two things.
(1) This stupid change was needed to please "make sparse", or we'd
get this:
repository.c:21:19: error: symbol 'the_repository' was not declared. Should it be static?
gmake: *** [Makefile:3259: repository.sp] Error 1
repository.c | 2 ++
1 file changed, 2 insertions(+)
diff --git c/repository.c w/repository.c
index 95d10cc4a0..22ef85b0b3 100644
--- c/repository.c
+++ w/repository.c
@@ -18,6 +18,8 @@
/* The main repository */
static struct repository the_repo;
+
+extern struct repository *the_repository;
struct repository *the_repository = &the_repo;
/*
(2) Aside from a few trivial and expected textual conflicts to be
resolved, there were a few new files added that needed
merge-fixes, with which I have this topic at the tip of the
'seen' branch.
index-info.c | 2 ++
pseudo-merge.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/index-info.c b/index-info.c
index 5d61e61e28..791380f910 100644
--- a/index-info.c
+++ b/index-info.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "index-info.h"
#include "hash.h"
diff --git a/pseudo-merge.c b/pseudo-merge.c
index e3e0393f11..f0fde13c47 100644
--- a/pseudo-merge.c
+++ b/pseudo-merge.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "pseudo-merge.h"
#include "date.h"
--
2.45.2-683-gddb3e810f1
^ permalink raw reply related [flat|nested] 94+ messages in thread
* Re: [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-13 18:48 ` Junio C Hamano
@ 2024-06-13 23:14 ` Ramsay Jones
2024-06-13 23:18 ` Junio C Hamano
0 siblings, 1 reply; 94+ messages in thread
From: Ramsay Jones @ 2024-06-13 23:14 UTC (permalink / raw)
To: Junio C Hamano, Patrick Steinhardt
Cc: git, Ghanshyam Thakkar, brian m. carlson
On 13/06/2024 19:48, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Patrick Steinhardt <ps@pks.im> writes:
>>
>>> this is the second version of my patch series that introduce a new
>>> `USE_THE_REPOSITORY_VARIABLE` macro. If undefined, then declarations
>>> like `the_repository`, `the_hash_algo` and a subset of functions that
>>> implicitly depend on either of these are hidden away.
>>
>> ;-)
>
> Two things.
>
> (1) This stupid change was needed to please "make sparse", or we'd
> get this:
>
> repository.c:21:19: error: symbol 'the_repository' was not declared. Should it be static?
> gmake: *** [Makefile:3259: repository.sp] Error 1
>
> repository.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git c/repository.c w/repository.c
> index 95d10cc4a0..22ef85b0b3 100644
> --- c/repository.c
> +++ w/repository.c
> @@ -18,6 +18,8 @@
>
> /* The main repository */
> static struct repository the_repo;
> +
> +extern struct repository *the_repository;
> struct repository *the_repository = &the_repo;
>
Hmm, odd; isn't the declaration of 'the_repository' from
the "repository.h" header file visible at this point?
puzzled.
ATB,
Ramsay Jones
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-13 23:14 ` Ramsay Jones
@ 2024-06-13 23:18 ` Junio C Hamano
2024-06-13 23:55 ` Ramsay Jones
0 siblings, 1 reply; 94+ messages in thread
From: Junio C Hamano @ 2024-06-13 23:18 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Patrick Steinhardt, git, Ghanshyam Thakkar, brian m. carlson
On Thu, Jun 13, 2024 at 4:15 PM Ramsay Jones
<ramsay@ramsayjones.plus.com> wrote:
>
> Hmm, odd; isn't the declaration of 'the_repository' from
> the "repository.h" header file visible at this point?
No. The declaration is guarded with USE_THE_REPOSITORY_VARIABLE CPP macro
in the header, and repository.c does not define it.
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-13 23:18 ` Junio C Hamano
@ 2024-06-13 23:55 ` Ramsay Jones
2024-06-14 0:17 ` Junio C Hamano
0 siblings, 1 reply; 94+ messages in thread
From: Ramsay Jones @ 2024-06-13 23:55 UTC (permalink / raw)
To: Junio C Hamano
Cc: Patrick Steinhardt, git, Ghanshyam Thakkar, brian m. carlson
On 14/06/2024 00:18, Junio C Hamano wrote:
> On Thu, Jun 13, 2024 at 4:15 PM Ramsay Jones
> <ramsay@ramsayjones.plus.com> wrote:
>>
>> Hmm, odd; isn't the declaration of 'the_repository' from
>> the "repository.h" header file visible at this point?
>
> No. The declaration is guarded with USE_THE_REPOSITORY_VARIABLE CPP macro
> in the header, and repository.c does not define it.
>
Ah, OK. I haven't been following too closely and didn't
notice that the declaration in the header file was now
conditional. :(
But that does beg the question - why is repository.c not
defining the USE_THE_REPOSITORY_VARIABLE?
ATB,
Ramsay Jones
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-13 23:55 ` Ramsay Jones
@ 2024-06-14 0:17 ` Junio C Hamano
2024-06-14 5:28 ` Patrick Steinhardt
0 siblings, 1 reply; 94+ messages in thread
From: Junio C Hamano @ 2024-06-14 0:17 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Patrick Steinhardt, git, Ghanshyam Thakkar, brian m. carlson
Ramsay Jones <ramsay@ramsayjones.plus.com> writes:
> On 14/06/2024 00:18, Junio C Hamano wrote:
>> On Thu, Jun 13, 2024 at 4:15 PM Ramsay Jones
>> <ramsay@ramsayjones.plus.com> wrote:
>>>
>>> Hmm, odd; isn't the declaration of 'the_repository' from
>>> the "repository.h" header file visible at this point?
>>
>> No. The declaration is guarded with USE_THE_REPOSITORY_VARIABLE CPP macro
>> in the header, and repository.c does not define it.
>>
>
> Ah, OK. I haven't been following too closely and didn't
> notice that the declaration in the header file was now
> conditional. :(
>
> But that does beg the question - why is repository.c not
> defining the USE_THE_REPOSITORY_VARIABLE?
I think the goal of the series is to eventually get to the point
where nobody uses the_repository variable. If repository.c, which
consists of a set of service routines that work on a repository
instance, defined it, showing willingness to implicitly rely on
the_repository through things like get_oid_hex() (which would rely
on the_repository->hash_algo), that would go the opposite direction,
so everything, other than the definition of the_repository variable
itself that allows other files that still do rely implicitly on the
variable to link with it, in repository.c would actively want to
refuse to use services only available to those who define USE_THE_*
macro.
It is a similar pattern we took when we weaned ourselves off of
the_index compatibility macros. The read-cache.c was the central
thing that defined the in-core index services, and it was the first
thing that lost the_index compatibility macros like read_cache(),
add_file_to_cache(), etc. that implicitly worked on the singleton
the_index instance, while everybody else still relied on the
singleton and services that implicitly worked on the singleton.
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()`
2024-06-13 15:39 ` Junio C Hamano
@ 2024-06-14 5:23 ` Patrick Steinhardt
0 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 5:23 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Phillip Wood, git, Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 1347 bytes --]
On Thu, Jun 13, 2024 at 08:39:18AM -0700, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
> > diff --git a/sequencer.c b/sequencer.c
> >> index 68d62a12ff..823691e379 100644
> >> --- a/sequencer.c
> >> +++ b/sequencer.c
> >> @@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
> >> unborn = 1;
> >> } else if (unborn)
> >> oidcpy(&head, the_hash_algo->empty_tree);
> >> - if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
> >> + if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
> >
> > The hunk fragment shows that we already have a struct repository
> > instance in "r" which we should use instead of "the_repository" here.
>
> Yes, but the same "it is better to make a faithful conversion first,
> corrections separately in a later step" would apply.
Yeah, this is what I'm aiming for. In large patch series like this I
think it increases the risk of regression quite significantly if we also
try to deviate from the preceding code and do the "right" thing, even if
it is seemingly obvious. So I rather do a faithful conversion that does
not change the behaviour and leave conversion away from `the_repository`
to later steps after this series.
I can amend the commit message to say so.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-14 0:17 ` Junio C Hamano
@ 2024-06-14 5:28 ` Patrick Steinhardt
2024-06-14 15:54 ` Junio C Hamano
0 siblings, 1 reply; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 5:28 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Ramsay Jones, git, Ghanshyam Thakkar, brian m. carlson
[-- Attachment #1: Type: text/plain, Size: 1896 bytes --]
On Thu, Jun 13, 2024 at 05:17:08PM -0700, Junio C Hamano wrote:
> Ramsay Jones <ramsay@ramsayjones.plus.com> writes:
>
> > On 14/06/2024 00:18, Junio C Hamano wrote:
> >> On Thu, Jun 13, 2024 at 4:15 PM Ramsay Jones
> >> <ramsay@ramsayjones.plus.com> wrote:
> >>>
> >>> Hmm, odd; isn't the declaration of 'the_repository' from
> >>> the "repository.h" header file visible at this point?
> >>
> >> No. The declaration is guarded with USE_THE_REPOSITORY_VARIABLE CPP macro
> >> in the header, and repository.c does not define it.
> >>
> >
> > Ah, OK. I haven't been following too closely and didn't
> > notice that the declaration in the header file was now
> > conditional. :(
> >
> > But that does beg the question - why is repository.c not
> > defining the USE_THE_REPOSITORY_VARIABLE?
>
> I think the goal of the series is to eventually get to the point
> where nobody uses the_repository variable. If repository.c, which
> consists of a set of service routines that work on a repository
> instance, defined it, showing willingness to implicitly rely on
> the_repository through things like get_oid_hex() (which would rely
> on the_repository->hash_algo), that would go the opposite direction,
> so everything, other than the definition of the_repository variable
> itself that allows other files that still do rely implicitly on the
> variable to link with it, in repository.c would actively want to
> refuse to use services only available to those who define USE_THE_*
> macro.
Exactly, that's why it doesn't declare `USE_THE_REPOSITORY_VARIABLE`.
The macro doesn't only guard use of `the_repository`, but does also
guards other functions that implicitly relies on it, and we do not want
to use these in "repository.c". So even though the added `extern`
declaration is somewhat ugly, I think it is preferable over defining the
macro.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* [PATCH v3 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (22 preceding siblings ...)
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
@ 2024-06-14 6:49 ` Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
` (21 more replies)
23 siblings, 22 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:49 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 20597 bytes --]
Hi,
this is the third version of my patch series that introduces the
`USE_THE_REPOSITORY_VARIABLE` macro. When unset, this will cause us to
hide `the_repository`, `the_hash_algo` and several other functions that
implicitly rely on those global variables from our headers. This is a
first step towards fully getting rid of this global state in favor of
passing it down explicitly via function parameters.
Changes compared to v2:
- Note in a commit message that we aim to have a faithful conversion
when introducing a `struct git_hash_algo` parameter to functions. So
even in case the calling context has a `struct git_hash_algo`
available via a local repository, we still use `the_repository` such
that there cannot be a change in behaviour here. Fixing those sites
will be left for a future patch series such that we can avoid any
kind of regressions caused by this comparatively large refactoring.
I also adapted some conversions to fully follow through with this
intent.
- Fix an issue with sparse by adding another `extern` declaration of
`the_repository` to "repository.c".
Thanks!
Patrick
Patrick Steinhardt (20):
hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
hash: require hash algorithm in `hasheq()`, `hashcmp()` and
`hashclr()`
hash: require hash algorithm in `oidread()` and `oidclr()`
global: ensure that object IDs are always padded
hash: convert `oidcmp()` and `oideq()` to compare whole hash
hash: make `is_null_oid()` independent of `the_repository`
hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
hash: require hash algorithm in `empty_tree_oid_hex()`
global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
refs: avoid include cycle with "repository.h"
hash-ll: merge with "hash.h"
http-fetch: don't crash when parsing packfile without a repo
oidset: pass hash algorithm when parsing file
protocol-caps: use hash algorithm from passed-in repository
replace-object: use hash algorithm from passed-in repository
compat/fsmonitor: fix socket path in networked SHA256 repos
t/helper: use correct object hash in partial-clone helper
t/helper: fix segfault in "oid-array" command without repository
t/helper: remove dependency on `the_repository` in "proc-receive"
hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
add-interactive.c | 4 +-
add-patch.c | 4 +-
apply.c | 4 +-
apply.h | 2 +-
archive-tar.c | 3 +
archive-zip.c | 3 +
archive.c | 2 +
attr.c | 2 +
bisect.c | 2 +
blame.c | 4 +-
bloom.c | 1 +
branch.c | 2 +
builtin.h | 8 +
builtin/am.c | 8 +-
builtin/blame.c | 3 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 43 ++-
builtin/fetch-pack.c | 4 +-
builtin/index-pack.c | 11 +-
builtin/log.c | 4 +-
builtin/merge.c | 7 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 3 +-
builtin/pack-redundant.c | 10 +-
builtin/patch-id.c | 6 +-
builtin/pull.c | 6 +-
builtin/receive-pack.c | 4 +-
builtin/replace.c | 2 +-
builtin/rm.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-objects.c | 9 +-
builtin/update-ref.c | 8 +-
bulk-checkin.c | 3 +
bundle-uri.c | 2 +
bundle.c | 2 +
cache-tree.c | 7 +-
checkout.c | 2 +
checkout.h | 2 +-
chunk-format.c | 2 +
chunk-format.h | 2 +-
combine-diff.c | 2 +
commit-graph.c | 22 +-
commit-graph.h | 2 +
commit-reach.c | 2 +
commit.c | 2 +
common-main.c | 2 +
compat/fsmonitor/fsm-ipc-darwin.c | 7 +-
compat/sha1-chunked.c | 2 +-
compat/win32/trace2_win32_process_info.c | 2 +
config.c | 3 +
connected.c | 2 +
convert.c | 2 +
convert.h | 2 +-
csum-file.c | 9 +-
csum-file.h | 2 +-
delta-islands.c | 2 +
diagnose.c | 2 +
diff-lib.c | 7 +-
diff.c | 9 +-
diff.h | 2 +-
diffcore-break.c | 3 +
diffcore-rename.c | 7 +-
diffcore.h | 2 +-
dir.c | 9 +-
dir.h | 2 +-
entry.c | 2 +
environment.c | 3 +
fetch-pack.c | 2 +
fmt-merge-msg.c | 2 +
fsck.c | 5 +-
fsmonitor-ipc.c | 2 +
git.c | 2 +
hash-ll.h | 310 ----------------
hash-lookup.c | 5 +-
hash.h | 366 ++++++++++++++++---
help.c | 2 +
hex.c | 8 +-
hex.h | 28 +-
http-backend.c | 2 +
http-fetch.c | 8 +-
http-push.c | 5 +-
http-walker.c | 6 +-
http.c | 2 +
list-objects-filter-options.c | 2 +
list-objects-filter.c | 2 +
list-objects.c | 2 +
log-tree.c | 2 +
loose.c | 2 +
loose.h | 2 +
ls-refs.c | 2 +
mailmap.c | 2 +
match-trees.c | 6 +-
merge-blobs.c | 2 +
merge-ort.c | 2 +
merge-ort.h | 2 +-
merge-recursive.c | 3 +
merge.c | 2 +
midx-write.c | 2 +
midx.c | 5 +-
negotiator/default.c | 2 +
negotiator/skipping.c | 2 +
notes-cache.c | 2 +
notes-merge.c | 8 +-
notes-utils.c | 2 +
notes.c | 14 +-
object-file-convert.c | 6 +-
object-file.c | 19 +-
object-name.c | 2 +
object.c | 2 +
object.h | 2 +-
oid-array.c | 2 +
oidmap.h | 2 +-
oidset.c | 8 +-
oidset.h | 4 +-
oidtree.c | 4 +-
oidtree.h | 2 +-
oss-fuzz/fuzz-commit-graph.c | 2 +
pack-bitmap-write.c | 6 +-
pack-bitmap.c | 5 +-
pack-check.c | 7 +-
pack-revindex.c | 2 +
pack-write.c | 5 +-
packfile.c | 20 +-
packfile.h | 2 +
parallel-checkout.c | 8 +-
parse-options-cb.c | 2 +
path.c | 3 +
pathspec.c | 2 +
pretty.c | 2 +
progress.c | 2 +
promisor-remote.c | 2 +
protocol-caps.c | 5 +-
range-diff.c | 2 +
reachable.c | 2 +
read-cache-ll.h | 2 +-
read-cache.c | 21 +-
rebase-interactive.c | 2 +
ref-filter.c | 2 +
reflog-walk.c | 2 +
reflog.c | 2 +
refs.c | 8 +-
refs.h | 8 +-
refs/files-backend.c | 8 +-
refs/packed-backend.c | 8 +-
refs/ref-cache.h | 2 +-
refs/reftable-backend.c | 39 +-
refspec.c | 2 +
reftable/dump.c | 2 +-
reftable/reftable-record.h | 2 +-
reftable/system.h | 2 +-
remote-curl.c | 2 +
remote.c | 10 +-
remote.h | 2 +-
replace-object.c | 2 +-
repository.c | 8 +
repository.h | 9 +-
rerere.c | 2 +
reset.c | 2 +
reset.h | 2 +-
resolve-undo.c | 5 +-
resolve-undo.h | 2 +-
revision.c | 2 +
run-command.c | 2 +
scalar.c | 2 +
send-pack.c | 2 +
sequencer.c | 8 +-
serve.c | 4 +-
server-info.c | 2 +
setup.c | 2 +
shallow.c | 2 +
split-index.c | 4 +-
split-index.h | 2 +-
streaming.c | 3 +
submodule-config.c | 4 +-
submodule.c | 8 +-
t/helper/test-bitmap.c | 2 +
t/helper/test-bloom.c | 2 +
t/helper/test-cache-tree.c | 2 +
t/helper/test-dump-cache-tree.c | 2 +
t/helper/test-dump-fsmonitor.c | 2 +
t/helper/test-dump-split-index.c | 2 +
t/helper/test-dump-untracked-cache.c | 2 +
t/helper/test-find-pack.c | 2 +
t/helper/test-fsmonitor-client.c | 2 +
t/helper/test-hash-speed.c | 2 +-
t/helper/test-lazy-init-name-hash.c | 2 +
t/helper/test-match-trees.c | 2 +
t/helper/test-oid-array.c | 4 +
t/helper/test-oidmap.c | 2 +
t/helper/test-pack-mtimes.c | 2 +
t/helper/test-partial-clone.c | 2 +-
t/helper/test-proc-receive.c | 9 +-
t/helper/test-reach.c | 2 +
t/helper/test-read-cache.c | 2 +
t/helper/test-read-graph.c | 2 +
t/helper/test-read-midx.c | 2 +
t/helper/test-ref-store.c | 2 +
t/helper/test-repository.c | 2 +
t/helper/test-revision-walking.c | 2 +
t/helper/test-scrap-cache-tree.c | 2 +
t/helper/test-sha1.c | 2 +-
t/helper/test-sha256.c | 2 +-
t/helper/test-submodule-config.c | 4 +-
t/helper/test-submodule-nested-repo-config.c | 2 +
t/helper/test-submodule.c | 2 +
t/helper/test-trace2.c | 2 +
t/helper/test-write-cache.c | 2 +
t/t0064-oid-array.sh | 18 +
t/t5550-http-fetch-dumb.sh | 6 +
t/test-lib-functions.sh | 5 +
t/unit-tests/lib-oid.h | 2 +-
t/unit-tests/t-example-decorate.c | 2 +
tag.c | 2 +
tmp-objdir.c | 2 +
transport-helper.c | 2 +
transport.c | 2 +
tree-diff.c | 1 +
tree-walk.c | 6 +-
tree-walk.h | 2 +-
tree.c | 2 +
unpack-trees.c | 2 +
upload-pack.c | 2 +
walker.c | 2 +
worktree.c | 2 +
wt-status.c | 6 +-
xdiff-interface.c | 2 +
xdiff-interface.h | 2 +-
227 files changed, 1002 insertions(+), 617 deletions(-)
delete mode 100644 hash-ll.h
Range-diff against v2:
1: d2154e8c45 = 1: d2154e8c45 hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
2: aa468c3d88 ! 2: c481479598 hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()`
@@ Commit message
As those functions are now independent of `the_repository`, we can move
them from "hash.h" to "hash-ll.h".
+ Note that both in this and subsequent commits in this series we always
+ just pass `the_repository->hash_algo` as input even if it is obvious
+ that there is a repository in the context that we should be using the
+ hash from instead. This is done to be on the safe side and not introduce
+ any regressions. All callsites should eventually be amended to use a
+ repo passed via parameters, but this is outside the scope of this patch
+ series.
+
Signed-off-by: Patrick Steinhardt <ps@pks.im>
## builtin/index-pack.c ##
@@ pack-check.c: static int verify_packfile(struct repository *r,
r->hash_algo->final_fn(hash, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
- if (!hasheq(hash, pack_sig))
-+ if (!hasheq(hash, pack_sig, r->hash_algo))
++ if (!hasheq(hash, pack_sig, the_repository->hash_algo))
err = error("%s pack checksum mismatch",
p->pack_name);
- if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig))
+ if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig,
-+ r->hash_algo))
++ the_repository->hash_algo))
err = error("%s pack checksum does not match its index",
p->pack_name);
unuse_pack(w_curs);
3: 403ea4485b ! 3: 226173a92b hash: require hash algorithm in `oidread()` and `oidclr()`
@@ commit-graph.c: static struct tree *load_tree_for_commit(struct repository *r,
st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
- oidread(&oid, commit_data);
-+ oidread(&oid, commit_data, r->hash_algo);
++ oidread(&oid, commit_data, the_repository->hash_algo);
set_commit_tree(c, lookup_tree(r, &oid));
return c->maybe_tree;
@@ commit-graph.c: int write_commit_graph(struct object_directory *odb,
struct object_id oid;
- oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
-+ r->hash_algo);
++ the_repository->hash_algo);
oid_array_append(&ctx->oids, &oid);
}
}
@@ commit-graph.c: static int verify_one_commit_graph(struct repository *r,
- oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
-+ r->hash_algo);
++ the_repository->hash_algo);
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
graph_report(_("commit-graph has incorrect OID order: %s then %s"),
4: fa263d6b07 = 4: 3947c0c04d global: ensure that object IDs are always padded
5: a7df209bda = 5: 91eb94bc0b hash: convert `oidcmp()` and `oideq()` to compare whole hash
6: 9058837c93 = 6: 9ae29e1912 hash: make `is_null_oid()` independent of `the_repository`
7: d26584dc8f = 7: da48d5fdea hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
8: 4858cca25f = 8: 1cf25bec3e hash: require hash algorithm in `empty_tree_oid_hex()`
9: cb3694ad0e ! 9: 7e023a335f global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
@@ remote.c
#include "abspath.h"
#include "config.h"
+ ## repository.c ##
+@@
+ #include "promisor-remote.h"
+ #include "refs.h"
+
++/*
++ * We do not define `USE_THE_REPOSITORY_VARIABLE` in this file because we do
++ * not want to rely on functions that implicitly use `the_repository`. This
++ * means that the `extern` declaration of `the_repository` isn't visible here,
++ * which makes sparse unhappy. We thus declare it here.
++ */
++extern struct repository *the_repository;
++
+ /* The main repository */
+ static struct repository the_repo;
+ struct repository *the_repository = &the_repo;
+
## repository.h ##
@@ repository.h: struct repository {
unsigned different_commondir:1;
10: 4492548209 = 10: 74c88ebc39 refs: avoid include cycle with "repository.h"
11: f3cbc4b9f9 = 11: fe4550ba0c hash-ll: merge with "hash.h"
12: 9178098dd7 = 12: 30babd8a67 http-fetch: don't crash when parsing packfile without a repo
13: 0b4436c32b = 13: fa41a85c7e oidset: pass hash algorithm when parsing file
14: c7abfbc489 = 14: 0b42208e2f protocol-caps: use hash algorithm from passed-in repository
15: 9ae4fdb8f1 = 15: e1f4bffea1 replace-object: use hash algorithm from passed-in repository
16: 3ceb726655 = 16: 5b8f981ea2 compat/fsmonitor: fix socket path in networked SHA256 repos
17: 74e5489bd0 = 17: ad83b17ad0 t/helper: use correct object hash in partial-clone helper
18: 470aea1fc8 = 18: a488363bcb t/helper: fix segfault in "oid-array" command without repository
19: 1f0682fc7d = 19: 5de7a01af5 t/helper: remove dependency on `the_repository` in "proc-receive"
20: 16fb86c2b2 = 20: 436ffc0570 hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* [PATCH v3 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
@ 2024-06-14 6:49 ` Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
` (20 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:49 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]
The functions `is_empty_{blob,tree}_sha1()` are mostly unused, except
for a single callsite in "read-cache.c". Most callsites have long since
been converted to use the equivalents that accept a `struct object_id`
instead of a string.
Adapt the remaining callsite and drop those functions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash.h | 10 ----------
read-cache.c | 2 +-
2 files changed, 1 insertion(+), 11 deletions(-)
diff --git a/hash.h b/hash.h
index e064807c17..a1161e1b22 100644
--- a/hash.h
+++ b/hash.h
@@ -84,21 +84,11 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash)
oidread_algop(oid, hash, the_hash_algo);
}
-static inline int is_empty_blob_sha1(const unsigned char *sha1)
-{
- return hasheq(sha1, the_hash_algo->empty_blob->hash);
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
}
-static inline int is_empty_tree_sha1(const unsigned char *sha1)
-{
- return hasheq(sha1, the_hash_algo->empty_tree->hash);
-}
-
static inline int is_empty_tree_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_tree);
diff --git a/read-cache.c b/read-cache.c
index 447109aa76..10e002ce6d 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
/* Racily smudged entry? */
if (!ce->ce_stat_data.sd_size) {
- if (!is_empty_blob_sha1(ce->oid.hash))
+ if (!is_empty_blob_oid(&ce->oid))
changed |= DATA_CHANGED;
}
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()`
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
@ 2024-06-14 6:49 ` Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 03/20] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
` (19 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:49 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 17823 bytes --]
Many of our hash functions have two variants, one receiving a `struct
git_hash_algo` and one that derives it via `the_repository`. Adapt all
of those functions to always require the hash algorithm as input and
drop the variants that do not accept one.
As those functions are now independent of `the_repository`, we can move
them from "hash.h" to "hash-ll.h".
Note that both in this and subsequent commits in this series we always
just pass `the_repository->hash_algo` as input even if it is obvious
that there is a repository in the context that we should be using the
hash from instead. This is done to be on the safe side and not introduce
any regressions. All callsites should eventually be amended to use a
repo passed via parameters, but this is outside the scope of this patch
series.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/index-pack.c | 6 +++---
builtin/pack-redundant.c | 8 +++++---
builtin/unpack-objects.c | 3 ++-
commit-graph.c | 3 ++-
csum-file.c | 6 +++---
hash-ll.h | 15 +++++++++++++--
hash-lookup.c | 3 ++-
hash.h | 24 ++----------------------
http-walker.c | 2 +-
match-trees.c | 2 +-
notes.c | 2 +-
pack-bitmap-write.c | 4 ++--
pack-bitmap.c | 3 ++-
pack-check.c | 5 +++--
pack-write.c | 3 ++-
packfile.c | 8 ++++----
read-cache.c | 8 ++++----
17 files changed, 52 insertions(+), 53 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 856428fef9..ea727fba16 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1204,7 +1204,7 @@ static void parse_pack_objects(unsigned char *hash)
the_hash_algo->init_fn(&tmp_ctx);
the_hash_algo->clone_fn(&tmp_ctx, &input_ctx);
the_hash_algo->final_fn(hash, &tmp_ctx);
- if (!hasheq(fill(the_hash_algo->rawsz), hash))
+ if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo))
die(_("pack is corrupted (SHA1 mismatch)"));
use(the_hash_algo->rawsz);
@@ -1307,11 +1307,11 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
stop_progress_msg(&progress, msg.buf);
strbuf_release(&msg);
finalize_hashfile(f, tail_hash, FSYNC_COMPONENT_PACK, 0);
- hashcpy(read_hash, pack_hash);
+ hashcpy(read_hash, pack_hash, the_repository->hash_algo);
fixup_pack_header_footer(output_fd, pack_hash,
curr_pack, nr_objects,
read_hash, consumed_bytes-the_hash_algo->rawsz);
- if (!hasheq(read_hash, tail_hash))
+ if (!hasheq(read_hash, tail_hash, the_repository->hash_algo))
die(_("Unexpected tail checksum for %s "
"(disk corruption?)"), curr_pack);
}
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 4c735ba069..103c11b9d3 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -155,7 +155,7 @@ static inline struct llist_item * llist_sorted_remove(struct llist *list, const
l = (hint == NULL) ? list->front : hint;
prev = NULL;
while (l) {
- const int cmp = hashcmp(l->oid.hash, oid);
+ const int cmp = hashcmp(l->oid.hash, oid, the_repository->hash_algo);
if (cmp > 0) /* not in list, since sorted */
return prev;
if (!cmp) { /* found */
@@ -258,7 +258,8 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
while (p1_off < p1->pack->num_objects * p1_step &&
p2_off < p2->pack->num_objects * p2_step)
{
- const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
+ const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off,
+ the_repository->hash_algo);
/* cmp ~ p1 - p2 */
if (cmp == 0) {
p1_hint = llist_sorted_remove(p1->unique_objects,
@@ -296,7 +297,8 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
while (p1_off < p1->num_objects * p1_step &&
p2_off < p2->num_objects * p2_step)
{
- int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
+ int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off,
+ the_repository->hash_algo);
/* cmp ~ p1 - p2 */
if (cmp == 0) {
ret++;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f1c85a00ae..0855572c27 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -674,7 +674,8 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
if (fsck_finish(&fsck_options))
die(_("fsck error in pack objects"));
}
- if (!hasheq(fill(the_hash_algo->rawsz), oid.hash))
+ if (!hasheq(fill(the_hash_algo->rawsz), oid.hash,
+ the_repository->hash_algo))
die("final sha1 did not match");
use(the_hash_algo->rawsz);
diff --git a/commit-graph.c b/commit-graph.c
index e5dd3553df..3429156b28 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -565,7 +565,8 @@ static int add_graph_to_chain(struct commit_graph *g,
if (!cur_g ||
!oideq(&oids[n], &cur_g->oid) ||
- !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n))) {
+ !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n),
+ the_repository->hash_algo)) {
warning(_("commit-graph chain does not match"));
return 0;
}
diff --git a/csum-file.c b/csum-file.c
index 870748e016..f4be0804b7 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -68,12 +68,12 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
hashflush(f);
if (f->skip_hash)
- hashclr(f->buffer);
+ hashclr(f->buffer, the_repository->hash_algo);
else
the_hash_algo->final_fn(f->buffer, &f->ctx);
if (result)
- hashcpy(result, f->buffer);
+ hashcpy(result, f->buffer, the_repository->hash_algo);
if (flags & CSUM_HASH_IN_STREAM)
flush(f, f->buffer, the_hash_algo->rawsz);
if (flags & CSUM_FSYNC)
@@ -237,5 +237,5 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
the_hash_algo->update_fn(&ctx, data, data_len);
the_hash_algo->final_fn(got, &ctx);
- return hasheq(got, data + data_len);
+ return hasheq(got, data + data_len, the_repository->hash_algo);
}
diff --git a/hash-ll.h b/hash-ll.h
index 2cfde63ae1..fabdd8ecc7 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -245,7 +245,7 @@ static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
const struct object_id *null_oid(void);
-static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* Teach the compiler that there are only two possibilities of hash size
@@ -256,7 +256,7 @@ static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *
return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
-static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* We write this here instead of deferring to hashcmp so that the
@@ -267,6 +267,17 @@ static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *s
return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
+static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
+ const struct git_hash_algo *algop)
+{
+ memcpy(sha_dst, sha_src, algop->rawsz);
+}
+
+static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
+{
+ memset(hash, 0, algop->rawsz);
+}
+
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
diff --git a/hash-lookup.c b/hash-lookup.c
index 9f0f95e2b9..9aa6b82eb7 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -112,7 +112,8 @@ int bsearch_hash(const unsigned char *hash, const uint32_t *fanout_nbo,
while (lo < hi) {
unsigned mi = lo + (hi - lo) / 2;
- int cmp = hashcmp(table + mi * stride, hash);
+ int cmp = hashcmp(table + mi * stride, hash,
+ the_repository->hash_algo);
if (!cmp) {
if (result)
diff --git a/hash.h b/hash.h
index a1161e1b22..714938e2eb 100644
--- a/hash.h
+++ b/hash.h
@@ -6,11 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
-{
- return hashcmp_algop(sha1, sha2, the_hash_algo);
-}
-
static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
{
const struct git_hash_algo *algop;
@@ -18,12 +13,7 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o
algop = the_hash_algo;
else
algop = &hash_algos[oid1->algo];
- return hashcmp_algop(oid1->hash, oid2->hash, algop);
-}
-
-static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
-{
- return hasheq_algop(sha1, sha2, the_hash_algo);
+ return hashcmp(oid1->hash, oid2->hash, algop);
}
static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
@@ -33,7 +23,7 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi
algop = the_hash_algo;
else
algop = &hash_algos[oid1->algo];
- return hasheq_algop(oid1->hash, oid2->hash, algop);
+ return hasheq(oid1->hash, oid2->hash, algop);
}
static inline int is_null_oid(const struct object_id *oid)
@@ -41,11 +31,6 @@ static inline int is_null_oid(const struct object_id *oid)
return oideq(oid, null_oid());
}
-static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
-{
- memcpy(sha_dst, sha_src, the_hash_algo->rawsz);
-}
-
/* 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)
@@ -62,11 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
dst->algo = src->algo;
}
-static inline void hashclr(unsigned char *hash)
-{
- memset(hash, 0, the_hash_algo->rawsz);
-}
-
static inline void oidclr(struct object_id *oid)
{
memset(oid->hash, 0, GIT_MAX_RAWSZ);
diff --git a/http-walker.c b/http-walker.c
index b395ef1327..cf7f8c82bc 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -485,7 +485,7 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
list_for_each(pos, head) {
obj_req = list_entry(pos, struct object_request, node);
- if (hasheq(obj_req->oid.hash, hash))
+ if (hasheq(obj_req->oid.hash, hash, the_repository->hash_algo))
break;
}
if (!obj_req)
diff --git a/match-trees.c b/match-trees.c
index 3412b6a140..849b391d3d 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -237,7 +237,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
} else {
rewrite_with = oid2;
}
- hashcpy(rewrite_here, rewrite_with->hash);
+ hashcpy(rewrite_here, rewrite_with->hash, the_repository->hash_algo);
status = write_object_file(buf, sz, OBJ_TREE, result);
free(buf);
return status;
diff --git a/notes.c b/notes.c
index 53ca25c814..5296fd863f 100644
--- a/notes.c
+++ b/notes.c
@@ -149,7 +149,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
void **p = note_tree_search(t, &tree, &n, key_sha1);
if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
- if (hasheq(key_sha1, l->key_oid.hash))
+ if (hasheq(key_sha1, l->key_oid.hash, the_repository->hash_algo))
return l;
}
return NULL;
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 6cae670412..59d2e3a387 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -790,7 +790,7 @@ static void write_hash_cache(struct hashfile *f,
void bitmap_writer_set_checksum(struct bitmap_writer *writer,
const unsigned char *sha1)
{
- hashcpy(writer->pack_checksum, sha1);
+ hashcpy(writer->pack_checksum, sha1, the_repository->hash_algo);
}
void bitmap_writer_finish(struct bitmap_writer *writer,
@@ -816,7 +816,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
header.version = htons(default_version);
header.options = htons(flags | options);
header.entry_count = htonl(writer->selected_nr);
- hashcpy(header.checksum, writer->pack_checksum);
+ hashcpy(header.checksum, writer->pack_checksum, the_repository->hash_algo);
hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz);
dump_bitmap(f, writer->commits);
diff --git a/pack-bitmap.c b/pack-bitmap.c
index fe8e8a51d3..184d28f05c 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -367,7 +367,8 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
if (load_bitmap_header(bitmap_git) < 0)
goto cleanup;
- if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum)) {
+ if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum,
+ the_repository->hash_algo)) {
error(_("checksum doesn't match in MIDX and bitmap"));
goto cleanup;
}
diff --git a/pack-check.c b/pack-check.c
index 25104d5b14..e7b214fcbd 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -78,10 +78,11 @@ static int verify_packfile(struct repository *r,
} while (offset < pack_sig_ofs);
r->hash_algo->final_fn(hash, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
- if (!hasheq(hash, pack_sig))
+ if (!hasheq(hash, pack_sig, the_repository->hash_algo))
err = error("%s pack checksum mismatch",
p->pack_name);
- if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig))
+ if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig,
+ the_repository->hash_algo))
err = error("%s pack checksum does not match its index",
p->pack_name);
unuse_pack(w_curs);
diff --git a/pack-write.c b/pack-write.c
index 80ecfa544c..eef625fa5b 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -428,7 +428,8 @@ void fixup_pack_header_footer(int pack_fd,
if (partial_pack_offset == 0) {
unsigned char hash[GIT_MAX_RAWSZ];
the_hash_algo->final_fn(hash, &old_hash_ctx);
- if (!hasheq(hash, partial_pack_hash))
+ if (!hasheq(hash, partial_pack_hash,
+ the_repository->hash_algo))
die("Unexpected checksum for %s "
"(disk corruption?)", pack_name);
/*
diff --git a/packfile.c b/packfile.c
index d4df7fdeea..9156e9122c 100644
--- a/packfile.c
+++ b/packfile.c
@@ -242,7 +242,7 @@ struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
struct packed_git *p = alloc_packed_git(alloc);
memcpy(p->pack_name, path, alloc); /* includes NUL */
- hashcpy(p->hash, sha1);
+ hashcpy(p->hash, sha1, the_repository->hash_algo);
if (check_packed_git_idx(idx_path, p)) {
free(p);
return NULL;
@@ -596,7 +596,7 @@ static int open_packed_git_1(struct packed_git *p)
if (read_result != hashsz)
return error("packfile %s signature is unavailable", p->pack_name);
idx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;
- if (!hasheq(hash, idx_hash))
+ if (!hasheq(hash, idx_hash, the_repository->hash_algo))
return error("packfile %s does not match index", p->pack_name);
return 0;
}
@@ -751,7 +751,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
p->mtime = st.st_mtime;
if (path_len < the_hash_algo->hexsz ||
get_hash_hex(path + path_len - the_hash_algo->hexsz, p->hash))
- hashclr(p->hash);
+ hashclr(p->hash, the_repository->hash_algo);
return p;
}
@@ -1971,7 +1971,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
return 0;
}
- hashcpy(oid.hash, sha1);
+ hashcpy(oid.hash, sha1, the_repository->hash_algo);
if (bsearch_pack(&oid, p, &result))
return nth_packed_object_offset(p, result);
return 0;
diff --git a/read-cache.c b/read-cache.c
index 10e002ce6d..2642ac9558 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1735,7 +1735,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
the_hash_algo->final_fn(hash, &c);
- if (!hasheq(hash, start))
+ if (!hasheq(hash, start, the_repository->hash_algo))
return error(_("bad index file sha1 signature"));
return 0;
}
@@ -2641,7 +2641,7 @@ static void copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,
ondisk->uid = htonl(ce->ce_stat_data.sd_uid);
ondisk->gid = htonl(ce->ce_stat_data.sd_gid);
ondisk->size = htonl(ce->ce_stat_data.sd_size);
- hashcpy(ondisk->data, ce->oid.hash);
+ hashcpy(ondisk->data, ce->oid.hash, the_repository->hash_algo);
flags = ce->ce_flags & ~CE_NAMEMASK;
flags |= (ce_namelen(ce) >= CE_NAMEMASK ? CE_NAMEMASK : ce_namelen(ce));
@@ -2730,7 +2730,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)
if (n != the_hash_algo->rawsz)
goto out;
- if (!hasheq(istate->oid.hash, hash))
+ if (!hasheq(istate->oid.hash, hash, the_repository->hash_algo))
goto out;
close(fd);
@@ -3603,7 +3603,7 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size)
src_offset += extsize;
}
the_hash_algo->final_fn(hash, &c);
- if (!hasheq(hash, (const unsigned char *)index))
+ if (!hasheq(hash, (const unsigned char *)index, the_repository->hash_algo))
return 0;
/* Validate that the extension offsets returned us back to the eoie extension. */
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 03/20] hash: require hash algorithm in `oidread()` and `oidclr()`
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
@ 2024-06-14 6:49 ` Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 04/20] global: ensure that object IDs are always padded Patrick Steinhardt
` (18 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:49 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 48455 bytes --]
Both `oidread()` and `oidclr()` use `the_repository` to derive the hash
function that shall be used. Require callers to pass in the hash
algorithm to get rid of this implicit dependency.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
blame.c | 2 +-
builtin/am.c | 8 +++----
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 39 +++++++++++++++++---------------
builtin/fetch-pack.c | 4 ++--
builtin/index-pack.c | 5 ++--
builtin/log.c | 2 +-
builtin/merge.c | 4 ++--
builtin/notes.c | 2 +-
builtin/pack-objects.c | 3 ++-
builtin/pack-redundant.c | 2 +-
builtin/patch-id.c | 6 ++---
builtin/pull.c | 6 ++---
builtin/receive-pack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rm.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-objects.c | 6 ++---
builtin/update-ref.c | 8 +++----
cache-tree.c | 3 ++-
commit-graph.c | 17 +++++++++-----
diff-lib.c | 4 ++--
diff.c | 6 ++---
dir.c | 6 ++---
hash-ll.h | 14 ++++++++++++
hash.h | 17 --------------
http-push.c | 2 +-
http-walker.c | 2 +-
match-trees.c | 2 +-
midx.c | 3 ++-
notes-merge.c | 6 ++---
notes.c | 8 +++----
object-file-convert.c | 2 +-
object-file.c | 4 ++--
packfile.c | 10 ++++----
read-cache.c | 8 ++++---
refs.c | 6 ++---
refs/files-backend.c | 6 ++---
refs/packed-backend.c | 6 ++---
refs/reftable-backend.c | 37 ++++++++++++++++++------------
remote.c | 8 +++----
resolve-undo.c | 3 ++-
sequencer.c | 4 ++--
split-index.c | 2 +-
submodule-config.c | 2 +-
t/helper/test-submodule-config.c | 2 +-
tree-walk.c | 4 ++--
48 files changed, 163 insertions(+), 140 deletions(-)
diff --git a/apply.c b/apply.c
index 901b67e625..528939abb6 100644
--- a/apply.c
+++ b/apply.c
@@ -3680,7 +3680,7 @@ static int try_threeway(struct apply_state *state,
if (status) {
patch->conflicted_threeway = 1;
if (patch->is_new)
- oidclr(&patch->threeway_stage[0]);
+ oidclr(&patch->threeway_stage[0], the_repository->hash_algo);
else
oidcpy(&patch->threeway_stage[0], &pre_oid);
oidcpy(&patch->threeway_stage[1], &our_oid);
diff --git a/blame.c b/blame.c
index 33586b9777..a80f5e2e61 100644
--- a/blame.c
+++ b/blame.c
@@ -1246,7 +1246,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
goto error_out;
return 0;
error_out:
- oidclr(&origin->blob_oid);
+ oidclr(&origin->blob_oid, the_repository->hash_algo);
origin->mode = S_IFINVALID;
return -1;
}
diff --git a/builtin/am.c b/builtin/am.c
index 36839029d2..45c305ec86 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -408,7 +408,7 @@ static void am_load(struct am_state *state)
read_commit_msg(state);
if (read_state_file(&sb, state, "original-commit", 1) < 0)
- oidclr(&state->orig_commit);
+ oidclr(&state->orig_commit, the_repository->hash_algo);
else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
die(_("could not parse %s"), am_path(state, "original-commit"));
@@ -1121,7 +1121,7 @@ static void am_next(struct am_state *state)
unlink(am_path(state, "author-script"));
unlink(am_path(state, "final-commit"));
- oidclr(&state->orig_commit);
+ oidclr(&state->orig_commit, the_repository->hash_algo);
unlink(am_path(state, "original-commit"));
refs_delete_ref(get_main_ref_store(the_repository), NULL,
"REBASE_HEAD", NULL, REF_NO_DEREF);
@@ -2151,11 +2151,11 @@ static int safe_to_abort(const struct am_state *state)
if (get_oid_hex(sb.buf, &abort_safety))
die(_("could not parse %s"), am_path(state, "abort-safety"));
} else
- oidclr(&abort_safety);
+ oidclr(&abort_safety, the_repository->hash_algo);
strbuf_release(&sb);
if (repo_get_oid(the_repository, "HEAD", &head))
- oidclr(&head);
+ oidclr(&head, the_repository->hash_algo);
if (oideq(&head, &abort_safety))
return 1;
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 4693d18cc9..4b6e8c6832 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -415,7 +415,7 @@ static char *generate_fake_oid(void)
struct object_id oid;
char *hex = xmallocz(GIT_MAX_HEXSZ);
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
put_be32(oid.hash + hashsz - 4, counter++);
return oid_to_hex_r(hex, &oid);
}
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index d1c0243d04..12543488f3 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1279,8 +1279,10 @@ static void load_tree(struct tree_entry *root)
e->versions[0].mode = e->versions[1].mode;
e->name = to_atom(c, strlen(c));
c += e->name->str_len + 1;
- oidread(&e->versions[0].oid, (unsigned char *)c);
- oidread(&e->versions[1].oid, (unsigned char *)c);
+ oidread(&e->versions[0].oid, (unsigned char *)c,
+ the_repository->hash_algo);
+ oidread(&e->versions[1].oid, (unsigned char *)c,
+ the_repository->hash_algo);
c += the_hash_algo->rawsz;
}
free(buf);
@@ -1386,7 +1388,7 @@ static void tree_content_replace(
{
if (!S_ISDIR(mode))
die("Root cannot be a non-directory");
- oidclr(&root->versions[0].oid);
+ oidclr(&root->versions[0].oid, the_repository->hash_algo);
oidcpy(&root->versions[1].oid, oid);
if (root->tree)
release_tree_content_recursive(root->tree);
@@ -1445,7 +1447,7 @@ static int tree_content_set(
if (S_ISDIR(e->versions[0].mode))
e->versions[0].mode |= NO_DELTA;
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
if (!S_ISDIR(e->versions[1].mode)) {
@@ -1455,7 +1457,7 @@ static int tree_content_set(
if (!e->tree)
load_tree(e);
if (tree_content_set(e, slash1 + 1, oid, mode, subtree)) {
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
return 0;
@@ -1467,7 +1469,7 @@ static int tree_content_set(
e = new_tree_entry();
e->name = to_atom(p, n);
e->versions[0].mode = 0;
- oidclr(&e->versions[0].oid);
+ oidclr(&e->versions[0].oid, the_repository->hash_algo);
t->entries[t->entry_count++] = e;
if (*slash1) {
e->tree = new_tree_content(8);
@@ -1478,7 +1480,7 @@ static int tree_content_set(
e->versions[1].mode = mode;
oidcpy(&e->versions[1].oid, oid);
}
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
@@ -1523,7 +1525,8 @@ static int tree_content_remove(
if (tree_content_remove(e, slash1 + 1, backup_leaf, 0)) {
for (n = 0; n < e->tree->entry_count; n++) {
if (e->tree->entries[n]->versions[1].mode) {
- oidclr(&root->versions[1].oid);
+ oidclr(&root->versions[1].oid,
+ the_repository->hash_algo);
return 1;
}
}
@@ -1542,8 +1545,8 @@ static int tree_content_remove(
release_tree_content_recursive(e->tree);
e->tree = NULL;
e->versions[1].mode = 0;
- oidclr(&e->versions[1].oid);
- oidclr(&root->versions[1].oid);
+ oidclr(&e->versions[1].oid, the_repository->hash_algo);
+ oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
@@ -1609,7 +1612,7 @@ static int update_branch(struct branch *b)
return 0;
}
if (refs_read_ref(get_main_ref_store(the_repository), b->name, &old_oid))
- oidclr(&old_oid);
+ oidclr(&old_oid, the_repository->hash_algo);
if (!force_update && !is_null_oid(&old_oid)) {
struct commit *old_cmit, *new_cmit;
int ret;
@@ -2550,8 +2553,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
static void file_change_deleteall(struct branch *b)
{
release_tree_content_recursive(b->branch_tree.tree);
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
load_tree(&b->branch_tree);
b->num_notes = 0;
}
@@ -2570,8 +2573,8 @@ static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
static void parse_from_existing(struct branch *b)
{
if (is_null_oid(&b->oid)) {
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
} else {
unsigned long size;
char *buf;
@@ -2894,9 +2897,9 @@ static void parse_reset_branch(const char *arg)
b = lookup_branch(arg);
if (b) {
- oidclr(&b->oid);
- oidclr(&b->branch_tree.versions[0].oid);
- oidclr(&b->branch_tree.versions[1].oid);
+ oidclr(&b->oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+ oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
if (b->branch_tree.tree) {
release_tree_content_recursive(b->branch_tree.tree);
b->branch_tree.tree = NULL;
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 44c05ee86c..af329e8d5c 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -29,11 +29,11 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
; /* <oid>, leave oid as name */
} else {
/* <ref>, clear cruft from oid */
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
}
} else {
/* <ref>, clear cruft from get_oid_hex */
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
}
ref = alloc_ref(name);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index ea727fba16..fd968d673d 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -528,7 +528,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
switch (obj->type) {
case OBJ_REF_DELTA:
- oidread(ref_oid, fill(the_hash_algo->rawsz));
+ oidread(ref_oid, fill(the_hash_algo->rawsz),
+ the_repository->hash_algo);
use(the_hash_algo->rawsz);
break;
case OBJ_OFS_DELTA:
@@ -1372,7 +1373,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
obj[1].idx.offset += write_compressed(f, buf, size);
obj[0].idx.crc32 = crc32_end(f);
hashflush(f);
- oidread(&obj->idx.oid, sha1);
+ oidread(&obj->idx.oid, sha1, the_repository->hash_algo);
return obj;
}
diff --git a/builtin/log.c b/builtin/log.c
index 78a247d8a9..ccbda8a005 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1938,7 +1938,7 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
free(bases->patch_id);
bases->nr_patch_id = 0;
bases->alloc_patch_id = 0;
- oidclr(&bases->base_commit);
+ oidclr(&bases->base_commit, the_repository->hash_algo);
}
static const char *diff_title(struct strbuf *sb,
diff --git a/builtin/merge.c b/builtin/merge.c
index daed2d4e1e..abe66311c7 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -494,7 +494,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_branchname(&bname, remote, 0);
remote = bname.buf;
- oidclr(&branch_head);
+ oidclr(&branch_head, the_repository->hash_algo);
remote_head = get_merge_parent(remote);
if (!remote_head)
die(_("'%s' does not point to a commit"), remote);
@@ -1690,7 +1690,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* index and working tree polluted.
*/
if (save_state(&stash))
- oidclr(&stash);
+ oidclr(&stash, the_repository->hash_algo);
for (i = 0; i < use_strategies_nr; i++) {
int ret, cnt;
diff --git a/builtin/notes.c b/builtin/notes.c
index 7f80b3449b..d9c356e354 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -828,7 +828,7 @@ static int merge_commit(struct notes_merge_options *o)
if (partial->parents)
oidcpy(&parent_oid, &partial->parents->item->object.oid);
else
- oidclr(&parent_oid);
+ oidclr(&parent_oid, the_repository->hash_algo);
CALLOC_ARRAY(t, 1);
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 638f5c57f0..2b00983a99 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2078,7 +2078,8 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
oidread(&base_ref,
use_pack(p, &w_curs,
entry->in_pack_offset + used,
- NULL));
+ NULL),
+ the_repository->hash_algo);
have_base = 1;
}
entry->in_pack_header_size = used + the_hash_algo->rawsz;
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 103c11b9d3..dd9bf35f5b 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -100,7 +100,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
const unsigned char *oid)
{
struct llist_item *new_item = llist_item_get();
- oidread(&new_item->oid, oid);
+ oidread(&new_item->oid, oid, the_repository->hash_algo);
new_item->next = NULL;
if (after) {
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 583099cacf..d790ae6354 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -70,7 +70,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
git_hash_ctx ctx;
the_hash_algo->init_fn(&ctx);
- oidclr(result);
+ oidclr(result, the_repository->hash_algo);
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
char *line = line_buf->buf;
@@ -166,7 +166,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
}
if (!found_next)
- oidclr(next_oid);
+ oidclr(next_oid, the_repository->hash_algo);
flush_one_hunk(result, &ctx);
@@ -179,7 +179,7 @@ static void generate_id_list(int stable, int verbatim)
int patchlen;
struct strbuf line_buf = STRBUF_INIT;
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
while (!feof(stdin)) {
patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim);
flush_current_id(patchlen, &oid, &result);
diff --git a/builtin/pull.c b/builtin/pull.c
index d622202bce..2a73e673f3 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -1038,7 +1038,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
die_conclude_merge();
if (repo_get_oid(the_repository, "HEAD", &orig_head))
- oidclr(&orig_head);
+ oidclr(&orig_head, the_repository->hash_algo);
if (opt_rebase) {
if (opt_autostash == -1)
@@ -1053,7 +1053,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
_("Please commit or stash them."), 1, 0);
if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
- oidclr(&rebase_fork_point);
+ oidclr(&rebase_fork_point, the_repository->hash_algo);
}
if (run_fetch(repo, refspecs))
@@ -1063,7 +1063,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
return 0;
if (repo_get_oid(the_repository, "HEAD", &curr_head))
- oidclr(&curr_head);
+ oidclr(&curr_head, the_repository->hash_algo);
if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
!oideq(&orig_head, &curr_head)) {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 01c1f04ece..aa5ba27d17 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -741,7 +741,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
already_done = 1;
if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
&push_cert_oid))
- oidclr(&push_cert_oid);
+ oidclr(&push_cert_oid, the_repository->hash_algo);
memset(&sigcheck, '\0', sizeof(sigcheck));
diff --git a/builtin/replace.c b/builtin/replace.c
index ce9f6974d2..1ef833c07f 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -167,7 +167,7 @@ static int check_ref_valid(struct object_id *object,
return error(_("'%s' is not a valid ref name"), ref->buf);
if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev))
- oidclr(prev);
+ oidclr(prev, the_repository->hash_algo);
else if (!force)
return error(_("replace ref '%s' already exists"), ref->buf);
return 0;
diff --git a/builtin/rm.c b/builtin/rm.c
index d195c16e74..0e79cbab62 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -377,7 +377,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (!force) {
struct object_id oid;
if (repo_get_oid(the_repository, "HEAD", &oid))
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
if (check_local_mod(&oid, index_only))
exit(1);
}
diff --git a/builtin/tag.c b/builtin/tag.c
index 6e2c0cf342..a1fb218512 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -650,7 +650,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die(_("'%s' is not a valid tag name."), tag);
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
- oidclr(&prev);
+ oidclr(&prev, the_repository->hash_algo);
else if (!force)
die(_("tag '%s' already exists"), tag);
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 0855572c27..08fa2a7a74 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -439,7 +439,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
struct object_id base_oid;
if (type == OBJ_REF_DELTA) {
- oidread(&base_oid, fill(the_hash_algo->rawsz));
+ oidread(&base_oid, fill(the_hash_algo->rawsz), the_repository->hash_algo);
use(the_hash_algo->rawsz);
delta_data = get_data(delta_size);
if (!delta_data)
@@ -451,7 +451,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
return; /* we are done */
else {
/* cannot resolve yet --- queue it */
- oidclr(&obj_list[nr].oid);
+ oidclr(&obj_list[nr].oid, the_repository->hash_algo);
add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
return;
}
@@ -500,7 +500,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
* The delta base object is itself a delta that
* has not been resolved yet.
*/
- oidclr(&obj_list[nr].oid);
+ oidclr(&obj_list[nr].oid, the_repository->hash_algo);
add_delta_to_list(nr, null_oid(), base_offset,
delta_data, delta_size);
return;
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 6cda1c08aa..f8a5b087f8 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -122,7 +122,7 @@ static int parse_next_oid(const char **next, const char *end,
goto invalid;
} else {
/* Without -z, an empty value means all zeros: */
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
}
} else {
/* With -z, read the next NUL-terminated line */
@@ -142,7 +142,7 @@ static int parse_next_oid(const char **next, const char *end,
/* With -z, treat an empty value as all zeros: */
warning("%s %s: missing <new-oid>, treating as zero",
command, refname);
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
} else {
/*
* With -z, an empty non-required value means
@@ -291,7 +291,7 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
if (parse_next_oid(&next, end, &old_oid, "verify", refname,
PARSE_SHA1_OLD))
- oidclr(&old_oid);
+ oidclr(&old_oid, the_repository->hash_algo);
if (*next != line_termination)
die("verify %s: extra input: %s", refname, next);
@@ -564,7 +564,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
* The empty string implies that the reference
* must not already exist:
*/
- oidclr(&oldoid);
+ oidclr(&oldoid, the_repository->hash_algo);
else if (repo_get_oid(the_repository, oldval, &oldoid))
die("%s: not a valid old SHA1", oldval);
}
diff --git a/cache-tree.c b/cache-tree.c
index 387c0a3e5b..e4255c4d02 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -578,7 +578,8 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
if (0 <= it->entry_count) {
if (size < rawsz)
goto free_return;
- oidread(&it->oid, (const unsigned char *)buf);
+ oidread(&it->oid, (const unsigned char *)buf,
+ the_repository->hash_algo);
buf += rawsz;
size -= rawsz;
}
diff --git a/commit-graph.c b/commit-graph.c
index 3429156b28..98cbd53eea 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -475,7 +475,8 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
FREE_AND_NULL(graph->bloom_filter_settings);
}
- oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len);
+ oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len,
+ the_repository->hash_algo);
free_chunkfile(cf);
return graph;
@@ -838,7 +839,8 @@ static void load_oid_from_graph(struct commit_graph *g,
lex_index = pos - g->num_commits_in_base;
- oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index));
+ oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index),
+ the_repository->hash_algo);
}
static struct commit_list **insert_parent_or_die(struct repository *r,
@@ -1080,7 +1082,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
commit_data = g->chunk_commit_data +
st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
- oidread(&oid, commit_data);
+ oidread(&oid, commit_data, the_repository->hash_algo);
set_commit_tree(c, lookup_tree(r, &oid));
return c->maybe_tree;
@@ -2556,7 +2558,8 @@ int write_commit_graph(struct object_directory *odb,
struct commit_graph *g = ctx->r->objects->commit_graph;
for (i = 0; i < g->num_commits; i++) {
struct object_id oid;
- oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ the_repository->hash_algo);
oid_array_append(&ctx->oids, &oid);
}
}
@@ -2675,7 +2678,8 @@ static int verify_one_commit_graph(struct repository *r,
for (i = 0; i < g->num_commits; i++) {
struct commit *graph_commit;
- oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ the_repository->hash_algo);
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2719,7 +2723,8 @@ static int verify_one_commit_graph(struct repository *r,
timestamp_t generation;
display_progress(progress, ++(*seen));
- oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+ the_repository->hash_algo);
graph_commit = lookup_commit(r, &cur_oid);
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
diff --git a/diff-lib.c b/diff-lib.c
index 5a5a50c5a1..3fb8d79fef 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
dpath->next = NULL;
memcpy(dpath->path, ce->name, path_len);
dpath->path[path_len] = '\0';
- oidclr(&dpath->oid);
+ oidclr(&dpath->oid, the_repository->hash_algo);
memset(&(dpath->parent[0]), 0,
sizeof(struct combine_diff_parent)*5);
@@ -412,7 +412,7 @@ static int show_modified(struct rev_info *revs,
memcpy(p->path, new_entry->name, pathlen);
p->path[pathlen] = 0;
p->mode = mode;
- oidclr(&p->oid);
+ oidclr(&p->oid, the_repository->hash_algo);
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
p->parent[0].status = DIFF_STATUS_MODIFIED;
p->parent[0].mode = new_entry->ce_mode;
diff --git a/diff.c b/diff.c
index e70301df76..60d1f7be81 100644
--- a/diff.c
+++ b/diff.c
@@ -4567,7 +4567,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
if (!one->oid_valid) {
struct stat st;
if (one->is_stdin) {
- oidclr(&one->oid);
+ oidclr(&one->oid, the_repository->hash_algo);
return;
}
if (lstat(one->path, &st) < 0)
@@ -4577,7 +4577,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
}
}
else
- oidclr(&one->oid);
+ oidclr(&one->oid, the_repository->hash_algo);
}
static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
@@ -6404,7 +6404,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
the_hash_algo->init_fn(&ctx);
memset(&data, 0, sizeof(struct patch_id_t));
data.ctx = &ctx;
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
for (i = 0; i < q->nr; i++) {
xpparam_t xpp;
diff --git a/dir.c b/dir.c
index 45be4ad261..5de421c29c 100644
--- a/dir.c
+++ b/dir.c
@@ -1687,7 +1687,7 @@ static void prep_exclude(struct dir_struct *dir,
}
/* Try to read per-directory file */
- oidclr(&oid_stat.oid);
+ oidclr(&oid_stat.oid, the_repository->hash_algo);
oid_stat.valid = 0;
if (dir->exclude_per_dir &&
/*
@@ -3794,7 +3794,7 @@ static void read_oid(size_t pos, void *cb)
rd->data = rd->end + 1;
return;
}
- oidread(&ud->exclude_oid, rd->data);
+ oidread(&ud->exclude_oid, rd->data, the_repository->hash_algo);
rd->data += the_hash_algo->rawsz;
}
@@ -3802,7 +3802,7 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
const unsigned char *sha1)
{
stat_data_from_disk(&oid_stat->stat, data);
- oidread(&oid_stat->oid, sha1);
+ oidread(&oid_stat->oid, sha1, the_repository->hash_algo);
oid_stat->valid = 1;
}
diff --git a/hash-ll.h b/hash-ll.h
index fabdd8ecc7..dbb96369fc 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -284,6 +284,20 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src)
dst->algo = src->algo;
}
+static inline void oidread(struct object_id *oid, const unsigned char *hash,
+ const struct git_hash_algo *algop)
+{
+ memcpy(oid->hash, hash, algop->rawsz);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline void oidclr(struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
static inline struct object_id *oiddup(const struct object_id *src)
{
struct object_id *dst = xmalloc(sizeof(struct object_id));
diff --git a/hash.h b/hash.h
index 714938e2eb..43623a0c86 100644
--- a/hash.h
+++ b/hash.h
@@ -47,23 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
dst->algo = src->algo;
}
-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_algop(struct object_id *oid, const unsigned char *hash, const struct git_hash_algo *algop)
-{
- memcpy(oid->hash, hash, algop->rawsz);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline void oidread(struct object_id *oid, const unsigned char *hash)
-{
- oidread_algop(oid, hash, the_hash_algo);
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
diff --git a/http-push.c b/http-push.c
index 1fe51226fd..86de238b84 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1552,7 +1552,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
free(url);
FREE_AND_NULL(*symref);
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
if (buffer.len == 0)
return;
diff --git a/http-walker.c b/http-walker.c
index cf7f8c82bc..b7110b6f82 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -152,7 +152,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
newreq = xmalloc(sizeof(*newreq));
newreq->walker = walker;
- oidread(&newreq->oid, sha1);
+ oidread(&newreq->oid, sha1, the_repository->hash_algo);
newreq->repo = data->alt;
newreq->state = WAITING;
newreq->req = NULL;
diff --git a/match-trees.c b/match-trees.c
index 849b391d3d..50c42e2061 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -229,7 +229,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
oid_to_hex(oid1));
if (*subpath) {
struct object_id tree_oid;
- oidread(&tree_oid, rewrite_here);
+ oidread(&tree_oid, rewrite_here, the_repository->hash_algo);
status = splice_tree(&tree_oid, subpath, oid2, &subtree);
if (status)
return status;
diff --git a/midx.c b/midx.c
index bc4797196f..1e75f1a7eb 100644
--- a/midx.c
+++ b/midx.c
@@ -304,7 +304,8 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
if (n >= m->num_objects)
return NULL;
- oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
+ oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
+ the_repository->hash_algo);
return oid;
}
diff --git a/notes-merge.c b/notes-merge.c
index 6a9a139b12..801941c2d1 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -240,7 +240,7 @@ static void diff_tree_local(struct notes_merge_options *o,
* (will be overwritten by following addition)
*/
if (oideq(&mp->local, &uninitialized))
- oidclr(&mp->local);
+ oidclr(&mp->local, the_repository->hash_algo);
} else if (is_null_oid(&p->one->oid)) { /* addition */
/*
* Either this is a true addition (1), or it is part
@@ -556,7 +556,7 @@ int notes_merge(struct notes_merge_options *o,
assert(o->local_ref && o->remote_ref);
assert(!strcmp(o->local_ref, local_tree->ref));
- oidclr(result_oid);
+ oidclr(result_oid, the_repository->hash_algo);
trace_printf("notes_merge(o->local_ref = %s, o->remote_ref = %s)\n",
o->local_ref, o->remote_ref);
@@ -579,7 +579,7 @@ int notes_merge(struct notes_merge_options *o,
* unborn ref, perform the merge using an empty notes tree.
*/
if (!check_refname_format(o->remote_ref, 0)) {
- oidclr(&remote_oid);
+ oidclr(&remote_oid, the_repository->hash_algo);
remote = NULL;
} else {
die("Failed to resolve remote notes ref '%s'",
diff --git a/notes.c b/notes.c
index 5296fd863f..3a8da92fb9 100644
--- a/notes.c
+++ b/notes.c
@@ -353,7 +353,7 @@ static void add_non_note(struct notes_tree *t, char *path,
n->next = NULL;
n->path = path;
n->mode = mode;
- oidread(&n->oid, sha1);
+ oidread(&n->oid, sha1, the_repository->hash_algo);
t->prev_non_note = n;
if (!t->first_non_note) {
@@ -1036,7 +1036,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid));
- oidclr(&root_tree.key_oid);
+ oidclr(&root_tree.key_oid, the_repository->hash_algo);
oidcpy(&root_tree.val_oid, &oid);
load_subtree(t, &root_tree, t->root, 0);
}
@@ -1146,8 +1146,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
if (!t)
t = &default_notes_tree;
assert(t->initialized);
- oidread(&l.key_oid, object_sha1);
- oidclr(&l.val_oid);
+ oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
+ oidclr(&l.val_oid, the_repository->hash_algo);
note_tree_remove(t, t->root, 0, &l);
if (is_null_oid(&l.val_oid)) /* no note was removed */
return 1;
diff --git a/object-file-convert.c b/object-file-convert.c
index 4f6189095b..f684038f7f 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -56,7 +56,7 @@ static int decode_tree_entry_raw(struct object_id *oid, const char **path,
return -1;
*len = strlen(*path) + 1;
- oidread_algop(oid, (const unsigned char *)*path + *len, algo);
+ oidread(oid, (const unsigned char *)*path + *len, algo);
return 0;
}
diff --git a/object-file.c b/object-file.c
index a40300ce4a..c161e3e2a5 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1446,7 +1446,7 @@ static int loose_object_info(struct repository *r,
int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
/*
* If we don't care about type or size, then we don't
@@ -1580,7 +1580,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
diff --git a/packfile.c b/packfile.c
index 9156e9122c..ec7312cd20 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1251,7 +1251,7 @@ static int get_delta_base_oid(struct packed_git *p,
{
if (type == OBJ_REF_DELTA) {
unsigned char *base = use_pack(p, w_curs, curpos, NULL);
- oidread(oid, base);
+ oidread(oid, base, the_repository->hash_algo);
return 0;
} else if (type == OBJ_OFS_DELTA) {
uint32_t base_pos;
@@ -1593,7 +1593,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
goto out;
}
} else
- oidclr(oi->delta_base_oid);
+ oidclr(oi->delta_base_oid, the_repository->hash_algo);
}
oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :
@@ -1917,10 +1917,12 @@ int nth_packed_object_id(struct object_id *oid,
return -1;
index += 4 * 256;
if (p->index_version == 1) {
- oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4));
+ oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4),
+ the_repository->hash_algo);
} else {
index += 8;
- oidread(oid, index + st_mult(hashsz, n));
+ oidread(oid, index + st_mult(hashsz, n),
+ the_repository->hash_algo);
}
return 0;
}
diff --git a/read-cache.c b/read-cache.c
index 2642ac9558..836f1db721 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1728,7 +1728,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
end = (unsigned char *)hdr + size;
start = end - the_hash_algo->rawsz;
- oidread(&oid, start);
+ oidread(&oid, start, the_repository->hash_algo);
if (oideq(&oid, null_oid()))
return 0;
@@ -1876,7 +1876,8 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
ce->ce_flags = flags & ~CE_NAMEMASK;
ce->ce_namelen = len;
ce->index = 0;
- oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data));
+ oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data),
+ the_repository->hash_algo);
if (expand_name_field) {
if (copy_len)
@@ -2249,7 +2250,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
if (verify_hdr(hdr, mmap_size) < 0)
goto unmap;
- oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
+ oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz,
+ the_repository->hash_algo);
istate->version = ntohl(hdr->hdr_version);
istate->cache_nr = ntohl(hdr->hdr_entries);
istate->cache_alloc = alloc_nr(istate->cache_nr);
diff --git a/refs.c b/refs.c
index 1304d3dd87..6e7caefdcf 100644
--- a/refs.c
+++ b/refs.c
@@ -1822,7 +1822,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
failure_errno != ENOTDIR)
return NULL;
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
if (*flags & REF_BAD_NAME)
*flags |= REF_ISBROKEN;
return refname;
@@ -1832,7 +1832,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
if (!(read_flags & REF_ISSYMREF)) {
if (*flags & REF_BAD_NAME) {
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
*flags |= REF_ISBROKEN;
}
return refname;
@@ -1840,7 +1840,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
refname = sb_refname.buf;
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
- oidclr(oid);
+ oidclr(oid, the_repository->hash_algo);
return refname;
}
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4519b46171..b484b5880d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -246,7 +246,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
&oid, &flag)) {
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
flag |= REF_ISBROKEN;
} else if (is_null_oid(&oid)) {
/*
@@ -263,7 +263,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
if (!refname_is_safe(refname))
die("loose refname is dangerous: %s", refname);
- oidclr(&oid);
+ oidclr(&oid, the_repository->hash_algo);
flag |= REF_BAD_NAME | REF_ISBROKEN;
}
add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));
@@ -1150,7 +1150,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
&lock->old_oid, NULL))
- oidclr(&lock->old_oid);
+ oidclr(&lock->old_oid, the_repository->hash_algo);
goto out;
error_return:
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index c4c1e36aa2..5ab1b21d10 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -894,7 +894,7 @@ static int next_record(struct packed_ref_iterator *iter)
if (!refname_is_safe(iter->base.refname))
die("packed refname is dangerous: %s",
iter->base.refname);
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
iter->base.flags |= REF_BAD_NAME | REF_ISBROKEN;
}
if (iter->snapshot->peeled == PEELED_FULLY ||
@@ -919,13 +919,13 @@ static int next_record(struct packed_ref_iterator *iter)
* we suppress it if the reference is broken:
*/
if ((iter->base.flags & REF_ISBROKEN)) {
- oidclr(&iter->peeled);
+ oidclr(&iter->peeled, the_repository->hash_algo);
iter->base.flags &= ~REF_KNOWS_PEELED;
} else {
iter->base.flags |= REF_KNOWS_PEELED;
}
} else {
- oidclr(&iter->peeled);
+ oidclr(&iter->peeled, the_repository->hash_algo);
}
return ITER_OK;
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 9886fc67a4..57df2aba66 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -217,7 +217,8 @@ static int read_ref_without_reload(struct reftable_stack *stack,
strbuf_addstr(referent, ref.value.symref);
*type |= REF_ISSYMREF;
} else if (reftable_ref_record_val1(&ref)) {
- oidread(oid, reftable_ref_record_val1(&ref));
+ oidread(oid, reftable_ref_record_val1(&ref),
+ the_repository->hash_algo);
} else {
/* We got a tombstone, which should not happen. */
BUG("unhandled reference value type %d", ref.value_type);
@@ -483,15 +484,17 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
switch (iter->ref.value_type) {
case REFTABLE_REF_VAL1:
- oidread(&iter->oid, iter->ref.value.val1);
+ oidread(&iter->oid, iter->ref.value.val1,
+ the_repository->hash_algo);
break;
case REFTABLE_REF_VAL2:
- oidread(&iter->oid, iter->ref.value.val2.value);
+ oidread(&iter->oid, iter->ref.value.val2.value,
+ the_repository->hash_algo);
break;
case REFTABLE_REF_SYMREF:
if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname,
RESOLVE_REF_READING, &iter->oid, &flags))
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
break;
default:
BUG("unhandled reference value type %d", iter->ref.value_type);
@@ -503,7 +506,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
if (check_refname_format(iter->ref.refname, REFNAME_ALLOW_ONELEVEL)) {
if (!refname_is_safe(iter->ref.refname))
die(_("refname is dangerous: %s"), iter->ref.refname);
- oidclr(&iter->oid);
+ oidclr(&iter->oid, the_repository->hash_algo);
flags |= REF_BAD_NAME | REF_ISBROKEN;
}
@@ -545,7 +548,8 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,
(struct reftable_ref_iterator *)ref_iterator;
if (iter->ref.value_type == REFTABLE_REF_VAL2) {
- oidread(peeled, iter->ref.value.val2.target_value);
+ oidread(peeled, iter->ref.value.val2.target_value,
+ the_repository->hash_algo);
return 0;
}
@@ -1776,8 +1780,8 @@ static int yield_log_record(struct reftable_log_record *log,
struct object_id old_oid, new_oid;
const char *full_committer;
- oidread(&old_oid, log->value.update.old_hash);
- oidread(&new_oid, log->value.update.new_hash);
+ oidread(&old_oid, log->value.update.old_hash, the_repository->hash_algo);
+ oidread(&new_oid, log->value.update.new_hash, the_repository->hash_algo);
/*
* When both the old object ID and the new object ID are null
@@ -2178,7 +2182,8 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
if (ret < 0)
goto done;
if (reftable_ref_record_val1(&ref_record))
- oidread(&oid, reftable_ref_record_val1(&ref_record));
+ oidread(&oid, reftable_ref_record_val1(&ref_record),
+ the_repository->hash_algo);
prepare_fn(refname, &oid, policy_cb_data);
while (1) {
@@ -2193,8 +2198,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
break;
}
- oidread(&old_oid, log.value.update.old_hash);
- oidread(&new_oid, log.value.update.new_hash);
+ oidread(&old_oid, log.value.update.old_hash,
+ the_repository->hash_algo);
+ oidread(&new_oid, log.value.update.new_hash,
+ the_repository->hash_algo);
/*
* Skip over the reflog existence marker. We will add it back
@@ -2225,8 +2232,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
struct object_id old_oid, new_oid;
*dest = logs[i];
- oidread(&old_oid, logs[i].value.update.old_hash);
- oidread(&new_oid, logs[i].value.update.new_hash);
+ oidread(&old_oid, logs[i].value.update.old_hash,
+ the_repository->hash_algo);
+ oidread(&new_oid, logs[i].value.update.new_hash,
+ the_repository->hash_algo);
if (should_prune_fn(&old_oid, &new_oid, logs[i].value.update.email,
(timestamp_t)logs[i].value.update.time,
@@ -2243,7 +2252,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
reftable_ref_record_val1(&ref_record))
- oidread(&arg.update_oid, last_hash);
+ oidread(&arg.update_oid, last_hash, the_repository->hash_algo);
arg.refs = refs;
arg.records = rewritten;
diff --git a/remote.c b/remote.c
index dcb5492c85..1064171085 100644
--- a/remote.c
+++ b/remote.c
@@ -1164,7 +1164,7 @@ static void tail_link_ref(struct ref *ref, struct ref ***tail)
static struct ref *alloc_delete_ref(void)
{
struct ref *ref = alloc_ref("(delete)");
- oidclr(&ref->new_oid);
+ oidclr(&ref->new_oid, the_repository->hash_algo);
return ref;
}
@@ -2531,7 +2531,7 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
if (!*colon)
entry->use_tracking = 1;
else if (!colon[1])
- oidclr(&entry->expect);
+ oidclr(&entry->expect, the_repository->hash_algo);
else if (repo_get_oid(the_repository, colon + 1, &entry->expect))
return error(_("cannot parse expected object name '%s'"),
colon + 1);
@@ -2733,7 +2733,7 @@ static void apply_cas(struct push_cas_option *cas,
else if (remote_tracking(remote, ref->name,
&ref->old_oid_expect,
&ref->tracking_ref))
- oidclr(&ref->old_oid_expect);
+ oidclr(&ref->old_oid_expect, the_repository->hash_algo);
else
ref->check_reachable = cas->use_force_if_includes;
return;
@@ -2747,7 +2747,7 @@ static void apply_cas(struct push_cas_option *cas,
if (remote_tracking(remote, ref->name,
&ref->old_oid_expect,
&ref->tracking_ref))
- oidclr(&ref->old_oid_expect);
+ oidclr(&ref->old_oid_expect, the_repository->hash_algo);
else
ref->check_reachable = cas->use_force_if_includes;
}
diff --git a/resolve-undo.c b/resolve-undo.c
index cd02dc9928..4e6f0e4676 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -93,7 +93,8 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
continue;
if (size < rawsz)
goto error;
- oidread(&ui->oid[i], (const unsigned char *)data);
+ oidread(&ui->oid[i], (const unsigned char *)data,
+ the_repository->hash_algo);
size -= rawsz;
data += rawsz;
}
diff --git a/sequencer.c b/sequencer.c
index 30513e87bf..68d62a12ff 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3334,12 +3334,12 @@ static int rollback_is_safe(void)
strbuf_release(&sb);
}
else if (errno == ENOENT)
- oidclr(&expected_head);
+ oidclr(&expected_head, the_repository->hash_algo);
else
die_errno(_("could not read '%s'"), git_path_abort_safety_file());
if (repo_get_oid(the_repository, "HEAD", &actual_head))
- oidclr(&actual_head);
+ oidclr(&actual_head, the_repository->hash_algo);
return oideq(&actual_head, &expected_head);
}
diff --git a/split-index.c b/split-index.c
index 8c38687c04..058a8f448e 100644
--- a/split-index.c
+++ b/split-index.c
@@ -29,7 +29,7 @@ int read_link_extension(struct index_state *istate,
if (sz < the_hash_algo->rawsz)
return error("corrupt link extension (too short)");
si = init_split_index(istate);
- oidread(&si->base_oid, data);
+ oidread(&si->base_oid, data, the_repository->hash_algo);
data += the_hash_algo->rawsz;
sz -= the_hash_algo->rawsz;
if (!sz)
diff --git a/submodule-config.c b/submodule-config.c
index ec45ea67b9..ad43a282da 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -682,7 +682,7 @@ static int gitmodule_oid_from_commit(const struct object_id *treeish_name,
int ret = 0;
if (is_null_oid(treeish_name)) {
- oidclr(gitmodules_oid);
+ oidclr(gitmodules_oid, the_repository->hash_algo);
return 1;
}
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 9df2f03ac8..4b809d9dca 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -44,7 +44,7 @@ int cmd__submodule_config(int argc, const char **argv)
path_or_name = arg[1];
if (commit[0] == '\0')
- oidclr(&commit_oid);
+ oidclr(&commit_oid, the_repository->hash_algo);
else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
die_usage(argc, argv, "Commit not found.");
diff --git a/tree-walk.c b/tree-walk.c
index 6565d9ad99..535a3a2539 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -38,8 +38,8 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
desc->entry.path = path;
desc->entry.mode = (desc->flags & TREE_DESC_RAW_MODES) ? mode : canon_mode(mode);
desc->entry.pathlen = len - 1;
- oidread_algop(&desc->entry.oid, (const unsigned char *)path + len,
- desc->algo);
+ oidread(&desc->entry.oid, (const unsigned char *)path + len,
+ desc->algo);
return 0;
}
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 04/20] global: ensure that object IDs are always padded
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (2 preceding siblings ...)
2024-06-14 6:49 ` [PATCH v3 03/20] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
@ 2024-06-14 6:49 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
` (17 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:49 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 6452 bytes --]
The `oidcmp()` and `oideq()` functions only compare the prefix length as
specified by the given hash algorithm. This mandates that the object IDs
have a valid hash algorithm set, or otherwise we wouldn't be able to
figure out that prefix. As we do not have a hash algorithm in many
cases, for example when handling null object IDs, this assumption cannot
always be fulfilled. We thus have a fallback in place that instead uses
`the_repository` to derive the hash function. This implicit dependency
is hidden away from callers and can be quite surprising, especially in
contexts where there may be no repository.
In theory, we can adapt those functions to always memcmp(3P) the whole
length of their hash arrays. But there exist a couple of sites where we
populate `struct object_id`s such that only the prefix of its hash that
is actually used by the hash algorithm is populated. The remaining bytes
are left uninitialized. The fact that those bytes are uninitialized also
leads to warnings under Valgrind in some places where we copy those
bytes.
Refactor callsites where we populate object IDs to always initialize all
bytes. This also allows us to get rid of `oidcpy_with_padding()`, for
one because the input is now fully initialized, and because `oidcpy()`
will now always copy the whole hash array.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 2 ++
hash.h | 16 ----------------
hex.c | 6 +++++-
http-push.c | 1 +
notes.c | 2 ++
object-file.c | 2 ++
oidtree.c | 4 ++--
parallel-checkout.c | 8 +-------
8 files changed, 15 insertions(+), 26 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index dbb96369fc..b72f84f4ae 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -288,6 +288,8 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash,
const struct git_hash_algo *algop)
{
memcpy(oid->hash, hash, algop->rawsz);
+ if (algop->rawsz < GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
oid->algo = hash_algo_by_ptr(algop);
}
diff --git a/hash.h b/hash.h
index 43623a0c86..e43e3d8b5a 100644
--- a/hash.h
+++ b/hash.h
@@ -31,22 +31,6 @@ static inline int is_null_oid(const struct object_id *oid)
return oideq(oid, null_oid());
}
-/* 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;
-
- memcpy(dst->hash, src->hash, hashsz);
- memset(dst->hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
- dst->algo = src->algo;
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
diff --git a/hex.c b/hex.c
index d42262bdca..bc9e86a978 100644
--- a/hex.c
+++ b/hex.c
@@ -25,8 +25,12 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid,
const struct git_hash_algo *algop)
{
int ret = get_hash_hex_algop(hex, oid->hash, algop);
- if (!ret)
+ if (!ret) {
oid_set_algo(oid, algop);
+ if (algop->rawsz != GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0,
+ GIT_MAX_RAWSZ - algop->rawsz);
+ }
return ret;
}
diff --git a/http-push.c b/http-push.c
index 86de238b84..a97df4a1fb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1016,6 +1016,7 @@ 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)
{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
oid->algo = hash_algo_by_ptr(the_hash_algo);
if (strlen(path) != the_hash_algo->hexsz + 1)
diff --git a/notes.c b/notes.c
index 3a8da92fb9..afe2e2882e 100644
--- a/notes.c
+++ b/notes.c
@@ -427,6 +427,8 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
hashsz - prefix_len))
goto handle_non_note; /* entry.path is not a SHA1 */
+ memset(object_oid.hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
+
type = PTR_TYPE_NOTE;
} else if (path_len == 2) {
/* This is potentially an internal node */
diff --git a/object-file.c b/object-file.c
index c161e3e2a5..bb97f8a809 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2743,6 +2743,8 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
!hex_to_bytes(oid.hash + 1, de->d_name,
the_hash_algo->rawsz - 1)) {
oid_set_algo(&oid, the_hash_algo);
+ memset(oid.hash + the_hash_algo->rawsz, 0,
+ GIT_MAX_RAWSZ - the_hash_algo->rawsz);
if (obj_cb) {
r = obj_cb(&oid, path->buf, data);
if (r)
diff --git a/oidtree.c b/oidtree.c
index daef175dc7..92d03b52db 100644
--- a/oidtree.c
+++ b/oidtree.c
@@ -42,7 +42,7 @@ void oidtree_insert(struct oidtree *ot, const struct object_id *oid)
* Clear the padding and copy the result in separate steps to
* respect the 4-byte alignment needed by struct object_id.
*/
- oidcpy_with_padding(&k, oid);
+ oidcpy(&k, oid);
memcpy(on->k, &k, sizeof(k));
/*
@@ -60,7 +60,7 @@ int oidtree_contains(struct oidtree *ot, const struct object_id *oid)
struct object_id k;
size_t klen = sizeof(k);
- oidcpy_with_padding(&k, oid);
+ oidcpy(&k, oid);
if (oid->algo == GIT_HASH_UNKNOWN)
klen -= sizeof(oid->algo);
diff --git a/parallel-checkout.c b/parallel-checkout.c
index b5a714c711..08b960aac8 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -429,13 +429,7 @@ static void send_one_item(int fd, struct parallel_checkout_item *pc_item)
fixed_portion->ident = pc_item->ca.ident;
fixed_portion->name_len = name_len;
fixed_portion->working_tree_encoding_len = working_tree_encoding_len;
- /*
- * We pad the unused bytes in the hash array because, otherwise,
- * Valgrind would complain about passing uninitialized bytes to a
- * write() syscall. The warning doesn't represent any real risk here,
- * but it could hinder the detection of actual errors.
- */
- oidcpy_with_padding(&fixed_portion->oid, &pc_item->ce->oid);
+ oidcpy(&fixed_portion->oid, &pc_item->ce->oid);
variant = data + sizeof(*fixed_portion);
if (working_tree_encoding_len) {
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (3 preceding siblings ...)
2024-06-14 6:49 ` [PATCH v3 04/20] global: ensure that object IDs are always padded Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-17 9:18 ` Karthik Nayak
2024-06-14 6:50 ` [PATCH v3 06/20] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
` (16 subsequent siblings)
21 siblings, 1 reply; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 6009 bytes --]
With the preceding commit, the hash array of object IDs is now fully
zero-padded even when the hash algorithm's output is smaller than the
array length. With that, we can now adapt both `oidcmp()` and `oideq()`
to unconditionally memcmp(3P) the whole array instead of depending on
the hash size.
While it may feel inefficient to compare unused bytes for e.g. SHA-1, in
practice the compiler should now be able to produce code that is better
optimized both because we have no branch anymore, but also because the
size to compare is now known at compile time. Goldbolt spits out the
following assembly on an x86_64 platform with GCC 14.1 for the old and
new implementations of `oidcmp()`:
oidcmp_old:
movsx rax, DWORD PTR [rdi+32]
test eax, eax
jne .L2
mov rax, QWORD PTR the_repository[rip]
cmp QWORD PTR [rax+16], 32
je .L6
.L4:
mov edx, 20
jmp memcmp
.L2:
lea rdx, [rax+rax*2]
lea rax, [rax+rdx*4]
lea rax, hash_algos[0+rax*8]
cmp QWORD PTR [rax+16], 32
jne .L4
.L6:
mov edx, 32
jmp memcmp
oidcmp_new:
mov edx, 32
jmp memcmp
The new implementation gets ridi of all the branches and effectively
only ends setting up `edx` for `memcmp()` and then calling it.
And for `oideq()`:
oideq_old:
movsx rcx, DWORD PTR [rdi+32]
mov rax, rdi
mov rdx, rsi
test ecx, ecx
jne .L2
mov rcx, QWORD PTR the_repository[rip]
cmp QWORD PTR [rcx+16], 32
mov rcx, QWORD PTR [rax]
je .L12
.L4:
mov rsi, QWORD PTR [rax+8]
xor rcx, QWORD PTR [rdx]
xor rsi, QWORD PTR [rdx+8]
or rcx, rsi
je .L13
.L8:
mov eax, 1
test eax, eax
sete al
movzx eax, al
ret
.L2:
lea rsi, [rcx+rcx*2]
lea rcx, [rcx+rsi*4]
lea rcx, hash_algos[0+rcx*8]
cmp QWORD PTR [rcx+16], 32
mov rcx, QWORD PTR [rax]
jne .L4
.L12:
mov rsi, QWORD PTR [rax+8]
xor rcx, QWORD PTR [rdx]
xor rsi, QWORD PTR [rdx+8]
or rcx, rsi
jne .L8
mov rcx, QWORD PTR [rax+16]
mov rax, QWORD PTR [rax+24]
xor rcx, QWORD PTR [rdx+16]
xor rax, QWORD PTR [rdx+24]
or rcx, rax
jne .L8
xor eax, eax
.L14:
test eax, eax
sete al
movzx eax, al
ret
.L13:
mov edi, DWORD PTR [rdx+16]
cmp DWORD PTR [rax+16], edi
jne .L8
xor eax, eax
jmp .L14
oideq_new:
mov rax, QWORD PTR [rdi]
mov rdx, QWORD PTR [rdi+8]
xor rax, QWORD PTR [rsi]
xor rdx, QWORD PTR [rsi+8]
or rax, rdx
je .L5
.L2:
mov eax, 1
xor eax, 1
ret
.L5:
mov rax, QWORD PTR [rdi+16]
mov rdx, QWORD PTR [rdi+24]
xor rax, QWORD PTR [rsi+16]
xor rdx, QWORD PTR [rsi+24]
or rax, rdx
jne .L2
xor eax, eax
xor eax, 1
ret
Interestingly, the compiler decides to split the comparisons into two so
that it first compares the lower half of the object ID for equality and
then the upper half. If the first check shows a difference, then we
wouldn't even end up comparing the second half.
In both cases, the new generated code is significantly shorter and has
way less branches. While I didn't benchmark the change, I'd be surprised
if the new code was slower.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 10 ++++++++++
hash.h | 20 --------------------
2 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index b72f84f4ae..b04fe12aef 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -278,6 +278,16 @@ static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algo
memset(hash, 0, algop->rawsz);
}
+static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
diff --git a/hash.h b/hash.h
index e43e3d8b5a..ddc2e5ca47 100644
--- a/hash.h
+++ b/hash.h
@@ -6,26 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-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(oid1->hash, oid2->hash, algop);
-}
-
-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(oid1->hash, oid2->hash, algop);
-}
-
static inline int is_null_oid(const struct object_id *oid)
{
return oideq(oid, null_oid());
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 06/20] hash: make `is_null_oid()` independent of `the_repository`
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (4 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
` (15 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1496 bytes --]
The function `is_null_oid()` uses `oideq(oid, null_oid())` to check
whether a given object ID is the all-zero object ID. `null_oid()`
implicitly relies on `the_repository` though to return the correct null
object ID.
Get rid of this dependency by always comparing the complete hash array
for being all-zeroes. This is possible due to the refactoring of object
IDs so that their hash arrays are always fully initialized.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hash-ll.h | 6 ++++++
hash.h | 5 -----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/hash-ll.h b/hash-ll.h
index b04fe12aef..faf6c292d2 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -341,6 +341,12 @@ static inline unsigned int oidhash(const struct object_id *oid)
return hash;
}
+static inline int is_null_oid(const struct object_id *oid)
+{
+ static const unsigned char null_hash[GIT_MAX_RAWSZ];
+ return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
+}
+
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
diff --git a/hash.h b/hash.h
index ddc2e5ca47..84f2296cfb 100644
--- a/hash.h
+++ b/hash.h
@@ -6,11 +6,6 @@
#define the_hash_algo the_repository->hash_algo
-static inline int is_null_oid(const struct object_id *oid)
-{
- return oideq(oid, null_oid());
-}
-
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (5 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 06/20] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
` (14 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 3968 bytes --]
Both functions `is_empty_{blob,tree}_oid()` use `the_repository` to
derive the hash function that shall be used. Require callers to pass in
the hash algorithm to get rid of this implicit dependency.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 4 +++-
cache-tree.c | 2 +-
diffcore-rename.c | 4 ++--
hash-ll.h | 12 ++++++++++++
hash.h | 10 ----------
read-cache.c | 2 +-
6 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 12543488f3..d21c4053a7 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2361,7 +2361,9 @@ static void file_change_m(const char *p, struct branch *b)
parse_path_eol(&path, p, "path");
/* Git does not track empty, non-toplevel directories. */
- if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *path.buf) {
+ if (S_ISDIR(mode) &&
+ is_empty_tree_oid(&oid, the_repository->hash_algo) &&
+ *path.buf) {
tree_content_remove(&b->branch_tree, path.buf, NULL, 0);
return;
}
diff --git a/cache-tree.c b/cache-tree.c
index e4255c4d02..3290a1b8dd 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -422,7 +422,7 @@ static int update_one(struct cache_tree *it,
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
- if (contains_ita && is_empty_tree_oid(oid))
+ if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo))
continue;
strbuf_grow(&buffer, entlen + 100);
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 5a6e2bcac7..5abb958651 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -1422,7 +1422,7 @@ void diffcore_rename_extended(struct diff_options *options,
strcmp(options->single_follow, p->two->path))
continue; /* not interested */
else if (!options->flags.rename_empty &&
- is_empty_blob_oid(&p->two->oid))
+ is_empty_blob_oid(&p->two->oid, the_repository->hash_algo))
continue;
else if (add_rename_dst(p) < 0) {
warning("skipping rename detection, detected"
@@ -1432,7 +1432,7 @@ void diffcore_rename_extended(struct diff_options *options,
}
}
else if (!options->flags.rename_empty &&
- is_empty_blob_oid(&p->one->oid))
+ is_empty_blob_oid(&p->one->oid, the_repository->hash_algo))
continue;
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
/*
diff --git a/hash-ll.h b/hash-ll.h
index faf6c292d2..1000a9af22 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -350,4 +350,16 @@ static inline int is_null_oid(const struct object_id *oid)
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
+static inline int is_empty_blob_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_blob);
+}
+
+static inline int is_empty_tree_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_tree);
+}
+
#endif
diff --git a/hash.h b/hash.h
index 84f2296cfb..39a0164be3 100644
--- a/hash.h
+++ b/hash.h
@@ -6,14 +6,4 @@
#define the_hash_algo the_repository->hash_algo
-static inline int is_empty_blob_oid(const struct object_id *oid)
-{
- return oideq(oid, the_hash_algo->empty_blob);
-}
-
-static inline int is_empty_tree_oid(const struct object_id *oid)
-{
- return oideq(oid, the_hash_algo->empty_tree);
-}
-
#endif
diff --git a/read-cache.c b/read-cache.c
index 836f1db721..085b22faf3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
/* Racily smudged entry? */
if (!ce->ce_stat_data.sd_size) {
- if (!is_empty_blob_oid(&ce->oid))
+ if (!is_empty_blob_oid(&ce->oid, the_repository->hash_algo))
changed |= DATA_CHANGED;
}
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 08/20] hash: require hash algorithm in `empty_tree_oid_hex()`
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (6 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
` (13 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 6668 bytes --]
The `empty_tree_oid_hex()` function use `the_repository` to derive the
hash function that shall be used. Require callers to pass in the hash
algorithm to get rid of this implicit dependency.
While at it, remove the unused `empty_blob_oid_hex()` function.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
add-interactive.c | 2 +-
add-patch.c | 2 +-
builtin/merge.c | 3 ++-
builtin/receive-pack.c | 2 +-
hash-ll.h | 3 +--
object-file.c | 10 ++--------
sequencer.c | 2 +-
submodule.c | 6 +++---
wt-status.c | 4 ++--
9 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/add-interactive.c b/add-interactive.c
index b5d6cd689a..a0961096cd 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
s.skip_unseen = filter && i;
opt.def = is_initial ?
- empty_tree_oid_hex() : oid_to_hex(&head_oid);
+ empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
repo_init_revisions(r, &rev, NULL);
setup_revisions(0, NULL, &rev, &opt);
diff --git a/add-patch.c b/add-patch.c
index 814de57c4a..86181770f2 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -420,7 +420,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
/* could be on an unborn branch */
!strcmp("HEAD", s->revision) &&
repo_get_oid(the_repository, "HEAD", &oid) ?
- empty_tree_oid_hex() : s->revision);
+ empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
}
color_arg_index = args.nr;
/* Use `--no-color` explicitly, just in case `diff.color = always`. */
diff --git a/builtin/merge.c b/builtin/merge.c
index abe66311c7..bb94b7df21 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -330,7 +330,8 @@ static void read_empty(const struct object_id *oid)
{
struct child_process cmd = CHILD_PROCESS_INIT;
- strvec_pushl(&cmd.args, "read-tree", "-m", "-u", empty_tree_oid_hex(),
+ strvec_pushl(&cmd.args, "read-tree", "-m", "-u",
+ empty_tree_oid_hex(the_repository->hash_algo),
oid_to_hex(oid), NULL);
cmd.git_cmd = 1;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index aa5ba27d17..41d5fb8e60 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1371,7 +1371,7 @@ static const char *push_to_deploy(unsigned char *sha1,
strvec_pushl(&child.args, "diff-index", "--quiet", "--cached",
"--ignore-submodules",
/* diff-index with either HEAD or an empty tree */
- head_has_history() ? "HEAD" : empty_tree_oid_hex(),
+ head_has_history() ? "HEAD" : empty_tree_oid_hex(the_repository->hash_algo),
"--", NULL);
strvec_pushv(&child.env, env->v);
child.no_stdin = 1;
diff --git a/hash-ll.h b/hash-ll.h
index 1000a9af22..3161c778b9 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -347,8 +347,7 @@ static inline int is_null_oid(const struct object_id *oid)
return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
}
-const char *empty_tree_oid_hex(void);
-const char *empty_blob_oid_hex(void);
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
static inline int is_empty_blob_oid(const struct object_id *oid,
const struct git_hash_algo *algop)
diff --git a/object-file.c b/object-file.c
index bb97f8a809..72318c8dd4 100644
--- a/object-file.c
+++ b/object-file.c
@@ -227,16 +227,10 @@ const struct object_id *null_oid(void)
return the_hash_algo->null_oid;
}
-const char *empty_tree_oid_hex(void)
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
{
static char buf[GIT_MAX_HEXSZ + 1];
- return oid_to_hex_r(buf, the_hash_algo->empty_tree);
-}
-
-const char *empty_blob_oid_hex(void)
-{
- static char buf[GIT_MAX_HEXSZ + 1];
- return oid_to_hex_r(buf, the_hash_algo->empty_blob);
+ return oid_to_hex_r(buf, algop->empty_tree);
}
int hash_algo_by_name(const char *name)
diff --git a/sequencer.c b/sequencer.c
index 68d62a12ff..823691e379 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
unborn = 1;
} else if (unborn)
oidcpy(&head, the_hash_algo->empty_tree);
- if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
+ if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
NULL, 0))
return error_dirty_index(r, opts);
}
diff --git a/submodule.c b/submodule.c
index 759cf1e1cd..caf3aa5600 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2119,7 +2119,7 @@ static void submodule_reset_index(const char *path, const char *super_prefix)
strvec_pushf(&cp.args, "--super-prefix=%s%s/",
(super_prefix ? super_prefix : ""), path);
- strvec_push(&cp.args, empty_tree_oid_hex());
+ strvec_push(&cp.args, empty_tree_oid_hex(the_repository->hash_algo));
if (run_command(&cp))
die(_("could not reset submodule index"));
@@ -2229,9 +2229,9 @@ int submodule_move_head(const char *path, const char *super_prefix,
strvec_push(&cp.args, "-m");
if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
- strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex());
+ strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex(the_repository->hash_algo));
- strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex());
+ strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex(the_repository->hash_algo));
if (run_command(&cp)) {
ret = error(_("Submodule '%s' could not be updated."), path);
diff --git a/wt-status.c b/wt-status.c
index ff4be071ca..5051f5e599 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -641,7 +641,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
repo_init_revisions(s->repo, &rev, NULL);
memset(&opt, 0, sizeof(opt));
- opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
+ opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.flags.override_submodule_config = 1;
@@ -1136,7 +1136,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
rev.diffopt.ita_invisible_in_index = 1;
memset(&opt, 0, sizeof(opt));
- opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
+ opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (7 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-17 9:30 ` Karthik Nayak
2024-06-14 6:50 ` [PATCH v3 10/20] refs: avoid include cycle with "repository.h" Patrick Steinhardt
` (12 subsequent siblings)
21 siblings, 1 reply; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 55347 bytes --]
Use of the `the_repository` variable is deprecated nowadays, and we
slowly but steadily convert the codebase to not use it anymore. Instead,
callers should be passing down the repository to work on via parameters.
It is hard though to prove that a given code unit does not use this
variable anymore. The most trivial case, merely demonstrating that there
is no direct use of `the_repository`, is already a bit of a pain during
code reviews as the reviewer needs to manually verify claims made by the
patch author. The bigger problem though is that we have many interfaces
that implicitly rely on `the_repository`.
Introduce a new `USE_THE_REPOSITORY_VARIABLE` macro that allows code
units to opt into usage of `the_repository`. The intent of this macro is
to demonstrate that a certain code unit does not use this variable
anymore, and to keep it from new dependencies on it in future changes,
be it explicit or implicit
For now, the macro only guards `the_repository` itself as well as
`the_hash_algo`. There are many more known interfaces where we have an
implicit dependency on `the_repository`, but those are not guarded at
the current point in time. Over time though, we should start to add
guards as required (or even better, just remove them).
Define the macro as required in our code units. As expected, most of our
code still relies on the global variable. Nearly all of our builtins
rely on the variable as there is no way yet to pass `the_repository` to
their entry point. For now, declare the macro in "biultin.h" to keep the
required changes at least a little bit more contained.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
add-interactive.c | 2 ++
add-patch.c | 2 ++
apply.c | 2 ++
archive-tar.c | 3 +++
archive-zip.c | 3 +++
archive.c | 2 ++
attr.c | 2 ++
bisect.c | 2 ++
blame.c | 2 ++
branch.c | 2 ++
builtin.h | 8 ++++++++
builtin/blame.c | 2 +-
builtin/log.c | 2 +-
bulk-checkin.c | 3 +++
bundle-uri.c | 2 ++
bundle.c | 2 ++
cache-tree.c | 2 ++
checkout.c | 2 ++
chunk-format.c | 2 ++
combine-diff.c | 2 ++
commit-graph.c | 2 ++
commit-reach.c | 2 ++
commit.c | 2 ++
common-main.c | 2 ++
compat/win32/trace2_win32_process_info.c | 2 ++
config.c | 3 +++
connected.c | 2 ++
convert.c | 2 ++
csum-file.c | 3 +++
delta-islands.c | 2 ++
diagnose.c | 2 ++
diff-lib.c | 3 +++
diff.c | 3 +++
diffcore-break.c | 3 +++
diffcore-rename.c | 3 +++
dir.c | 3 +++
entry.c | 2 ++
environment.c | 3 +++
fetch-pack.c | 2 ++
fmt-merge-msg.c | 2 ++
fsck.c | 2 ++
fsmonitor-ipc.c | 2 ++
git.c | 2 ++
hash-lookup.c | 2 ++
hash.h | 4 +++-
help.c | 2 ++
hex.c | 2 ++
http-backend.c | 2 ++
http-push.c | 2 ++
http-walker.c | 2 ++
http.c | 2 ++
list-objects-filter-options.c | 2 ++
list-objects-filter.c | 2 ++
list-objects.c | 2 ++
log-tree.c | 2 ++
loose.c | 2 ++
ls-refs.c | 2 ++
mailmap.c | 2 ++
match-trees.c | 2 ++
merge-blobs.c | 2 ++
merge-ort.c | 2 ++
merge-recursive.c | 3 +++
merge.c | 2 ++
midx-write.c | 2 ++
midx.c | 2 ++
negotiator/default.c | 2 ++
negotiator/skipping.c | 2 ++
notes-cache.c | 2 ++
notes-merge.c | 2 ++
notes-utils.c | 2 ++
notes.c | 2 ++
object-file-convert.c | 2 ++
object-file.c | 3 +++
object-name.c | 2 ++
object.c | 2 ++
oid-array.c | 2 ++
oss-fuzz/fuzz-commit-graph.c | 2 ++
pack-bitmap-write.c | 2 ++
pack-bitmap.c | 2 ++
pack-check.c | 2 ++
pack-revindex.c | 2 ++
pack-write.c | 2 ++
packfile.c | 2 ++
parse-options-cb.c | 2 ++
path.c | 3 +++
pathspec.c | 2 ++
pretty.c | 2 ++
progress.c | 2 ++
promisor-remote.c | 2 ++
range-diff.c | 2 ++
reachable.c | 2 ++
read-cache.c | 3 +++
rebase-interactive.c | 2 ++
ref-filter.c | 2 ++
reflog-walk.c | 2 ++
reflog.c | 2 ++
refs.c | 2 ++
refs/files-backend.c | 2 ++
refs/packed-backend.c | 2 ++
refs/reftable-backend.c | 2 ++
refspec.c | 2 ++
remote-curl.c | 2 ++
remote.c | 2 ++
repository.c | 8 ++++++++
repository.h | 2 ++
rerere.c | 2 ++
reset.c | 2 ++
resolve-undo.c | 2 ++
revision.c | 2 ++
run-command.c | 2 ++
scalar.c | 2 ++
send-pack.c | 2 ++
sequencer.c | 2 ++
serve.c | 2 ++
server-info.c | 2 ++
setup.c | 2 ++
shallow.c | 2 ++
split-index.c | 2 ++
streaming.c | 3 +++
submodule-config.c | 2 ++
submodule.c | 2 ++
t/helper/test-bitmap.c | 2 ++
t/helper/test-bloom.c | 2 ++
t/helper/test-cache-tree.c | 2 ++
t/helper/test-dump-cache-tree.c | 2 ++
t/helper/test-dump-fsmonitor.c | 2 ++
t/helper/test-dump-split-index.c | 2 ++
t/helper/test-dump-untracked-cache.c | 2 ++
t/helper/test-find-pack.c | 2 ++
t/helper/test-fsmonitor-client.c | 2 ++
t/helper/test-lazy-init-name-hash.c | 2 ++
t/helper/test-match-trees.c | 2 ++
t/helper/test-oidmap.c | 2 ++
t/helper/test-pack-mtimes.c | 2 ++
t/helper/test-reach.c | 2 ++
t/helper/test-read-cache.c | 2 ++
t/helper/test-read-graph.c | 2 ++
t/helper/test-read-midx.c | 2 ++
t/helper/test-ref-store.c | 2 ++
t/helper/test-repository.c | 2 ++
t/helper/test-revision-walking.c | 2 ++
t/helper/test-scrap-cache-tree.c | 2 ++
t/helper/test-submodule-config.c | 2 ++
t/helper/test-submodule-nested-repo-config.c | 2 ++
t/helper/test-submodule.c | 2 ++
t/helper/test-trace2.c | 2 ++
t/helper/test-write-cache.c | 2 ++
t/unit-tests/t-example-decorate.c | 2 ++
tag.c | 2 ++
tmp-objdir.c | 2 ++
transport-helper.c | 2 ++
transport.c | 2 ++
tree-walk.c | 2 ++
tree.c | 2 ++
unpack-trees.c | 2 ++
upload-pack.c | 2 ++
walker.c | 2 ++
worktree.c | 2 ++
wt-status.c | 2 ++
xdiff-interface.c | 2 ++
160 files changed, 347 insertions(+), 3 deletions(-)
diff --git a/add-interactive.c b/add-interactive.c
index a0961096cd..49042b3026 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "add-interactive.h"
#include "color.h"
diff --git a/add-patch.c b/add-patch.c
index 86181770f2..99e037c1e2 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "add-interactive.h"
#include "advice.h"
diff --git a/apply.c b/apply.c
index 528939abb6..ff939f908a 100644
--- a/apply.c
+++ b/apply.c
@@ -7,6 +7,8 @@
*
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
diff --git a/archive-tar.c b/archive-tar.c
index 8ae30125f8..e7b3489e1e 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2005, 2006 Rene Scharfe
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
diff --git a/archive-zip.c b/archive-zip.c
index fd1d3f816d..9f32730181 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2006 Rene Scharfe
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "archive.h"
diff --git a/archive.c b/archive.c
index 5287fcdd8e..7bd60d0632 100644
--- a/archive.c
+++ b/archive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/attr.c b/attr.c
index 300f994ba6..b5ed83c90e 100644
--- a/attr.c
+++ b/attr.c
@@ -6,6 +6,8 @@
* an insanely large number of attributes.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/bisect.c b/bisect.c
index 4ea703bec1..135f94ba09 100644
--- a/bisect.c
+++ b/bisect.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/blame.c b/blame.c
index a80f5e2e61..d403c46a35 100644
--- a/blame.c
+++ b/blame.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "refs.h"
#include "object-store-ll.h"
diff --git a/branch.c b/branch.c
index df5d24fec6..c887ea2151 100644
--- a/branch.c
+++ b/branch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/builtin.h b/builtin.h
index 7eda9b2486..14fa017160 100644
--- a/builtin.h
+++ b/builtin.h
@@ -1,6 +1,14 @@
#ifndef BUILTIN_H
#define BUILTIN_H
+/*
+ * TODO: Almost all of our builtins access `the_repository` by necessity
+ * because they do not get passed a pointer to it. We should adapt the function
+ * signature of those main functions to accept a `struct repository *` and then
+ * remove the macro here.
+ */
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
/*
diff --git a/builtin/blame.c b/builtin/blame.c
index e09ff0155a..de89fff3f8 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -5,7 +5,7 @@
* See COPYING for licensing conditions
*/
-#include "git-compat-util.h"
+#include "builtin.h"
#include "config.h"
#include "color.h"
#include "builtin.h"
diff --git a/builtin/log.c b/builtin/log.c
index ccbda8a005..00305bea51 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -4,7 +4,7 @@
* (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano
*/
-#include "git-compat-util.h"
+#include "builtin.h"
#include "abspath.h"
#include "config.h"
#include "environment.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index eb46b88637..da8673199b 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2011, Google Inc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bulk-checkin.h"
#include "environment.h"
diff --git a/bundle-uri.c b/bundle-uri.c
index 91b3319a5c..804fbcfbfa 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bundle-uri.h"
#include "bundle.h"
diff --git a/bundle.c b/bundle.c
index 95367c2d0a..82c285b905 100644
--- a/bundle.c
+++ b/bundle.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "lockfile.h"
#include "bundle.h"
diff --git a/cache-tree.c b/cache-tree.c
index 3290a1b8dd..50610c3f3c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/checkout.c b/checkout.c
index cfaea4bd10..0b1cf8b40b 100644
--- a/checkout.c
+++ b/checkout.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-name.h"
#include "remote.h"
diff --git a/chunk-format.c b/chunk-format.c
index cdc7f39b70..2dde24e6a3 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "chunk-format.h"
#include "csum-file.h"
diff --git a/combine-diff.c b/combine-diff.c
index 4960d904ac..829a44e416 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-store-ll.h"
#include "commit.h"
diff --git a/commit-graph.c b/commit-graph.c
index 98cbd53eea..e1070ee6e7 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "csum-file.h"
diff --git a/commit-reach.c b/commit-reach.c
index 384aee1ab3..dabc2972e4 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "commit-graph.h"
diff --git a/commit.c b/commit.c
index 1d08951007..4956803e11 100644
--- a/commit.c
+++ b/commit.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"
diff --git a/common-main.c b/common-main.c
index b86f40600f..8e68ac9e42 100644
--- a/common-main.c
+++ b/common-main.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "exec-cmd.h"
#include "gettext.h"
diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
index 3ef0936f6f..f147da706a 100644
--- a/compat/win32/trace2_win32_process_info.c
+++ b/compat/win32/trace2_win32_process_info.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../../git-compat-util.h"
#include "../../json-writer.h"
#include "../../repository.h"
diff --git a/config.c b/config.c
index abce05b774..7951029644 100644
--- a/config.c
+++ b/config.c
@@ -5,6 +5,9 @@
* Copyright (C) Johannes Schindelin, 2005
*
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
diff --git a/connected.c b/connected.c
index 8f89376dbc..87cc4b57a1 100644
--- a/connected.c
+++ b/connected.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/convert.c b/convert.c
index f2b9f01354..d8737fe0f2 100644
--- a/convert.c
+++ b/convert.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/csum-file.c b/csum-file.c
index f4be0804b7..8abbf01325 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -7,6 +7,9 @@
* files. Useful when you write a file that you want to be
* able to verify hasn't been messed with afterwards.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "progress.h"
#include "csum-file.h"
diff --git a/delta-islands.c b/delta-islands.c
index 89d51b72e3..ffe1ca2814 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object.h"
#include "commit.h"
diff --git a/diagnose.c b/diagnose.c
index 4d096c857f..cc2d535b60 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diagnose.h"
#include "compat/disk.h"
diff --git a/diff-lib.c b/diff-lib.c
index 3fb8d79fef..b0d0f711e8 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "diff.h"
diff --git a/diff.c b/diff.c
index 60d1f7be81..d4579d5f76 100644
--- a/diff.c
+++ b/diff.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
diff --git a/diffcore-break.c b/diffcore-break.c
index 49ba38aa7c..831b66b5c3 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diffcore.h"
#include "hash.h"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 5abb958651..ae504007cf 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -2,6 +2,9 @@
*
* Copyright (C) 2005 Junio C Hamano
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "diff.h"
#include "diffcore.h"
diff --git a/dir.c b/dir.c
index 5de421c29c..b7a6625ebd 100644
--- a/dir.c
+++ b/dir.c
@@ -5,6 +5,9 @@
* Copyright (C) Linus Torvalds, 2005-2006
* Junio Hamano, 2005-2006
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/entry.c b/entry.c
index b8c257f6f9..fe1f74d140 100644
--- a/entry.c
+++ b/entry.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-store-ll.h"
#include "dir.h"
diff --git a/environment.c b/environment.c
index 701d515135..5cea2c9f54 100644
--- a/environment.c
+++ b/environment.c
@@ -7,6 +7,9 @@
* even if you might want to know where the git directory etc
* are.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "branch.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index eba9e420ea..e6e14b3874 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 7d144b803a..b8bca89c0c 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/fsck.c b/fsck.c
index dd0a33028e..432996cbb6 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "date.h"
#include "dir.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 45471b5b74..f1b1631111 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "simple-ipc.h"
diff --git a/git.c b/git.c
index 683bb69194..e35af9b0e5 100644
--- a/git.c
+++ b/git.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "builtin.h"
#include "config.h"
#include "environment.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index 9aa6b82eb7..5f808caa51 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "hash-lookup.h"
diff --git a/hash.h b/hash.h
index 39a0164be3..cb85d26a2f 100644
--- a/hash.h
+++ b/hash.h
@@ -4,6 +4,8 @@
#include "hash-ll.h"
#include "repository.h"
-#define the_hash_algo the_repository->hash_algo
+#ifdef USE_THE_REPOSITORY_VARIABLE
+# define the_hash_algo the_repository->hash_algo
+#endif
#endif
diff --git a/help.c b/help.c
index 1d057aa607..10fdb1a03d 100644
--- a/help.c
+++ b/help.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "builtin.h"
diff --git a/hex.c b/hex.c
index bc9e86a978..5ca78a7744 100644
--- a/hex.c
+++ b/hex.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "hex.h"
diff --git a/http-backend.c b/http-backend.c
index 5b65287ac9..7c0b3be968 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/http-push.c b/http-push.c
index a97df4a1fb..7315a694aa 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/http-walker.c b/http-walker.c
index b7110b6f82..e417a7f51c 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "hex.h"
diff --git a/http.c b/http.c
index 67cc47d28f..6536816e81 100644
--- a/http.c
+++ b/http.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "git-curl-compat.h"
#include "hex.h"
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index c5f363ca6f..00611107d2 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 4346f8da45..49e2fa6f97 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "gettext.h"
diff --git a/list-objects.c b/list-objects.c
index 11ad8be411..985d008799 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"
diff --git a/log-tree.c b/log-tree.c
index 41416de4e3..223a4d9463 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit-reach.h"
#include "config.h"
diff --git a/loose.c b/loose.c
index f6faa6216a..a8bf772172 100644
--- a/loose.c
+++ b/loose.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
diff --git a/ls-refs.c b/ls-refs.c
index 398afe4ce3..2dd925b43d 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/mailmap.c b/mailmap.c
index b2efe29b3d..534a3eb4f0 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "string-list.h"
diff --git a/match-trees.c b/match-trees.c
index 50c42e2061..f17c74d483 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "match-trees.h"
diff --git a/merge-blobs.c b/merge-blobs.c
index 2f659fd014..0ad0390fea 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-ll.h"
#include "blob.h"
diff --git a/merge-ort.c b/merge-ort.c
index eaede6cead..691db9050e 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -14,6 +14,8 @@
* "cale", "peedy", or "ins" instead of "ort"?)
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-ort.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 8ff29ed09e..46ee364af7 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3,6 +3,9 @@
* Fredrik Kuivinen.
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "merge-recursive.h"
diff --git a/merge.c b/merge.c
index 752a937fa9..fe3efa4b24 100644
--- a/merge.c
+++ b/merge.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/midx-write.c b/midx-write.c
index 55a6b63bac..9a194e8aac 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/midx.c b/midx.c
index 1e75f1a7eb..3992b05465 100644
--- a/midx.c
+++ b/midx.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "dir.h"
diff --git a/negotiator/default.c b/negotiator/default.c
index 518b3c43b2..e3fa5c3324 100644
--- a/negotiator/default.c
+++ b/negotiator/default.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "default.h"
#include "../commit.h"
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
index b7e008c2fd..f109928ad0 100644
--- a/negotiator/skipping.c
+++ b/negotiator/skipping.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "skipping.h"
#include "../commit.h"
diff --git a/notes-cache.c b/notes-cache.c
index 038db01ca0..ecfdf6e43b 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-store-ll.h"
diff --git a/notes-merge.c b/notes-merge.c
index 801941c2d1..d95e683414 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "commit.h"
diff --git a/notes-utils.c b/notes-utils.c
index e33aa86c4b..bca71274be 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/notes.c b/notes.c
index afe2e2882e..b6a13d0980 100644
--- a/notes.c
+++ b/notes.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/object-file-convert.c b/object-file-convert.c
index f684038f7f..958f61f094 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "strbuf.h"
diff --git a/object-file.c b/object-file.c
index 72318c8dd4..a6555ed68c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -6,6 +6,9 @@
* This handles basic git object files - packing, unpacking,
* creation etc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/object-name.c b/object-name.c
index 523af6f64f..d7509514bc 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "object-name.h"
#include "advice.h"
diff --git a/object.c b/object.c
index 93b5d97fdb..0c0fcb76c0 100644
--- a/object.c
+++ b/object.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/oid-array.c b/oid-array.c
index 1f36651754..9cac974395 100644
--- a/oid-array.c
+++ b/oid-array.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "oid-array.h"
#include "hash-lookup.h"
diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c
index 75e668a057..951c9c082f 100644
--- a/oss-fuzz/fuzz-commit-graph.c
+++ b/oss-fuzz/fuzz-commit-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit-graph.h"
#include "repository.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 59d2e3a387..37a8ad0fb3 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 184d28f05c..7eafdce4ee 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "gettext.h"
diff --git a/pack-check.c b/pack-check.c
index e7b214fcbd..e883dae3f2 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index fc63aa76a2..de922b47d2 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
diff --git a/pack-write.c b/pack-write.c
index eef625fa5b..d07f03d0ab 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/packfile.c b/packfile.c
index ec7312cd20..813584646f 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/parse-options-cb.c b/parse-options-cb.c
index d99d688d3c..3fb7ce68ca 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "parse-options.h"
#include "branch.h"
diff --git a/path.c b/path.c
index adfb3d3eb7..19f7684f38 100644
--- a/path.c
+++ b/path.c
@@ -1,6 +1,9 @@
/*
* Utilities for paths and pathnames
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
diff --git a/pathspec.c b/pathspec.c
index 2133b9fe60..fe1f0f41af 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "parse.h"
diff --git a/pretty.c b/pretty.c
index 22a81506b7..2c14a88abc 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/progress.c b/progress.c
index c83cb60bf1..0d44c18edc 100644
--- a/progress.c
+++ b/progress.c
@@ -9,6 +9,8 @@
*/
#define GIT_TEST_PROGRESS_ONLY
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "pager.h"
#include "progress.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 2ca7c2ae48..317e1b127f 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/range-diff.c b/range-diff.c
index c45b6d849c..5f01605550 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/reachable.c b/reachable.c
index 1224b30008..46613a6bb6 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/read-cache.c b/read-cache.c
index 085b22faf3..48bf24f87c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,6 +3,9 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "bulk-checkin.h"
#include "config.h"
diff --git a/rebase-interactive.c b/rebase-interactive.c
index c343e16fcd..e93b385523 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "editor.h"
diff --git a/ref-filter.c b/ref-filter.c
index f7fb0c7e0e..8c5e673fc0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
diff --git a/reflog-walk.c b/reflog-walk.c
index 5f09552c5c..c7070b13b0 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "refs.h"
diff --git a/reflog.c b/reflog.c
index 3c80950186..5ca944529b 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "object-store-ll.h"
diff --git a/refs.c b/refs.c
index 6e7caefdcf..727ed6c1d6 100644
--- a/refs.c
+++ b/refs.c
@@ -2,6 +2,8 @@
* The backend-independent part of the reference module.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index b484b5880d..35931bc71e 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../copy.h"
#include "../environment.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 5ab1b21d10..a0666407cd 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../config.h"
#include "../dir.h"
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 57df2aba66..6e34eb2188 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../abspath.h"
#include "../chdir-notify.h"
diff --git a/refspec.c b/refspec.c
index d60932f4de..c2e3e24351 100644
--- a/refspec.c
+++ b/refspec.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/remote-curl.c b/remote-curl.c
index 6008d7e87c..1930f83cc7 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "git-curl-compat.h"
#include "config.h"
diff --git a/remote.c b/remote.c
index 1064171085..5fab7f0970 100644
--- a/remote.c
+++ b/remote.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/repository.c b/repository.c
index 95d10cc4a0..9825a30899 100644
--- a/repository.c
+++ b/repository.c
@@ -16,6 +16,14 @@
#include "promisor-remote.h"
#include "refs.h"
+/*
+ * We do not define `USE_THE_REPOSITORY_VARIABLE` in this file because we do
+ * not want to rely on functions that implicitly use `the_repository`. This
+ * means that the `extern` declaration of `the_repository` isn't visible here,
+ * which makes sparse unhappy. We thus declare it here.
+ */
+extern struct repository *the_repository;
+
/* The main repository */
static struct repository the_repo;
struct repository *the_repository = &the_repo;
diff --git a/repository.h b/repository.h
index a35cd77c35..29727edec6 100644
--- a/repository.h
+++ b/repository.h
@@ -197,7 +197,9 @@ struct repository {
unsigned different_commondir:1;
};
+#ifdef USE_THE_REPOSITORY_VARIABLE
extern struct repository *the_repository;
+#endif
/*
* Define a custom repository layout. Any field can be NULL, which
diff --git a/rerere.c b/rerere.c
index c7e1f8fd25..597256fa5b 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/reset.c b/reset.c
index 937f11c0f4..9550dea03d 100644
--- a/reset.c
+++ b/reset.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "cache-tree.h"
#include "gettext.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 4e6f0e4676..8c9911affb 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "hash.h"
diff --git a/revision.c b/revision.c
index 7ddf0f151a..40da255953 100644
--- a/revision.c
+++ b/revision.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/run-command.c b/run-command.c
index 31b20123d8..f5fde92b7c 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "run-command.h"
#include "environment.h"
diff --git a/scalar.c b/scalar.c
index 331b91dbdb..a1cb4b45b5 100644
--- a/scalar.c
+++ b/scalar.c
@@ -2,6 +2,8 @@
* The Scalar command-line interface.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "gettext.h"
diff --git a/send-pack.c b/send-pack.c
index 37f59d4f66..b42e6986df 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
diff --git a/sequencer.c b/sequencer.c
index 823691e379..8083fe20bf 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
diff --git a/serve.c b/serve.c
index aa651b73e9..33608ea4d5 100644
--- a/serve.c
+++ b/serve.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
diff --git a/server-info.c b/server-info.c
index 6feaa457c5..97e839c33d 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "environment.h"
diff --git a/setup.c b/setup.c
index 20f380825b..7e1169eb86 100644
--- a/setup.c
+++ b/setup.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "copy.h"
diff --git a/shallow.c b/shallow.c
index a0b181ba8a..31a6ca40fe 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "repository.h"
diff --git a/split-index.c b/split-index.c
index 058a8f448e..120c8190b1 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
diff --git a/streaming.c b/streaming.c
index 10adf625b2..38839511af 100644
--- a/streaming.c
+++ b/streaming.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2011, Google Inc.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "convert.h"
#include "environment.h"
diff --git a/submodule-config.c b/submodule-config.c
index ad43a282da..9b0bb0b9f4 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "dir.h"
#include "environment.h"
diff --git a/submodule.c b/submodule.c
index caf3aa5600..ab99a30253 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index af43ee1cb5..1f18d57007 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "git-compat-util.h"
#include "pack-bitmap.h"
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index 1281e66876..f7f9b62002 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "bloom.h"
#include "hex.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index dc89ecfd71..5cdef3ebef 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "gettext.h"
#include "hex.h"
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 02b0b46c3f..3f0c7d0ed0 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hash.h"
#include "hex.h"
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 4f215fea02..1b7f37a84f 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "read-cache-ll.h"
#include "repository.h"
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index f472691a3c..a6720faf9c 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index 9ff67c3967..4f010d5324 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "dir.h"
#include "hex.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index e8bd793e58..14b2b0c12c 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "object-name.h"
#include "object-store.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 8280984d08..02bfe92e8d 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -3,6 +3,8 @@
* a `git fsmonitor--daemon` daemon.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "parse-options.h"
#include "fsmonitor-ipc.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 5f33bb7b8f..40f5df4412 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "environment.h"
#include "name-hash.h"
diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c
index d0db5ff26f..e0e2048320 100644
--- a/t/helper/test-match-trees.c
+++ b/t/helper/test-match-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "match-trees.h"
diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c
index bd30244a54..c03cfa5ecf 100644
--- a/t/helper/test-oidmap.c
+++ b/t/helper/test-oidmap.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "object-name.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 67a964ef90..f8f9afbb5b 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 1ba226f1f9..5dd374379c 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit.h"
#include "commit-reach.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index e803c43ece..d285c656bd 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "config.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8c7a83f578..d9e980d04c 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 4acae41bb9..83effc2b5f 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "midx.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index ad24300170..637b8b294e 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "refs.h"
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 0c7c5aa4dd..c6a074df3d 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit-graph.h"
#include "commit.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index f346951bc2..071f5bd1e2 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -8,6 +8,8 @@
* published by the Free Software Foundation.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "commit.h"
#include "diff.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 737cbe475b..64fff6e9e3 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "lockfile.h"
#include "read-cache-ll.h"
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 4b809d9dca..cbe93f2f9e 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "config.h"
#include "hash.h"
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index ecd40ded99..6ca069ce63 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index 7197969a08..22e518d229 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "test-tool-utils.h"
#include "parse-options.h"
diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c
index 1adac29a57..cd955ec63e 100644
--- a/t/helper/test-trace2.c
+++ b/t/helper/test-trace2.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "strvec.h"
#include "run-command.h"
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index 7e3da380a9..b37dd2c5d6 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "lockfile.h"
#include "read-cache-ll.h"
diff --git a/t/unit-tests/t-example-decorate.c b/t/unit-tests/t-example-decorate.c
index 3c856a8cf2..a4a75db735 100644
--- a/t/unit-tests/t-example-decorate.c
+++ b/t/unit-tests/t-example-decorate.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-lib.h"
#include "object.h"
#include "decorate.h"
diff --git a/tag.c b/tag.c
index 52bbe50819..d24170e340 100644
--- a/tag.c
+++ b/tag.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "environment.h"
#include "tag.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 3509258be5..a8e4553f27 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tmp-objdir.h"
#include "abspath.h"
diff --git a/transport-helper.c b/transport-helper.c
index 9820947ab2..09b3560ffd 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "transport.h"
#include "quote.h"
diff --git a/transport.c b/transport.c
index 83ddea8fbc..b9c8827ed9 100644
--- a/transport.c
+++ b/transport.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
diff --git a/tree-walk.c b/tree-walk.c
index 535a3a2539..a033397965 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "tree-walk.h"
#include "dir.h"
diff --git a/tree.c b/tree.c
index 7973d3f9a8..ad86ad1ba9 100644
--- a/tree.c
+++ b/tree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "hex.h"
#include "tree.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 304ea2ed86..7dc884fafd 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "strvec.h"
diff --git a/upload-pack.c b/upload-pack.c
index b726f7a57d..0052c6a4dc 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/walker.c b/walker.c
index 946d86b04e..0fafdc97cf 100644
--- a/walker.c
+++ b/walker.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
diff --git a/worktree.c b/worktree.c
index 70844d023a..f3c4c8ec54 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
diff --git a/wt-status.c b/wt-status.c
index 5051f5e599..8815df419e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "wt-status.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 16ed8ac492..d5dc88661e 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "config.h"
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 10/20] refs: avoid include cycle with "repository.h"
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (8 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 11/20] hash-ll: merge with "hash.h" Patrick Steinhardt
` (11 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1797 bytes --]
There is an include cycle between "refs.h" and "repository.h" via
"commit.h", "object.h" and "hash.h". This has the effect that several
definitions of structs and enums will not be visible once we merge
"hash-ll.h" back into "hash.h" in the next commit.
The only reason that "repository.h" includes "refs.h" is the definition
of `enum ref_storage_format`. Move it into "repository.h" and have
"refs.h" include "repository.h" instead to fix the cycle.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
refs.h | 8 +-------
repository.h | 7 ++++++-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/refs.h b/refs.h
index 76d25df4de..a9716e5d25 100644
--- a/refs.h
+++ b/refs.h
@@ -2,21 +2,15 @@
#define REFS_H
#include "commit.h"
+#include "repository.h"
struct object_id;
struct ref_store;
-struct repository;
struct strbuf;
struct string_list;
struct string_list_item;
struct worktree;
-enum ref_storage_format {
- REF_STORAGE_FORMAT_UNKNOWN,
- REF_STORAGE_FORMAT_FILES,
- REF_STORAGE_FORMAT_REFTABLE,
-};
-
enum ref_storage_format ref_storage_format_by_name(const char *name);
const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_format);
diff --git a/repository.h b/repository.h
index 29727edec6..6ce6826c26 100644
--- a/repository.h
+++ b/repository.h
@@ -1,7 +1,6 @@
#ifndef REPOSITORY_H
#define REPOSITORY_H
-#include "refs.h"
#include "strmap.h"
struct config_set;
@@ -27,6 +26,12 @@ enum fetch_negotiation_setting {
FETCH_NEGOTIATION_NOOP,
};
+enum ref_storage_format {
+ REF_STORAGE_FORMAT_UNKNOWN,
+ REF_STORAGE_FORMAT_FILES,
+ REF_STORAGE_FORMAT_REFTABLE,
+};
+
struct repo_settings {
int initialized;
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 11/20] hash-ll: merge with "hash.h"
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (9 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 10/20] refs: avoid include cycle with "repository.h" Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 12/20] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
` (10 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 36788 bytes --]
The "hash-ll.h" header was introduced via d1cbe1e6d8 (hash-ll.h: split
out of hash.h to remove dependency on repository.h, 2023-04-22) to make
explicit the split between hash-related functions that rely on the
global `the_repository`, and those that don't. This split is no longer
necessary now that we we have removed the reliance on `the_repository`.
Merge "hash-ll.h" back into "hash.h". This causes some code units to not
include "repository.h" anymore, which requires us to add some forward
declarations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.h | 2 +-
bloom.c | 1 +
checkout.h | 2 +-
chunk-format.h | 2 +-
commit-graph.h | 2 +
compat/sha1-chunked.c | 2 +-
convert.h | 2 +-
csum-file.h | 2 +-
diff.h | 2 +-
diffcore.h | 2 +-
dir.h | 2 +-
hash-ll.h | 364 -------------------------------------
hash.h | 362 +++++++++++++++++++++++++++++++++++-
hex.h | 2 +-
loose.h | 2 +
merge-ort.h | 2 +-
object-file-convert.c | 2 +-
object.h | 2 +-
oidmap.h | 2 +-
oidtree.h | 2 +-
packfile.h | 2 +
protocol-caps.c | 2 +-
read-cache-ll.h | 2 +-
refs/ref-cache.h | 2 +-
reftable/dump.c | 2 +-
reftable/reftable-record.h | 2 +-
reftable/system.h | 2 +-
remote.h | 2 +-
reset.h | 2 +-
resolve-undo.h | 2 +-
serve.c | 2 +-
split-index.h | 2 +-
t/helper/test-hash-speed.c | 2 +-
t/helper/test-sha1.c | 2 +-
t/helper/test-sha256.c | 2 +-
t/unit-tests/lib-oid.h | 2 +-
tree-diff.c | 1 +
tree-walk.h | 2 +-
xdiff-interface.h | 2 +-
39 files changed, 400 insertions(+), 398 deletions(-)
delete mode 100644 hash-ll.h
diff --git a/apply.h b/apply.h
index 7cd38b1443..b9f18ce87d 100644
--- a/apply.h
+++ b/apply.h
@@ -1,7 +1,7 @@
#ifndef APPLY_H
#define APPLY_H
-#include "hash-ll.h"
+#include "hash.h"
#include "lockfile.h"
#include "string-list.h"
#include "strmap.h"
diff --git a/bloom.c b/bloom.c
index e529f7605c..bbf146fc30 100644
--- a/bloom.c
+++ b/bloom.c
@@ -6,6 +6,7 @@
#include "commit-graph.h"
#include "commit.h"
#include "commit-slab.h"
+#include "repository.h"
define_commit_slab(bloom_filter_slab, struct bloom_filter);
diff --git a/checkout.h b/checkout.h
index ba15a13fb3..55920e7aeb 100644
--- a/checkout.h
+++ b/checkout.h
@@ -1,7 +1,7 @@
#ifndef CHECKOUT_H
#define CHECKOUT_H
-#include "hash-ll.h"
+#include "hash.h"
/*
* Check if the branch name uniquely matches a branch name on a remote
diff --git a/chunk-format.h b/chunk-format.h
index 14b76180ef..212a0a6af1 100644
--- a/chunk-format.h
+++ b/chunk-format.h
@@ -1,7 +1,7 @@
#ifndef CHUNK_FORMAT_H
#define CHUNK_FORMAT_H
-#include "hash-ll.h"
+#include "hash.h"
struct hashfile;
struct chunkfile;
diff --git a/commit-graph.h b/commit-graph.h
index e519cb81cb..6781940195 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -122,6 +122,8 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
struct commit_graph *read_commit_graph_one(struct repository *r,
struct object_directory *odb);
+struct repo_settings;
+
/*
* Callers should initialize the repo_settings with prepare_repo_settings()
* prior to calling parse_commit_graph().
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index a4a6f930d7..0446f9983f 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "hash-ll.h"
+#include "hash.h"
int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
{
diff --git a/convert.h b/convert.h
index d925589444..0a6e4086b8 100644
--- a/convert.h
+++ b/convert.h
@@ -4,7 +4,7 @@
#ifndef CONVERT_H
#define CONVERT_H
-#include "hash-ll.h"
+#include "hash.h"
#include "string-list.h"
struct index_state;
diff --git a/csum-file.h b/csum-file.h
index bc5bec27ac..566e05cbd2 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -1,7 +1,7 @@
#ifndef CSUM_FILE_H
#define CSUM_FILE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "write-or-die.h"
struct progress;
diff --git a/diff.h b/diff.h
index 66bd8aeb29..9901c8ca8c 100644
--- a/diff.h
+++ b/diff.h
@@ -4,7 +4,7 @@
#ifndef DIFF_H
#define DIFF_H
-#include "hash-ll.h"
+#include "hash.h"
#include "pathspec.h"
#include "strbuf.h"
diff --git a/diffcore.h b/diffcore.h
index 5ffe4ec788..1701ed50b9 100644
--- a/diffcore.h
+++ b/diffcore.h
@@ -4,7 +4,7 @@
#ifndef DIFFCORE_H
#define DIFFCORE_H
-#include "hash-ll.h"
+#include "hash.h"
struct diff_options;
struct mem_pool;
diff --git a/dir.h b/dir.h
index 1398a53fb4..69a76d8bdd 100644
--- a/dir.h
+++ b/dir.h
@@ -1,7 +1,7 @@
#ifndef DIR_H
#define DIR_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "pathspec.h"
#include "statinfo.h"
diff --git a/hash-ll.h b/hash-ll.h
deleted file mode 100644
index 3161c778b9..0000000000
--- a/hash-ll.h
+++ /dev/null
@@ -1,364 +0,0 @@
-#ifndef HASH_LL_H
-#define HASH_LL_H
-
-#if defined(SHA1_APPLE)
-#include <CommonCrypto/CommonDigest.h>
-#elif defined(SHA1_OPENSSL)
-# include <openssl/sha.h>
-# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
-# define SHA1_NEEDS_CLONE_HELPER
-# include "sha1/openssl.h"
-# endif
-#elif defined(SHA1_DC)
-#include "sha1dc_git.h"
-#else /* SHA1_BLK */
-#include "block-sha1/sha1.h"
-#endif
-
-#if defined(SHA256_NETTLE)
-#include "sha256/nettle.h"
-#elif defined(SHA256_GCRYPT)
-#define SHA256_NEEDS_CLONE_HELPER
-#include "sha256/gcrypt.h"
-#elif defined(SHA256_OPENSSL)
-# include <openssl/sha.h>
-# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
-# define SHA256_NEEDS_CLONE_HELPER
-# include "sha256/openssl.h"
-# endif
-#else
-#include "sha256/block/sha256.h"
-#endif
-
-#ifndef platform_SHA_CTX
-/*
- * platform's underlying implementation of SHA-1; could be OpenSSL,
- * blk_SHA, Apple CommonCrypto, etc... Note that the relevant
- * SHA-1 header may have already defined platform_SHA_CTX for our
- * own implementations like block-sha1, so we list
- * the default for OpenSSL compatible SHA-1 implementations here.
- */
-#define platform_SHA_CTX SHA_CTX
-#define platform_SHA1_Init SHA1_Init
-#define platform_SHA1_Update SHA1_Update
-#define platform_SHA1_Final SHA1_Final
-#endif
-
-#define git_SHA_CTX platform_SHA_CTX
-#define git_SHA1_Init platform_SHA1_Init
-#define git_SHA1_Update platform_SHA1_Update
-#define git_SHA1_Final platform_SHA1_Final
-
-#ifdef platform_SHA1_Clone
-#define git_SHA1_Clone platform_SHA1_Clone
-#endif
-
-#ifndef platform_SHA256_CTX
-#define platform_SHA256_CTX SHA256_CTX
-#define platform_SHA256_Init SHA256_Init
-#define platform_SHA256_Update SHA256_Update
-#define platform_SHA256_Final SHA256_Final
-#endif
-
-#define git_SHA256_CTX platform_SHA256_CTX
-#define git_SHA256_Init platform_SHA256_Init
-#define git_SHA256_Update platform_SHA256_Update
-#define git_SHA256_Final platform_SHA256_Final
-
-#ifdef platform_SHA256_Clone
-#define git_SHA256_Clone platform_SHA256_Clone
-#endif
-
-#ifdef SHA1_MAX_BLOCK_SIZE
-#include "compat/sha1-chunked.h"
-#undef git_SHA1_Update
-#define git_SHA1_Update git_SHA1_Update_Chunked
-#endif
-
-#ifndef SHA1_NEEDS_CLONE_HELPER
-static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
-{
- memcpy(dst, src, sizeof(*dst));
-}
-#endif
-
-#ifndef SHA256_NEEDS_CLONE_HELPER
-static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
-{
- memcpy(dst, src, sizeof(*dst));
-}
-#endif
-
-/*
- * Note that these constants are suitable for indexing the hash_algos array and
- * comparing against each other, but are otherwise arbitrary, so they should not
- * be exposed to the user or serialized to disk. To know whether a
- * git_hash_algo struct points to some usable hash function, test the format_id
- * field for being non-zero. Use the name field for user-visible situations and
- * the format_id field for fixed-length fields on disk.
- */
-/* An unknown hash function. */
-#define GIT_HASH_UNKNOWN 0
-/* SHA-1 */
-#define GIT_HASH_SHA1 1
-/* SHA-256 */
-#define GIT_HASH_SHA256 2
-/* Number of algorithms supported (including unknown). */
-#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
-
-/* "sha1", big-endian */
-#define GIT_SHA1_FORMAT_ID 0x73686131
-
-/* The length in bytes and in hex digits of an object name (SHA-1 value). */
-#define GIT_SHA1_RAWSZ 20
-#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
-/* The block size of SHA-1. */
-#define GIT_SHA1_BLKSZ 64
-
-/* "s256", big-endian */
-#define GIT_SHA256_FORMAT_ID 0x73323536
-
-/* The length in bytes and in hex digits of an object name (SHA-256 value). */
-#define GIT_SHA256_RAWSZ 32
-#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
-/* The block size of SHA-256. */
-#define GIT_SHA256_BLKSZ 64
-
-/* The length in byte and in hex digits of the largest possible hash value. */
-#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
-#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
-/* The largest possible block size for any supported hash. */
-#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
-
-struct object_id {
- unsigned char hash[GIT_MAX_RAWSZ];
- int algo; /* XXX requires 4-byte alignment */
-};
-
-#define GET_OID_QUIETLY 01
-#define GET_OID_COMMIT 02
-#define GET_OID_COMMITTISH 04
-#define GET_OID_TREE 010
-#define GET_OID_TREEISH 020
-#define GET_OID_BLOB 040
-#define GET_OID_FOLLOW_SYMLINKS 0100
-#define GET_OID_RECORD_PATH 0200
-#define GET_OID_ONLY_TO_DIE 04000
-#define GET_OID_REQUIRE_PATH 010000
-#define GET_OID_HASH_ANY 020000
-
-#define GET_OID_DISAMBIGUATORS \
- (GET_OID_COMMIT | GET_OID_COMMITTISH | \
- GET_OID_TREE | GET_OID_TREEISH | \
- GET_OID_BLOB)
-
-enum get_oid_result {
- FOUND = 0,
- MISSING_OBJECT = -1, /* The requested object is missing */
- SHORT_NAME_AMBIGUOUS = -2,
- /* The following only apply when symlinks are followed */
- DANGLING_SYMLINK = -4, /*
- * The initial symlink is there, but
- * (transitively) points to a missing
- * in-tree file
- */
- SYMLINK_LOOP = -5,
- NOT_DIR = -6, /*
- * Somewhere along the symlink chain, a path is
- * requested which contains a file as a
- * non-final element.
- */
-};
-
-/* A suitably aligned type for stack allocations of hash contexts. */
-union git_hash_ctx {
- git_SHA_CTX sha1;
- git_SHA256_CTX sha256;
-};
-typedef union git_hash_ctx git_hash_ctx;
-
-typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
-typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src);
-typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
-typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
-typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx);
-
-struct git_hash_algo {
- /*
- * The name of the algorithm, as appears in the config file and in
- * messages.
- */
- const char *name;
-
- /* A four-byte version identifier, used in pack indices. */
- uint32_t format_id;
-
- /* The length of the hash in binary. */
- size_t rawsz;
-
- /* The length of the hash in hex characters. */
- size_t hexsz;
-
- /* The block size of the hash. */
- size_t blksz;
-
- /* The hash initialization function. */
- git_hash_init_fn init_fn;
-
- /* The hash context cloning function. */
- git_hash_clone_fn clone_fn;
-
- /* The hash update function. */
- git_hash_update_fn update_fn;
-
- /* The hash finalization function. */
- git_hash_final_fn final_fn;
-
- /* The hash finalization function for object IDs. */
- git_hash_final_oid_fn final_oid_fn;
-
- /* The OID of the empty tree. */
- const struct object_id *empty_tree;
-
- /* The OID of the empty blob. */
- const struct object_id *empty_blob;
-
- /* The all-zeros OID. */
- const struct object_id *null_oid;
-};
-extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
-
-/*
- * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
- * the name doesn't match a known algorithm.
- */
-int hash_algo_by_name(const char *name);
-/* Identical, except based on the format ID. */
-int hash_algo_by_id(uint32_t format_id);
-/* Identical, except based on the length. */
-int hash_algo_by_length(int len);
-/* Identical, except for a pointer to struct git_hash_algo. */
-static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
-{
- return p - hash_algos;
-}
-
-const struct object_id *null_oid(void);
-
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
-{
- /*
- * Teach the compiler that there are only two possibilities of hash size
- * here, so that it can optimize for this case as much as possible.
- */
- if (algop->rawsz == GIT_MAX_RAWSZ)
- return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
- return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
-}
-
-static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
-{
- /*
- * We write this here instead of deferring to hashcmp so that the
- * compiler can properly inline it and avoid calling memcmp.
- */
- if (algop->rawsz == GIT_MAX_RAWSZ)
- return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
- return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
-}
-
-static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
- const struct git_hash_algo *algop)
-{
- memcpy(sha_dst, sha_src, algop->rawsz);
-}
-
-static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
-{
- memset(hash, 0, algop->rawsz);
-}
-
-static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
-{
- return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
-}
-
-static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
-{
- return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
-}
-
-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;
-}
-
-static inline void oidread(struct object_id *oid, const unsigned char *hash,
- const struct git_hash_algo *algop)
-{
- memcpy(oid->hash, hash, algop->rawsz);
- if (algop->rawsz < GIT_MAX_RAWSZ)
- memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline void oidclr(struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- memset(oid->hash, 0, GIT_MAX_RAWSZ);
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline struct object_id *oiddup(const struct object_id *src)
-{
- struct object_id *dst = xmalloc(sizeof(struct object_id));
- oidcpy(dst, src);
- return dst;
-}
-
-static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
-{
- oid->algo = hash_algo_by_ptr(algop);
-}
-
-/*
- * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
- * for use in hash tables. Cryptographic hashes are supposed to have
- * uniform distribution, so in contrast to `memhash()`, this just copies
- * the first `sizeof(int)` bytes without shuffling any bits. Note that
- * the results will be different on big-endian and little-endian
- * platforms, so they should not be stored or transferred over the net.
- */
-static inline unsigned int oidhash(const struct object_id *oid)
-{
- /*
- * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
- * platforms that don't support unaligned reads.
- */
- unsigned int hash;
- memcpy(&hash, oid->hash, sizeof(hash));
- return hash;
-}
-
-static inline int is_null_oid(const struct object_id *oid)
-{
- static const unsigned char null_hash[GIT_MAX_RAWSZ];
- return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
-}
-
-const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
-
-static inline int is_empty_blob_oid(const struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- return oideq(oid, algop->empty_blob);
-}
-
-static inline int is_empty_tree_oid(const struct object_id *oid,
- const struct git_hash_algo *algop)
-{
- return oideq(oid, algop->empty_tree);
-}
-
-#endif
diff --git a/hash.h b/hash.h
index cb85d26a2f..72ffbc862e 100644
--- a/hash.h
+++ b/hash.h
@@ -1,11 +1,369 @@
#ifndef HASH_H
#define HASH_H
-#include "hash-ll.h"
-#include "repository.h"
+#if defined(SHA1_APPLE)
+#include <CommonCrypto/CommonDigest.h>
+#elif defined(SHA1_OPENSSL)
+# include <openssl/sha.h>
+# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
+# define SHA1_NEEDS_CLONE_HELPER
+# include "sha1/openssl.h"
+# endif
+#elif defined(SHA1_DC)
+#include "sha1dc_git.h"
+#else /* SHA1_BLK */
+#include "block-sha1/sha1.h"
+#endif
+
+#if defined(SHA256_NETTLE)
+#include "sha256/nettle.h"
+#elif defined(SHA256_GCRYPT)
+#define SHA256_NEEDS_CLONE_HELPER
+#include "sha256/gcrypt.h"
+#elif defined(SHA256_OPENSSL)
+# include <openssl/sha.h>
+# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
+# define SHA256_NEEDS_CLONE_HELPER
+# include "sha256/openssl.h"
+# endif
+#else
+#include "sha256/block/sha256.h"
+#endif
+
+#ifndef platform_SHA_CTX
+/*
+ * platform's underlying implementation of SHA-1; could be OpenSSL,
+ * blk_SHA, Apple CommonCrypto, etc... Note that the relevant
+ * SHA-1 header may have already defined platform_SHA_CTX for our
+ * own implementations like block-sha1, so we list
+ * the default for OpenSSL compatible SHA-1 implementations here.
+ */
+#define platform_SHA_CTX SHA_CTX
+#define platform_SHA1_Init SHA1_Init
+#define platform_SHA1_Update SHA1_Update
+#define platform_SHA1_Final SHA1_Final
+#endif
+
+#define git_SHA_CTX platform_SHA_CTX
+#define git_SHA1_Init platform_SHA1_Init
+#define git_SHA1_Update platform_SHA1_Update
+#define git_SHA1_Final platform_SHA1_Final
+
+#ifdef platform_SHA1_Clone
+#define git_SHA1_Clone platform_SHA1_Clone
+#endif
+
+#ifndef platform_SHA256_CTX
+#define platform_SHA256_CTX SHA256_CTX
+#define platform_SHA256_Init SHA256_Init
+#define platform_SHA256_Update SHA256_Update
+#define platform_SHA256_Final SHA256_Final
+#endif
+
+#define git_SHA256_CTX platform_SHA256_CTX
+#define git_SHA256_Init platform_SHA256_Init
+#define git_SHA256_Update platform_SHA256_Update
+#define git_SHA256_Final platform_SHA256_Final
+
+#ifdef platform_SHA256_Clone
+#define git_SHA256_Clone platform_SHA256_Clone
+#endif
+
+#ifdef SHA1_MAX_BLOCK_SIZE
+#include "compat/sha1-chunked.h"
+#undef git_SHA1_Update
+#define git_SHA1_Update git_SHA1_Update_Chunked
+#endif
+
+#ifndef SHA1_NEEDS_CLONE_HELPER
+static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
+{
+ memcpy(dst, src, sizeof(*dst));
+}
+#endif
+
+#ifndef SHA256_NEEDS_CLONE_HELPER
+static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
+{
+ memcpy(dst, src, sizeof(*dst));
+}
+#endif
+
+/*
+ * Note that these constants are suitable for indexing the hash_algos array and
+ * comparing against each other, but are otherwise arbitrary, so they should not
+ * be exposed to the user or serialized to disk. To know whether a
+ * git_hash_algo struct points to some usable hash function, test the format_id
+ * field for being non-zero. Use the name field for user-visible situations and
+ * the format_id field for fixed-length fields on disk.
+ */
+/* An unknown hash function. */
+#define GIT_HASH_UNKNOWN 0
+/* SHA-1 */
+#define GIT_HASH_SHA1 1
+/* SHA-256 */
+#define GIT_HASH_SHA256 2
+/* Number of algorithms supported (including unknown). */
+#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
+
+/* "sha1", big-endian */
+#define GIT_SHA1_FORMAT_ID 0x73686131
+
+/* The length in bytes and in hex digits of an object name (SHA-1 value). */
+#define GIT_SHA1_RAWSZ 20
+#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
+/* The block size of SHA-1. */
+#define GIT_SHA1_BLKSZ 64
+
+/* "s256", big-endian */
+#define GIT_SHA256_FORMAT_ID 0x73323536
+
+/* The length in bytes and in hex digits of an object name (SHA-256 value). */
+#define GIT_SHA256_RAWSZ 32
+#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
+/* The block size of SHA-256. */
+#define GIT_SHA256_BLKSZ 64
+
+/* The length in byte and in hex digits of the largest possible hash value. */
+#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
+#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
+/* The largest possible block size for any supported hash. */
+#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
+
+struct object_id {
+ unsigned char hash[GIT_MAX_RAWSZ];
+ int algo; /* XXX requires 4-byte alignment */
+};
+
+#define GET_OID_QUIETLY 01
+#define GET_OID_COMMIT 02
+#define GET_OID_COMMITTISH 04
+#define GET_OID_TREE 010
+#define GET_OID_TREEISH 020
+#define GET_OID_BLOB 040
+#define GET_OID_FOLLOW_SYMLINKS 0100
+#define GET_OID_RECORD_PATH 0200
+#define GET_OID_ONLY_TO_DIE 04000
+#define GET_OID_REQUIRE_PATH 010000
+#define GET_OID_HASH_ANY 020000
+
+#define GET_OID_DISAMBIGUATORS \
+ (GET_OID_COMMIT | GET_OID_COMMITTISH | \
+ GET_OID_TREE | GET_OID_TREEISH | \
+ GET_OID_BLOB)
+
+enum get_oid_result {
+ FOUND = 0,
+ MISSING_OBJECT = -1, /* The requested object is missing */
+ SHORT_NAME_AMBIGUOUS = -2,
+ /* The following only apply when symlinks are followed */
+ DANGLING_SYMLINK = -4, /*
+ * The initial symlink is there, but
+ * (transitively) points to a missing
+ * in-tree file
+ */
+ SYMLINK_LOOP = -5,
+ NOT_DIR = -6, /*
+ * Somewhere along the symlink chain, a path is
+ * requested which contains a file as a
+ * non-final element.
+ */
+};
#ifdef USE_THE_REPOSITORY_VARIABLE
+# include "repository.h"
# define the_hash_algo the_repository->hash_algo
#endif
+/* A suitably aligned type for stack allocations of hash contexts. */
+union git_hash_ctx {
+ git_SHA_CTX sha1;
+ git_SHA256_CTX sha256;
+};
+typedef union git_hash_ctx git_hash_ctx;
+
+typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
+typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src);
+typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
+typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
+typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx);
+
+struct git_hash_algo {
+ /*
+ * The name of the algorithm, as appears in the config file and in
+ * messages.
+ */
+ const char *name;
+
+ /* A four-byte version identifier, used in pack indices. */
+ uint32_t format_id;
+
+ /* The length of the hash in binary. */
+ size_t rawsz;
+
+ /* The length of the hash in hex characters. */
+ size_t hexsz;
+
+ /* The block size of the hash. */
+ size_t blksz;
+
+ /* The hash initialization function. */
+ git_hash_init_fn init_fn;
+
+ /* The hash context cloning function. */
+ git_hash_clone_fn clone_fn;
+
+ /* The hash update function. */
+ git_hash_update_fn update_fn;
+
+ /* The hash finalization function. */
+ git_hash_final_fn final_fn;
+
+ /* The hash finalization function for object IDs. */
+ git_hash_final_oid_fn final_oid_fn;
+
+ /* The OID of the empty tree. */
+ const struct object_id *empty_tree;
+
+ /* The OID of the empty blob. */
+ const struct object_id *empty_blob;
+
+ /* The all-zeros OID. */
+ const struct object_id *null_oid;
+};
+extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
+
+/*
+ * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
+ * the name doesn't match a known algorithm.
+ */
+int hash_algo_by_name(const char *name);
+/* Identical, except based on the format ID. */
+int hash_algo_by_id(uint32_t format_id);
+/* Identical, except based on the length. */
+int hash_algo_by_length(int len);
+/* Identical, except for a pointer to struct git_hash_algo. */
+static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
+{
+ return p - hash_algos;
+}
+
+const struct object_id *null_oid(void);
+
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+{
+ /*
+ * Teach the compiler that there are only two possibilities of hash size
+ * here, so that it can optimize for this case as much as possible.
+ */
+ if (algop->rawsz == GIT_MAX_RAWSZ)
+ return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
+ return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+}
+
+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
+{
+ /*
+ * We write this here instead of deferring to hashcmp so that the
+ * compiler can properly inline it and avoid calling memcmp.
+ */
+ if (algop->rawsz == GIT_MAX_RAWSZ)
+ return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
+ return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+}
+
+static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
+ const struct git_hash_algo *algop)
+{
+ memcpy(sha_dst, sha_src, algop->rawsz);
+}
+
+static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
+{
+ memset(hash, 0, algop->rawsz);
+}
+
+static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
+{
+ return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
+}
+
+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;
+}
+
+static inline void oidread(struct object_id *oid, const unsigned char *hash,
+ const struct git_hash_algo *algop)
+{
+ memcpy(oid->hash, hash, algop->rawsz);
+ if (algop->rawsz < GIT_MAX_RAWSZ)
+ memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline void oidclr(struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ memset(oid->hash, 0, GIT_MAX_RAWSZ);
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline struct object_id *oiddup(const struct object_id *src)
+{
+ struct object_id *dst = xmalloc(sizeof(struct object_id));
+ oidcpy(dst, src);
+ return dst;
+}
+
+static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
+{
+ oid->algo = hash_algo_by_ptr(algop);
+}
+
+/*
+ * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
+ * for use in hash tables. Cryptographic hashes are supposed to have
+ * uniform distribution, so in contrast to `memhash()`, this just copies
+ * the first `sizeof(int)` bytes without shuffling any bits. Note that
+ * the results will be different on big-endian and little-endian
+ * platforms, so they should not be stored or transferred over the net.
+ */
+static inline unsigned int oidhash(const struct object_id *oid)
+{
+ /*
+ * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
+ * platforms that don't support unaligned reads.
+ */
+ unsigned int hash;
+ memcpy(&hash, oid->hash, sizeof(hash));
+ return hash;
+}
+
+static inline int is_null_oid(const struct object_id *oid)
+{
+ static const unsigned char null_hash[GIT_MAX_RAWSZ];
+ return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
+}
+
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
+
+static inline int is_empty_blob_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_blob);
+}
+
+static inline int is_empty_tree_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_tree);
+}
+
#endif
diff --git a/hex.h b/hex.h
index e0b83f776f..9809667f33 100644
--- a/hex.h
+++ b/hex.h
@@ -1,7 +1,7 @@
#ifndef HEX_H
#define HEX_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hex-ll.h"
/*
diff --git a/loose.h b/loose.h
index 2c2957072c..28512306e5 100644
--- a/loose.h
+++ b/loose.h
@@ -3,6 +3,8 @@
#include "khash.h"
+struct repository;
+
struct loose_object_map {
kh_oid_map_t *to_compat;
kh_oid_map_t *to_storage;
diff --git a/merge-ort.h b/merge-ort.h
index ce56ec1a78..a994c9a5fc 100644
--- a/merge-ort.h
+++ b/merge-ort.h
@@ -2,7 +2,7 @@
#define MERGE_ORT_H
#include "merge-recursive.h"
-#include "hash-ll.h"
+#include "hash.h"
struct commit;
struct tree;
diff --git a/object-file-convert.c b/object-file-convert.c
index 958f61f094..3887d6d57b 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -5,7 +5,7 @@
#include "strbuf.h"
#include "hex.h"
#include "repository.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "hash.h"
#include "object.h"
#include "loose.h"
diff --git a/object.h b/object.h
index 73b4ec3904..9fa42d51d9 100644
--- a/object.h
+++ b/object.h
@@ -1,7 +1,7 @@
#ifndef OBJECT_H
#define OBJECT_H
-#include "hash-ll.h"
+#include "hash.h"
struct buffer_slab;
struct repository;
diff --git a/oidmap.h b/oidmap.h
index 05c673eb7c..fad412827a 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -1,7 +1,7 @@
#ifndef OIDMAP_H
#define OIDMAP_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
/*
diff --git a/oidtree.h b/oidtree.h
index 55c83513fd..77898f510a 100644
--- a/oidtree.h
+++ b/oidtree.h
@@ -2,7 +2,7 @@
#define OIDTREE_H
#include "cbtree.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "mem-pool.h"
struct oidtree {
diff --git a/packfile.h b/packfile.h
index 28c8fd3e39..eb18ec15db 100644
--- a/packfile.h
+++ b/packfile.h
@@ -101,6 +101,8 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
+struct raw_object_store;
+
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
diff --git a/protocol-caps.c b/protocol-caps.c
index 75f4cbb0a7..fe8d1d5c63 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -3,7 +3,7 @@
#include "gettext.h"
#include "hex.h"
#include "pkt-line.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "hex.h"
#include "object.h"
#include "object-store-ll.h"
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 09414afd04..e0e39607ef 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -1,7 +1,7 @@
#ifndef READ_CACHE_LL_H
#define READ_CACHE_LL_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "statinfo.h"
diff --git a/refs/ref-cache.h b/refs/ref-cache.h
index 95c76e27c8..31ebe24f6c 100644
--- a/refs/ref-cache.h
+++ b/refs/ref-cache.h
@@ -1,7 +1,7 @@
#ifndef REFS_REF_CACHE_H
#define REFS_REF_CACHE_H
-#include "hash-ll.h"
+#include "hash.h"
struct ref_dir;
struct ref_store;
diff --git a/reftable/dump.c b/reftable/dump.c
index 41abbb8ecf..dd65d9e8bb 100644
--- a/reftable/dump.c
+++ b/reftable/dump.c
@@ -7,7 +7,7 @@ license that can be found in the LICENSE file or at
*/
#include "git-compat-util.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "reftable-blocksource.h"
#include "reftable-error.h"
diff --git a/reftable/reftable-record.h b/reftable/reftable-record.h
index 2a2943cd13..ff486eb1f7 100644
--- a/reftable/reftable-record.h
+++ b/reftable/reftable-record.h
@@ -9,7 +9,7 @@ license that can be found in the LICENSE file or at
#ifndef REFTABLE_RECORD_H
#define REFTABLE_RECORD_H
-#include "hash-ll.h"
+#include "hash.h"
#include <stdint.h>
/*
diff --git a/reftable/system.h b/reftable/system.h
index 5d8b6dede5..d0cabd5d17 100644
--- a/reftable/system.h
+++ b/reftable/system.h
@@ -15,7 +15,7 @@ license that can be found in the LICENSE file or at
#include "lockfile.h"
#include "strbuf.h"
#include "tempfile.h"
-#include "hash-ll.h" /* hash ID, sizes.*/
+#include "hash.h" /* hash ID, sizes.*/
#include "dir.h" /* remove_dir_recursively, for tests.*/
int hash_size(uint32_t id);
diff --git a/remote.h b/remote.h
index e8c6655e42..7d04e1be1b 100644
--- a/remote.h
+++ b/remote.h
@@ -1,7 +1,7 @@
#ifndef REMOTE_H
#define REMOTE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "hashmap.h"
#include "refspec.h"
diff --git a/reset.h b/reset.h
index 10708d8ddc..a28f81829d 100644
--- a/reset.h
+++ b/reset.h
@@ -1,7 +1,7 @@
#ifndef RESET_H
#define RESET_H
-#include "hash-ll.h"
+#include "hash.h"
#include "repository.h"
#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
diff --git a/resolve-undo.h b/resolve-undo.h
index f3f8462751..89a3227262 100644
--- a/resolve-undo.h
+++ b/resolve-undo.h
@@ -6,7 +6,7 @@ struct index_state;
struct pathspec;
struct string_list;
-#include "hash-ll.h"
+#include "hash.h"
struct resolve_undo_info {
unsigned int mode[3];
diff --git a/serve.c b/serve.c
index 33608ea4d5..884cd84ca8 100644
--- a/serve.c
+++ b/serve.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
-#include "hash-ll.h"
+#include "hash.h"
#include "pkt-line.h"
#include "version.h"
#include "ls-refs.h"
diff --git a/split-index.h b/split-index.h
index 15a29cd08c..1a153f47ba 100644
--- a/split-index.h
+++ b/split-index.h
@@ -1,7 +1,7 @@
#ifndef SPLIT_INDEX_H
#define SPLIT_INDEX_H
-#include "hash-ll.h"
+#include "hash.h"
struct index_state;
struct strbuf;
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index b235da594f..7de822af51 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
#define NUM_SECONDS 3
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index dcb7f6c003..e60d000c03 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
int cmd__sha1(int ac, const char **av)
{
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 08cf149001..2fb20438f3 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "hash-ll.h"
+#include "hash.h"
int cmd__sha256(int ac, const char **av)
{
diff --git a/t/unit-tests/lib-oid.h b/t/unit-tests/lib-oid.h
index bfde639190..8d2acca768 100644
--- a/t/unit-tests/lib-oid.h
+++ b/t/unit-tests/lib-oid.h
@@ -1,7 +1,7 @@
#ifndef LIB_OID_H
#define LIB_OID_H
-#include "hash-ll.h"
+#include "hash.h"
/*
* Convert arbitrary hex string to object_id.
diff --git a/tree-diff.c b/tree-diff.c
index 46107772d1..9252481df3 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -8,6 +8,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "environment.h"
+#include "repository.h"
/*
* Some mode bits are also used internally for computations.
diff --git a/tree-walk.h b/tree-walk.h
index 0b1067fbc5..aaea689f9a 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -1,7 +1,7 @@
#ifndef TREE_WALK_H
#define TREE_WALK_H
-#include "hash-ll.h"
+#include "hash.h"
struct index_state;
struct repository;
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 38537169b7..1ed430b622 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -1,7 +1,7 @@
#ifndef XDIFF_INTERFACE_H
#define XDIFF_INTERFACE_H
-#include "hash-ll.h"
+#include "hash.h"
#include "xdiff/xdiff.h"
/*
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 12/20] http-fetch: don't crash when parsing packfile without a repo
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (10 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 11/20] hash-ll: merge with "hash.h" Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 13/20] oidset: pass hash algorithm when parsing file Patrick Steinhardt
` (9 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 3160 bytes --]
The git-http-fetch(1) command accepts a `--packfile=` option, which
allows the user to specify that it shall fetch a specific packfile,
only. The parameter here is the hash of the packfile, which is specific
to the object hash used by the repository. This requirement is implicit
though via our use of `parse_oid_hex()`, which internally uses
`the_repository`.
The git-http-fetch(1) command allows for there to be no repository
though, which only exists such that we can show usage via the "-h"
option. In that case though, starting with c8aed5e8da (repository: stop
setting SHA1 as the default object hash, 2024-05-07), `the_repository`
does not have its object hash initialized anymore and thus we would
crash when trying to parse the object ID outside of a repository.
Fix this issue by dying immediately when we see a "--packfile="
parameter when outside a Git repository. This is not a functional
regression as we would die later on with the same error anyway.
Add a test to detect the segfault. We use the "nongit" function to do
so, which we need to allow-list in `test_must_fail ()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
http-fetch.c | 8 +++++++-
t/t5550-http-fetch-dumb.sh | 6 ++++++
t/test-lib-functions.sh | 5 +++++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/http-fetch.c b/http-fetch.c
index bec94988bb..d460bb1837 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
@@ -127,8 +129,12 @@ int cmd_main(int argc, const char **argv)
} else if (skip_prefix(argv[arg], "--packfile=", &p)) {
const char *end;
+ if (nongit)
+ die(_("not a git repository"));
+
packfile = 1;
- if (parse_oid_hex(p, &packfile_hash, &end) || *end)
+ if (parse_oid_hex_algop(p, &packfile_hash, &end,
+ the_repository->hash_algo) || *end)
die(_("argument to --packfile must be a valid hash (got '%s')"), p);
} else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
strvec_push(&index_pack_args, p);
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index 5f16cbc58d..ea8e48f627 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -25,6 +25,12 @@ test_expect_success 'setup repository' '
git commit -m two
'
+test_expect_success 'packfile without repository does not crash' '
+ echo "fatal: not a git repository" >expect &&
+ test_must_fail nongit git http-fetch --packfile=abc 2>err &&
+ test_cmp expect err
+'
+
setup_post_update_server_info_hook () {
test_hook --setup -C "$1" post-update <<-\EOF &&
exec git update-server-info
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 862d80c974..34bc7d7da4 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1096,6 +1096,11 @@ test_must_fail_acceptable () {
done
fi
+ if test "$1" = "nongit"
+ then
+ shift
+ fi
+
case "$1" in
git|__git*|scalar|test-tool|test_terminal)
return 0
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 13/20] oidset: pass hash algorithm when parsing file
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (11 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 12/20] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 14/20] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
` (8 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 3242 bytes --]
The `oidset_parse_file_carefully()` function implicitly depends on
`the_repository` when parsing object IDs. Fix this by having callers
pass in the hash algorithm to use.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/blame.c | 1 +
fsck.c | 3 ++-
oidset.c | 8 +++++---
oidset.h | 4 +++-
4 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index de89fff3f8..18f1a3cea0 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -852,6 +852,7 @@ static void build_ignorelist(struct blame_scoreboard *sb,
oidset_clear(&sb->ignore_list);
else
oidset_parse_file_carefully(&sb->ignore_list, i->string,
+ the_repository->hash_algo,
peel_to_commit_oid, sb);
}
for_each_string_list_item(i, ignore_rev_list) {
diff --git a/fsck.c b/fsck.c
index 432996cbb6..304f4a17ec 100644
--- a/fsck.c
+++ b/fsck.c
@@ -205,7 +205,8 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
if (!strcmp(buf, "skiplist")) {
if (equal == len)
die("skiplist requires a path");
- oidset_parse_file(&options->skiplist, buf + equal + 1);
+ oidset_parse_file(&options->skiplist, buf + equal + 1,
+ the_repository->hash_algo);
buf += len + 1;
continue;
}
diff --git a/oidset.c b/oidset.c
index 91d1385910..8d36aef8dc 100644
--- a/oidset.c
+++ b/oidset.c
@@ -48,12 +48,14 @@ void oidset_clear(struct oidset *set)
oidset_init(set, 0);
}
-void oidset_parse_file(struct oidset *set, const char *path)
+void oidset_parse_file(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop)
{
- oidset_parse_file_carefully(set, path, NULL, NULL);
+ oidset_parse_file_carefully(set, path, algop, NULL, NULL);
}
void oidset_parse_file_carefully(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop,
oidset_parse_tweak_fn fn, void *cbdata)
{
FILE *fp;
@@ -79,7 +81,7 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,
if (!sb.len)
continue;
- if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
+ if (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\0')
die("invalid object name: %s", sb.buf);
if (fn && fn(&oid, cbdata))
continue;
diff --git a/oidset.h b/oidset.h
index 262f4256d6..0106b6f278 100644
--- a/oidset.h
+++ b/oidset.h
@@ -80,7 +80,8 @@ void oidset_clear(struct oidset *set);
* are allowed. Leading whitespace and empty or white-space only lines are
* ignored.
*/
-void oidset_parse_file(struct oidset *set, const char *path);
+void oidset_parse_file(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop);
/*
* Similar to the above, but with a callback which can (1) return non-zero to
@@ -89,6 +90,7 @@ void oidset_parse_file(struct oidset *set, const char *path);
*/
typedef int (*oidset_parse_tweak_fn)(struct object_id *, void *);
void oidset_parse_file_carefully(struct oidset *set, const char *path,
+ const struct git_hash_algo *algop,
oidset_parse_tweak_fn fn, void *cbdata);
struct oidset_iter {
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 14/20] protocol-caps: use hash algorithm from passed-in repository
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (12 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 13/20] oidset: pass hash algorithm when parsing file Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 15/20] replace-object: " Patrick Steinhardt
` (7 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]
In `send_info()`, we pass in a repository but then use `get_oid_hex()`
to parse passed-in object IDs, which implicitly uses `the_repository`.
Fix this by using the hash algorithm from the passed-in repository
instead.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
protocol-caps.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/protocol-caps.c b/protocol-caps.c
index fe8d1d5c63..855f279c2f 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -7,6 +7,7 @@
#include "hex.h"
#include "object.h"
#include "object-store-ll.h"
+#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
@@ -52,7 +53,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
struct object_id oid;
unsigned long object_size;
- if (get_oid_hex(oid_str, &oid) < 0) {
+ if (get_oid_hex_algop(oid_str, &oid, r->hash_algo) < 0) {
packet_writer_error(
writer,
"object-info: protocol error, expected to get oid, not '%s'",
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 15/20] replace-object: use hash algorithm from passed-in repository
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (13 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 14/20] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos Patrick Steinhardt
` (6 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 939 bytes --]
In `register_replace_ref()`, we pass in a repository but then use
`get_oid_hex()` to parse passed-in object IDs, which implicitly uses
`the_repository`. Fix this by using the hash algorithm from the
passed-in repository instead.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
replace-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/replace-object.c b/replace-object.c
index 73f5acbcd9..59252d565e 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -20,7 +20,7 @@ static int register_replace_ref(const char *refname,
const char *hash = slash ? slash + 1 : refname;
struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj));
- if (get_oid_hex(hash, &repl_obj->original.oid)) {
+ if (get_oid_hex_algop(hash, &repl_obj->original.oid, r->hash_algo)) {
free(repl_obj);
warning(_("bad replace ref name: %s"), refname);
return 0;
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (14 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 15/20] replace-object: " Patrick Steinhardt
@ 2024-06-14 6:50 ` Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 17/20] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
` (5 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:50 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 2024 bytes --]
The IPC socket used by the fsmonitor on Darwin is usually contained in
the Git repository itself. When the repository is hosted on a networked
filesystem though, we instead create the socket path in the user's home
directory or the socket directory. In that case, we derive the path by
hashing the repository path.
But while we always use SHA1 to hash the repository path, we then end up
using `hash_to_hex()` to append the computed hash to the socket path.
This is wrong because `hash_to_hex()` uses the hash algorithm configured
in `the_repository`, which may not be SHA1. The consequence is that we
may append uninitialized bytes to the path when operating in a SHA256
repository.
Fix this bug by using `hash_to_hex_algop()` with SHA1.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
compat/fsmonitor/fsm-ipc-darwin.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 6f3a95410c..52f4f29720 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -17,7 +17,7 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
git_SHA_CTX sha1ctx;
char *sock_dir = NULL;
struct strbuf ipc_file = STRBUF_INIT;
- unsigned char hash[GIT_MAX_RAWSZ];
+ unsigned char hash[GIT_SHA1_RAWSZ];
if (!r)
BUG("No repository passed into fsmonitor_ipc__get_path");
@@ -41,9 +41,10 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
/* Create the socket file in either socketDir or $HOME */
if (sock_dir && *sock_dir) {
strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s",
- sock_dir, hash_to_hex(hash));
+ sock_dir, hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
} else {
- strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash));
+ strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s",
+ hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
}
free(sock_dir);
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 17/20] t/helper: use correct object hash in partial-clone helper
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (15 preceding siblings ...)
2024-06-14 6:50 ` [PATCH v3 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos Patrick Steinhardt
@ 2024-06-14 6:51 ` Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 18/20] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
` (4 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:51 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]
The `object_info()` function of the partial-clone helper is responsible
for checking the object ID of a repository other than `the_repository`.
We use `parse_oid_hex()` in this function though, which means that we
still depend on `the_repository->hash_algo`.
Fix this by using the object hash of the function-local repository.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-partial-clone.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 910a128614..0ead529167 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -21,7 +21,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
if (repo_init(&r, gitdir, NULL))
die("could not init repo");
- if (parse_oid_hex(oid_hex, &oid, &p))
+ if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
if (oid_object_info_extended(&r, &oid, &oi, 0))
die("could not obtain object info");
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 18/20] t/helper: fix segfault in "oid-array" command without repository
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (16 preceding siblings ...)
2024-06-14 6:51 ` [PATCH v3 17/20] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
@ 2024-06-14 6:51 ` Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 19/20] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
` (3 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:51 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 2118 bytes --]
The "oid-array" test helper can supposedly work without a Git
repository, but will in fact crash because `the_repository->hash_algo`
is not initialized. This is because `oid_pos()`, which is used by
`oid_array_lookup()`, depends on `the_hash_algo->rawsz`.
Ideally, we'd adapt `oid_pos()` to not depend on `the_hash_algo`
anymore. That is a bigger untertaking though, so instead we fall back to
SHA1 when there is no repository.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-oid-array.c | 4 ++++
t/t0064-oid-array.sh | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c
index aafe398ef0..076b849cbf 100644
--- a/t/helper/test-oid-array.c
+++ b/t/helper/test-oid-array.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "hex.h"
#include "oid-array.h"
@@ -17,6 +19,8 @@ int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
int nongit_ok;
setup_git_directory_gently(&nongit_ok);
+ if (nongit_ok)
+ repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
while (strbuf_getline(&line, stdin) != EOF) {
const char *arg;
diff --git a/t/t0064-oid-array.sh b/t/t0064-oid-array.sh
index 88c89e8f48..de74b692d0 100755
--- a/t/t0064-oid-array.sh
+++ b/t/t0064-oid-array.sh
@@ -15,6 +15,24 @@ echoid () {
done
}
+test_expect_success 'without repository' '
+ cat >expect <<-EOF &&
+ 4444444444444444444444444444444444444444
+ 5555555555555555555555555555555555555555
+ 8888888888888888888888888888888888888888
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ EOF
+ cat >input <<-EOF &&
+ append 4444444444444444444444444444444444444444
+ append 5555555555555555555555555555555555555555
+ append 8888888888888888888888888888888888888888
+ append aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ for_each_unique
+ EOF
+ nongit test-tool oid-array <input >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'ordered enumeration' '
echoid "" 44 55 88 aa >expect &&
{
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 19/20] t/helper: remove dependency on `the_repository` in "proc-receive"
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (17 preceding siblings ...)
2024-06-14 6:51 ` [PATCH v3 18/20] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
@ 2024-06-14 6:51 ` Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
` (2 subsequent siblings)
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:51 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 2061 bytes --]
The "proc-receive" test helper implicitly relies on `the_repository` via
`parse_oid_hex()`. This isn't necessary though, and in fact the whole
command does not depend on `the_repository` at all.
Stop setting up `the_repository` and use `parse_oid_hex_any()` to parse
object IDs.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
t/helper/test-proc-receive.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index f30022d222..29361c7aab 100644
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -3,8 +3,8 @@
#include "hex.h"
#include "parse-options.h"
#include "pkt-line.h"
-#include "setup.h"
#include "sigchain.h"
+#include "string-list.h"
static const char *proc_receive_usage[] = {
"test-tool proc-receive [<options>]",
@@ -92,9 +92,9 @@ static void proc_receive_read_commands(struct packet_reader *reader,
if (die_read_commands)
die("die with the --die-read-commands option");
- if (parse_oid_hex(reader->line, &old_oid, &p) ||
+ if (parse_oid_hex_any(reader->line, &old_oid, &p) == GIT_HASH_UNKNOWN ||
*p++ != ' ' ||
- parse_oid_hex(p, &new_oid, &p) ||
+ parse_oid_hex_any(p, &new_oid, &p) == GIT_HASH_UNKNOWN ||
*p++ != ' ')
die("protocol error: expected 'old new ref', got '%s'",
reader->line);
@@ -128,7 +128,6 @@ static void proc_receive_read_push_options(struct packet_reader *reader,
int cmd__proc_receive(int argc, const char **argv)
{
- int nongit_ok = 0;
struct packet_reader reader;
struct command *commands = NULL;
struct string_list push_options = STRING_LIST_INIT_DUP;
@@ -154,8 +153,6 @@ int cmd__proc_receive(int argc, const char **argv)
OPT_END()
};
- setup_git_directory_gently(&nongit_ok);
-
argc = parse_options(argc, argv, "test-tools", options, proc_receive_usage, 0);
if (argc > 0)
usage_msg_opt("Too many arguments.", proc_receive_usage, options);
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* [PATCH v3 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (18 preceding siblings ...)
2024-06-14 6:51 ` [PATCH v3 19/20] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
@ 2024-06-14 6:51 ` Patrick Steinhardt
2024-06-18 9:56 ` [PATCH v3 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Phillip Wood
2024-06-18 20:22 ` Karthik Nayak
21 siblings, 0 replies; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-14 6:51 UTC (permalink / raw)
To: git; +Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 2848 bytes --]
Guard declarations of functions that implicitly use `the_repository`
with `USE_THE_REPOSITORY_VARIABLE` such that callers don't accidentally
rely on that global variable.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
hex.h | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/hex.h b/hex.h
index 9809667f33..e9ccb54065 100644
--- a/hex.h
+++ b/hex.h
@@ -13,10 +13,6 @@
* input, so it is safe to pass this function an arbitrary
* null-terminated string.
*/
-int get_hash_hex(const char *hex, unsigned char *hash);
-int get_oid_hex(const char *hex, struct object_id *oid);
-
-/* Like get_oid_hex, but for an arbitrary hash algorithm. */
int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop);
/*
@@ -35,7 +31,6 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_h
char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *);
char *oid_to_hex_r(char *out, const struct object_id *oid);
char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */
-char *hash_to_hex(const unsigned char *hash); /* same static buffer */
char *oid_to_hex(const struct object_id *oid); /* same static buffer */
/*
@@ -45,13 +40,9 @@ char *oid_to_hex(const struct object_id *oid); /* same static buffer */
* other invalid character. end is only updated on success; otherwise, it is
* unmodified.
*/
-int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
-
-/* Like parse_oid_hex, but for an arbitrary hash algorithm. */
int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end,
const struct git_hash_algo *algo);
-
/*
* These functions work like get_oid_hex and parse_oid_hex, but they will parse
* a hex value for any algorithm. The algorithm is detected based on the length
@@ -61,4 +52,19 @@ int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end
int get_oid_hex_any(const char *hex, struct object_id *oid);
int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end);
-#endif
+#ifdef USE_THE_REPOSITORY_VARIABLE
+
+/* Like get_oid_hex_algop, but for `the_hash_algo`. */
+int get_hash_hex(const char *hex, unsigned char *hash);
+int get_oid_hex(const char *hex, struct object_id *oid);
+
+/* Like parse_oid_hex_algop, but uses `the_hash_algo`. */
+int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
+
+/*
+ * Same as `hash_to_hex_algop()`, but uses `the_hash_algo`.
+ */
+char *hash_to_hex(const unsigned char *hash);
+
+#endif /* USE_THE_REPOSITORY_VARIABLE */
+#endif /* HEX_H */
--
2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 94+ messages in thread
* Re: [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-14 5:28 ` Patrick Steinhardt
@ 2024-06-14 15:54 ` Junio C Hamano
0 siblings, 0 replies; 94+ messages in thread
From: Junio C Hamano @ 2024-06-14 15:54 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Ramsay Jones, git, Ghanshyam Thakkar, brian m. carlson
Patrick Steinhardt <ps@pks.im> writes:
>> > But that does beg the question - why is repository.c not
>> > defining the USE_THE_REPOSITORY_VARIABLE?
>>
>> I think the goal of the series is to eventually get to the point
>> where nobody uses the_repository variable. If repository.c, which
>> consists of a set of service routines that work on a repository
>> instance, defined it, showing willingness to implicitly rely on
>> the_repository through things like get_oid_hex() (which would rely
>> on the_repository->hash_algo), that would go the opposite direction,
>> so everything, other than the definition of the_repository variable
>> itself that allows other files that still do rely implicitly on the
>> variable to link with it, in repository.c would actively want to
>> refuse to use services only available to those who define USE_THE_*
>> macro.
>
> Exactly, that's why it doesn't declare `USE_THE_REPOSITORY_VARIABLE`.
> The macro doesn't only guard use of `the_repository`, but does also
> guards other functions that implicitly relies on it, and we do not want
> to use these in "repository.c". So even though the added `extern`
> declaration is somewhat ugly, I think it is preferable over defining the
> macro.
Slightly off-topic, but in retrospect, the approach of marking "this
file is done" taken by the very initial version of the "no more
implicit access to the_index" series may have been easier to grok
easier to grok for reviewers casually looking at it from the
sideline, than marking "this file still needs work". When we
gradually deprecated the convenience API that implicitly access
the_index instance, we marked with NO_THE_INDEX_COMPATIBILITY_MACROS
the files that no longer require it (in other words, we are done
with the file wrt the transition). We later flipped the polarity
and gave USE_THE_INDEX_COMPATIBILITY_MACROS to those that are not
marked with NO_THE_INDEX_COMPATIBILITY_MACROS as we progressed and
the source files that still used the convenience API has become
minorities.
Anyway, I think now people understood what this series aims to
achieve and how it does so, hopefully.
Thanks.
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v3 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash
2024-06-14 6:50 ` [PATCH v3 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
@ 2024-06-17 9:18 ` Karthik Nayak
0 siblings, 0 replies; 94+ messages in thread
From: Karthik Nayak @ 2024-06-17 9:18 UTC (permalink / raw)
To: Patrick Steinhardt, git
Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 6286 bytes --]
Patrick Steinhardt <ps@pks.im> writes:
> With the preceding commit, the hash array of object IDs is now fully
> zero-padded even when the hash algorithm's output is smaller than the
> array length. With that, we can now adapt both `oidcmp()` and `oideq()`
> to unconditionally memcmp(3P) the whole array instead of depending on
> the hash size.
>
> While it may feel inefficient to compare unused bytes for e.g. SHA-1, in
> practice the compiler should now be able to produce code that is better
> optimized both because we have no branch anymore, but also because the
> size to compare is now known at compile time. Goldbolt spits out the
> following assembly on an x86_64 platform with GCC 14.1 for the old and
> new implementations of `oidcmp()`:
>
> oidcmp_old:
> movsx rax, DWORD PTR [rdi+32]
> test eax, eax
> jne .L2
> mov rax, QWORD PTR the_repository[rip]
> cmp QWORD PTR [rax+16], 32
> je .L6
> .L4:
> mov edx, 20
> jmp memcmp
> .L2:
> lea rdx, [rax+rax*2]
> lea rax, [rax+rdx*4]
> lea rax, hash_algos[0+rax*8]
> cmp QWORD PTR [rax+16], 32
> jne .L4
> .L6:
> mov edx, 32
> jmp memcmp
>
> oidcmp_new:
> mov edx, 32
> jmp memcmp
>
> The new implementation gets ridi of all the branches and effectively
s/ridi/rid
> only ends setting up `edx` for `memcmp()` and then calling it.
>
> And for `oideq()`:
>
> oideq_old:
> movsx rcx, DWORD PTR [rdi+32]
> mov rax, rdi
> mov rdx, rsi
> test ecx, ecx
> jne .L2
> mov rcx, QWORD PTR the_repository[rip]
> cmp QWORD PTR [rcx+16], 32
> mov rcx, QWORD PTR [rax]
> je .L12
> .L4:
> mov rsi, QWORD PTR [rax+8]
> xor rcx, QWORD PTR [rdx]
> xor rsi, QWORD PTR [rdx+8]
> or rcx, rsi
> je .L13
> .L8:
> mov eax, 1
> test eax, eax
> sete al
> movzx eax, al
> ret
> .L2:
> lea rsi, [rcx+rcx*2]
> lea rcx, [rcx+rsi*4]
> lea rcx, hash_algos[0+rcx*8]
> cmp QWORD PTR [rcx+16], 32
> mov rcx, QWORD PTR [rax]
> jne .L4
> .L12:
> mov rsi, QWORD PTR [rax+8]
> xor rcx, QWORD PTR [rdx]
> xor rsi, QWORD PTR [rdx+8]
> or rcx, rsi
> jne .L8
> mov rcx, QWORD PTR [rax+16]
> mov rax, QWORD PTR [rax+24]
> xor rcx, QWORD PTR [rdx+16]
> xor rax, QWORD PTR [rdx+24]
> or rcx, rax
> jne .L8
> xor eax, eax
> .L14:
> test eax, eax
> sete al
> movzx eax, al
> ret
> .L13:
> mov edi, DWORD PTR [rdx+16]
> cmp DWORD PTR [rax+16], edi
> jne .L8
> xor eax, eax
> jmp .L14
>
> oideq_new:
> mov rax, QWORD PTR [rdi]
> mov rdx, QWORD PTR [rdi+8]
> xor rax, QWORD PTR [rsi]
> xor rdx, QWORD PTR [rsi+8]
> or rax, rdx
> je .L5
> .L2:
> mov eax, 1
> xor eax, 1
> ret
> .L5:
> mov rax, QWORD PTR [rdi+16]
> mov rdx, QWORD PTR [rdi+24]
> xor rax, QWORD PTR [rsi+16]
> xor rdx, QWORD PTR [rsi+24]
> or rax, rdx
> jne .L2
> xor eax, eax
> xor eax, 1
> ret
>
> Interestingly, the compiler decides to split the comparisons into two so
> that it first compares the lower half of the object ID for equality and
> then the upper half. If the first check shows a difference, then we
> wouldn't even end up comparing the second half.
>
> In both cases, the new generated code is significantly shorter and has
> way less branches. While I didn't benchmark the change, I'd be surprised
> if the new code was slower.
>
This was nice to read, thanks for adding the ASM here.
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> hash-ll.h | 10 ++++++++++
> hash.h | 20 --------------------
> 2 files changed, 10 insertions(+), 20 deletions(-)
>
> diff --git a/hash-ll.h b/hash-ll.h
> index b72f84f4ae..b04fe12aef 100644
> --- a/hash-ll.h
> +++ b/hash-ll.h
> @@ -278,6 +278,16 @@ static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algo
> memset(hash, 0, algop->rawsz);
> }
>
> +static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
> +{
> + return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
> +}
> +
> +static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
> +{
> + return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
> +}
> +
> static inline void oidcpy(struct object_id *dst, const struct object_id *src)
> {
> memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
> diff --git a/hash.h b/hash.h
> index e43e3d8b5a..ddc2e5ca47 100644
> --- a/hash.h
> +++ b/hash.h
> @@ -6,26 +6,6 @@
>
> #define the_hash_algo the_repository->hash_algo
>
> -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(oid1->hash, oid2->hash, algop);
> -}
> -
> -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(oid1->hash, oid2->hash, algop);
> -}
> -
> static inline int is_null_oid(const struct object_id *oid)
> {
> return oideq(oid, null_oid());
> --
> 2.45.2.457.g8d94cfb545.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-14 6:50 ` [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
@ 2024-06-17 9:30 ` Karthik Nayak
2024-06-18 5:16 ` Patrick Steinhardt
0 siblings, 1 reply; 94+ messages in thread
From: Karthik Nayak @ 2024-06-17 9:30 UTC (permalink / raw)
To: Patrick Steinhardt, git
Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1996 bytes --]
Patrick Steinhardt <ps@pks.im> writes:
> Use of the `the_repository` variable is deprecated nowadays, and we
> slowly but steadily convert the codebase to not use it anymore. Instead,
> callers should be passing down the repository to work on via parameters.
>
> It is hard though to prove that a given code unit does not use this
> variable anymore. The most trivial case, merely demonstrating that there
> is no direct use of `the_repository`, is already a bit of a pain during
> code reviews as the reviewer needs to manually verify claims made by the
> patch author. The bigger problem though is that we have many interfaces
> that implicitly rely on `the_repository`.
>
> Introduce a new `USE_THE_REPOSITORY_VARIABLE` macro that allows code
> units to opt into usage of `the_repository`. The intent of this macro is
> to demonstrate that a certain code unit does not use this variable
> anymore, and to keep it from new dependencies on it in future changes,
> be it explicit or implicit
>
> For now, the macro only guards `the_repository` itself as well as
> `the_hash_algo`. There are many more known interfaces where we have an
> implicit dependency on `the_repository`, but those are not guarded at
> the current point in time. Over time though, we should start to add
> guards as required (or even better, just remove them).
>
> Define the macro as required in our code units. As expected, most of our
> code still relies on the global variable. Nearly all of our builtins
> rely on the variable as there is no way yet to pass `the_repository` to
> their entry point. For now, declare the macro in "biultin.h" to keep the
s/biultin.h/builtin.h
[snip]
> diff --git a/hash.h b/hash.h
> index 39a0164be3..cb85d26a2f 100644
> --- a/hash.h
> +++ b/hash.h
> @@ -4,6 +4,8 @@
> #include "hash-ll.h"
> #include "repository.h"
>
> -#define the_hash_algo the_repository->hash_algo
> +#ifdef USE_THE_REPOSITORY_VARIABLE
> +# define the_hash_algo the_repository->hash_algo
s/# define/#define/
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-17 9:30 ` Karthik Nayak
@ 2024-06-18 5:16 ` Patrick Steinhardt
2024-06-18 9:25 ` Karthik Nayak
0 siblings, 1 reply; 94+ messages in thread
From: Patrick Steinhardt @ 2024-06-18 5:16 UTC (permalink / raw)
To: Karthik Nayak
Cc: git, Ghanshyam Thakkar, brian m. carlson, Phillip Wood,
Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 673 bytes --]
On Mon, Jun 17, 2024 at 05:30:31AM -0400, Karthik Nayak wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/hash.h b/hash.h
> > index 39a0164be3..cb85d26a2f 100644
> > --- a/hash.h
> > +++ b/hash.h
> > @@ -4,6 +4,8 @@
> > #include "hash-ll.h"
> > #include "repository.h"
> >
> > -#define the_hash_algo the_repository->hash_algo
> > +#ifdef USE_THE_REPOSITORY_VARIABLE
> > +# define the_hash_algo the_repository->hash_algo
>
> s/# define/#define/
This is in fact intentional. We aren't strictly following this in our
codebase, but when nesting preprocessor macros into ifdefs then we often
indent the inner macros with spaces.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-18 5:16 ` Patrick Steinhardt
@ 2024-06-18 9:25 ` Karthik Nayak
2024-06-18 15:58 ` Junio C Hamano
0 siblings, 1 reply; 94+ messages in thread
From: Karthik Nayak @ 2024-06-18 9:25 UTC (permalink / raw)
To: Patrick Steinhardt
Cc: git, Ghanshyam Thakkar, brian m. carlson, Phillip Wood,
Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 758 bytes --]
Patrick Steinhardt <ps@pks.im> writes:
> On Mon, Jun 17, 2024 at 05:30:31AM -0400, Karthik Nayak wrote:
>> Patrick Steinhardt <ps@pks.im> writes:
>> > diff --git a/hash.h b/hash.h
>> > index 39a0164be3..cb85d26a2f 100644
>> > --- a/hash.h
>> > +++ b/hash.h
>> > @@ -4,6 +4,8 @@
>> > #include "hash-ll.h"
>> > #include "repository.h"
>> >
>> > -#define the_hash_algo the_repository->hash_algo
>> > +#ifdef USE_THE_REPOSITORY_VARIABLE
>> > +# define the_hash_algo the_repository->hash_algo
>>
>> s/# define/#define/
>
> This is in fact intentional. We aren't strictly following this in our
> codebase, but when nesting preprocessor macros into ifdefs then we often
> indent the inner macros with spaces.
>
> Patrick
That's something I didn't know. Thanks.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v3 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (19 preceding siblings ...)
2024-06-14 6:51 ` [PATCH v3 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
@ 2024-06-18 9:56 ` Phillip Wood
2024-06-18 20:22 ` Karthik Nayak
21 siblings, 0 replies; 94+ messages in thread
From: Phillip Wood @ 2024-06-18 9:56 UTC (permalink / raw)
To: Patrick Steinhardt, git
Cc: Ghanshyam Thakkar, brian m. carlson, Junio C Hamano
Hi Patrick
On 14/06/2024 07:49, Patrick Steinhardt wrote:
> Changes compared to v2:
>
> - Note in a commit message that we aim to have a faithful conversion
> when introducing a `struct git_hash_algo` parameter to functions. So
> even in case the calling context has a `struct git_hash_algo`
> available via a local repository, we still use `the_repository` such
> that there cannot be a change in behaviour here. Fixing those sites
> will be left for a future patch series such that we can avoid any
> kind of regressions caused by this comparatively large refactoring.
> I also adapted some conversions to fully follow through with this
> intent.
Thanks for clarifying that in the commit message of Patch 2.
Best Wishes
Phillip
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-18 9:25 ` Karthik Nayak
@ 2024-06-18 15:58 ` Junio C Hamano
2024-06-18 16:56 ` Junio C Hamano
2024-06-18 20:20 ` Karthik Nayak
0 siblings, 2 replies; 94+ messages in thread
From: Junio C Hamano @ 2024-06-18 15:58 UTC (permalink / raw)
To: Karthik Nayak
Cc: Patrick Steinhardt, git, Ghanshyam Thakkar, brian m. carlson,
Phillip Wood
Karthik Nayak <karthik.188@gmail.com> writes:
>>> s/# define/#define/
>>
>> This is in fact intentional. We aren't strictly following this in our
>> codebase, but when nesting preprocessor macros into ifdefs then we often
>> indent the inner macros with spaces.
>>
>> Patrick
>
> That's something I didn't know. Thanks.
Unlike borrowed sources in compat/, in our codebase, such
indentation is minority. IOW "often indent" -> "sometimes indent".
A quick look at an early part of git-compat-util.h would show that
even within a single file we are not consistent at all.
#if __STDC_VERSION__ - 0 < 199901L
#error "Required C99 support is in a test phase. Please see git-compat-util.h for more details."
#endif
#ifdef USE_MSVC_CRTDBG
#include <stdlib.h>
#include <crtdbg.h>
#endif
#define _FILE_OFFSET_BITS 64
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
# define GIT_GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
#define GIT_GNUC_PREREQ(maj, min) 0
#endif
#ifndef FLEX_ARRAY
#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
#elif defined(__GNUC__)
# if (__GNUC__ >= 3)
# define FLEX_ARRAY /* empty */
# else
# define FLEX_ARRAY 0 /* older GNU extension */
# endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define FLEX_ARRAY /* empty */
#endif
...
We may want to eventually fix this, but we need to decide what the
desirable layout is. I am not sure if the indented version is
easier to read and maintain, but one thing that is sure is that a
mixed mess is harder than either. In the above excerpt, you cannot
tell if I quoted everything related to FLEX_ARRAY (in other words,
if "#ifndef FLEX_ARRAY" is already closed in the excerpt) without
carefully looking.
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-18 15:58 ` Junio C Hamano
@ 2024-06-18 16:56 ` Junio C Hamano
2024-06-18 20:20 ` Karthik Nayak
1 sibling, 0 replies; 94+ messages in thread
From: Junio C Hamano @ 2024-06-18 16:56 UTC (permalink / raw)
To: Karthik Nayak
Cc: Patrick Steinhardt, git, Ghanshyam Thakkar, brian m. carlson,
Phillip Wood
Junio C Hamano <gitster@pobox.com> writes:
> We may want to eventually fix this, but we need to decide what the
> desirable layout is. I am not sure if the indented version is
> easier to read and maintain, but one thing that is sure is that a
> mixed mess is harder than either. In the above excerpt, you cannot
> tell if I quoted everything related to FLEX_ARRAY (in other words,
> if "#ifndef FLEX_ARRAY" is already closed in the excerpt) without
> carefully looking.
Here is how a patch to reindent (which is full of patch noise and
not enough value by itself) looks like.
----- >8 ---------- >8 ---------- >8 ---------- >8 -----
Subject: [PATCH] git-compat-util.h: reindent CPP directives
Karthik noticed that Patrick used a not-so-consistently-used
convention to indent the CPP directives inside #if/#else/#endif by
one extra space, which may look like a typo to an eye unfamiliar
with the convention. Unlike compat/ with borrowed sources, we do
not use the convention very much, and even when it is used, we are
very inconsistent.
Taking git-compat-util.h as an example, here is how a "normalized"
version of that file would look like. It makes it immediately
obvious that an unindented CPP directive (like #define and #include)
is in effect for any and all architectures, so there might be a
readability value in such a change, even though the one-time patch
noise is a bit annoying.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
use strict;
use warnings;
my $level = 0;
my %levelchange = (
if => [0, 1],
ifdef => [0, 1],
ifndef => [0, 1],
else => [-1, 0],
elif => [-1, 0],
endif => [-1, -1],
);
my $file_name = undef;
while (<>) {
if (!defined $file_name || $ARGV ne $file_name) {
$. = 0;
$file_name = $ARGV;
# Special case for the header files
if ($file_name =~ /\.h$/) {
# cause early part of a header file
# #ifndef FILENAME_H
# #define FILENAME_H
# and the corresponding #endif at the end
# not to be indented.
$level = -1;
} else {
$level = 0;
}
}
# Not a CPP directive? copy it out.
if (!/^\s*#\s*(\S+)(.*)/) {
print;
next;
}
#
my ($what, $rest) = ($1, $2);
my $thislevel = $level;
if (exists $levelchange{$what}) {
$thislevel = $level + $levelchange{$what}[0];
$level = $level + $levelchange{$what}[1];
}
if ($thislevel < 0) {
$thislevel = 0;
}
print "#", " " x $thislevel, "$what$rest\n";
}
---
git-compat-util.h | 528 +++++++++++++++++++++++-----------------------
1 file changed, 264 insertions(+), 264 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index ca7678a379..dd9edb30e1 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -11,7 +11,7 @@
* directive, but please report the details of your system to
* git@vger.kernel.org.
*/
-#error "Required C99 support is in a test phase. Please see git-compat-util.h for more details."
+# error "Required C99 support is in a test phase. Please see git-compat-util.h for more details."
#endif
#ifdef USE_MSVC_CRTDBG
@@ -19,8 +19,8 @@
* For these to work they must appear very early in each
* file -- before most of the standard header files.
*/
-#include <stdlib.h>
-#include <crtdbg.h>
+# include <stdlib.h>
+# include <crtdbg.h>
#endif
struct strbuf;
@@ -41,7 +41,7 @@ struct strbuf;
# define GIT_GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
- #define GIT_GNUC_PREREQ(maj, min) 0
+# define GIT_GNUC_PREREQ(maj, min) 0
#endif
@@ -57,23 +57,23 @@ struct strbuf;
* here, we can fall back to use the "safer but a bit wasteful" one
* later.
*/
-#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
-#elif defined(__GNUC__)
-# if (__GNUC__ >= 3)
+# if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
+# elif defined(__GNUC__)
+# if (__GNUC__ >= 3)
+# define FLEX_ARRAY /* empty */
+# else
+# define FLEX_ARRAY 0 /* older GNU extension */
+# endif
+# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define FLEX_ARRAY /* empty */
-# else
-# define FLEX_ARRAY 0 /* older GNU extension */
# endif
-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
-# define FLEX_ARRAY /* empty */
-#endif
/*
* Otherwise, default to safer but a bit wasteful traditional style
*/
-#ifndef FLEX_ARRAY
-# define FLEX_ARRAY 1
-#endif
+# ifndef FLEX_ARRAY
+# define FLEX_ARRAY 1
+# endif
#endif
@@ -153,9 +153,9 @@ struct strbuf;
(a) > maximum_unsigned_value_of_type(a) >> (shift))
#ifdef __GNUC__
-#define TYPEOF(x) (__typeof__(x))
+# define TYPEOF(x) (__typeof__(x))
#else
-#define TYPEOF(x)
+# define TYPEOF(x)
#endif
#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))
@@ -167,7 +167,7 @@ struct strbuf;
#define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
#ifdef __MINGW64__
-#define _POSIX_C_SOURCE 1
+# define _POSIX_C_SOURCE 1
#elif defined(__sun__)
/*
* On Solaris, when _XOPEN_EXTENDED is set, its header file
@@ -177,16 +177,16 @@ struct strbuf;
* non XPG6 programs must be compiled with a pre-c99 compiler.
*/
# if __STDC_VERSION__ - 0 >= 199901L
-# define _XOPEN_SOURCE 600
+# define _XOPEN_SOURCE 600
# else
-# define _XOPEN_SOURCE 500
+# define _XOPEN_SOURCE 500
# endif
#elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && \
!defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) && \
!defined(__TANDEM) && !defined(__QNX__) && !defined(__MirBSD__) && \
!defined(__CYGWIN__)
-#define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */
-#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
+# define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */
+# define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
#endif
#define _ALL_SOURCE 1
#define _GNU_SOURCE 1
@@ -196,38 +196,38 @@ struct strbuf;
#define _SGI_SOURCE 1
#if GIT_GNUC_PREREQ(4, 5)
-#define UNUSED __attribute__((unused)) \
+# define UNUSED __attribute__((unused)) \
__attribute__((deprecated ("parameter declared as UNUSED")))
#elif defined(__GNUC__)
-#define UNUSED __attribute__((unused)) \
+# define UNUSED __attribute__((unused)) \
__attribute__((deprecated))
#else
-#define UNUSED
+# define UNUSED
#endif
#if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */
# if !defined(_WIN32_WINNT)
# define _WIN32_WINNT 0x0600
# endif
-#define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */
-#include <winsock2.h>
-#ifndef NO_UNIX_SOCKETS
-#include <afunix.h>
-#endif
-#include <windows.h>
-#define GIT_WINDOWS_NATIVE
+# define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */
+# include <winsock2.h>
+# ifndef NO_UNIX_SOCKETS
+# include <afunix.h>
+# endif
+# include <windows.h>
+# define GIT_WINDOWS_NATIVE
#endif
#if defined(NO_UNIX_SOCKETS) || !defined(GIT_WINDOWS_NATIVE)
static inline int _have_unix_sockets(void)
{
-#if defined(NO_UNIX_SOCKETS)
+# if defined(NO_UNIX_SOCKETS)
return 0;
-#else
+# else
return 1;
-#endif
+# endif
}
-#define have_unix_sockets _have_unix_sockets
+# define have_unix_sockets _have_unix_sockets
#endif
#include <unistd.h>
@@ -240,13 +240,13 @@ static inline int _have_unix_sockets(void)
#include <stdbool.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
-#include <strings.h> /* for strcasecmp() */
+# include <strings.h> /* for strcasecmp() */
#endif
#include <errno.h>
#include <limits.h>
#include <locale.h>
#ifdef NEEDS_SYS_PARAM_H
-#include <sys/param.h>
+# include <sys/param.h>
#endif
#include <sys/types.h>
#include <dirent.h>
@@ -258,15 +258,15 @@ static inline int _have_unix_sockets(void)
#include <utime.h>
#include <syslog.h>
#if !defined(NO_POLL_H)
-#include <poll.h>
+# include <poll.h>
#elif !defined(NO_SYS_POLL_H)
-#include <sys/poll.h>
+# include <sys/poll.h>
#else
/* Pull the compat stuff */
-#include <poll.h>
+# include <poll.h>
#endif
#ifdef HAVE_BSD_SYSCTL
-#include <sys/sysctl.h>
+# include <sys/sysctl.h>
#endif
/* Used by compat/win32/path-utils.h, and more */
@@ -276,44 +276,44 @@ static inline int is_xplatform_dir_sep(int c)
}
#if defined(__CYGWIN__)
-#include "compat/win32/path-utils.h"
+# include "compat/win32/path-utils.h"
#endif
#if defined(__MINGW32__)
/* pull in Windows compatibility stuff */
-#include "compat/win32/path-utils.h"
-#include "compat/mingw.h"
+# include "compat/win32/path-utils.h"
+# include "compat/mingw.h"
#elif defined(_MSC_VER)
-#include "compat/win32/path-utils.h"
-#include "compat/msvc.h"
-#else
-#include <sys/utsname.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <sys/statvfs.h>
-#include <termios.h>
-#ifndef NO_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <pwd.h>
-#include <sys/un.h>
-#ifndef NO_INTTYPES_H
-#include <inttypes.h>
+# include "compat/win32/path-utils.h"
+# include "compat/msvc.h"
#else
-#include <stdint.h>
-#endif
-#ifdef HAVE_ARC4RANDOM_LIBBSD
-#include <bsd/stdlib.h>
-#endif
-#ifdef HAVE_GETRANDOM
-#include <sys/random.h>
-#endif
-#ifdef NO_INTPTR_T
+# include <sys/utsname.h>
+# include <sys/wait.h>
+# include <sys/resource.h>
+# include <sys/socket.h>
+# include <sys/ioctl.h>
+# include <sys/statvfs.h>
+# include <termios.h>
+# ifndef NO_SYS_SELECT_H
+# include <sys/select.h>
+# endif
+# include <netinet/in.h>
+# include <netinet/tcp.h>
+# include <arpa/inet.h>
+# include <netdb.h>
+# include <pwd.h>
+# include <sys/un.h>
+# ifndef NO_INTTYPES_H
+# include <inttypes.h>
+# else
+# include <stdint.h>
+# endif
+# ifdef HAVE_ARC4RANDOM_LIBBSD
+# include <bsd/stdlib.h>
+# endif
+# ifdef HAVE_GETRANDOM
+# include <sys/random.h>
+# endif
+# ifdef NO_INTPTR_T
/*
* On I16LP32, ILP32 and LP64 "long" is the safe bet, however
* on LLP86, IL33LLP64 and P64 it needs to be "long long",
@@ -323,15 +323,15 @@ static inline int is_xplatform_dir_sep(int c)
*/
typedef long intptr_t;
typedef unsigned long uintptr_t;
-#endif
-#undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */
-#include <grp.h>
-#define _ALL_SOURCE 1
+# endif
+# undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */
+# include <grp.h>
+# define _ALL_SOURCE 1
#endif
/* used on Mac OS X */
#ifdef PRECOMPOSE_UNICODE
-#include "compat/precompose_utf8.h"
+# include "compat/precompose_utf8.h"
#else
static inline const char *precompose_argv_prefix(int argc UNUSED,
const char **argv UNUSED,
@@ -344,16 +344,16 @@ static inline const char *precompose_string_if_needed(const char *in)
return in;
}
-#define probe_utf8_pathname_composition()
+# define probe_utf8_pathname_composition()
#endif
#ifdef MKDIR_WO_TRAILING_SLASH
-#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
+# define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
int compat_mkdir_wo_trailing_slash(const char*, mode_t);
#endif
#ifdef time
-#undef time
+# undef time
#endif
static inline time_t git_time(time_t *tloc)
{
@@ -384,34 +384,34 @@ static inline int git_setitimer(int which UNUSED,
struct itimerval *newvalue UNUSED) {
return 0; /* pretend success */
}
-#undef setitimer
-#define setitimer(which,value,ovalue) git_setitimer(which,value,ovalue)
+# undef setitimer
+# define setitimer(which,value,ovalue) git_setitimer(which,value,ovalue)
#endif
#ifndef NO_LIBGEN_H
-#include <libgen.h>
+# include <libgen.h>
#else
-#define basename gitbasename
+# define basename gitbasename
char *gitbasename(char *);
-#define dirname gitdirname
+# define dirname gitdirname
char *gitdirname(char *);
#endif
#ifndef NO_ICONV
-#include <iconv.h>
+# include <iconv.h>
#endif
#ifndef NO_OPENSSL
-#ifdef __APPLE__
-#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
-#define __AVAILABILITY_MACROS_USES_AVAILABILITY 0
-#include <AvailabilityMacros.h>
-#undef DEPRECATED_ATTRIBUTE
-#define DEPRECATED_ATTRIBUTE
-#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
-#endif
-#include <openssl/ssl.h>
-#include <openssl/err.h>
+# ifdef __APPLE__
+# undef __AVAILABILITY_MACROS_USES_AVAILABILITY
+# define __AVAILABILITY_MACROS_USES_AVAILABILITY 0
+# include <AvailabilityMacros.h>
+# undef DEPRECATED_ATTRIBUTE
+# define DEPRECATED_ATTRIBUTE
+# undef __AVAILABILITY_MACROS_USES_AVAILABILITY
+# endif
+# include <openssl/ssl.h>
+# include <openssl/err.h>
#endif
#ifdef HAVE_SYSINFO
@@ -422,22 +422,22 @@ char *gitdirname(char *);
* not on some systems (e.g. z/OS).
*/
#ifndef NI_MAXHOST
-#define NI_MAXHOST 1025
+# define NI_MAXHOST 1025
#endif
#ifndef NI_MAXSERV
-#define NI_MAXSERV 32
+# define NI_MAXSERV 32
#endif
/* On most systems <limits.h> would have given us this, but
* not on some systems (e.g. GNU/Hurd).
*/
#ifndef PATH_MAX
-#define PATH_MAX 4096
+# define PATH_MAX 4096
#endif
#ifndef NAME_MAX
-#define NAME_MAX 255
+# define NAME_MAX 255
#endif
typedef uintmax_t timestamp_t;
@@ -447,14 +447,14 @@ typedef uintmax_t timestamp_t;
#define TIME_MIN 0
#ifndef PATH_SEP
-#define PATH_SEP ':'
+# define PATH_SEP ':'
#endif
#ifdef HAVE_PATHS_H
-#include <paths.h>
+# include <paths.h>
#endif
#ifndef _PATH_DEFPATH
-#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
+# define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
#endif
#ifndef platform_core_config
@@ -466,12 +466,12 @@ static inline int noop_core_config(const char *var UNUSED,
{
return 0;
}
-#define platform_core_config noop_core_config
+# define platform_core_config noop_core_config
#endif
int lstat_cache_aware_rmdir(const char *path);
#if !defined(__MINGW32__) && !defined(_MSC_VER)
-#define rmdir lstat_cache_aware_rmdir
+# define rmdir lstat_cache_aware_rmdir
#endif
#ifndef has_dos_drive_prefix
@@ -479,7 +479,7 @@ static inline int git_has_dos_drive_prefix(const char *path UNUSED)
{
return 0;
}
-#define has_dos_drive_prefix git_has_dos_drive_prefix
+# define has_dos_drive_prefix git_has_dos_drive_prefix
#endif
#ifndef skip_dos_drive_prefix
@@ -487,7 +487,7 @@ static inline int git_skip_dos_drive_prefix(char **path UNUSED)
{
return 0;
}
-#define skip_dos_drive_prefix git_skip_dos_drive_prefix
+# define skip_dos_drive_prefix git_skip_dos_drive_prefix
#endif
static inline int git_is_dir_sep(int c)
@@ -495,7 +495,7 @@ static inline int git_is_dir_sep(int c)
return c == '/';
}
#ifndef is_dir_sep
-#define is_dir_sep git_is_dir_sep
+# define is_dir_sep git_is_dir_sep
#endif
#ifndef offset_1st_component
@@ -503,20 +503,20 @@ static inline int git_offset_1st_component(const char *path)
{
return is_dir_sep(path[0]);
}
-#define offset_1st_component git_offset_1st_component
+# define offset_1st_component git_offset_1st_component
#endif
#ifndef is_valid_path
-#define is_valid_path(path) 1
+# define is_valid_path(path) 1
#endif
#ifndef is_path_owned_by_current_user
-#ifdef __TANDEM
-#define ROOT_UID 65535
-#else
-#define ROOT_UID 0
-#endif
+# ifdef __TANDEM
+# define ROOT_UID 65535
+# else
+# define ROOT_UID 0
+# endif
/*
* Do not use this function when
@@ -576,7 +576,7 @@ static inline int is_path_owned_by_current_uid(const char *path,
return st.st_uid == euid;
}
-#define is_path_owned_by_current_user is_path_owned_by_current_uid
+# define is_path_owned_by_current_user is_path_owned_by_current_uid
#endif
#ifndef find_last_dir_sep
@@ -584,7 +584,7 @@ static inline char *git_find_last_dir_sep(const char *path)
{
return strrchr(path, '/');
}
-#define find_last_dir_sep git_find_last_dir_sep
+# define find_last_dir_sep git_find_last_dir_sep
#endif
#ifndef has_dir_sep
@@ -592,53 +592,53 @@ static inline int git_has_dir_sep(const char *path)
{
return !!strchr(path, '/');
}
-#define has_dir_sep(path) git_has_dir_sep(path)
+# define has_dir_sep(path) git_has_dir_sep(path)
#endif
#ifndef query_user_email
-#define query_user_email() NULL
+# define query_user_email() NULL
#endif
#ifdef __TANDEM
-#include <floss.h(floss_execl,floss_execlp,floss_execv,floss_execvp)>
-#include <floss.h(floss_getpwuid)>
-#ifndef NSIG
+# include <floss.h(floss_execl,floss_execlp,floss_execv,floss_execvp)>
+# include <floss.h(floss_getpwuid)>
+# ifndef NSIG
/*
* NonStop NSE and NSX do not provide NSIG. SIGGUARDIAN(99) is the highest
* known, by detective work using kill -l as a list is all signals
* instead of signal.h where it should be.
*/
-# define NSIG 100
-#endif
+# define NSIG 100
+# endif
#endif
#if defined(__HP_cc) && (__HP_cc >= 61000)
-#define NORETURN __attribute__((noreturn))
-#define NORETURN_PTR
+# define NORETURN __attribute__((noreturn))
+# define NORETURN_PTR
#elif defined(__GNUC__) && !defined(NO_NORETURN)
-#define NORETURN __attribute__((__noreturn__))
-#define NORETURN_PTR __attribute__((__noreturn__))
+# define NORETURN __attribute__((__noreturn__))
+# define NORETURN_PTR __attribute__((__noreturn__))
#elif defined(_MSC_VER)
-#define NORETURN __declspec(noreturn)
-#define NORETURN_PTR
+# define NORETURN __declspec(noreturn)
+# define NORETURN_PTR
#else
-#define NORETURN
-#define NORETURN_PTR
-#ifndef __GNUC__
-#ifndef __attribute__
-#define __attribute__(x)
-#endif
-#endif
+# define NORETURN
+# define NORETURN_PTR
+# ifndef __GNUC__
+# ifndef __attribute__
+# define __attribute__(x)
+# endif
+# endif
#endif
/* The sentinel attribute is valid from gcc version 4.0 */
#if defined(__GNUC__) && (__GNUC__ >= 4)
-#define LAST_ARG_MUST_BE_NULL __attribute__((sentinel))
+# define LAST_ARG_MUST_BE_NULL __attribute__((sentinel))
/* warn_unused_result exists as of gcc 3.4.0, but be lazy and check 4.0 */
-#define RESULT_MUST_BE_USED __attribute__ ((warn_unused_result))
+# define RESULT_MUST_BE_USED __attribute__ ((warn_unused_result))
#else
-#define LAST_ARG_MUST_BE_NULL
-#define RESULT_MUST_BE_USED
+# define LAST_ARG_MUST_BE_NULL
+# define RESULT_MUST_BE_USED
#endif
#define MAYBE_UNUSED __attribute__((__unused__))
@@ -660,17 +660,17 @@ void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
#ifndef NO_OPENSSL
-#ifdef APPLE_COMMON_CRYPTO
-#include "compat/apple-common-crypto.h"
-#else
-#include <openssl/evp.h>
-#include <openssl/hmac.h>
-#endif /* APPLE_COMMON_CRYPTO */
-#include <openssl/x509v3.h>
+# ifdef APPLE_COMMON_CRYPTO
+# include "compat/apple-common-crypto.h"
+# else
+# include <openssl/evp.h>
+# include <openssl/hmac.h>
+# endif /* APPLE_COMMON_CRYPTO */
+# include <openssl/x509v3.h>
#endif /* NO_OPENSSL */
#ifdef HAVE_OPENSSL_CSPRNG
-#include <openssl/rand.h>
+# include <openssl/rand.h>
#endif
/*
@@ -683,8 +683,8 @@ static inline int const_error(void)
{
return -1;
}
-#define error(...) (error(__VA_ARGS__), const_error())
-#define error_errno(...) (error_errno(__VA_ARGS__), const_error())
+# define error(...) (error(__VA_ARGS__), const_error())
+# define error_errno(...) (error_errno(__VA_ARGS__), const_error())
#endif
typedef void (*report_fn)(const char *, va_list params);
@@ -782,32 +782,32 @@ static inline bool strip_suffix(const char *str, const char *suffix,
#if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
-#ifndef PROT_READ
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define MAP_PRIVATE 1
-#endif
+# ifndef PROT_READ
+# define PROT_READ 1
+# define PROT_WRITE 2
+# define MAP_PRIVATE 1
+# endif
-#define mmap git_mmap
-#define munmap git_munmap
+# define mmap git_mmap
+# define munmap git_munmap
void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
int git_munmap(void *start, size_t length);
#else /* NO_MMAP || USE_WIN32_MMAP */
-#include <sys/mman.h>
+# include <sys/mman.h>
#endif /* NO_MMAP || USE_WIN32_MMAP */
#ifdef NO_MMAP
/* This value must be multiple of (pagesize * 2) */
-#define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)
+# define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)
#else /* NO_MMAP */
/* This value must be multiple of (pagesize * 2) */
-#define DEFAULT_PACKED_GIT_WINDOW_SIZE \
+# define DEFAULT_PACKED_GIT_WINDOW_SIZE \
(sizeof(void*) >= 8 \
? 1 * 1024 * 1024 * 1024 \
: 32 * 1024 * 1024)
@@ -815,46 +815,46 @@ int git_munmap(void *start, size_t length);
#endif /* NO_MMAP */
#ifndef MAP_FAILED
-#define MAP_FAILED ((void *)-1)
+# define MAP_FAILED ((void *)-1)
#endif
#ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
-#define on_disk_bytes(st) ((st).st_size)
+# define on_disk_bytes(st) ((st).st_size)
#else
-#define on_disk_bytes(st) ((st).st_blocks * 512)
+# define on_disk_bytes(st) ((st).st_blocks * 512)
#endif
#ifdef NEEDS_MODE_TRANSLATION
-#undef S_IFMT
-#undef S_IFREG
-#undef S_IFDIR
-#undef S_IFLNK
-#undef S_IFBLK
-#undef S_IFCHR
-#undef S_IFIFO
-#undef S_IFSOCK
-#define S_IFMT 0170000
-#define S_IFREG 0100000
-#define S_IFDIR 0040000
-#define S_IFLNK 0120000
-#define S_IFBLK 0060000
-#define S_IFCHR 0020000
-#define S_IFIFO 0010000
-#define S_IFSOCK 0140000
-#ifdef stat
-#undef stat
-#endif
-#define stat(path, buf) git_stat(path, buf)
+# undef S_IFMT
+# undef S_IFREG
+# undef S_IFDIR
+# undef S_IFLNK
+# undef S_IFBLK
+# undef S_IFCHR
+# undef S_IFIFO
+# undef S_IFSOCK
+# define S_IFMT 0170000
+# define S_IFREG 0100000
+# define S_IFDIR 0040000
+# define S_IFLNK 0120000
+# define S_IFBLK 0060000
+# define S_IFCHR 0020000
+# define S_IFIFO 0010000
+# define S_IFSOCK 0140000
+# ifdef stat
+# undef stat
+# endif
+# define stat(path, buf) git_stat(path, buf)
int git_stat(const char *, struct stat *);
-#ifdef fstat
-#undef fstat
-#endif
-#define fstat(fd, buf) git_fstat(fd, buf)
+# ifdef fstat
+# undef fstat
+# endif
+# define fstat(fd, buf) git_fstat(fd, buf)
int git_fstat(int, struct stat *);
-#ifdef lstat
-#undef lstat
-#endif
-#define lstat(path, buf) git_lstat(path, buf)
+# ifdef lstat
+# undef lstat
+# endif
+# define lstat(path, buf) git_lstat(path, buf)
int git_lstat(const char *, struct stat *);
#endif
@@ -862,67 +862,67 @@ int git_lstat(const char *, struct stat *);
((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? (32 * 1024L * 1024L) : 256))
#ifdef NO_PREAD
-#define pread git_pread
+# define pread git_pread
ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);
#endif
#ifdef NO_SETENV
-#define setenv gitsetenv
+# define setenv gitsetenv
int gitsetenv(const char *, const char *, int);
#endif
#ifdef NO_MKDTEMP
-#define mkdtemp gitmkdtemp
+# define mkdtemp gitmkdtemp
char *gitmkdtemp(char *);
#endif
#ifdef NO_UNSETENV
-#define unsetenv gitunsetenv
+# define unsetenv gitunsetenv
int gitunsetenv(const char *);
#endif
#ifdef NO_STRCASESTR
-#define strcasestr gitstrcasestr
+# define strcasestr gitstrcasestr
char *gitstrcasestr(const char *haystack, const char *needle);
#endif
#ifdef NO_STRLCPY
-#define strlcpy gitstrlcpy
+# define strlcpy gitstrlcpy
size_t gitstrlcpy(char *, const char *, size_t);
#endif
#ifdef NO_STRTOUMAX
-#define strtoumax gitstrtoumax
+# define strtoumax gitstrtoumax
uintmax_t gitstrtoumax(const char *, char **, int);
-#define strtoimax gitstrtoimax
+# define strtoimax gitstrtoimax
intmax_t gitstrtoimax(const char *, char **, int);
#endif
#ifdef NO_HSTRERROR
-#define hstrerror githstrerror
+# define hstrerror githstrerror
const char *githstrerror(int herror);
#endif
#ifdef NO_MEMMEM
-#define memmem gitmemmem
+# define memmem gitmemmem
void *gitmemmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen);
#endif
#ifdef OVERRIDE_STRDUP
-#ifdef strdup
-#undef strdup
-#endif
-#define strdup gitstrdup
+# ifdef strdup
+# undef strdup
+# endif
+# define strdup gitstrdup
char *gitstrdup(const char *s);
#endif
#ifdef NO_GETPAGESIZE
-#define getpagesize() sysconf(_SC_PAGESIZE)
+# define getpagesize() sysconf(_SC_PAGESIZE)
#endif
#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
+# define O_CLOEXEC 0
#endif
#ifdef FREAD_READS_DIRECTORIES
@@ -936,34 +936,34 @@ FILE *git_fopen(const char*, const char*);
#endif
#ifdef SNPRINTF_RETURNS_BOGUS
-#ifdef snprintf
-#undef snprintf
-#endif
-#define snprintf git_snprintf
+# ifdef snprintf
+# undef snprintf
+# endif
+# define snprintf git_snprintf
int git_snprintf(char *str, size_t maxsize,
const char *format, ...);
-#ifdef vsnprintf
-#undef vsnprintf
-#endif
-#define vsnprintf git_vsnprintf
+# ifdef vsnprintf
+# undef vsnprintf
+# endif
+# define vsnprintf git_vsnprintf
int git_vsnprintf(char *str, size_t maxsize,
const char *format, va_list ap);
#endif
#ifdef OPEN_RETURNS_EINTR
-#undef open
-#define open git_open_with_retry
+# undef open
+# define open git_open_with_retry
int git_open_with_retry(const char *path, int flag, ...);
#endif
#ifdef __GLIBC_PREREQ
-#if __GLIBC_PREREQ(2, 1)
-#define HAVE_STRCHRNUL
-#endif
+# if __GLIBC_PREREQ(2, 1)
+# define HAVE_STRCHRNUL
+# endif
#endif
#ifndef HAVE_STRCHRNUL
-#define strchrnul gitstrchrnul
+# define strchrnul gitstrchrnul
static inline char *gitstrchrnul(const char *s, int c)
{
while (*s && *s != c)
@@ -981,7 +981,7 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);
#endif
#ifdef NO_PTHREADS
-#define atexit git_atexit
+# define atexit git_atexit
int git_atexit(void (*handler)(void));
#endif
@@ -1252,7 +1252,7 @@ static inline size_t xsize_t(off_t len)
}
#ifndef HOST_NAME_MAX
-#define HOST_NAME_MAX 256
+# define HOST_NAME_MAX 256
#endif
#include "sane-ctype.h"
@@ -1325,7 +1325,7 @@ static inline int strtol_i(char const *s, int base, int *result)
void git_stable_qsort(void *base, size_t nmemb, size_t size,
int(*compar)(const void *, const void *));
#ifdef INTERNAL_QSORT
-#define qsort git_stable_qsort
+# define qsort git_stable_qsort
#endif
#define QSORT(base, n, compar) sane_qsort((base), (n), sizeof(*(base)), compar)
@@ -1342,7 +1342,7 @@ static inline void sane_qsort(void *base, size_t nmemb, size_t size,
#ifndef HAVE_ISO_QSORT_S
int git_qsort_s(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *, void *), void *ctx);
-#define qsort_s git_qsort_s
+# define qsort_s git_qsort_s
#endif
#define QSORT_S(base, n, compar, ctx) do { \
@@ -1351,7 +1351,7 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,
} while (0)
#ifndef REG_STARTEND
-#error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
+# error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
#endif
static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
@@ -1365,7 +1365,7 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
#ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
int git_regcomp(regex_t *preg, const char *pattern, int cflags);
-#define regcomp git_regcomp
+# define regcomp git_regcomp
#endif
#ifndef DIR_HAS_BSD_GROUP_SEMANTICS
@@ -1375,23 +1375,23 @@ int git_regcomp(regex_t *preg, const char *pattern, int cflags);
#endif
#ifdef NO_NSEC
-#undef USE_NSEC
-#define ST_CTIME_NSEC(st) 0
-#define ST_MTIME_NSEC(st) 0
+# undef USE_NSEC
+# define ST_CTIME_NSEC(st) 0
+# define ST_MTIME_NSEC(st) 0
#else
-#ifdef USE_ST_TIMESPEC
-#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec))
-#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtimespec.tv_nsec))
-#else
-#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))
-#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))
-#endif
+# ifdef USE_ST_TIMESPEC
+# define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec))
+# define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtimespec.tv_nsec))
+# else
+# define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))
+# define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))
+# endif
#endif
#ifdef UNRELIABLE_FSTAT
-#define fstat_is_reliable() 0
+# define fstat_is_reliable() 0
#else
-#define fstat_is_reliable() 1
+# define fstat_is_reliable() 1
#endif
#ifndef va_copy
@@ -1400,11 +1400,11 @@ int git_regcomp(regex_t *preg, const char *pattern, int cflags);
* pointer into the stack frame, a simple assignment will work on
* many systems. But let's try to be more portable.
*/
-#ifdef __va_copy
-#define va_copy(dst, src) __va_copy(dst, src)
-#else
-#define va_copy(dst, src) ((dst) = (src))
-#endif
+# ifdef __va_copy
+# define va_copy(dst, src) __va_copy(dst, src)
+# else
+# define va_copy(dst, src) ((dst) = (src))
+# endif
#endif
/* usage.c: only to be used for testing BUG() implementation (see test-tool) */
@@ -1425,11 +1425,11 @@ void bug_fl(const char *file, int line, const char *fmt, ...);
} while (0)
#ifndef FSYNC_METHOD_DEFAULT
-#ifdef __APPLE__
-#define FSYNC_METHOD_DEFAULT FSYNC_METHOD_WRITEOUT_ONLY
-#else
-#define FSYNC_METHOD_DEFAULT FSYNC_METHOD_FSYNC
-#endif
+# ifdef __APPLE__
+# define FSYNC_METHOD_DEFAULT FSYNC_METHOD_WRITEOUT_ONLY
+# else
+# define FSYNC_METHOD_DEFAULT FSYNC_METHOD_FSYNC
+# endif
#endif
#ifndef SHELL_PATH
@@ -1445,12 +1445,12 @@ static inline void git_funlockfile(FILE *fh UNUSED)
{
; /* nothing */
}
-#undef flockfile
-#undef funlockfile
-#undef getc_unlocked
-#define flockfile(fh) git_flockfile(fh)
-#define funlockfile(fh) git_funlockfile(fh)
-#define getc_unlocked(fh) getc(fh)
+# undef flockfile
+# undef funlockfile
+# undef getc_unlocked
+# define flockfile(fh) git_flockfile(fh)
+# define funlockfile(fh) git_funlockfile(fh)
+# define getc_unlocked(fh) getc(fh)
#endif
#ifdef FILENO_IS_A_MACRO
@@ -1465,7 +1465,7 @@ int git_fileno(FILE *stream);
int git_access(const char *path, int mode);
# ifndef COMPAT_CODE_ACCESS
# ifdef access
-# undef access
+# undef access
# endif
# define access(path, mode) git_access(path, mode)
# endif
@@ -1510,9 +1510,9 @@ int common_exit(const char *file, int line, int code);
*/
#ifdef SUPPRESS_ANNOTATED_LEAKS
void unleak_memory(const void *ptr, size_t len);
-#define UNLEAK(var) unleak_memory(&(var), sizeof(var))
+# define UNLEAK(var) unleak_memory(&(var), sizeof(var))
#else
-#define UNLEAK(var) do {} while (0)
+# define UNLEAK(var) do {} while (0)
#endif
#define z_const
@@ -1565,9 +1565,9 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)
* everywhere.
*/
#if defined(__GNUC__) /* clang sets this, too */
-#define OFFSETOF_VAR(ptr, member) offsetof(__typeof__(*ptr), member)
+# define OFFSETOF_VAR(ptr, member) offsetof(__typeof__(*ptr), member)
#else /* !__GNUC__ */
-#define OFFSETOF_VAR(ptr, member) \
+# define OFFSETOF_VAR(ptr, member) \
((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))
#endif /* !__GNUC__ */
--
2.45.2-709-g1ffe7c8bd7
^ permalink raw reply related [flat|nested] 94+ messages in thread
* Re: [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-18 15:58 ` Junio C Hamano
2024-06-18 16:56 ` Junio C Hamano
@ 2024-06-18 20:20 ` Karthik Nayak
1 sibling, 0 replies; 94+ messages in thread
From: Karthik Nayak @ 2024-06-18 20:20 UTC (permalink / raw)
To: Junio C Hamano
Cc: Patrick Steinhardt, git, Ghanshyam Thakkar, brian m. carlson,
Phillip Wood
[-- Attachment #1: Type: text/plain, Size: 2909 bytes --]
Junio C Hamano <gitster@pobox.com> writes:
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>>>> s/# define/#define/
>>>
>>> This is in fact intentional. We aren't strictly following this in our
>>> codebase, but when nesting preprocessor macros into ifdefs then we often
>>> indent the inner macros with spaces.
>>>
>>> Patrick
>>
>> That's something I didn't know. Thanks.
>
> Unlike borrowed sources in compat/, in our codebase, such
> indentation is minority. IOW "often indent" -> "sometimes indent".
>
> A quick look at an early part of git-compat-util.h would show that
> even within a single file we are not consistent at all.
>
> #if __STDC_VERSION__ - 0 < 199901L
> #error "Required C99 support is in a test phase. Please see git-compat-util.h for more details."
> #endif
>
> #ifdef USE_MSVC_CRTDBG
> #include <stdlib.h>
> #include <crtdbg.h>
> #endif
>
> #define _FILE_OFFSET_BITS 64
>
> #if defined(__GNUC__) && defined(__GNUC_MINOR__)
> # define GIT_GNUC_PREREQ(maj, min) \
> ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
> #else
> #define GIT_GNUC_PREREQ(maj, min) 0
> #endif
>
> #ifndef FLEX_ARRAY
> #if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
> #elif defined(__GNUC__)
> # if (__GNUC__ >= 3)
> # define FLEX_ARRAY /* empty */
> # else
> # define FLEX_ARRAY 0 /* older GNU extension */
> # endif
> #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
> # define FLEX_ARRAY /* empty */
> #endif
> ...
>
>
> We may want to eventually fix this, but we need to decide what the
> desirable layout is. I am not sure if the indented version is
> easier to read and maintain, but one thing that is sure is that a
> mixed mess is harder than either. In the above excerpt, you cannot
> tell if I quoted everything related to FLEX_ARRAY (in other words,
> if "#ifndef FLEX_ARRAY" is already closed in the excerpt) without
> carefully looking.
Perhaps putting the options next to each other is good way to think of
about the _desired layout_.
#ifndef FLEX_ARRAY
#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
#elif defined(__GNUC__)
# if (__GNUC__ >= 3)
# define FLEX_ARRAY /* empty */
# else
# define FLEX_ARRAY 0 /* older GNU extension */
# endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define FLEX_ARRAY /* empty */
#endif
#ifndef FLEX_ARRAY
#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
#elif defined(__GNUC__)
#if (__GNUC__ >= 3)
#define FLEX_ARRAY /* empty */
#else
#define FLEX_ARRAY 0 /* older GNU extension */
#endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define FLEX_ARRAY /* empty */
#endif
Somehow I feel the latter makes it a bit easier to grasp blocks, but
overall I think its more important that we pick one and perhaps add it
to 'Documentation/CodingGuidelines'.
Also, I did look at your response patch, but will leave it for someone
with perl experience to review.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
* Re: [PATCH v3 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
` (20 preceding siblings ...)
2024-06-18 9:56 ` [PATCH v3 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Phillip Wood
@ 2024-06-18 20:22 ` Karthik Nayak
21 siblings, 0 replies; 94+ messages in thread
From: Karthik Nayak @ 2024-06-18 20:22 UTC (permalink / raw)
To: Patrick Steinhardt, git
Cc: Ghanshyam Thakkar, brian m. carlson, Phillip Wood, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1405 bytes --]
Patrick Steinhardt <ps@pks.im> writes:
> Hi,
>
> this is the third version of my patch series that introduces the
> `USE_THE_REPOSITORY_VARIABLE` macro. When unset, this will cause us to
> hide `the_repository`, `the_hash_algo` and several other functions that
> implicitly rely on those global variables from our headers. This is a
> first step towards fully getting rid of this global state in favor of
> passing it down explicitly via function parameters.
>
> Changes compared to v2:
>
> - Note in a commit message that we aim to have a faithful conversion
> when introducing a `struct git_hash_algo` parameter to functions. So
> even in case the calling context has a `struct git_hash_algo`
> available via a local repository, we still use `the_repository` such
> that there cannot be a change in behaviour here. Fixing those sites
> will be left for a future patch series such that we can avoid any
> kind of regressions caused by this comparatively large refactoring.
> I also adapted some conversions to fully follow through with this
> intent.
>
> - Fix an issue with sparse by adding another `extern` declaration of
> `the_repository` to "repository.c".
>
> Thanks!
>
I forgot to reply here earlier.
I went through the patches and only found 2 small typos, overall this
was an elaborate set of patches. I don't expect a reroll for that
however. Thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 94+ messages in thread
end of thread, other threads:[~2024-06-18 20:22 UTC | newest]
Thread overview: 94+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 01/21] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 02/21] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 03/21] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 04/21] global: ensure that object IDs are always padded Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 05/21] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 06/21] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 07/21] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 08/21] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 09/21] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 10/21] refs: avoid include cycle with "repository.h" Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 11/21] hash-ll: merge with "hash.h" Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 12/21] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 13/21] oidset: pass hash algorithm when parsing file Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 14/21] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 15/21] replace-object: " Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 16/21] compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC Patrick Steinhardt
2024-06-11 23:16 ` brian m. carlson
2024-06-12 7:38 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 17/21] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 18/21] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
2024-06-11 13:23 ` Ghanshyam Thakkar
2024-06-11 11:59 ` [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree" Patrick Steinhardt
2024-06-11 12:57 ` Ghanshyam Thakkar
2024-06-12 7:38 ` Patrick Steinhardt
2024-06-11 23:17 ` brian m. carlson
2024-06-12 7:38 ` Patrick Steinhardt
2024-06-11 11:59 ` [PATCH 20/21] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
2024-06-11 11:59 ` [PATCH 21/21] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2024-06-11 23:24 ` [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro brian m. carlson
2024-06-12 7:37 ` Patrick Steinhardt
2024-06-12 10:12 ` Ghanshyam Thakkar
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 03/20] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 04/20] global: ensure that object IDs are always padded Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 06/20] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
2024-06-13 10:01 ` Phillip Wood
2024-06-13 15:39 ` Junio C Hamano
2024-06-14 5:23 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 10/20] refs: avoid include cycle with "repository.h" Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 11/20] hash-ll: merge with "hash.h" Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 12/20] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 13/20] oidset: pass hash algorithm when parsing file Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 14/20] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 15/20] replace-object: " Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 17/20] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 18/20] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 19/20] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2024-06-13 18:01 ` [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Junio C Hamano
2024-06-13 18:48 ` Junio C Hamano
2024-06-13 23:14 ` Ramsay Jones
2024-06-13 23:18 ` Junio C Hamano
2024-06-13 23:55 ` Ramsay Jones
2024-06-14 0:17 ` Junio C Hamano
2024-06-14 5:28 ` Patrick Steinhardt
2024-06-14 15:54 ` Junio C Hamano
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 03/20] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 04/20] global: ensure that object IDs are always padded Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
2024-06-17 9:18 ` Karthik Nayak
2024-06-14 6:50 ` [PATCH v3 06/20] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-17 9:30 ` Karthik Nayak
2024-06-18 5:16 ` Patrick Steinhardt
2024-06-18 9:25 ` Karthik Nayak
2024-06-18 15:58 ` Junio C Hamano
2024-06-18 16:56 ` Junio C Hamano
2024-06-18 20:20 ` Karthik Nayak
2024-06-14 6:50 ` [PATCH v3 10/20] refs: avoid include cycle with "repository.h" Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 11/20] hash-ll: merge with "hash.h" Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 12/20] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 13/20] oidset: pass hash algorithm when parsing file Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 14/20] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 15/20] replace-object: " Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 17/20] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 18/20] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 19/20] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2024-06-18 9:56 ` [PATCH v3 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Phillip Wood
2024-06-18 20:22 ` Karthik Nayak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).