Skip to content

Commit f6e174b

Browse files
pks-tgitster
authored andcommitted
object-file-convert: stop depending on the_repository
There are multiple sites in "object-file-convert.c" where we use the global `the_repository` variable, either explicitly or implicitly by using `the_hash_algo`. All of these callsites are transitively called from `convert_object_file()`, which indeed has no repo as input. Refactor the function so that it receives a repository as a parameter and pass it through to all internal functions to get rid of the dependency. Remove the `USE_THE_REPOSITORY_VARIABLE` define. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a6768d commit f6e174b

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int do_sign(struct strbuf *buffer, struct object_id **compat_oid,
172172
if (compat) {
173173
const struct git_hash_algo *algo = the_repository->hash_algo;
174174

175-
if (convert_object_file(&compat_buf, algo, compat,
175+
if (convert_object_file(the_repository ,&compat_buf, algo, compat,
176176
buffer->buf, buffer->len, OBJ_TAG, 1))
177177
goto out;
178178
if (sign_buffer(&compat_buf, &compat_sig, keyid))

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ static int convert_commit_extra_headers(const struct commit_extra_header *orig,
13801380
struct commit_extra_header *new;
13811381
CALLOC_ARRAY(new, 1);
13821382
if (!strcmp(orig->key, "mergetag")) {
1383-
if (convert_object_file(&out, algo, compat,
1383+
if (convert_object_file(the_repository, &out, algo, compat,
13841384
orig->value, orig->len,
13851385
OBJ_TAG, 1)) {
13861386
free(new);

object-file-convert.c

Lines changed: 16 additions & 13 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"
@@ -63,7 +62,8 @@ static int decode_tree_entry_raw(struct object_id *oid, const char **path,
6362
return 0;
6463
}
6564

66-
static int convert_tree_object(struct strbuf *out,
65+
static int convert_tree_object(struct repository *repo,
66+
struct strbuf *out,
6767
const struct git_hash_algo *from,
6868
const struct git_hash_algo *to,
6969
const char *buffer, size_t size)
@@ -78,7 +78,7 @@ static int convert_tree_object(struct strbuf *out,
7878
if (decode_tree_entry_raw(&entry_oid, &path, &pathlen, from, p,
7979
end - p))
8080
return error(_("failed to decode tree entry"));
81-
if (repo_oid_to_algop(the_repository, &entry_oid, to, &mapped_oid))
81+
if (repo_oid_to_algop(repo, &entry_oid, to, &mapped_oid))
8282
return error(_("failed to map tree entry for %s"), oid_to_hex(&entry_oid));
8383
strbuf_add(out, p, path - p);
8484
strbuf_add(out, path, pathlen);
@@ -88,7 +88,8 @@ static int convert_tree_object(struct strbuf *out,
8888
return 0;
8989
}
9090

91-
static int convert_tag_object(struct strbuf *out,
91+
static int convert_tag_object(struct repository *repo,
92+
struct strbuf *out,
9293
const struct git_hash_algo *from,
9394
const struct git_hash_algo *to,
9495
const char *buffer, size_t size)
@@ -105,7 +106,7 @@ static int convert_tag_object(struct strbuf *out,
105106
return error("bogus tag object");
106107
if (parse_oid_hex_algop(buffer + 7, &oid, &p, from) < 0)
107108
return error("bad tag object ID");
108-
if (repo_oid_to_algop(the_repository, &oid, to, &mapped_oid))
109+
if (repo_oid_to_algop(repo, &oid, to, &mapped_oid))
109110
return error("unable to map tree %s in tag object",
110111
oid_to_hex(&oid));
111112
size -= ((p + 1) - buffer);
@@ -139,7 +140,8 @@ static int convert_tag_object(struct strbuf *out,
139140
return 0;
140141
}
141142

142-
static int convert_commit_object(struct strbuf *out,
143+
static int convert_commit_object(struct repository *repo,
144+
struct strbuf *out,
143145
const struct git_hash_algo *from,
144146
const struct git_hash_algo *to,
145147
const char *buffer, size_t size)
@@ -165,7 +167,7 @@ static int convert_commit_object(struct strbuf *out,
165167
(p != eol))
166168
return error(_("bad %s in commit"), "tree");
167169

168-
if (repo_oid_to_algop(the_repository, &oid, to, &mapped_oid))
170+
if (repo_oid_to_algop(repo, &oid, to, &mapped_oid))
169171
return error(_("unable to map %s %s in commit object"),
170172
"tree", oid_to_hex(&oid));
171173
strbuf_addf(out, "tree %s\n", oid_to_hex(&mapped_oid));
@@ -177,7 +179,7 @@ static int convert_commit_object(struct strbuf *out,
177179
(p != eol))
178180
return error(_("bad %s in commit"), "parent");
179181

180-
if (repo_oid_to_algop(the_repository, &oid, to, &mapped_oid))
182+
if (repo_oid_to_algop(repo, &oid, to, &mapped_oid))
181183
return error(_("unable to map %s %s in commit object"),
182184
"parent", oid_to_hex(&oid));
183185

@@ -202,7 +204,7 @@ static int convert_commit_object(struct strbuf *out,
202204
}
203205

204206
/* Compute the new tag object */
205-
if (convert_tag_object(&new_tag, from, to, tag.buf, tag.len)) {
207+
if (convert_tag_object(repo, &new_tag, from, to, tag.buf, tag.len)) {
206208
strbuf_release(&tag);
207209
strbuf_release(&new_tag);
208210
return -1;
@@ -241,7 +243,8 @@ static int convert_commit_object(struct strbuf *out,
241243
return 0;
242244
}
243245

244-
int convert_object_file(struct strbuf *outbuf,
246+
int convert_object_file(struct repository *repo,
247+
struct strbuf *outbuf,
245248
const struct git_hash_algo *from,
246249
const struct git_hash_algo *to,
247250
const void *buf, size_t len,
@@ -256,13 +259,13 @@ int convert_object_file(struct strbuf *outbuf,
256259

257260
switch (type) {
258261
case OBJ_COMMIT:
259-
ret = convert_commit_object(outbuf, from, to, buf, len);
262+
ret = convert_commit_object(repo, outbuf, from, to, buf, len);
260263
break;
261264
case OBJ_TREE:
262-
ret = convert_tree_object(outbuf, from, to, buf, len);
265+
ret = convert_tree_object(repo, outbuf, from, to, buf, len);
263266
break;
264267
case OBJ_TAG:
265-
ret = convert_tag_object(outbuf, from, to, buf, len);
268+
ret = convert_tag_object(repo, outbuf, from, to, buf, len);
266269
break;
267270
default:
268271
/* Not implemented yet, so fail. */

object-file-convert.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ int repo_oid_to_algop(struct repository *repo, const struct object_id *src,
1414
* Convert an object file from one hash algorithm to another algorithm.
1515
* Return -1 on failure, 0 on success.
1616
*/
17-
int convert_object_file(struct strbuf *outbuf,
17+
int convert_object_file(struct repository *repo,
18+
struct strbuf *outbuf,
1819
const struct git_hash_algo *from,
1920
const struct git_hash_algo *to,
2021
const void *buf, size_t len,

object-file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ static int oid_object_info_convert(struct repository *r,
17931793
if (type == -1)
17941794
return -1;
17951795
if (type != OBJ_BLOB) {
1796-
ret = convert_object_file(&outbuf,
1796+
ret = convert_object_file(the_repository, &outbuf,
17971797
the_hash_algo, input_algo,
17981798
content, size, type, !do_die);
17991799
free(content);
@@ -2510,7 +2510,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
25102510
hash_object_file(compat, buf, len, type, &compat_oid);
25112511
else {
25122512
struct strbuf converted = STRBUF_INIT;
2513-
convert_object_file(&converted, algo, compat,
2513+
convert_object_file(the_repository, &converted, algo, compat,
25142514
buf, len, type, 0);
25152515
hash_object_file(compat, converted.buf, converted.len,
25162516
type, &compat_oid);
@@ -2550,7 +2550,8 @@ int write_object_file_literally(const void *buf, unsigned long len,
25502550
&compat_oid);
25512551
else if (compat_type != -1) {
25522552
struct strbuf converted = STRBUF_INIT;
2553-
convert_object_file(&converted, algo, compat,
2553+
convert_object_file(the_repository,
2554+
&converted, algo, compat,
25542555
buf, len, compat_type, 0);
25552556
hash_object_file(compat, converted.buf, converted.len,
25562557
compat_type, &compat_oid);

0 commit comments

Comments
 (0)