Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
f6e174b2 1a6768d1

+24 -19
+1 -1
builtin/tag.c
··· 172 172 if (compat) { 173 173 const struct git_hash_algo *algo = the_repository->hash_algo; 174 174 175 - if (convert_object_file(&compat_buf, algo, compat, 175 + if (convert_object_file(the_repository ,&compat_buf, algo, compat, 176 176 buffer->buf, buffer->len, OBJ_TAG, 1)) 177 177 goto out; 178 178 if (sign_buffer(&compat_buf, &compat_sig, keyid))
+1 -1
commit.c
··· 1380 1380 struct commit_extra_header *new; 1381 1381 CALLOC_ARRAY(new, 1); 1382 1382 if (!strcmp(orig->key, "mergetag")) { 1383 - if (convert_object_file(&out, algo, compat, 1383 + if (convert_object_file(the_repository, &out, algo, compat, 1384 1384 orig->value, orig->len, 1385 1385 OBJ_TAG, 1)) { 1386 1386 free(new);
+16 -13
object-file-convert.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 1 #define DISABLE_SIGN_COMPARE_WARNINGS 3 2 4 3 #include "git-compat-util.h" ··· 63 62 return 0; 64 63 } 65 64 66 - static int convert_tree_object(struct strbuf *out, 65 + static int convert_tree_object(struct repository *repo, 66 + struct strbuf *out, 67 67 const struct git_hash_algo *from, 68 68 const struct git_hash_algo *to, 69 69 const char *buffer, size_t size) ··· 78 78 if (decode_tree_entry_raw(&entry_oid, &path, &pathlen, from, p, 79 79 end - p)) 80 80 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)) 82 82 return error(_("failed to map tree entry for %s"), oid_to_hex(&entry_oid)); 83 83 strbuf_add(out, p, path - p); 84 84 strbuf_add(out, path, pathlen); ··· 88 88 return 0; 89 89 } 90 90 91 - static int convert_tag_object(struct strbuf *out, 91 + static int convert_tag_object(struct repository *repo, 92 + struct strbuf *out, 92 93 const struct git_hash_algo *from, 93 94 const struct git_hash_algo *to, 94 95 const char *buffer, size_t size) ··· 105 106 return error("bogus tag object"); 106 107 if (parse_oid_hex_algop(buffer + 7, &oid, &p, from) < 0) 107 108 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)) 109 110 return error("unable to map tree %s in tag object", 110 111 oid_to_hex(&oid)); 111 112 size -= ((p + 1) - buffer); ··· 139 140 return 0; 140 141 } 141 142 142 - static int convert_commit_object(struct strbuf *out, 143 + static int convert_commit_object(struct repository *repo, 144 + struct strbuf *out, 143 145 const struct git_hash_algo *from, 144 146 const struct git_hash_algo *to, 145 147 const char *buffer, size_t size) ··· 165 167 (p != eol)) 166 168 return error(_("bad %s in commit"), "tree"); 167 169 168 - if (repo_oid_to_algop(the_repository, &oid, to, &mapped_oid)) 170 + if (repo_oid_to_algop(repo, &oid, to, &mapped_oid)) 169 171 return error(_("unable to map %s %s in commit object"), 170 172 "tree", oid_to_hex(&oid)); 171 173 strbuf_addf(out, "tree %s\n", oid_to_hex(&mapped_oid)); ··· 177 179 (p != eol)) 178 180 return error(_("bad %s in commit"), "parent"); 179 181 180 - if (repo_oid_to_algop(the_repository, &oid, to, &mapped_oid)) 182 + if (repo_oid_to_algop(repo, &oid, to, &mapped_oid)) 181 183 return error(_("unable to map %s %s in commit object"), 182 184 "parent", oid_to_hex(&oid)); 183 185 ··· 202 204 } 203 205 204 206 /* 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)) { 206 208 strbuf_release(&tag); 207 209 strbuf_release(&new_tag); 208 210 return -1; ··· 241 243 return 0; 242 244 } 243 245 244 - int convert_object_file(struct strbuf *outbuf, 246 + int convert_object_file(struct repository *repo, 247 + struct strbuf *outbuf, 245 248 const struct git_hash_algo *from, 246 249 const struct git_hash_algo *to, 247 250 const void *buf, size_t len, ··· 256 259 257 260 switch (type) { 258 261 case OBJ_COMMIT: 259 - ret = convert_commit_object(outbuf, from, to, buf, len); 262 + ret = convert_commit_object(repo, outbuf, from, to, buf, len); 260 263 break; 261 264 case OBJ_TREE: 262 - ret = convert_tree_object(outbuf, from, to, buf, len); 265 + ret = convert_tree_object(repo, outbuf, from, to, buf, len); 263 266 break; 264 267 case OBJ_TAG: 265 - ret = convert_tag_object(outbuf, from, to, buf, len); 268 + ret = convert_tag_object(repo, outbuf, from, to, buf, len); 266 269 break; 267 270 default: 268 271 /* Not implemented yet, so fail. */
+2 -1
object-file-convert.h
··· 14 14 * Convert an object file from one hash algorithm to another algorithm. 15 15 * Return -1 on failure, 0 on success. 16 16 */ 17 - int convert_object_file(struct strbuf *outbuf, 17 + int convert_object_file(struct repository *repo, 18 + struct strbuf *outbuf, 18 19 const struct git_hash_algo *from, 19 20 const struct git_hash_algo *to, 20 21 const void *buf, size_t len,
+4 -3
object-file.c
··· 1793 1793 if (type == -1) 1794 1794 return -1; 1795 1795 if (type != OBJ_BLOB) { 1796 - ret = convert_object_file(&outbuf, 1796 + ret = convert_object_file(the_repository, &outbuf, 1797 1797 the_hash_algo, input_algo, 1798 1798 content, size, type, !do_die); 1799 1799 free(content); ··· 2510 2510 hash_object_file(compat, buf, len, type, &compat_oid); 2511 2511 else { 2512 2512 struct strbuf converted = STRBUF_INIT; 2513 - convert_object_file(&converted, algo, compat, 2513 + convert_object_file(the_repository, &converted, algo, compat, 2514 2514 buf, len, type, 0); 2515 2515 hash_object_file(compat, converted.buf, converted.len, 2516 2516 type, &compat_oid); ··· 2550 2550 &compat_oid); 2551 2551 else if (compat_type != -1) { 2552 2552 struct strbuf converted = STRBUF_INIT; 2553 - convert_object_file(&converted, algo, compat, 2553 + convert_object_file(the_repository, 2554 + &converted, algo, compat, 2554 2555 buf, len, compat_type, 0); 2555 2556 hash_object_file(compat, converted.buf, converted.len, 2556 2557 compat_type, &compat_oid);