cache.h: add repository argument to oid_object_info

Add a repository argument to allow the callers of oid_object_info to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet. As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time. Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Apr 25, 2018 at 11:20 UTC 0df8e96566ddcae4adc4efc096944c064f60b8bd
32 files changed +67 -53
archive-tar.c
+1 -1
@@ -276,7 +276,7 @@ static int write_tar_entry(struct archiver_args *args,
276 memcpy(header.name, path, pathlen);
277
278 if (S_ISREG(mode) && !args->convert &&
279 - oid_object_info(oid, &size) == OBJ_BLOB &&
279 + oid_object_info(the_repository, oid, &size) == OBJ_BLOB &&
280 size > big_file_threshold)
281 buffer = NULL;
282 else if (S_ISLNK(mode) || S_ISREG(mode)) {
archive-zip.c
+2 -1
@@ -325,7 +325,8 @@ static int write_zip_entry(struct archiver_args *args,
325 compressed_size = 0;
326 buffer = NULL;
327 } else if (S_ISREG(mode) || S_ISLNK(mode)) {
328 - enum object_type type = oid_object_info(oid, &size);
328 + enum object_type type = oid_object_info(the_repository, oid,
329 + &size);
330
331 method = 0;
332 attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
blame.c
+2 -2
@@ -81,7 +81,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
81 unsigned mode;
82
83 if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
84 - oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
84 + oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB)
85 return;
86 }
87
@@ -504,7 +504,7 @@ static int fill_blob_sha1_and_mode(struct blame_origin *origin)
504 return 0;
505 if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
506 goto error_out;
507 - if (oid_object_info(&origin->blob_oid, NULL) != OBJ_BLOB)
507 + if (oid_object_info(the_repository, &origin->blob_oid, NULL) != OBJ_BLOB)
508 goto error_out;
509 return 0;
510 error_out:
builtin/blame.c
+1 -1
@@ -655,7 +655,7 @@ static int is_a_rev(const char *name)
655
656 if (get_oid(name, &oid))
657 return 0;
658 - return OBJ_NONE < oid_object_info(&oid, NULL);
658 + return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
659 }
660
661 int cmd_blame(int argc, const char **argv, const char *prefix)
builtin/cat-file.c
+3 -3
@@ -116,7 +116,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
116 /* else fallthrough */
117
118 case 'p':
119 - type = oid_object_info(&oid, NULL);
119 + type = oid_object_info(the_repository, &oid, NULL);
120 if (type < 0)
121 die("Not a valid object name %s", obj_name);
122
@@ -140,7 +140,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
140 case 0:
141 if (type_from_string(exp_type) == OBJ_BLOB) {
142 struct object_id blob_oid;
143 - if (oid_object_info(&oid, NULL) == OBJ_TAG) {
143 + if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
144 char *buffer = read_object_file(&oid, &type,
145 &size);
146 const char *target;
@@ -151,7 +151,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
151 } else
152 oidcpy(&blob_oid, &oid);
153
154 - if (oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
154 + if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB)
155 return stream_blob_to_fd(1, &blob_oid, NULL, 0);
156 /*
157 * we attempted to dereference a tag to a blob
builtin/describe.c
+1 -1
@@ -502,7 +502,7 @@ static void describe(const char *arg, int last_one)
502
503 if (cmit)
504 describe_commit(&oid, &sb);
505 - else if (oid_object_info(&oid, NULL) == OBJ_BLOB)
505 + else if (oid_object_info(the_repository, &oid, NULL) == OBJ_BLOB)
506 describe_blob(oid, &sb);
507 else
508 die(_("%s is neither a commit nor blob"), arg);
builtin/fast-export.c
+1 -1
@@ -947,7 +947,7 @@ static void import_marks(char *input_file)
947 if (last_idnum < mark)
948 last_idnum = mark;
949
950 - type = oid_object_info(&oid, NULL);
950 + type = oid_object_info(the_repository, &oid, NULL);
951 if (type < 0)
952 die("object not found: %s", oid_to_hex(&oid));
953
builtin/fetch.c
+1 -1
@@ -637,7 +637,7 @@ static int update_local_ref(struct ref *ref,
637 struct branch *current_branch = branch_get(NULL);
638 const char *pretty_ref = prettify_refname(ref->name);
639
640 - type = oid_object_info(&ref->new_oid, NULL);
640 + type = oid_object_info(the_repository, &ref->new_oid, NULL);
641 if (type < 0)
642 die(_("object %s not found"), oid_to_hex(&ref->new_oid));
643
builtin/fsck.c
+2 -1
@@ -67,7 +67,8 @@ static const char *printable_type(struct object *obj)
67 const char *ret;
68
69 if (obj->type == OBJ_NONE) {
70 - enum object_type type = oid_object_info(&obj->oid, NULL);
70 + enum object_type type = oid_object_info(the_repository,
71 + &obj->oid, NULL);
72 if (type > 0)
73 object_as_type(obj, type, 0);
74 }
builtin/index-pack.c
+2 -2
@@ -223,7 +223,7 @@ static unsigned check_object(struct object *obj)
223
224 if (!(obj->flags & FLAG_CHECKED)) {
225 unsigned long size;
226 - int type = oid_object_info(&obj->oid, &size);
226 + int type = oid_object_info(the_repository, &obj->oid, &size);
227 if (type <= 0)
228 die(_("did not receive expected object %s"),
229 oid_to_hex(&obj->oid));
@@ -812,7 +812,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
812 enum object_type has_type;
813 unsigned long has_size;
814 read_lock();
815 - has_type = oid_object_info(oid, &has_size);
815 + has_type = oid_object_info(the_repository, oid, &has_size);
816 if (has_type < 0)
817 die(_("cannot read existing object info %s"), oid_to_hex(oid));
818 if (has_type != type || has_size != size)
builtin/ls-tree.c
+1 -1
@@ -94,7 +94,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
94 char size_text[24];
95 if (!strcmp(type, blob_type)) {
96 unsigned long size;
97 - if (oid_object_info(oid, &size) == OBJ_BAD)
97 + if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
98 xsnprintf(size_text, sizeof(size_text),
99 "BAD");
100 else
builtin/mktree.c
+1 -1
@@ -116,7 +116,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
116 }
117
118 /* Check the type of object identified by sha1 */
119 - obj_type = oid_object_info(&oid, NULL);
119 + obj_type = oid_object_info(the_repository, &oid, NULL);
120 if (obj_type < 0) {
121 if (allow_missing) {
122 ; /* no problem - missing objects are presumed to be of the right type */
builtin/pack-objects.c
+5 -3
@@ -1516,7 +1516,8 @@ static void check_object(struct object_entry *entry)
1516 unuse_pack(&w_curs);
1517 }
1518
1519 - entry->type = oid_object_info(&entry->idx.oid, &entry->size);
1519 + entry->type = oid_object_info(the_repository, &entry->idx.oid,
1520 + &entry->size);
1521 /*
1522 * The error condition is checked in prepare_pack(). This is
1523 * to permit a missing preferred base object to be ignored
@@ -1578,7 +1579,8 @@ static void drop_reused_delta(struct object_entry *entry)
1579 * And if that fails, the error will be recorded in entry->type
1580 * and dealt with in prepare_pack().
1581 */
1581 - entry->type = oid_object_info(&entry->idx.oid, &entry->size);
1582 + entry->type = oid_object_info(the_repository, &entry->idx.oid,
1583 + &entry->size);
1584 }
1585 }
1586
@@ -2706,7 +2708,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
2708 static int add_loose_object(const struct object_id *oid, const char *path,
2709 void *data)
2710 {
2709 - enum object_type type = oid_object_info(oid, NULL);
2711 + enum object_type type = oid_object_info(the_repository, oid, NULL);
2712
2713 if (type < 0) {
2714 warning("loose object at %s could not be examined", path);
builtin/prune.c
+2 -1
@@ -50,7 +50,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
50 if (st.st_mtime > expire)
51 return 0;
52 if (show_only || verbose) {
53 - enum object_type type = oid_object_info(oid, NULL);
53 + enum object_type type = oid_object_info(the_repository, oid,
54 + NULL);
55 printf("%s %s\n", oid_to_hex(oid),
56 (type > 0) ? type_name(type) : "unknown");
57 }
builtin/replace.c
+6 -5
@@ -55,8 +55,9 @@ static int show_reference(const char *refname, const struct object_id *oid,
55 if (get_oid(refname, &object))
56 return error("Failed to resolve '%s' as a valid ref.", refname);
57
58 - obj_type = oid_object_info(&object, NULL);
59 - repl_type = oid_object_info(oid, NULL);
58 + obj_type = oid_object_info(the_repository, &object,
59 + NULL);
60 + repl_type = oid_object_info(the_repository, oid, NULL);
61
62 printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
63 oid_to_hex(oid), type_name(repl_type));
@@ -164,8 +165,8 @@ static int replace_object_oid(const char *object_ref,
165 struct ref_transaction *transaction;
166 struct strbuf err = STRBUF_INIT;
167
167 - obj_type = oid_object_info(object, NULL);
168 - repl_type = oid_object_info(repl, NULL);
168 + obj_type = oid_object_info(the_repository, object, NULL);
169 + repl_type = oid_object_info(the_repository, repl, NULL);
170 if (!force && obj_type != repl_type)
171 die("Objects must be of the same type.\n"
172 "'%s' points to a replaced object of type '%s'\n"
@@ -292,7 +293,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
293 if (get_oid(object_ref, &old_oid) < 0)
294 die("Not a valid object name: '%s'", object_ref);
295
295 - type = oid_object_info(&old_oid, NULL);
296 + type = oid_object_info(the_repository, &old_oid, NULL);
297 if (type < 0)
298 die("unable to get object type for %s", oid_to_hex(&old_oid));
299
builtin/tag.c
+2 -2
@@ -212,7 +212,7 @@ static void create_tag(const struct object_id *object, const char *tag,
212 struct strbuf header = STRBUF_INIT;
213 char *path = NULL;
214
215 - type = oid_object_info(object, NULL);
215 + type = oid_object_info(the_repository, object, NULL);
216 if (type <= OBJ_NONE)
217 die(_("bad object type."));
218
@@ -298,7 +298,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
298 }
299
300 strbuf_addstr(sb, " (");
301 - type = oid_object_info(oid, NULL);
301 + type = oid_object_info(the_repository, oid, NULL);
302 switch (type) {
303 default:
304 strbuf_addstr(sb, "object of unknown type");
builtin/unpack-objects.c
+1 -1
@@ -199,7 +199,7 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op
199
200 if (!(obj->flags & FLAG_OPEN)) {
201 unsigned long size;
202 - int type = oid_object_info(&obj->oid, &size);
202 + int type = oid_object_info(the_repository, &obj->oid, &size);
203 if (type != obj->type || type <= 0)
204 die("object of unexpected type");
205 obj->flags |= FLAG_WRITTEN;
cache.h
+2 -1
@@ -1192,7 +1192,8 @@ static inline void *read_object_file(const struct object_id *oid, enum object_ty
1192 }
1193
1194 /* Read and unpack an object file into memory, write memory to an object file */
1195 -extern int oid_object_info(const struct object_id *, unsigned long *);
1195 +#define oid_object_info(r, o, f) oid_object_info_##r(o, f)
1196 +int oid_object_info_the_repository(const struct object_id *, unsigned long *);
1197
1198 extern int hash_object_file(const void *buf, unsigned long len,
1199 const char *type, struct object_id *oid);
diff.c
+2 -1
@@ -3638,7 +3638,8 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
3638 else {
3639 enum object_type type;
3640 if (size_only || (flags & CHECK_BINARY)) {
3641 - type = oid_object_info(&s->oid, &s->size);
3641 + type = oid_object_info(the_repository, &s->oid,
3642 + &s->size);
3643 if (type < 0)
3644 die("unable to read %s",
3645 oid_to_hex(&s->oid));
fast-import.c
+9 -5
@@ -1917,7 +1917,8 @@ static void read_marks(void)
1917 die("corrupt mark line: %s", line);
1918 e = find_object(&oid);
1919 if (!e) {
1920 - enum object_type type = oid_object_info(&oid, NULL);
1920 + enum object_type type = oid_object_info(the_repository,
1921 + &oid, NULL);
1922 if (type < 0)
1923 die("object not found: %s", oid_to_hex(&oid));
1924 e = insert_object(&oid);
@@ -2447,7 +2448,8 @@ static void file_change_m(const char *p, struct branch *b)
2448 enum object_type expected = S_ISDIR(mode) ?
2449 OBJ_TREE: OBJ_BLOB;
2450 enum object_type type = oe ? oe->type :
2450 - oid_object_info(&oid, NULL);
2451 + oid_object_info(the_repository, &oid,
2452 + NULL);
2453 if (type < 0)
2454 die("%s not found: %s",
2455 S_ISDIR(mode) ? "Tree" : "Blob",
@@ -2608,7 +2610,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
2610 die("Not a blob (actually a %s): %s",
2611 type_name(oe->type), command_buf.buf);
2612 } else if (!is_null_oid(&oid)) {
2611 - enum object_type type = oid_object_info(&oid, NULL);
2613 + enum object_type type = oid_object_info(the_repository, &oid,
2614 + NULL);
2615 if (type < 0)
2616 die("Blob not found: %s", command_buf.buf);
2617 if (type != OBJ_BLOB)
@@ -2895,7 +2898,7 @@ static void parse_new_tag(const char *arg)
2898 } else if (!get_oid(from, &oid)) {
2899 struct object_entry *oe = find_object(&oid);
2900 if (!oe) {
2898 - type = oid_object_info(&oid, NULL);
2901 + type = oid_object_info(the_repository, &oid, NULL);
2902 if (type < 0)
2903 die("Not a valid object: %s", from);
2904 } else
@@ -3053,7 +3056,8 @@ static struct object_entry *dereference(struct object_entry *oe,
3056 unsigned long size;
3057 char *buf = NULL;
3058 if (!oe) {
3056 - enum object_type type = oid_object_info(oid, NULL);
3059 + enum object_type type = oid_object_info(the_repository, oid,
3060 + NULL);
3061 if (type < 0)
3062 die("object not found: %s", oid_to_hex(oid));
3063 /* cache it! */
list-objects-filter.c
+1 -1
@@ -117,7 +117,7 @@ static enum list_objects_filter_result filter_blobs_limit(
117 assert(obj->type == OBJ_BLOB);
118 assert((obj->flags & SEEN) == 0);
119
120 - t = oid_object_info(&obj->oid, &object_length);
120 + t = oid_object_info(the_repository, &obj->oid, &object_length);
121 if (t != OBJ_BLOB) { /* probably OBJ_NONE */
122 /*
123 * We DO NOT have the blob locally, so we cannot
object.c
+1 -1
@@ -257,7 +257,7 @@ struct object *parse_object(const struct object_id *oid)
257
258 if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
259 (!obj && has_object_file(oid) &&
260 - oid_object_info(oid, NULL) == OBJ_BLOB)) {
260 + oid_object_info(the_repository, oid, NULL) == OBJ_BLOB)) {
261 if (check_object_signature(repl, NULL, 0, NULL) < 0) {
262 error("sha1 mismatch %s", oid_to_hex(oid));
263 return NULL;
pack-bitmap-write.c
+2 -1
@@ -73,7 +73,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
73 break;
74
75 default:
76 - real_type = oid_object_info(&entry->idx.oid, NULL);
76 + real_type = oid_object_info(the_repository,
77 + &entry->idx.oid, NULL);
78 break;
79 }
80
packfile.c
+1 -1
@@ -1114,7 +1114,7 @@ static int retry_bad_packed_offset(struct packed_git *p, off_t obj_offset)
1114 return OBJ_BAD;
1115 nth_packed_object_oid(&oid, p, revidx->nr);
1116 mark_bad_packed_object(p, oid.hash);
1117 - type = oid_object_info(&oid, NULL);
1117 + type = oid_object_info(the_repository, &oid, NULL);
1118 if (type <= OBJ_NONE)
1119 return OBJ_BAD;
1120 return type;
reachable.c
+1 -1
@@ -78,7 +78,7 @@ static void add_recent_object(const struct object_id *oid,
78 * later processing, and the revision machinery expects
79 * commits and tags to have been parsed.
80 */
81 - type = oid_object_info(oid, NULL);
81 + type = oid_object_info(the_repository, oid, NULL);
82 if (type < 0)
83 die("unable to get object info for %s", oid_to_hex(oid));
84
refs.c
+1 -1
@@ -302,7 +302,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid
302 struct object *o = lookup_unknown_object(name->hash);
303
304 if (o->type == OBJ_NONE) {
305 - int type = oid_object_info(name, NULL);
305 + int type = oid_object_info(the_repository, name, NULL);
306 if (type < 0 || !object_as_type(o, type, 0))
307 return PEEL_INVALID;
308 }
remote.c
+1 -1
@@ -1376,7 +1376,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
1376 continue; /* not a tag */
1377 if (string_list_has_string(&dst_tag, ref->name))
1378 continue; /* they already have it */
1379 - if (oid_object_info(&ref->new_oid, NULL) != OBJ_TAG)
1379 + if (oid_object_info(the_repository, &ref->new_oid, NULL) != OBJ_TAG)
1380 continue; /* be conservative */
1381 item = string_list_append(&src_tag, ref->name);
1382 item->util = ref;
sequencer.c
+2 -1
@@ -2876,7 +2876,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
2876
2877 if (!get_oid(name, &oid)) {
2878 if (!lookup_commit_reference_gently(&oid, 1)) {
2879 - enum object_type type = oid_object_info(&oid,
2879 + enum object_type type = oid_object_info(the_repository,
2880 + &oid,
2881 NULL);
2882 return error(_("%s: can't cherry-pick a %s"),
2883 name, type_name(type));
sha1_file.c
+2 -2
@@ -1322,7 +1322,7 @@ int oid_object_info_extended_the_repository(const struct object_id *oid, struct
1322 }
1323
1324 /* returns enum object_type or negative */
1325 -int oid_object_info(const struct object_id *oid, unsigned long *sizep)
1325 +int oid_object_info_the_repository(const struct object_id *oid, unsigned long *sizep)
1326 {
1327 enum object_type type;
1328 struct object_info oi = OBJECT_INFO_INIT;
@@ -1988,7 +1988,7 @@ int read_pack_header(int fd, struct pack_header *header)
1988
1989 void assert_oid_type(const struct object_id *oid, enum object_type expect)
1990 {
1991 - enum object_type type = oid_object_info(oid, NULL);
1991 + enum object_type type = oid_object_info(the_repository, oid, NULL);
1992 if (type < 0)
1993 die("%s is not a valid object", oid_to_hex(oid));
1994 if (type != expect)
sha1_name.c
+6 -6
@@ -223,7 +223,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
223
224 static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
225 {
226 - int kind = oid_object_info(oid, NULL);
226 + int kind = oid_object_info(the_repository, oid, NULL);
227 return kind == OBJ_COMMIT;
228 }
229
@@ -232,7 +232,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
232 struct object *obj;
233 int kind;
234
235 - kind = oid_object_info(oid, NULL);
235 + kind = oid_object_info(the_repository, oid, NULL);
236 if (kind == OBJ_COMMIT)
237 return 1;
238 if (kind != OBJ_TAG)
@@ -247,7 +247,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
247
248 static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
249 {
250 - int kind = oid_object_info(oid, NULL);
250 + int kind = oid_object_info(the_repository, oid, NULL);
251 return kind == OBJ_TREE;
252 }
253
@@ -256,7 +256,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
256 struct object *obj;
257 int kind;
258
259 - kind = oid_object_info(oid, NULL);
259 + kind = oid_object_info(the_repository, oid, NULL);
260 if (kind == OBJ_TREE || kind == OBJ_COMMIT)
261 return 1;
262 if (kind != OBJ_TAG)
@@ -271,7 +271,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
271
272 static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
273 {
274 - int kind = oid_object_info(oid, NULL);
274 + int kind = oid_object_info(the_repository, oid, NULL);
275 return kind == OBJ_BLOB;
276 }
277
@@ -350,7 +350,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
350 if (ds->fn && !ds->fn(oid, ds->cb_data))
351 return 0;
352
353 - type = oid_object_info(oid, NULL);
353 + type = oid_object_info(the_repository, oid, NULL);
354 if (type == OBJ_COMMIT) {
355 struct commit *commit = lookup_commit(oid);
356 if (commit) {
submodule.c
+1 -1
@@ -818,7 +818,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
818 {
819 struct has_commit_data *cb = data;
820
821 - enum object_type type = oid_object_info(oid, NULL);
821 + enum object_type type = oid_object_info(the_repository, oid, NULL);
822
823 switch (type) {
824 case OBJ_COMMIT:
tag.c
+1 -1
@@ -41,7 +41,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
41 unsigned long size;
42 int ret;
43
44 - type = oid_object_info(oid, NULL);
44 + type = oid_object_info(the_repository, oid, NULL);
45 if (type != OBJ_TAG)
46 return error("%s: cannot verify a non-tag object of type %s.",
47 name_to_report ?