Skip to content

Commit b81093a

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c27d22 commit b81093a

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ static int read_index_extension(struct index_state *istate,
17541754
istate->cache_tree = cache_tree_read(data, sz);
17551755
break;
17561756
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);
17581758
break;
17591759
case CACHE_EXT_LINK:
17601760
if (read_link_extension(istate, data, sz))
@@ -3033,7 +3033,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
30333033
istate->resolve_undo) {
30343034
strbuf_reset(&sb);
30353035

3036-
resolve_undo_write(&sb, istate->resolve_undo);
3036+
resolve_undo_write(&sb, istate->resolve_undo, the_hash_algo);
30373037
err = write_index_ext_header(f, eoie_c, CACHE_EXT_RESOLVE_UNDO,
30383038
sb.len) < 0;
30393039
hashwrite(f, sb.buf, sb.len);

resolve-undo.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "git-compat-util.h"
@@ -34,7 +33,8 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
3433
ui->mode[stage - 1] = ce->ce_mode;
3534
}
3635

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)
3838
{
3939
struct string_list_item *item;
4040
for_each_string_list_item(item, resolve_undo) {
@@ -50,18 +50,19 @@ void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo)
5050
for (i = 0; i < 3; i++) {
5151
if (!ui->mode[i])
5252
continue;
53-
strbuf_add(sb, ui->oid[i].hash, the_hash_algo->rawsz);
53+
strbuf_add(sb, ui->oid[i].hash, algop->rawsz);
5454
}
5555
}
5656
}
5757

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)
5960
{
6061
struct string_list *resolve_undo;
6162
size_t len;
6263
char *endptr;
6364
int i;
64-
const unsigned rawsz = the_hash_algo->rawsz;
65+
const unsigned rawsz = algop->rawsz;
6566

6667
CALLOC_ARRAY(resolve_undo, 1);
6768
resolve_undo->strdup_strings = 1;
@@ -96,8 +97,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
9697
continue;
9798
if (size < rawsz)
9899
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);
101101
size -= rawsz;
102102
data += rawsz;
103103
}

resolve-undo.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ struct resolve_undo_info {
1414
};
1515

1616
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);
1921
void resolve_undo_clear_index(struct index_state *);
2022
int unmerge_index_entry(struct index_state *, const char *, struct resolve_undo_info *, unsigned);
2123
void unmerge_index(struct index_state *, const struct pathspec *, unsigned);

0 commit comments

Comments
 (0)