resolve-undo: stop using `the_repository`

Stop using `the_repository` in the "resolve-undo" subsystem by passing in the hash algorithm when reading or writing resolve-undo information. While we could trivially update the caller to pass in the hash algorithm used by the index itself, we instead pass in `the_hash_algo`. This is mostly done to stay consistent with the rest of the code in that file, which isn't prepared to handle arbitrary repositories, either. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 17, 2024 at 07:43 UTC b81093aeae557d56277773dee710eb363c720b6e
3 files changed +13 -11
read-cache.c
+2 -2
@@ -1754,7 +1754,7 @@ static int read_index_extension(struct index_state *istate,
1754 istate->cache_tree = cache_tree_read(data, sz);
1755 break;
1756 case CACHE_EXT_RESOLVE_UNDO:
1757 - istate->resolve_undo = resolve_undo_read(data, sz);
1757 + istate->resolve_undo = resolve_undo_read(data, sz, the_hash_algo);
1758 break;
1759 case CACHE_EXT_LINK:
1760 if (read_link_extension(istate, data, sz))
@@ -3033,7 +3033,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
3033 istate->resolve_undo) {
3034 strbuf_reset(&sb);
3035
3036 - resolve_undo_write(&sb, istate->resolve_undo);
3036 + resolve_undo_write(&sb, istate->resolve_undo, the_hash_algo);
3037 err = write_index_ext_header(f, eoie_c, CACHE_EXT_RESOLVE_UNDO,
3038 sb.len) < 0;
3039 hashwrite(f, sb.buf, sb.len);
resolve-undo.c
+7 -7
@@ -1,4 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
1 #define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
@@ -34,7 +33,8 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
33 ui->mode[stage - 1] = ce->ce_mode;
34 }
35
37 -void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo)
36 +void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo,
37 + const struct git_hash_algo *algop)
38 {
39 struct string_list_item *item;
40 for_each_string_list_item(item, resolve_undo) {
@@ -50,18 +50,19 @@ void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo)
50 for (i = 0; i < 3; i++) {
51 if (!ui->mode[i])
52 continue;
53 - strbuf_add(sb, ui->oid[i].hash, the_hash_algo->rawsz);
53 + strbuf_add(sb, ui->oid[i].hash, algop->rawsz);
54 }
55 }
56 }
57
58 -struct string_list *resolve_undo_read(const char *data, unsigned long size)
58 +struct string_list *resolve_undo_read(const char *data, unsigned long size,
59 + const struct git_hash_algo *algop)
60 {
61 struct string_list *resolve_undo;
62 size_t len;
63 char *endptr;
64 int i;
64 - const unsigned rawsz = the_hash_algo->rawsz;
65 + const unsigned rawsz = algop->rawsz;
66
67 CALLOC_ARRAY(resolve_undo, 1);
68 resolve_undo->strdup_strings = 1;
@@ -96,8 +97,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
97 continue;
98 if (size < rawsz)
99 goto error;
99 - oidread(&ui->oid[i], (const unsigned char *)data,
100 - the_repository->hash_algo);
100 + oidread(&ui->oid[i], (const unsigned char *)data, algop);
101 size -= rawsz;
102 data += rawsz;
103 }
resolve-undo.h
+4 -2
@@ -14,8 +14,10 @@ struct resolve_undo_info {
14 };
15
16 void record_resolve_undo(struct index_state *, struct cache_entry *);
17 -void resolve_undo_write(struct strbuf *, struct string_list *);
18 -struct string_list *resolve_undo_read(const char *, unsigned long);
17 +void resolve_undo_write(struct strbuf *, struct string_list *,
18 + const struct git_hash_algo *algop);
19 +struct string_list *resolve_undo_read(const char *, unsigned long,
20 + const struct git_hash_algo *algop);
21 void resolve_undo_clear_index(struct index_state *);
22 int unmerge_index_entry(struct index_state *, const char *, struct resolve_undo_info *, unsigned);
23 void unmerge_index(struct index_state *, const struct pathspec *, unsigned);