From 109cd76dd3467bd05f8d2145b857006649741d5c Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:51 -0700 Subject: object: add repository argument to parse_object Add a repository argument to allow the callers of parse_object to be more specific about which repository to act on. 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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 4736151..d8db8f6 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -5,6 +5,7 @@ #include "log-tree.h" #include "builtin.h" #include "submodule.h" +#include "repository.h" static struct rev_info log_tree_opt; @@ -68,7 +69,7 @@ static int diff_tree_stdin(char *line) line[len-1] = 0; if (parse_oid_hex(line, &oid, &p)) return -1; - obj = parse_object(&oid); + obj = parse_object(the_repository, &oid); if (!obj) return -1; if (obj->type == OBJ_COMMIT) diff --git a/builtin/diff.c b/builtin/diff.c index b709b6e..d0421c9 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -400,7 +400,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) const char *name = entry->name; int flags = (obj->flags & UNINTERESTING); if (!obj->parsed) - obj = parse_object(&obj->oid); + obj = parse_object(the_repository, &obj->oid); obj = deref_tag(obj, NULL, 0); if (!obj) die(_("invalid object '%s' given."), name); diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 9ee6a4d..a16aeaa 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -801,7 +801,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name) /* handle nested tags */ while (tag && tag->object.type == OBJ_TAG) { - parse_object(&tag->object.oid); + parse_object(the_repository, &tag->object.oid); string_list_append(&extra_refs, full_name)->util = tag; tag = (struct tag *)tag->tagged; } diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 1b526ad..5e44589 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -11,6 +11,7 @@ #include "branch.h" #include "fmt-merge-msg.h" #include "gpg-interface.h" +#include "repository.h" static const char * const fmt_merge_msg_usage[] = { N_("git fmt-merge-msg [-m ] [--log[=] | --no-log] [--file ]"), @@ -343,7 +344,8 @@ static void shortlog(const char *name, const struct object_id *oid = &origin_data->oid; int limit = opts->shortlog_len; - branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ); + branch = deref_tag(parse_object(the_repository, oid), oid_to_hex(oid), + GIT_SHA1_HEXSZ); if (!branch || branch->type != OBJ_COMMIT) return; @@ -563,7 +565,7 @@ static void find_merge_parents(struct merge_parents *result, * "name" here and we do not want to contaminate its * util field yet. */ - obj = parse_object(&oid); + obj = parse_object(the_repository, &oid); parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT); if (!parent) continue; diff --git a/builtin/fsck.c b/builtin/fsck.c index 3ad4f16..2b09301 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -452,7 +452,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, { struct object *obj; - obj = parse_object(oid); + obj = parse_object(the_repository, oid); if (!obj) { if (is_promisor_object(oid)) { /* @@ -614,7 +614,7 @@ static int fsck_cache_tree(struct cache_tree *it) fprintf(stderr, "Checking cache tree\n"); if (0 <= it->entry_count) { - struct object *obj = parse_object(&it->oid); + struct object *obj = parse_object(the_repository, &it->oid); if (!obj) { error("%s: invalid sha1 pointer in cache-tree", oid_to_hex(&it->oid)); diff --git a/builtin/log.c b/builtin/log.c index c77af79..0521759 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -30,6 +30,7 @@ #include "gpg-interface.h" #include "progress.h" #include "commit-slab.h" +#include "repository.h" #define MAIL_DEFAULT_WRAP 72 @@ -619,7 +620,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) rev.shown_one = 1; if (ret) break; - o = parse_object(&t->tagged->oid); + o = parse_object(the_repository, &t->tagged->oid); if (!o) ret = error(_("Could not read object %s"), oid_to_hex(&t->tagged->oid)); diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 0eb4403..de54fa9 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "repository.h" #include "config.h" #include "commit.h" #include "tag.h" @@ -203,7 +204,7 @@ static int tipcmp(const void *a_, const void *b_) static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data) { - struct object *o = parse_object(oid); + struct object *o = parse_object(the_repository, oid); struct name_ref_data *data = cb_data; int can_abbreviate_output = data->tags_only && data->name_only; int deref = 0; @@ -261,7 +262,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo struct tag *t = (struct tag *) o; if (!t->tagged) break; /* broken repository */ - o = parse_object(&t->tagged->oid); + o = parse_object(the_repository, &t->tagged->oid); deref = 1; taggerdate = t->date; } @@ -451,7 +452,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) } commit = NULL; - object = parse_object(&oid); + object = parse_object(the_repository, &oid); if (object) { struct object *peeled = deref_tag(object, *argv, 0); if (peeled && peeled->type == OBJ_COMMIT) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 44c7c9e..400d31c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1108,8 +1108,8 @@ static const char *update(struct command *cmd, struct shallow_info *si) struct object *old_object, *new_object; struct commit *old_commit, *new_commit; - old_object = parse_object(old_oid); - new_object = parse_object(new_oid); + old_object = parse_object(the_repository, old_oid); + new_object = parse_object(the_repository, new_oid); if (!old_object || !new_object || old_object->type != OBJ_COMMIT || @@ -1132,7 +1132,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) if (is_null_oid(new_oid)) { struct strbuf err = STRBUF_INIT; - if (!parse_object(old_oid)) { + if (!parse_object(the_repository, old_oid)) { old_oid = NULL; if (ref_exists(name)) { rp_warning("Allowing deletion of corrupt ref."); diff --git a/builtin/reflog.c b/builtin/reflog.c index 00911929..948002b 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -2,6 +2,7 @@ #include "config.h" #include "lockfile.h" #include "object-store.h" +#include "repository.h" #include "commit.h" #include "refs.h" #include "dir.h" @@ -129,7 +130,7 @@ static int commit_is_complete(struct commit *commit) struct commit_list *parent; c = (struct commit *)object_array_pop(&study); - if (!c->object.parsed && !parse_object(&c->object.oid)) + if (!c->object.parsed && !parse_object(the_repository, &c->object.oid)) c->object.flags |= INCOMPLETE; if (c->object.flags & INCOMPLETE) { diff --git a/builtin/rev-list.c b/builtin/rev-list.c index e9bd4e3..cbaaae8 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -239,7 +239,7 @@ static int finish_object(struct object *obj, const char *name, void *cb_data) return 1; } if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT) - parse_object(&obj->oid); + parse_object(the_repository, &obj->oid); return 0; } diff --git a/bundle.c b/bundle.c index ba18e25..8283fff 100644 --- a/bundle.c +++ b/bundle.c @@ -2,6 +2,7 @@ #include "lockfile.h" #include "bundle.h" #include "object-store.h" +#include "repository.h" #include "object.h" #include "commit.h" #include "diff.h" @@ -142,7 +143,7 @@ int verify_bundle(struct bundle_header *header, int verbose) init_revisions(&revs, NULL); for (i = 0; i < p->nr; i++) { struct ref_list_entry *e = p->list + i; - struct object *o = parse_object(&e->oid); + struct object *o = parse_object(the_repository, &e->oid); if (o) { o->flags |= PREREQ_MARK; add_pending_object(&revs, o, e->name); @@ -167,7 +168,7 @@ int verify_bundle(struct bundle_header *header, int verbose) for (i = 0; i < p->nr; i++) { struct ref_list_entry *e = p->list + i; - struct object *o = parse_object(&e->oid); + struct object *o = parse_object(the_repository, &e->oid); assert(o); /* otherwise we'd have returned early */ if (o->flags & SHOWN) continue; diff --git a/commit.c b/commit.c index a7c0b5f..a29070a 100644 --- a/commit.c +++ b/commit.c @@ -27,7 +27,8 @@ const char *commit_type = "commit"; struct commit *lookup_commit_reference_gently(const struct object_id *oid, int quiet) { - struct object *obj = deref_tag(parse_object(oid), NULL, 0); + struct object *obj = deref_tag(parse_object(the_repository, oid), + NULL, 0); if (!obj) return NULL; @@ -1692,7 +1693,7 @@ struct commit *get_merge_parent(const char *name) struct object_id oid; if (get_oid(name, &oid)) return NULL; - obj = parse_object(&oid); + obj = parse_object(the_repository, &oid); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); if (commit && !merge_remote_util(commit)) set_merge_remote_desc(commit, name, obj); diff --git a/fetch-pack.c b/fetch-pack.c index dbd879a..6b406f1 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -84,7 +84,7 @@ static void cache_one_alternate(const char *refname, void *vcache) { struct alternate_object_cache *cache = vcache; - struct object *obj = parse_object(oid); + struct object *obj = parse_object(the_repository, oid); if (!obj || (obj->flags & ALTERNATE)) return; @@ -126,7 +126,8 @@ static void rev_list_push(struct commit *commit, int mark) static int rev_list_insert_ref(const char *refname, const struct object_id *oid) { - struct object *o = deref_tag(parse_object(oid), refname, 0); + struct object *o = deref_tag(parse_object(the_repository, oid), + refname, 0); if (o && o->type == OBJ_COMMIT) rev_list_push((struct commit *)o, SEEN); @@ -143,7 +144,8 @@ static int rev_list_insert_ref_oid(const char *refname, const struct object_id * static int clear_marks(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - struct object *o = deref_tag(parse_object(oid), refname, 0); + struct object *o = deref_tag(parse_object(the_repository, oid), + refname, 0); if (o && o->type == OBJ_COMMIT) clear_commit_marks((struct commit *)o, @@ -437,7 +439,7 @@ static int find_common(struct fetch_pack_args *args, if (!lookup_object(oid.hash)) die(_("object not found: %s"), line); /* make sure that it is parsed as shallow */ - if (!parse_object(&oid)) + if (!parse_object(the_repository, &oid)) die(_("error in object: %s"), line); if (unregister_shallow(&oid)) die(_("no shallow found: %s"), line); @@ -570,14 +572,14 @@ static struct commit_list *complete; static int mark_complete(const struct object_id *oid) { - struct object *o = parse_object(oid); + struct object *o = parse_object(the_repository, oid); while (o && o->type == OBJ_TAG) { struct tag *t = (struct tag *) o; if (!t->tagged) break; /* broken repository */ o->flags |= COMPLETE; - o = parse_object(&t->tagged->oid); + o = parse_object(the_repository, &t->tagged->oid); } if (o && o->type == OBJ_COMMIT) { struct commit *commit = (struct commit *)o; @@ -768,7 +770,7 @@ static int everything_local(struct fetch_pack_args *args, if (!has_object_file_with_flags(&ref->old_oid, flags)) continue; - o = parse_object(&ref->old_oid); + o = parse_object(the_repository, &ref->old_oid); if (!o) continue; @@ -1318,7 +1320,7 @@ static void receive_shallow_info(struct fetch_pack_args *args, if (!lookup_object(oid.hash)) die(_("object not found: %s"), reader->line); /* make sure that it is parsed as shallow */ - if (!parse_object(&oid)) + if (!parse_object(the_repository, &oid)) die(_("error in object: %s"), reader->line); if (unregister_shallow(&oid)) die(_("no shallow found: %s"), reader->line); diff --git a/fsck.c b/fsck.c index 4dfe65f..bb3d622 100644 --- a/fsck.c +++ b/fsck.c @@ -1,5 +1,6 @@ #include "cache.h" #include "object-store.h" +#include "repository.h" #include "object.h" #include "blob.h" #include "tree.h" @@ -511,7 +512,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options) return -1; if (obj->type == OBJ_NONE) - parse_object(&obj->oid); + parse_object(the_repository, &obj->oid); switch (obj->type) { case OBJ_BLOB: diff --git a/http-backend.c b/http-backend.c index adaef16..50ba4d5 100644 --- a/http-backend.c +++ b/http-backend.c @@ -436,7 +436,7 @@ static int show_text_ref(const char *name, const struct object_id *oid, { const char *name_nons = strip_namespace(name); struct strbuf *buf = cb_data; - struct object *o = parse_object(oid); + struct object *o = parse_object(the_repository, oid); if (!o) return 0; diff --git a/http-push.c b/http-push.c index 7e38522..37cbf07 100644 --- a/http-push.c +++ b/http-push.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "repository.h" #include "commit.h" #include "tag.h" #include "blob.h" @@ -14,6 +15,7 @@ #include "packfile.h" #include "object-store.h" + #ifdef EXPAT_NEEDS_XMLPARSE_H #include #else @@ -722,7 +724,7 @@ static void one_remote_object(const struct object_id *oid) obj = lookup_object(oid->hash); if (!obj) - obj = parse_object(oid); + obj = parse_object(the_repository, oid); /* Ignore remote objects that don't exist locally */ if (!obj) @@ -1459,7 +1461,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls) return; } - o = parse_object(&ref->old_oid); + o = parse_object(the_repository, &ref->old_oid); if (!o) { fprintf(stderr, "Unable to parse object %s for remote ref %s\n", diff --git a/log-tree.c b/log-tree.c index 4a3907f..0eb7c60 100644 --- a/log-tree.c +++ b/log-tree.c @@ -2,6 +2,7 @@ #include "config.h" #include "diff.h" #include "object-store.h" +#include "repository.h" #include "commit.h" #include "tag.h" #include "graph.h" @@ -98,13 +99,13 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, warning("invalid replace ref %s", refname); return 0; } - obj = parse_object(&original_oid); + obj = parse_object(the_repository, &original_oid); if (obj) add_name_decoration(DECORATION_GRAFTED, "replaced", obj); return 0; } - obj = parse_object(oid); + obj = parse_object(the_repository, oid); if (!obj) return 0; @@ -125,7 +126,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, if (!obj) break; if (!obj->parsed) - parse_object(&obj->oid); + parse_object(the_repository, &obj->oid); add_name_decoration(DECORATION_REF_TAG, refname, obj); } return 0; diff --git a/merge-recursive.c b/merge-recursive.c index 0e9f5a6..63bc0e2 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -9,6 +9,7 @@ #include "lockfile.h" #include "cache-tree.h" #include "object-store.h" +#include "repository.h" #include "commit.h" #include "blob.h" #include "builtin.h" @@ -3466,7 +3467,8 @@ static struct commit *get_ref(const struct object_id *oid, const char *name) { struct object *object; - object = deref_tag(parse_object(oid), name, strlen(name)); + object = deref_tag(parse_object(the_repository, oid), name, + strlen(name)); if (!object) return NULL; if (object->type == OBJ_TREE) diff --git a/object.c b/object.c index 9b0f819..bf1d9c6 100644 --- a/object.c +++ b/object.c @@ -239,14 +239,14 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type struct object *parse_object_or_die(const struct object_id *oid, const char *name) { - struct object *o = parse_object(oid); + struct object *o = parse_object(the_repository, oid); if (o) return o; die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid)); } -struct object *parse_object(const struct object_id *oid) +struct object *parse_object_the_repository(const struct object_id *oid) { unsigned long size; enum object_type type; diff --git a/object.h b/object.h index 1b96073..882f47f 100644 --- a/object.h +++ b/object.h @@ -120,7 +120,8 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet); * * Returns NULL if the object is missing or corrupt. */ -struct object *parse_object(const struct object_id *oid); +#define parse_object(r, oid) parse_object_##r(oid) +struct object *parse_object_the_repository(const struct object_id *oid); /* * Like parse_object, but will die() instead of returning NULL. If the diff --git a/packfile.c b/packfile.c index 7cd45aa..6974903 100644 --- a/packfile.c +++ b/packfile.c @@ -1934,7 +1934,7 @@ static int add_promisor_object(const struct object_id *oid, void *set_) { struct oidset *set = set_; - struct object *obj = parse_object(oid); + struct object *obj = parse_object(the_repository, oid); if (!obj) return 1; diff --git a/pretty.c b/pretty.c index 703fa6f..cbd25b6 100644 --- a/pretty.c +++ b/pretty.c @@ -1146,7 +1146,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ /* these depend on the commit */ if (!commit->object.parsed) - parse_object(&commit->object.oid); + parse_object(the_repository, &commit->object.oid); switch (placeholder[0]) { case 'H': /* commit hash */ diff --git a/ref-filter.c b/ref-filter.c index 0ab893a..044c28c 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -4,6 +4,7 @@ #include "refs.h" #include "wildmatch.h" #include "object-store.h" +#include "repository.h" #include "commit.h" #include "remote.h" #include "color.h" @@ -1914,7 +1915,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at, if (oid_array_lookup(points_at, oid) >= 0) return oid; - obj = parse_object(oid); + obj = parse_object(the_repository, oid); if (!obj) die(_("malformed object at '%s'"), refname); if (obj->type == OBJ_TAG) diff --git a/reflog-walk.c b/reflog-walk.c index 5008bbf..3561a8b 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -305,7 +305,8 @@ static struct commit *next_reflog_commit(struct commit_reflog *log) { for (; log->recno >= 0; log->recno--) { struct reflog_info *entry = &log->reflogs->items[log->recno]; - struct object *obj = parse_object(&entry->noid); + struct object *obj = parse_object(the_repository, + &entry->noid); if (obj && obj->type == OBJ_COMMIT) return (struct commit *)obj; diff --git a/refs/files-backend.c b/refs/files-backend.c index a9a066d..55c2ae0 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1660,7 +1660,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock, struct object *o; int fd; - o = parse_object(oid); + o = parse_object(the_repository, oid); if (!o) { strbuf_addf(err, "trying to write ref '%s' with nonexistent object %s", diff --git a/remote.c b/remote.c index 539285f..a5c04a0 100644 --- a/remote.c +++ b/remote.c @@ -1801,12 +1801,12 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid) * Both new_commit and old_commit must be commit-ish and new_commit is descendant of * old_commit. Otherwise we require --force. */ - o = deref_tag(parse_object(old_oid), NULL, 0); + o = deref_tag(parse_object(the_repository, old_oid), NULL, 0); if (!o || o->type != OBJ_COMMIT) return 0; old_commit = (struct commit *) o; - o = deref_tag(parse_object(new_oid), NULL, 0); + o = deref_tag(parse_object(the_repository, new_oid), NULL, 0); if (!o || o->type != OBJ_COMMIT) return 0; new_commit = (struct commit *) o; diff --git a/revision.c b/revision.c index 72abe23..8a2b285 100644 --- a/revision.c +++ b/revision.c @@ -197,7 +197,7 @@ void add_head_to_pending(struct rev_info *revs) struct object *obj; if (get_oid("HEAD", &oid)) return; - obj = parse_object(&oid); + obj = parse_object(the_repository, &oid); if (!obj) return; add_pending_object(revs, obj, "HEAD"); @@ -209,7 +209,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name, { struct object *object; - object = parse_object(oid); + object = parse_object(the_repository, oid); if (!object) { if (revs->ignore_missing) return object; @@ -246,7 +246,7 @@ static struct commit *handle_commit(struct rev_info *revs, add_pending_object(revs, object, tag->tag); if (!tag->tagged) die("bad tag"); - object = parse_object(&tag->tagged->oid); + object = parse_object(the_repository, &tag->tagged->oid); if (!object) { if (revs->ignore_missing_links || (flags & UNINTERESTING)) return NULL; @@ -1249,7 +1249,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data) { struct all_refs_cb *cb = cb_data; if (!is_null_oid(oid)) { - struct object *o = parse_object(oid); + struct object *o = parse_object(the_repository, oid); if (o) { o->flags |= cb->all_flags; /* ??? CMDLINEFLAGS ??? */ @@ -1577,8 +1577,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot, *dotdot = '\0'; } - a_obj = parse_object(&a_oid); - b_obj = parse_object(&b_oid); + a_obj = parse_object(the_repository, &a_oid); + b_obj = parse_object(the_repository, &b_oid); if (!a_obj || !b_obj) return dotdot_missing(arg, dotdot, revs, symmetric); @@ -2883,7 +2883,7 @@ static int mark_uninteresting(const struct object_id *oid, uint32_t pos, void *unused) { - struct object *o = parse_object(oid); + struct object *o = parse_object(the_repository, oid); o->flags |= UNINTERESTING | SEEN; return 0; } diff --git a/server-info.c b/server-info.c index 7ce6dcd..2abd0dc 100644 --- a/server-info.c +++ b/server-info.c @@ -56,7 +56,7 @@ static int add_info_ref(const char *path, const struct object_id *oid, int flag, void *cb_data) { FILE *fp = cb_data; - struct object *o = parse_object(oid); + struct object *o = parse_object(the_repository, oid); if (!o) return -1; diff --git a/sha1-name.c b/sha1-name.c index 60d9ef3..dd19aba 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -239,7 +239,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da return 0; /* We need to do this the hard way... */ - obj = deref_tag(parse_object(oid), NULL, 0); + obj = deref_tag(parse_object(the_repository, oid), NULL, 0); if (obj && obj->type == OBJ_COMMIT) return 1; return 0; @@ -263,7 +263,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_ return 0; /* We need to do this the hard way... */ - obj = deref_tag(parse_object(oid), NULL, 0); + obj = deref_tag(parse_object(the_repository, oid), NULL, 0); if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT)) return 1; return 0; @@ -891,7 +891,7 @@ struct object *peel_to_type(const char *name, int namelen, if (name && !namelen) namelen = strlen(name); while (1) { - if (!o || (!o->parsed && !parse_object(&o->oid))) + if (!o || (!o->parsed && !parse_object(the_repository, &o->oid))) return NULL; if (expected_type == OBJ_ANY || o->type == expected_type) return o; @@ -964,12 +964,12 @@ static int peel_onion(const char *name, int len, struct object_id *oid, if (get_oid_1(name, sp - name - 2, &outer, lookup_flags)) return -1; - o = parse_object(&outer); + o = parse_object(the_repository, &outer); if (!o) return -1; if (!expected_type) { o = deref_tag(o, name, sp - name - 2); - if (!o || (!o->parsed && !parse_object(&o->oid))) + if (!o || (!o->parsed && !parse_object(the_repository, &o->oid))) return -1; oidcpy(oid, &o->oid); return 0; @@ -1096,7 +1096,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid, int flag, void *cb_data) { struct commit_list **list = cb_data; - struct object *object = parse_object(oid); + struct object *object = parse_object(the_repository, oid); if (!object) return 0; if (object->type == OBJ_TAG) { @@ -1142,7 +1142,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid, int matches; commit = pop_most_recent_commit(&list, ONELINE_SEEN); - if (!parse_object(&commit->object.oid)) + if (!parse_object(the_repository, &commit->object.oid)) continue; buf = get_commit_buffer(commit, NULL); p = strstr(buf, "\n\n"); diff --git a/tag.c b/tag.c index 3be7206..7d282df 100644 --- a/tag.c +++ b/tag.c @@ -68,7 +68,8 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen) { while (o && o->type == OBJ_TAG) if (((struct tag *)o)->tagged) - o = parse_object(&((struct tag *)o)->tagged->oid); + o = parse_object(the_repository, + &((struct tag *)o)->tagged->oid); else o = NULL; if (!o && warn) { @@ -82,7 +83,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen) struct object *deref_tag_noverify(struct object *o) { while (o && o->type == OBJ_TAG) { - o = parse_object(&o->oid); + o = parse_object(the_repository, &o->oid); if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged) o = ((struct tag *)o)->tagged; else diff --git a/tree.c b/tree.c index bc7e990..533b6e6 100644 --- a/tree.c +++ b/tree.c @@ -8,6 +8,7 @@ #include "tag.h" #include "alloc.h" #include "tree-walk.h" +#include "repository.h" const char *tree_type = "tree"; @@ -244,7 +245,7 @@ void free_tree_buffer(struct tree *tree) struct tree *parse_tree_indirect(const struct object_id *oid) { - struct object *obj = parse_object(oid); + struct object *obj = parse_object(the_repository, oid); do { if (!obj) return NULL; @@ -257,6 +258,6 @@ struct tree *parse_tree_indirect(const struct object_id *oid) else return NULL; if (!obj->parsed) - parse_object(&obj->oid); + parse_object(the_repository, &obj->oid); } while (1); } diff --git a/upload-pack.c b/upload-pack.c index 936acab..d2b8511 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -3,6 +3,7 @@ #include "refs.h" #include "pkt-line.h" #include "sideband.h" +#include "repository.h" #include "object-store.h" #include "tag.h" #include "object.h" @@ -311,7 +312,7 @@ static int got_oid(const char *hex, struct object_id *oid) if (!has_object_file(oid)) return -1; - o = parse_object(oid); + o = parse_object(the_repository, oid); if (!o) die("oops (%s)", oid_to_hex(oid)); if (o->type == OBJ_COMMIT) { @@ -349,7 +350,7 @@ static int reachable(struct commit *want) break; } if (!commit->object.parsed) - parse_object(&commit->object.oid); + parse_object(the_repository, &commit->object.oid); if (commit->object.flags & REACHABLE) continue; commit->object.flags |= REACHABLE; @@ -800,7 +801,7 @@ static int process_shallow(const char *line, struct object_array *shallows) struct object *object; if (get_oid_hex(arg, &oid)) die("invalid shallow line: %s", line); - object = parse_object(&oid); + object = parse_object(the_repository, &oid); if (!object) return 1; if (object->type != OBJ_COMMIT) @@ -926,7 +927,7 @@ static void receive_needs(void) if (allow_filter && parse_feature_request(features, "filter")) filter_capability_requested = 1; - o = parse_object(&oid_buf); + o = parse_object(the_repository, &oid_buf); if (!o) { packet_write_fmt(1, "ERR upload-pack: not our ref %s", @@ -1167,7 +1168,7 @@ static int parse_want(const char *line) die("git upload-pack: protocol error, " "expected to get oid, not '%s'", line); - o = parse_object(&oid); + o = parse_object(the_repository, &oid); if (!o) { packet_write_fmt(1, "ERR upload-pack: not our ref %s", @@ -1279,7 +1280,7 @@ static int process_haves(struct oid_array *haves, struct oid_array *common) oid_array_append(common, oid); - o = parse_object(oid); + o = parse_object(the_repository, oid); if (!o) die("oops (%s)", oid_to_hex(oid)); if (o->type == OBJ_COMMIT) { diff --git a/walker.c b/walker.c index 86359ab..63002b1 100644 --- a/walker.c +++ b/walker.c @@ -1,5 +1,6 @@ #include "cache.h" #include "walker.h" +#include "repository.h" #include "object-store.h" #include "commit.h" #include "tree.h" @@ -178,7 +179,7 @@ static int loop(struct walker *walker) } } if (!obj->type) - parse_object(&obj->oid); + parse_object(the_repository, &obj->oid); if (process_object(walker, obj)) return -1; } -- cgit v0.10.2-6-g49f6 From 5abddd1eb72ca47cc84a9fc888c30ebaadde2eec Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:52 -0700 Subject: object: add repository argument to lookup_object Add a repository argument to allow callers of lookup_object 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 Signed-off-by: Junio C Hamano diff --git a/blob.c b/blob.c index 458dafa..75b737a 100644 --- a/blob.c +++ b/blob.c @@ -7,7 +7,7 @@ const char *blob_type = "blob"; struct blob *lookup_blob(const struct object_id *oid) { - struct object *obj = lookup_object(oid->hash); + struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) return create_object(the_repository, oid->hash, alloc_blob_node(the_repository)); diff --git a/builtin/fast-export.c b/builtin/fast-export.c index a16aeaa..e39c4e2 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -230,7 +230,7 @@ static void export_blob(const struct object_id *oid) if (is_null_oid(oid)) return; - object = lookup_object(oid->hash); + object = lookup_object(the_repository, oid->hash); if (object && object->flags & SHOWN) return; @@ -402,7 +402,8 @@ static void show_filemodify(struct diff_queue_struct *q, anonymize_sha1(&spec->oid) : spec->oid.hash)); else { - struct object *object = lookup_object(spec->oid.hash); + struct object *object = lookup_object(the_repository, + spec->oid.hash); printf("M %06o :%d ", spec->mode, get_object_mark(object)); } diff --git a/builtin/fsck.c b/builtin/fsck.c index 2b09301..12d01e9 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -410,7 +410,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, struct object *obj; if (!is_null_oid(oid)) { - obj = lookup_object(oid->hash); + obj = lookup_object(the_repository, oid->hash); if (obj && (obj->flags & HAS_OBJ)) { if (timestamp && name_objects) add_decoration(fsck_walk_options.object_names, @@ -763,7 +763,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) const char *arg = argv[i]; struct object_id oid; if (!get_oid(arg, &oid)) { - struct object *obj = lookup_object(oid.hash); + struct object *obj = lookup_object(the_repository, + oid.hash); if (!obj || !(obj->flags & HAS_OBJ)) { if (is_promisor_object(&oid)) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index de54fa9..f6eb419 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -379,7 +379,8 @@ static void name_rev_line(char *p, struct name_ref_data *data) *(p+1) = 0; if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) { struct object *o = - lookup_object(oid.hash); + lookup_object(the_repository, + oid.hash); if (o) name = get_rev_name(o, &buf); } diff --git a/builtin/prune.c b/builtin/prune.c index 70ec35a..72b0621 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -40,7 +40,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath, * Do we know about this object? * It must have been reachable */ - if (lookup_object(oid->hash)) + if (lookup_object(the_repository, oid->hash)) return 0; if (lstat(fullpath, &st)) { diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index cf585fc..335b5ed 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -331,7 +331,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base, { struct object *obj; struct obj_buffer *obj_buffer; - obj = lookup_object(base->hash); + obj = lookup_object(the_repository, base->hash); if (!obj) return 0; obj_buffer = lookup_object_buffer(obj); diff --git a/commit.c b/commit.c index a29070a..b4dbfd8 100644 --- a/commit.c +++ b/commit.c @@ -54,7 +54,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref struct commit *lookup_commit(const struct object_id *oid) { - struct object *obj = lookup_object(oid->hash); + struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) return create_object(the_repository, oid->hash, alloc_commit_node(the_repository)); diff --git a/fetch-pack.c b/fetch-pack.c index 6b406f1..771eb8a 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -362,7 +362,7 @@ static int find_common(struct fetch_pack_args *args, * interested in the case we *know* the object is * reachable and we have already scanned it. */ - if (((o = lookup_object(remote->hash)) != NULL) && + if (((o = lookup_object(the_repository, remote->hash)) != NULL) && (o->flags & COMPLETE)) { continue; } @@ -436,7 +436,7 @@ static int find_common(struct fetch_pack_args *args, if (skip_prefix(line, "unshallow ", &arg)) { if (get_oid_hex(arg, &oid)) die(_("invalid unshallow line: %s"), line); - if (!lookup_object(oid.hash)) + if (!lookup_object(the_repository, oid.hash)) die(_("object not found: %s"), line); /* make sure that it is parsed as shallow */ if (!parse_object(the_repository, &oid)) @@ -801,7 +801,8 @@ static int everything_local(struct fetch_pack_args *args, * Don't mark them common yet; the server has to be told so first. */ for (ref = *refs; ref; ref = ref->next) { - struct object *o = deref_tag(lookup_object(ref->old_oid.hash), + struct object *o = deref_tag(lookup_object(the_repository, + ref->old_oid.hash), NULL, 0); if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE)) @@ -821,7 +822,7 @@ static int everything_local(struct fetch_pack_args *args, const struct object_id *remote = &ref->old_oid; struct object *o; - o = lookup_object(remote->hash); + o = lookup_object(the_repository, remote->hash); if (!o || !(o->flags & COMPLETE)) { retval = 0; print_verbose(args, "want %s (%s)", oid_to_hex(remote), @@ -1120,7 +1121,7 @@ static void add_wants(const struct ref *wants, struct strbuf *req_buf) * interested in the case we *know* the object is * reachable and we have already scanned it. */ - if (((o = lookup_object(remote->hash)) != NULL) && + if (((o = lookup_object(the_repository, remote->hash)) != NULL) && (o->flags & COMPLETE)) { continue; } @@ -1317,7 +1318,7 @@ static void receive_shallow_info(struct fetch_pack_args *args, if (skip_prefix(reader->line, "unshallow ", &arg)) { if (get_oid_hex(arg, &oid)) die(_("invalid unshallow line: %s"), reader->line); - if (!lookup_object(oid.hash)) + if (!lookup_object(the_repository, oid.hash)) die(_("object not found: %s"), reader->line); /* make sure that it is parsed as shallow */ if (!parse_object(the_repository, &oid)) diff --git a/http-push.c b/http-push.c index 37cbf07..d2245cc 100644 --- a/http-push.c +++ b/http-push.c @@ -722,7 +722,7 @@ static void one_remote_object(const struct object_id *oid) { struct object *obj; - obj = lookup_object(oid->hash); + obj = lookup_object(the_repository, oid->hash); if (!obj) obj = parse_object(the_repository, oid); diff --git a/object.c b/object.c index bf1d9c6..002ebb6 100644 --- a/object.c +++ b/object.c @@ -84,7 +84,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i * Look up the record for the given sha1 in the hash map stored in * obj_hash. Return NULL if it was not found. */ -struct object *lookup_object(const unsigned char *sha1) +struct object *lookup_object_the_repository(const unsigned char *sha1) { unsigned int i, first; struct object *obj; @@ -179,7 +179,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet) struct object *lookup_unknown_object(const unsigned char *sha1) { - struct object *obj = lookup_object(sha1); + struct object *obj = lookup_object(the_repository, sha1); if (!obj) obj = create_object(the_repository, sha1, alloc_object_node(the_repository)); @@ -255,7 +255,7 @@ struct object *parse_object_the_repository(const struct object_id *oid) void *buffer; struct object *obj; - obj = lookup_object(oid->hash); + obj = lookup_object(the_repository, oid->hash); if (obj && obj->parsed) return obj; @@ -267,7 +267,7 @@ struct object *parse_object_the_repository(const struct object_id *oid) return NULL; } parse_blob_buffer(lookup_blob(oid), NULL, 0); - return lookup_object(oid->hash); + return lookup_object(the_repository, oid->hash); } buffer = read_object_file(oid, &type, &size); diff --git a/object.h b/object.h index 882f47f..f840a42 100644 --- a/object.h +++ b/object.h @@ -109,7 +109,8 @@ extern struct object *get_indexed_object(unsigned int); * half-initialised objects, the caller is expected to initialize them * by calling parse_object() on them. */ -struct object *lookup_object(const unsigned char *sha1); +#define lookup_object(r, s) lookup_object_##r(s) +struct object *lookup_object_the_repository(const unsigned char *sha1); extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj); diff --git a/reachable.c b/reachable.c index ffb976c..2ee5569 100644 --- a/reachable.c +++ b/reachable.c @@ -108,7 +108,7 @@ static int add_recent_loose(const struct object_id *oid, const char *path, void *data) { struct stat st; - struct object *obj = lookup_object(oid->hash); + struct object *obj = lookup_object(the_repository, oid->hash); if (obj && obj->flags & SEEN) return 0; @@ -133,7 +133,7 @@ static int add_recent_packed(const struct object_id *oid, struct packed_git *p, uint32_t pos, void *data) { - struct object *obj = lookup_object(oid->hash); + struct object *obj = lookup_object(the_repository, oid->hash); if (obj && obj->flags & SEEN) return 0; diff --git a/tag.c b/tag.c index 7d282df..1b95eb9 100644 --- a/tag.c +++ b/tag.c @@ -94,7 +94,7 @@ struct object *deref_tag_noverify(struct object *o) struct tag *lookup_tag(const struct object_id *oid) { - struct object *obj = lookup_object(oid->hash); + struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) return create_object(the_repository, oid->hash, alloc_tag_node(the_repository)); diff --git a/tree.c b/tree.c index 533b6e6..73e8a8a 100644 --- a/tree.c +++ b/tree.c @@ -197,7 +197,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match, struct tree *lookup_tree(const struct object_id *oid) { - struct object *obj = lookup_object(oid->hash); + struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) return create_object(the_repository, oid->hash, alloc_tree_node(the_repository)); diff --git a/upload-pack.c b/upload-pack.c index d2b8511..45e3a94 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -570,7 +570,7 @@ static int get_reachable_list(struct object_array *src, if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n') break; - o = lookup_object(sha1.hash); + o = lookup_object(the_repository, sha1.hash); if (o && o->type == OBJ_COMMIT) { o->flags &= ~TMP_MARK; } -- cgit v0.10.2-6-g49f6 From 1ec5bfd24e57c8d40d3f7d911fb9b85723282a46 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:53 -0700 Subject: object: add repository argument to parse_object_buffer Add a repository argument to allow the callers of parse_object_buffer to be more specific about which repository to act on. 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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/builtin/fast-export.c b/builtin/fast-export.c index e39c4e2..03a2e4b 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -244,7 +244,8 @@ static void export_blob(const struct object_id *oid) die ("Could not read blob %s", oid_to_hex(oid)); if (check_object_signature(oid, buf, size, type_name(type)) < 0) die("sha1 mismatch in blob %s", oid_to_hex(oid)); - object = parse_object_buffer(oid, type, size, buf, &eaten); + object = parse_object_buffer(the_repository, oid, type, + size, buf, &eaten); } if (!object) diff --git a/builtin/fsck.c b/builtin/fsck.c index 12d01e9..09cf533 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -392,7 +392,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, * verify_packfile(), data_valid variable for details. */ struct object *obj; - obj = parse_object_buffer(oid, type, size, buffer, eaten); + obj = parse_object_buffer(the_repository, oid, type, size, buffer, + eaten); if (!obj) { errors_found |= ERROR_OBJECT; return error("%s: object corrupt or missing", oid_to_hex(oid)); @@ -525,7 +526,9 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) if (!contents && type != OBJ_BLOB) BUG("read_loose_object streamed a non-blob"); - obj = parse_object_buffer(oid, type, size, contents, &eaten); + obj = parse_object_buffer(the_repository, oid, type, size, + contents, &eaten); + if (!obj) { errors_found |= ERROR_OBJECT; error("%s: object could not be parsed: %s", diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 74fe297..9c08cf3 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -851,7 +851,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, * we do not need to free the memory here, as the * buf is deleted by the caller. */ - obj = parse_object_buffer(oid, type, size, buf, + obj = parse_object_buffer(the_repository, oid, type, + size, buf, &eaten); if (!obj) die(_("invalid %s"), type_name(type)); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 335b5ed..75d1d5e 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -265,7 +265,8 @@ static void write_object(unsigned nr, enum object_type type, int eaten; hash_object_file(buf, size, type_name(type), &obj_list[nr].oid); added_object(nr, type, buf, size); - obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf, + obj = parse_object_buffer(the_repository, &obj_list[nr].oid, + type, size, buf, &eaten); if (!obj) die("invalid %s", type_name(type)); diff --git a/object.c b/object.c index 002ebb6..4971969 100644 --- a/object.c +++ b/object.c @@ -186,7 +186,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1) return obj; } -struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p) +struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p) { struct object *obj; *eaten_p = 0; @@ -278,7 +278,8 @@ struct object *parse_object_the_repository(const struct object_id *oid) return NULL; } - obj = parse_object_buffer(oid, type, size, buffer, &eaten); + obj = parse_object_buffer(the_repository, oid, type, size, + buffer, &eaten); if (!eaten) free(buffer); return obj; diff --git a/object.h b/object.h index f840a42..2ba23c0 100644 --- a/object.h +++ b/object.h @@ -135,7 +135,8 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name * parsing it. eaten_p indicates if the object has a borrowed copy * of buffer and the caller should not free() it. */ -struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p); +#define parse_object_buffer(r, o, t, s, b, e) parse_object_buffer_##r(o, t, s, b, e) +struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p); /** Returns the object, with potentially excess memory allocated. **/ struct object *lookup_unknown_object(const unsigned char *sha1); diff --git a/ref-filter.c b/ref-filter.c index 044c28c..ec9479a 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -807,7 +807,8 @@ static void *get_obj(const struct object_id *oid, struct object **obj, unsigned void *buf = read_object_file(oid, &type, sz); if (buf) - *obj = parse_object_buffer(oid, type, *sz, buf, eaten); + *obj = parse_object_buffer(the_repository, oid, type, *sz, + buf, eaten); else *obj = NULL; return buf; -- cgit v0.10.2-6-g49f6 From 1268dfac1e98e973c63abb142551c64bba6a44ca Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:54 -0700 Subject: object: add repository argument to object_as_type Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/blob.c b/blob.c index 75b737a..dada295 100644 --- a/blob.c +++ b/blob.c @@ -11,7 +11,7 @@ struct blob *lookup_blob(const struct object_id *oid) if (!obj) return create_object(the_repository, oid->hash, alloc_blob_node(the_repository)); - return object_as_type(obj, OBJ_BLOB, 0); + return object_as_type(the_repository, obj, OBJ_BLOB, 0); } int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size) diff --git a/builtin/fsck.c b/builtin/fsck.c index 09cf533..a906fe4 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -70,7 +70,7 @@ static const char *printable_type(struct object *obj) enum object_type type = oid_object_info(the_repository, &obj->oid, NULL); if (type > 0) - object_as_type(obj, type, 0); + object_as_type(the_repository, obj, type, 0); } ret = type_name(obj->type); diff --git a/commit.c b/commit.c index b4dbfd8..0d55600 100644 --- a/commit.c +++ b/commit.c @@ -32,7 +32,7 @@ struct commit *lookup_commit_reference_gently(const struct object_id *oid, if (!obj) return NULL; - return object_as_type(obj, OBJ_COMMIT, quiet); + return object_as_type(the_repository, obj, OBJ_COMMIT, quiet); } struct commit *lookup_commit_reference(const struct object_id *oid) @@ -58,7 +58,7 @@ struct commit *lookup_commit(const struct object_id *oid) if (!obj) return create_object(the_repository, oid->hash, alloc_commit_node(the_repository)); - return object_as_type(obj, OBJ_COMMIT, 0); + return object_as_type(the_repository, obj, OBJ_COMMIT, 0); } struct commit *lookup_commit_reference_by_name(const char *name) diff --git a/object.c b/object.c index 4971969..4049190 100644 --- a/object.c +++ b/object.c @@ -158,7 +158,7 @@ void *create_object(struct repository *r, const unsigned char *sha1, void *o) return obj; } -void *object_as_type(struct object *obj, enum object_type type, int quiet) +void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet) { if (obj->type == type) return obj; diff --git a/object.h b/object.h index 2ba23c0..3faa895 100644 --- a/object.h +++ b/object.h @@ -114,7 +114,8 @@ struct object *lookup_object_the_repository(const unsigned char *sha1); extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj); -void *object_as_type(struct object *obj, enum object_type type, int quiet); +#define object_as_type(r, o, t, q) object_as_type_##r(o, t, q) +void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet); /* * Returns the object, having parsed it to find out what it is. diff --git a/refs.c b/refs.c index 3b4508a..fcfd317 100644 --- a/refs.c +++ b/refs.c @@ -305,7 +305,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid if (o->type == OBJ_NONE) { int type = oid_object_info(the_repository, name, NULL); - if (type < 0 || !object_as_type(o, type, 0)) + if (type < 0 || !object_as_type(the_repository, o, type, 0)) return PEEL_INVALID; } diff --git a/tag.c b/tag.c index 1b95eb9..a14a4f2 100644 --- a/tag.c +++ b/tag.c @@ -98,7 +98,7 @@ struct tag *lookup_tag(const struct object_id *oid) if (!obj) return create_object(the_repository, oid->hash, alloc_tag_node(the_repository)); - return object_as_type(obj, OBJ_TAG, 0); + return object_as_type(the_repository, obj, OBJ_TAG, 0); } static timestamp_t parse_tag_date(const char *buf, const char *tail) diff --git a/tree.c b/tree.c index 73e8a8a..f31afb8 100644 --- a/tree.c +++ b/tree.c @@ -201,7 +201,7 @@ struct tree *lookup_tree(const struct object_id *oid) if (!obj) return create_object(the_repository, oid->hash, alloc_tree_node(the_repository)); - return object_as_type(obj, OBJ_TREE, 0); + return object_as_type(the_repository, obj, OBJ_TREE, 0); } int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size) -- cgit v0.10.2-6-g49f6 From da14a7ff99e1d011192a1fe330dd3fddf8977dc3 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:55 -0700 Subject: blob: add repository argument to lookup_blob Add a repository argument to allow the callers of lookup_blob to be more specific about which repository to act on. 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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/blob.c b/blob.c index dada295..17b9314 100644 --- a/blob.c +++ b/blob.c @@ -5,7 +5,7 @@ const char *blob_type = "blob"; -struct blob *lookup_blob(const struct object_id *oid) +struct blob *lookup_blob_the_repository(const struct object_id *oid) { struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) diff --git a/blob.h b/blob.h index 4460616..08bc344 100644 --- a/blob.h +++ b/blob.h @@ -9,7 +9,8 @@ struct blob { struct object object; }; -struct blob *lookup_blob(const struct object_id *oid); +#define lookup_blob(r, o) lookup_blob_##r(o) +struct blob *lookup_blob_the_repository(const struct object_id *oid); int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size); diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 03a2e4b..7d6b1d8 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -236,7 +236,7 @@ static void export_blob(const struct object_id *oid) if (anonymize) { buf = anonymize_blob(&size); - object = (struct object *)lookup_blob(oid); + object = (struct object *)lookup_blob(the_repository, oid); eaten = 0; } else { buf = read_object_file(oid, &type, &size); diff --git a/builtin/fsck.c b/builtin/fsck.c index a906fe4..2631919 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -810,7 +810,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) mode = active_cache[i]->ce_mode; if (S_ISGITLINK(mode)) continue; - blob = lookup_blob(&active_cache[i]->oid); + blob = lookup_blob(the_repository, + &active_cache[i]->oid); if (!blob) continue; obj = &blob->object; diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 9c08cf3..de311fe 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -832,7 +832,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, if (strict || do_fsck_object) { read_lock(); if (type == OBJ_BLOB) { - struct blob *blob = lookup_blob(oid); + struct blob *blob = lookup_blob(the_repository, oid); if (blob) blob->object.flags |= FLAG_CHECKED; else diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 8a8d579..f8023ba 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -2,6 +2,7 @@ #include "tree-walk.h" #include "xdiff-interface.h" #include "object-store.h" +#include "repository.h" #include "blob.h" #include "exec-cmd.h" #include "merge-blobs.h" @@ -170,7 +171,7 @@ static struct merge_list *create_entry(unsigned stage, unsigned mode, const stru res->stage = stage; res->path = path; res->mode = mode; - res->blob = lookup_blob(oid); + res->blob = lookup_blob(the_repository, oid); return res; } diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 75d1d5e..716408e 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -254,7 +254,7 @@ static void write_object(unsigned nr, enum object_type type, added_object(nr, type, buf, size); free(buf); - blob = lookup_blob(&obj_list[nr].oid); + blob = lookup_blob(the_repository, &obj_list[nr].oid); if (blob) blob->object.flags |= FLAG_WRITTEN; else diff --git a/fsck.c b/fsck.c index bb3d622..ea00f72 100644 --- a/fsck.c +++ b/fsck.c @@ -414,7 +414,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op result = options->walk(obj, OBJ_TREE, data, options); } else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) { - obj = (struct object *)lookup_blob(entry.oid); + obj = (struct object *)lookup_blob(the_repository, entry.oid); if (name && obj) put_object_name(options, obj, "%s%s", name, entry.path); @@ -1070,7 +1070,7 @@ int fsck_finish(struct fsck_options *options) if (oidset_contains(&gitmodules_done, oid)) continue; - blob = lookup_blob(oid); + blob = lookup_blob(the_repository, oid); if (!blob) { struct object *obj = lookup_unknown_object(oid->hash); ret |= report(options, obj, diff --git a/http-push.c b/http-push.c index d2245cc..191b51c 100644 --- a/http-push.c +++ b/http-push.c @@ -1314,7 +1314,8 @@ static struct object_list **process_tree(struct tree *tree, p = process_tree(lookup_tree(entry.oid), p); break; case OBJ_BLOB: - p = process_blob(lookup_blob(entry.oid), p); + p = process_blob(lookup_blob(the_repository, entry.oid), + p); break; default: /* Subproject commit - not in this repository */ diff --git a/list-objects.c b/list-objects.c index 3e5e199..04c45f6 100644 --- a/list-objects.c +++ b/list-objects.c @@ -167,7 +167,7 @@ static void process_tree(struct rev_info *revs, cb_data); else process_blob(revs, - lookup_blob(entry.oid), + lookup_blob(the_repository, entry.oid), show, base, entry.path, cb_data, filter_fn, filter_data); } diff --git a/object.c b/object.c index 4049190..fde816a 100644 --- a/object.c +++ b/object.c @@ -193,7 +193,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e obj = NULL; if (type == OBJ_BLOB) { - struct blob *blob = lookup_blob(oid); + struct blob *blob = lookup_blob(the_repository, oid); if (blob) { if (parse_blob_buffer(blob, buffer, size)) return NULL; @@ -266,7 +266,7 @@ struct object *parse_object_the_repository(const struct object_id *oid) error("sha1 mismatch %s", oid_to_hex(oid)); return NULL; } - parse_blob_buffer(lookup_blob(oid), NULL, 0); + parse_blob_buffer(lookup_blob(the_repository, oid), NULL, 0); return lookup_object(the_repository, oid->hash); } diff --git a/reachable.c b/reachable.c index 2ee5569..cc25f01 100644 --- a/reachable.c +++ b/reachable.c @@ -91,7 +91,7 @@ static void add_recent_object(const struct object_id *oid, obj = (struct object *)lookup_tree(oid); break; case OBJ_BLOB: - obj = (struct object *)lookup_blob(oid); + obj = (struct object *)lookup_blob(the_repository, oid); break; default: die("unknown object type for %s: %s", diff --git a/revision.c b/revision.c index 8a2b285..e382412 100644 --- a/revision.c +++ b/revision.c @@ -66,7 +66,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree) mark_tree_uninteresting(lookup_tree(entry.oid)); break; case OBJ_BLOB: - mark_blob_uninteresting(lookup_blob(entry.oid)); + mark_blob_uninteresting(lookup_blob(the_repository, entry.oid)); break; default: /* Subproject commit - not in this repository */ @@ -1348,7 +1348,7 @@ static void do_add_index_objects_to_pending(struct rev_info *revs, if (S_ISGITLINK(ce->ce_mode)) continue; - blob = lookup_blob(&ce->oid); + blob = lookup_blob(the_repository, &ce->oid); if (!blob) die("unable to add index blob to traversal"); add_pending_object_with_path(revs, &blob->object, "", diff --git a/tag.c b/tag.c index a14a4f2..a31ae75 100644 --- a/tag.c +++ b/tag.c @@ -154,7 +154,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) bufptr = nl + 1; if (!strcmp(type, blob_type)) { - item->tagged = (struct object *)lookup_blob(&oid); + item->tagged = (struct object *)lookup_blob(the_repository, &oid); } else if (!strcmp(type, tree_type)) { item->tagged = (struct object *)lookup_tree(&oid); } else if (!strcmp(type, commit_type)) { diff --git a/walker.c b/walker.c index 63002b1..5b56c72 100644 --- a/walker.c +++ b/walker.c @@ -54,7 +54,8 @@ static int process_tree(struct walker *walker, struct tree *tree) obj = &tree->object; } else { - struct blob *blob = lookup_blob(entry.oid); + struct blob *blob = lookup_blob(the_repository, + entry.oid); if (blob) obj = &blob->object; } -- cgit v0.10.2-6-g49f6 From f86bcc7b2ce6cad68ba1a48a528e380c6126705e Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:56 -0700 Subject: tree: add repository argument to lookup_tree Add a repository argument to allow the callers of lookup_tree to be more specific about which repository to act on. 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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/builtin/am.c b/builtin/am.c index 6273ea5..72e928c 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -32,6 +32,7 @@ #include "apply.h" #include "string-list.h" #include "packfile.h" +#include "repository.h" /** * Returns 1 if the file is empty or does not exist, 0 otherwise. @@ -1400,9 +1401,10 @@ static void write_index_patch(const struct am_state *state) FILE *fp; if (!get_oid_tree("HEAD", &head)) - tree = lookup_tree(&head); + tree = lookup_tree(the_repository, &head); else - tree = lookup_tree(the_hash_algo->empty_tree); + tree = lookup_tree(the_repository, + the_repository->hash_algo->empty_tree); fp = xfopen(am_path(state, "patch"), "w"); init_revisions(&rev_info, NULL); diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index d8db8f6..2990151 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -46,7 +46,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p) struct tree *tree2; if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p) return error("Need exactly two trees, separated by a space"); - tree2 = lookup_tree(&oid); + tree2 = lookup_tree(the_repository, &oid); if (!tree2 || parse_tree(tree2)) return -1; printf("%s %s\n", oid_to_hex(&tree1->object.oid), diff --git a/builtin/diff.c b/builtin/diff.c index d0421c9..7971530 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -386,7 +386,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix) add_head_to_pending(&rev); if (!rev.pending.nr) { struct tree *tree; - tree = lookup_tree(the_hash_algo->empty_tree); + tree = lookup_tree(the_repository, + the_repository->hash_algo->empty_tree); add_pending_object(&rev, &tree->object, "HEAD"); } break; diff --git a/builtin/reflog.c b/builtin/reflog.c index 948002b..5e12c85 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -66,7 +66,7 @@ static int tree_is_complete(const struct object_id *oid) int complete; struct tree *tree; - tree = lookup_tree(oid); + tree = lookup_tree(the_repository, oid); if (!tree) return 0; if (tree->object.flags & SEEN) diff --git a/cache-tree.c b/cache-tree.c index 6b46711..181d591 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -671,7 +671,8 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree) cnt++; else { struct cache_tree_sub *sub; - struct tree *subtree = lookup_tree(entry.oid); + struct tree *subtree = lookup_tree(the_repository, + entry.oid); if (!subtree->object.parsed) parse_tree(subtree); sub = cache_tree_sub(it, entry.path); diff --git a/commit-graph.c b/commit-graph.c index b63a1fc..d1a68f0 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -344,7 +344,7 @@ static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit * GRAPH_DATA_WIDTH * (c->graph_pos); hashcpy(oid.hash, commit_data); - c->maybe_tree = lookup_tree(&oid); + c->maybe_tree = lookup_tree(the_repository, &oid); return c->maybe_tree; } diff --git a/commit.c b/commit.c index 0d55600..2fa4220 100644 --- a/commit.c +++ b/commit.c @@ -383,7 +383,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s if (get_oid_hex(bufptr + 5, &parent) < 0) return error("bad tree pointer in commit %s", oid_to_hex(&item->object.oid)); - item->maybe_tree = lookup_tree(&parent); + item->maybe_tree = lookup_tree(the_repository, &parent); bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ pptr = &item->parents; diff --git a/fsck.c b/fsck.c index ea00f72..9345979 100644 --- a/fsck.c +++ b/fsck.c @@ -407,7 +407,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op continue; if (S_ISDIR(entry.mode)) { - obj = (struct object *)lookup_tree(entry.oid); + obj = (struct object *)lookup_tree(the_repository, entry.oid); if (name && obj) put_object_name(options, obj, "%s%s/", name, entry.path); diff --git a/http-push.c b/http-push.c index 191b51c..f7b70c4 100644 --- a/http-push.c +++ b/http-push.c @@ -1311,7 +1311,8 @@ static struct object_list **process_tree(struct tree *tree, while (tree_entry(&desc, &entry)) switch (object_type(entry.mode)) { case OBJ_TREE: - p = process_tree(lookup_tree(entry.oid), p); + p = process_tree(lookup_tree(the_repository, entry.oid), + p); break; case OBJ_BLOB: p = process_blob(lookup_blob(the_repository, entry.oid), diff --git a/list-objects.c b/list-objects.c index 04c45f6..782c0e1 100644 --- a/list-objects.c +++ b/list-objects.c @@ -158,7 +158,7 @@ static void process_tree(struct rev_info *revs, if (S_ISDIR(entry.mode)) process_tree(revs, - lookup_tree(entry.oid), + lookup_tree(the_repository, entry.oid), show, base, entry.path, cb_data, filter_fn, filter_data); else if (S_ISGITLINK(entry.mode)) diff --git a/merge-recursive.c b/merge-recursive.c index 63bc0e2..fbb044e 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -158,7 +158,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two, } if (!oidcmp(&two->object.oid, &shifted)) return two; - return lookup_tree(&shifted); + return lookup_tree(the_repository, &shifted); } static struct commit *make_virtual_commit(struct tree *tree, const char *comment) @@ -416,7 +416,7 @@ struct tree *write_tree_from_memory(struct merge_options *o) return NULL; } - result = lookup_tree(&active_cache_tree->oid); + result = lookup_tree(the_repository, &active_cache_tree->oid); return result; } @@ -3405,7 +3405,7 @@ int merge_recursive(struct merge_options *o, /* if there is no common ancestor, use an empty tree */ struct tree *tree; - tree = lookup_tree(the_hash_algo->empty_tree); + tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree); merged_common_ancestors = make_virtual_commit(tree, "ancestor"); } diff --git a/object.c b/object.c index fde816a..2acd3a0 100644 --- a/object.c +++ b/object.c @@ -200,7 +200,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e obj = &blob->object; } } else if (type == OBJ_TREE) { - struct tree *tree = lookup_tree(oid); + struct tree *tree = lookup_tree(the_repository, oid); if (tree) { obj = &tree->object; if (!tree->buffer) diff --git a/reachable.c b/reachable.c index cc25f01..6e9b810 100644 --- a/reachable.c +++ b/reachable.c @@ -88,7 +88,7 @@ static void add_recent_object(const struct object_id *oid, obj = parse_object_or_die(oid, NULL); break; case OBJ_TREE: - obj = (struct object *)lookup_tree(oid); + obj = (struct object *)lookup_tree(the_repository, oid); break; case OBJ_BLOB: obj = (struct object *)lookup_blob(the_repository, oid); diff --git a/revision.c b/revision.c index e382412..02e1296 100644 --- a/revision.c +++ b/revision.c @@ -63,7 +63,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree) while (tree_entry(&desc, &entry)) { switch (object_type(entry.mode)) { case OBJ_TREE: - mark_tree_uninteresting(lookup_tree(entry.oid)); + mark_tree_uninteresting(lookup_tree(the_repository, entry.oid)); break; case OBJ_BLOB: mark_blob_uninteresting(lookup_blob(the_repository, entry.oid)); @@ -1322,7 +1322,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, int i; if (it->entry_count >= 0) { - struct tree *tree = lookup_tree(&it->oid); + struct tree *tree = lookup_tree(the_repository, &it->oid); add_pending_object_with_path(revs, &tree->object, "", 040000, path->buf); } diff --git a/sequencer.c b/sequencer.c index 0a291c9..4cf7afb 100644 --- a/sequencer.c +++ b/sequencer.c @@ -433,7 +433,7 @@ static int read_oneliner(struct strbuf *buf, static struct tree *empty_tree(void) { - return lookup_tree(the_hash_algo->empty_tree); + return lookup_tree(the_repository, the_repository->hash_algo->empty_tree); } static int error_dirty_index(struct replay_opts *opts) diff --git a/tag.c b/tag.c index a31ae75..3101021 100644 --- a/tag.c +++ b/tag.c @@ -156,7 +156,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) if (!strcmp(type, blob_type)) { item->tagged = (struct object *)lookup_blob(the_repository, &oid); } else if (!strcmp(type, tree_type)) { - item->tagged = (struct object *)lookup_tree(&oid); + item->tagged = (struct object *)lookup_tree(the_repository, &oid); } else if (!strcmp(type, commit_type)) { item->tagged = (struct object *)lookup_commit(&oid); } else if (!strcmp(type, tag_type)) { diff --git a/tree.c b/tree.c index f31afb8..12b6960 100644 --- a/tree.c +++ b/tree.c @@ -120,7 +120,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, len = tree_entry_len(&entry); strbuf_add(base, entry.path, len); strbuf_addch(base, '/'); - retval = read_tree_1(lookup_tree(&oid), + retval = read_tree_1(lookup_tree(the_repository, &oid), base, stage, pathspec, fn, context); strbuf_setlen(base, oldlen); @@ -195,7 +195,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match, return 0; } -struct tree *lookup_tree(const struct object_id *oid) +struct tree *lookup_tree_the_repository(const struct object_id *oid) { struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) diff --git a/tree.h b/tree.h index e2a80be..2ea21ed 100644 --- a/tree.h +++ b/tree.h @@ -12,7 +12,8 @@ struct tree { unsigned long size; }; -struct tree *lookup_tree(const struct object_id *oid); +#define lookup_tree(r, oid) lookup_tree_##r(oid) +struct tree *lookup_tree_the_repository(const struct object_id *oid); int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); diff --git a/walker.c b/walker.c index 5b56c72..a3a2566 100644 --- a/walker.c +++ b/walker.c @@ -49,7 +49,8 @@ static int process_tree(struct walker *walker, struct tree *tree) if (S_ISGITLINK(entry.mode)) continue; if (S_ISDIR(entry.mode)) { - struct tree *tree = lookup_tree(entry.oid); + struct tree *tree = lookup_tree(the_repository, + entry.oid); if (tree) obj = &tree->object; } -- cgit v0.10.2-6-g49f6 From 21e1ee8f4f4b7767d506b02504e97f6bcaef13a0 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:57 -0700 Subject: commit: add repository argument to lookup_commit_reference_gently Add a repository argument to allow callers of lookup_commit_reference_gently 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 Signed-off-by: Junio C Hamano diff --git a/archive.c b/archive.c index 875dab6..78b0a39 100644 --- a/archive.c +++ b/archive.c @@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv, if (get_oid(name, &oid)) die("Not a valid object name"); - commit = lookup_commit_reference_gently(&oid, 1); + commit = lookup_commit_reference_gently(the_repository, &oid, 1); if (commit) { commit_sha1 = commit->object.oid.hash; archive_time = commit->date; diff --git a/blame.c b/blame.c index 0c4490a..5b022cc 100644 --- a/blame.c +++ b/blame.c @@ -1712,7 +1712,8 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs, /* Do we have HEAD? */ if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL)) return NULL; - head_commit = lookup_commit_reference_gently(&head_oid, 1); + head_commit = lookup_commit_reference_gently(the_repository, + &head_oid, 1); if (!head_commit) return NULL; diff --git a/builtin/checkout.c b/builtin/checkout.c index 2862765..40c27bf 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -379,7 +379,7 @@ static int checkout_paths(const struct checkout_opts *opts, die(_("unable to write new index file")); read_ref_full("HEAD", 0, &rev, NULL); - head = lookup_commit_reference_gently(&rev, 1); + head = lookup_commit_reference_gently(the_repository, &rev, 1); errs |= post_checkout_hook(head, head, 0); return errs; @@ -830,7 +830,7 @@ static int switch_branches(const struct checkout_opts *opts, memset(&old_branch_info, 0, sizeof(old_branch_info)); old_branch_info.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag); if (old_branch_info.path) - old_branch_info.commit = lookup_commit_reference_gently(&rev, 1); + old_branch_info.commit = lookup_commit_reference_gently(the_repository, &rev, 1); if (!(flag & REF_ISSYMREF)) old_branch_info.path = NULL; @@ -1004,7 +1004,7 @@ static int parse_branchname_arg(int argc, const char **argv, else new_branch_info->path = NULL; /* not an existing branch */ - new_branch_info->commit = lookup_commit_reference_gently(rev, 1); + new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1); if (!new_branch_info->commit) { /* not a commit */ *source_tree = parse_tree_indirect(rev); diff --git a/builtin/describe.c b/builtin/describe.c index 1e87f68..0b5d856 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -331,7 +331,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst) init_commit_names(&commit_names); n = hashmap_iter_first(&names, &iter); for (; n; n = hashmap_iter_next(&iter)) { - c = lookup_commit_reference_gently(&n->peeled, 1); + c = lookup_commit_reference_gently(the_repository, + &n->peeled, 1); if (c) *commit_names_at(&commit_names, c) = n; } @@ -509,7 +510,7 @@ static void describe(const char *arg, int last_one) if (get_oid(arg, &oid)) die(_("Not a valid object name %s"), arg); - cmit = lookup_commit_reference_gently(&oid, 1); + cmit = lookup_commit_reference_gently(the_repository, &oid, 1); if (cmit) describe_commit(&oid, &sb); diff --git a/builtin/fetch.c b/builtin/fetch.c index 83f36d7..f5d960b 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -684,8 +684,10 @@ static int update_local_ref(struct ref *ref, return r; } - current = lookup_commit_reference_gently(&ref->old_oid, 1); - updated = lookup_commit_reference_gently(&ref->new_oid, 1); + current = lookup_commit_reference_gently(the_repository, + &ref->old_oid, 1); + updated = lookup_commit_reference_gently(the_repository, + &ref->new_oid, 1); if (!current || !updated) { const char *msg; const char *what; @@ -818,7 +820,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, continue; } - commit = lookup_commit_reference_gently(&rm->old_oid, + commit = lookup_commit_reference_gently(the_repository, + &rm->old_oid, 1); if (!commit) rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE; diff --git a/builtin/reflog.c b/builtin/reflog.c index 5e12c85..3acef5a 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -196,7 +196,7 @@ static int keep_entry(struct commit **it, struct object_id *oid) if (is_null_oid(oid)) return 1; - commit = lookup_commit_reference_gently(oid, 1); + commit = lookup_commit_reference_gently(the_repository, oid, 1); if (!commit) return 0; @@ -265,7 +265,8 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit if (is_null_oid(oid)) return 0; - commit = lookup_commit_reference_gently(oid, 1); + commit = lookup_commit_reference_gently(the_repository, oid, + 1); /* Not a commit -- keep it */ if (!commit) @@ -322,7 +323,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid, struct commit *tip_commit; if (flags & REF_ISSYMREF) return 0; - tip_commit = lookup_commit_reference_gently(oid, 1); + tip_commit = lookup_commit_reference_gently(the_repository, oid, 1); if (!tip_commit) return 0; commit_list_insert(tip_commit, list); @@ -339,7 +340,8 @@ static void reflog_expiry_prepare(const char *refname, cb->tip_commit = NULL; cb->unreachable_expire_kind = UE_HEAD; } else { - cb->tip_commit = lookup_commit_reference_gently(oid, 1); + cb->tip_commit = lookup_commit_reference_gently(the_repository, + oid, 1); if (!cb->tip_commit) cb->unreachable_expire_kind = UE_ALWAYS; else diff --git a/builtin/show-branch.c b/builtin/show-branch.c index f2e985c..2456b47 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -378,7 +378,8 @@ static void sort_ref_range(int bottom, int top) static int append_ref(const char *refname, const struct object_id *oid, int allow_dups) { - struct commit *commit = lookup_commit_reference_gently(oid, 1); + struct commit *commit = lookup_commit_reference_gently(the_repository, + oid, 1); int i; if (!commit) diff --git a/bundle.c b/bundle.c index 8283fff..0a9f4ee 100644 --- a/bundle.c +++ b/bundle.c @@ -180,7 +180,7 @@ int verify_bundle(struct bundle_header *header, int verbose) /* Clean up objects used, as they will be reused. */ for (i = 0; i < p->nr; i++) { struct ref_list_entry *e = p->list + i; - commit = lookup_commit_reference_gently(&e->oid, 1); + commit = lookup_commit_reference_gently(the_repository, &e->oid, 1); if (commit) clear_commit_marks(commit, ALL_REV_FLAGS); } diff --git a/commit-graph.c b/commit-graph.c index d1a68f0..7801b51 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -701,7 +701,7 @@ void write_commit_graph(const char *obj_dir, if (commit_hex[i] && parse_oid_hex(commit_hex[i], &oid, &end)) continue; - result = lookup_commit_reference_gently(&oid, 1); + result = lookup_commit_reference_gently(the_repository, &oid, 1); if (result) { ALLOC_GROW(oids.list, oids.nr + 1, oids.alloc); diff --git a/commit.c b/commit.c index 2fa4220..756d557 100644 --- a/commit.c +++ b/commit.c @@ -24,8 +24,8 @@ int save_commit_buffer = 1; const char *commit_type = "commit"; -struct commit *lookup_commit_reference_gently(const struct object_id *oid, - int quiet) +struct commit *lookup_commit_reference_gently_the_repository( + const struct object_id *oid, int quiet) { struct object *obj = deref_tag(parse_object(the_repository, oid), NULL, 0); @@ -37,7 +37,7 @@ struct commit *lookup_commit_reference_gently(const struct object_id *oid, struct commit *lookup_commit_reference(const struct object_id *oid) { - return lookup_commit_reference_gently(oid, 0); + return lookup_commit_reference_gently(the_repository, oid, 0); } struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name) diff --git a/commit.h b/commit.h index 01b8b1d..000d194 100644 --- a/commit.h +++ b/commit.h @@ -65,7 +65,10 @@ const struct name_decoration *get_name_decoration(const struct object *obj); struct commit *lookup_commit(const struct object_id *oid); struct commit *lookup_commit_reference(const struct object_id *oid); -struct commit *lookup_commit_reference_gently(const struct object_id *oid, +#define lookup_commit_reference_gently(r, o, q) \ + lookup_commit_reference_gently_##r(o, q) +struct commit *lookup_commit_reference_gently_the_repository( + const struct object_id *oid, int quiet); struct commit *lookup_commit_reference_by_name(const char *name); diff --git a/fast-import.c b/fast-import.c index 4d55910..3ea5781 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1724,8 +1724,10 @@ static int update_branch(struct branch *b) if (!force_update && !is_null_oid(&old_oid)) { struct commit *old_cmit, *new_cmit; - old_cmit = lookup_commit_reference_gently(&old_oid, 0); - new_cmit = lookup_commit_reference_gently(&b->oid, 0); + old_cmit = lookup_commit_reference_gently(the_repository, + &old_oid, 0); + new_cmit = lookup_commit_reference_gently(the_repository, + &b->oid, 0); if (!old_cmit || !new_cmit) return error("Branch %s is missing commits.", b->name); diff --git a/notes-cache.c b/notes-cache.c index d577003..d87e7ca 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -1,6 +1,7 @@ #include "cache.h" #include "notes-cache.h" #include "object-store.h" +#include "repository.h" #include "commit.h" #include "refs.h" @@ -15,7 +16,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity) if (read_ref(ref, &oid) < 0) return 0; - commit = lookup_commit_reference_gently(&oid, 1); + commit = lookup_commit_reference_gently(the_repository, &oid, 1); if (!commit) return 0; diff --git a/ref-filter.c b/ref-filter.c index ec9479a..49021ee 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2026,7 +2026,8 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid, * non-commits early. The actual filtering is done later. */ if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) { - commit = lookup_commit_reference_gently(oid, 1); + commit = lookup_commit_reference_gently(the_repository, oid, + 1); if (!commit) return 0; /* We perform the filtering for the '--contains' option... */ @@ -2383,7 +2384,8 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) if (get_oid(arg, &oid)) die(_("malformed object name %s"), arg); - rf->merge_commit = lookup_commit_reference_gently(&oid, 0); + rf->merge_commit = lookup_commit_reference_gently(the_repository, + &oid, 0); if (!rf->merge_commit) return opterror(opt, "must point to a commit", 0); diff --git a/remote.c b/remote.c index a5c04a0..0f1a84d 100644 --- a/remote.c +++ b/remote.c @@ -1149,7 +1149,7 @@ static void add_to_tips(struct tips *tips, const struct object_id *oid) if (is_null_oid(oid)) return; - commit = lookup_commit_reference_gently(oid, 1); + commit = lookup_commit_reference_gently(the_repository, oid, 1); if (!commit || (commit->object.flags & TMP_MARK)) return; commit->object.flags |= TMP_MARK; @@ -1211,7 +1211,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds if (is_null_oid(&ref->new_oid)) continue; - commit = lookup_commit_reference_gently(&ref->new_oid, + commit = lookup_commit_reference_gently(the_repository, + &ref->new_oid, 1); if (!commit) /* not pushing a commit, which is not an error */ @@ -1435,8 +1436,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS; else if (!has_object_file(&ref->old_oid)) reject_reason = REF_STATUS_REJECT_FETCH_FIRST; - else if (!lookup_commit_reference_gently(&ref->old_oid, 1) || - !lookup_commit_reference_gently(&ref->new_oid, 1)) + else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) || + !lookup_commit_reference_gently(the_repository, &ref->new_oid, 1)) reject_reason = REF_STATUS_REJECT_NEEDS_FORCE; else if (!ref_newer(&ref->new_oid, &ref->old_oid)) reject_reason = REF_STATUS_REJECT_NONFASTFORWARD; diff --git a/sequencer.c b/sequencer.c index 4cf7afb..b4170b7 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3610,7 +3610,7 @@ int sequencer_pick_revisions(struct replay_opts *opts) continue; if (!get_oid(name, &oid)) { - if (!lookup_commit_reference_gently(&oid, 1)) { + if (!lookup_commit_reference_gently(the_repository, &oid, 1)) { enum object_type type = oid_object_info(the_repository, &oid, NULL); diff --git a/sha1-name.c b/sha1-name.c index dd19aba..4736118 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1251,13 +1251,13 @@ int get_oid_mb(const char *name, struct object_id *oid) } if (st) return st; - one = lookup_commit_reference_gently(&oid_tmp, 0); + one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0); if (!one) return -1; if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp)) return -1; - two = lookup_commit_reference_gently(&oid_tmp, 0); + two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0); if (!two) return -1; mbs = get_merge_bases(one, two); diff --git a/shallow.c b/shallow.c index e53067c..40054b9 100644 --- a/shallow.c +++ b/shallow.c @@ -492,7 +492,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid, struct commit_list *head = NULL; int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32); size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr); - struct commit *c = lookup_commit_reference_gently(oid, 1); + struct commit *c = lookup_commit_reference_gently(the_repository, oid, + 1); uint32_t *tmp; /* to be freed before return */ uint32_t *bitmap; @@ -554,7 +555,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid, static int mark_uninteresting(const char *refname, const struct object_id *oid, int flags, void *cb_data) { - struct commit *commit = lookup_commit_reference_gently(oid, 1); + struct commit *commit = lookup_commit_reference_gently(the_repository, + oid, 1); if (!commit) return 0; commit->object.flags |= UNINTERESTING; @@ -664,7 +666,8 @@ static int add_ref(const char *refname, const struct object_id *oid, { struct commit_array *ca = cb_data; ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc); - ca->commits[ca->nr] = lookup_commit_reference_gently(oid, 1); + ca->commits[ca->nr] = lookup_commit_reference_gently(the_repository, + oid, 1); if (ca->commits[ca->nr]) ca->nr++; return 0; diff --git a/walker.c b/walker.c index a3a2566..96990d8 100644 --- a/walker.c +++ b/walker.c @@ -207,7 +207,8 @@ static int interpret_target(struct walker *walker, char *target, struct object_i static int mark_complete(const char *path, const struct object_id *oid, int flag, void *cb_data) { - struct commit *commit = lookup_commit_reference_gently(oid, 1); + struct commit *commit = lookup_commit_reference_gently(the_repository, + oid, 1); if (commit) { commit->object.flags |= COMPLETE; diff --git a/wt-status.c b/wt-status.c index 8827a25..6c0e400 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1489,7 +1489,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state) /* sha1 is a commit? match without further lookup */ (!oidcmp(&cb.noid, &oid) || /* perhaps sha1 is a tag, try to dereference to a commit */ - ((commit = lookup_commit_reference_gently(&oid, 1)) != NULL && + ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL && !oidcmp(&cb.noid, &commit->object.oid)))) { const char *from = ref; if (!skip_prefix(from, "refs/tags/", &from)) -- cgit v0.10.2-6-g49f6 From 2122f6754c93be8f02bfb5704ed96c88fc9837a8 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:58 -0700 Subject: commit: add repository argument to lookup_commit_reference Add a repository argument to allow callers of lookup_commit_reference 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 Signed-off-by: Junio C Hamano diff --git a/bisect.c b/bisect.c index 6de1abd..e1275ba 100644 --- a/bisect.c +++ b/bisect.c @@ -724,7 +724,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout) static struct commit *get_commit_reference(const struct object_id *oid) { - struct commit *r = lookup_commit_reference(oid); + struct commit *r = lookup_commit_reference(the_repository, oid); if (!r) die(_("Not a valid commit name %s"), oid_to_hex(oid)); return r; diff --git a/blame.c b/blame.c index 5b022cc..8a0655a 100644 --- a/blame.c +++ b/blame.c @@ -119,7 +119,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc { struct commit *parent; - parent = lookup_commit_reference(oid); + parent = lookup_commit_reference(the_repository, oid); if (!parent) die("no such commit %s", oid_to_hex(oid)); return &commit_list_insert(parent, tail)->next; diff --git a/branch.c b/branch.c index 6a35dd3..ecd710d 100644 --- a/branch.c +++ b/branch.c @@ -302,7 +302,7 @@ void create_branch(const char *name, const char *start_name, break; } - if ((commit = lookup_commit_reference(&oid)) == NULL) + if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL) die(_("Not a valid branch point: '%s'."), start_name); oidcpy(&oid, &commit->object.oid); diff --git a/builtin/branch.c b/builtin/branch.c index 1876ca9..a50632f 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -121,7 +121,8 @@ static int branch_merged(int kind, const char *name, (reference_name = reference_name_to_free = resolve_refdup(upstream, RESOLVE_REF_READING, &oid, NULL)) != NULL) - reference_rev = lookup_commit_reference(&oid); + reference_rev = lookup_commit_reference(the_repository, + &oid); } if (!reference_rev) reference_rev = head_rev; @@ -154,7 +155,7 @@ static int check_branch_commit(const char *branchname, const char *refname, const struct object_id *oid, struct commit *head_rev, int kinds, int force) { - struct commit *rev = lookup_commit_reference(oid); + struct commit *rev = lookup_commit_reference(the_repository, oid); if (!rev) { error(_("Couldn't look up commit object for '%s'"), refname); return -1; @@ -208,7 +209,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, } if (!force) { - head_rev = lookup_commit_reference(&head_oid); + head_rev = lookup_commit_reference(the_repository, &head_oid); if (!head_rev) die(_("Couldn't look up commit object for HEAD")); } diff --git a/builtin/clone.c b/builtin/clone.c index 1d939af..4b3b48e 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -696,7 +696,8 @@ static void update_head(const struct ref *our, const struct ref *remote, install_branch_config(0, head, option_origin, our->name); } } else if (our) { - struct commit *c = lookup_commit_reference(&our->old_oid); + struct commit *c = lookup_commit_reference(the_repository, + &our->old_oid); /* --branch specifies a non-branch (i.e. tags), detach HEAD */ update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR); diff --git a/builtin/describe.c b/builtin/describe.c index 0b5d856..c8ff647 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -303,7 +303,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst) unsigned long seen_commits = 0; unsigned int unannotated_cnt = 0; - cmit = lookup_commit_reference(oid); + cmit = lookup_commit_reference(the_repository, oid); n = find_commit_name(&cmit->object.oid); if (n && (tags || all || n->prio == 2)) { diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 2990151..a5718d9 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -11,7 +11,7 @@ static struct rev_info log_tree_opt; static int diff_tree_commit_oid(const struct object_id *oid) { - struct commit *commit = lookup_commit_reference(oid); + struct commit *commit = lookup_commit_reference(the_repository, oid); if (!commit) return -1; return log_tree_commit(&log_tree_opt, commit); diff --git a/builtin/log.c b/builtin/log.c index 0521759..55a6286 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -907,8 +907,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids) o2 = rev->pending.objects[1].item; flags1 = o1->flags; flags2 = o2->flags; - c1 = lookup_commit_reference(&o1->oid); - c2 = lookup_commit_reference(&o2->oid); + c1 = lookup_commit_reference(the_repository, &o1->oid); + c2 = lookup_commit_reference(the_repository, &o2->oid); if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) die(_("Not a range.")); @@ -1864,7 +1864,8 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags) { struct object_id oid; if (get_oid(arg, &oid) == 0) { - struct commit *commit = lookup_commit_reference(&oid); + struct commit *commit = lookup_commit_reference(the_repository, + &oid); if (commit) { commit->object.flags |= flags; add_pending_object(revs, &commit->object, arg); diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 3b76001..bbead6f 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -6,6 +6,7 @@ #include "diff.h" #include "revision.h" #include "parse-options.h" +#include "repository.h" static int show_merge_base(struct commit **rev, int rev_nr, int show_all) { @@ -42,7 +43,7 @@ static struct commit *get_commit_reference(const char *arg) if (get_oid(arg, &revkey)) die("Not a valid object name %s", arg); - r = lookup_commit_reference(&revkey); + r = lookup_commit_reference(the_repository, &revkey); if (!r) die("Not a valid commit name %s", arg); @@ -171,7 +172,7 @@ static int handle_fork_point(int argc, const char **argv) if (get_oid(commitname, &oid)) die("Not a valid object name: '%s'", commitname); - derived = lookup_commit_reference(&oid); + derived = lookup_commit_reference(the_repository, &oid); memset(&revs, 0, sizeof(revs)); revs.initial = 1; for_each_reflog_ent(refname, collect_one_reflog_ent, &revs); diff --git a/builtin/notes.c b/builtin/notes.c index a0a1840..c05cd00 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -12,6 +12,7 @@ #include "builtin.h" #include "notes.h" #include "object-store.h" +#include "repository.h" #include "blob.h" #include "pretty.h" #include "refs.h" @@ -711,7 +712,7 @@ static int merge_commit(struct notes_merge_options *o) if (get_oid("NOTES_MERGE_PARTIAL", &oid)) die(_("failed to read ref NOTES_MERGE_PARTIAL")); - else if (!(partial = lookup_commit_reference(&oid))) + else if (!(partial = lookup_commit_reference(the_repository, &oid))) die(_("could not find commit from NOTES_MERGE_PARTIAL.")); else if (parse_commit(partial)) die(_("could not parse commit from NOTES_MERGE_PARTIAL.")); diff --git a/builtin/pull.c b/builtin/pull.c index 7197b22..4e78935 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -765,10 +765,13 @@ static int get_octopus_merge_base(struct object_id *merge_base, { struct commit_list *revs = NULL, *result; - commit_list_insert(lookup_commit_reference(curr_head), &revs); - commit_list_insert(lookup_commit_reference(merge_head), &revs); + commit_list_insert(lookup_commit_reference(the_repository, curr_head), + &revs); + commit_list_insert(lookup_commit_reference(the_repository, merge_head), + &revs); if (!is_null_oid(fork_point)) - commit_list_insert(lookup_commit_reference(fork_point), &revs); + commit_list_insert(lookup_commit_reference(the_repository, fork_point), + &revs); result = get_octopus_merge_bases(revs); free_commit_list(revs); @@ -944,9 +947,11 @@ int cmd_pull(int argc, const char **argv, const char *prefix) struct commit_list *list = NULL; struct commit *merge_head, *head; - head = lookup_commit_reference(&orig_head); + head = lookup_commit_reference(the_repository, + &orig_head); commit_list_insert(head, &list); - merge_head = lookup_commit_reference(&merge_heads.oid[0]); + merge_head = lookup_commit_reference(the_repository, + &merge_heads.oid[0]); if (is_descendant_of(merge_head, list)) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; diff --git a/builtin/replace.c b/builtin/replace.c index deabda2..0232f98 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -371,7 +371,7 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv) return error(_("Not a valid object name: '%s'"), argv[i]); } - if (!lookup_commit_reference(&oid)) { + if (!lookup_commit_reference(the_repository, &oid)) { strbuf_release(&new_parents); return error(_("could not parse %s"), argv[i]); } @@ -443,7 +443,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle) if (get_oid(old_ref, &old_oid) < 0) return error(_("Not a valid object name: '%s'"), old_ref); - commit = lookup_commit_reference(&old_oid); + commit = lookup_commit_reference(the_repository, &old_oid); if (!commit) return error(_("could not parse %s"), old_ref); diff --git a/builtin/reset.c b/builtin/reset.c index ffe41c9..d9871e5 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -319,7 +319,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) struct commit *commit; if (get_oid_committish(rev, &oid)) die(_("Failed to resolve '%s' as a valid revision."), rev); - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (!commit) die(_("Could not parse object '%s'."), rev); oidcpy(&oid, &commit->object.oid); @@ -396,7 +396,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) update_ref_status = reset_refs(rev, &oid); if (reset_type == HARD && !update_ref_status && !quiet) - print_new_head_line(lookup_commit_reference(&oid)); + print_new_head_line(lookup_commit_reference(the_repository, &oid)); } if (!pathspec.nr) remove_branch_state(); diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 2a6cb29..0f09bbb 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -280,8 +280,8 @@ static int try_difference(const char *arg) if (symmetric) { struct commit_list *exclude; struct commit *a, *b; - a = lookup_commit_reference(&start_oid); - b = lookup_commit_reference(&end_oid); + a = lookup_commit_reference(the_repository, &start_oid); + b = lookup_commit_reference(the_repository, &end_oid); if (!a || !b) { *dotdot = '.'; return 0; @@ -333,7 +333,7 @@ static int try_parent_shorthands(const char *arg) *dotdot = 0; if (get_oid_committish(arg, &oid) || - !(commit = lookup_commit_reference(&oid))) { + !(commit = lookup_commit_reference(the_repository, &oid))) { *dotdot = '^'; return 0; } diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 2456b47..4b9d3c0 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -831,7 +831,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) MAX_REVS), MAX_REVS); if (get_oid(ref_name[num_rev], &revkey)) die(_("'%s' is not a valid ref."), ref_name[num_rev]); - commit = lookup_commit_reference(&revkey); + commit = lookup_commit_reference(the_repository, &revkey); if (!commit) die(_("cannot find commit %s (%s)"), ref_name[num_rev], oid_to_hex(&revkey)); diff --git a/builtin/tag.c b/builtin/tag.c index 9919b03..9a19ffb 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -313,7 +313,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb) } free(buf); - if ((c = lookup_commit_reference(oid)) != NULL) + if ((c = lookup_commit_reference(the_repository, oid)) != NULL) strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT))); break; case OBJ_TREE: diff --git a/bundle.c b/bundle.c index 0a9f4ee..24cbe40 100644 --- a/bundle.c +++ b/bundle.c @@ -375,7 +375,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) * in terms of a tag (e.g. v2.0 from the range * "v1.0..v2.0")? */ - struct commit *one = lookup_commit_reference(&oid); + struct commit *one = lookup_commit_reference(the_repository, + &oid); struct object *obj; if (e->item == &(one->object)) { diff --git a/commit.c b/commit.c index 756d557..5e50a07 100644 --- a/commit.c +++ b/commit.c @@ -35,14 +35,14 @@ struct commit *lookup_commit_reference_gently_the_repository( return object_as_type(the_repository, obj, OBJ_COMMIT, quiet); } -struct commit *lookup_commit_reference(const struct object_id *oid) +struct commit *lookup_commit_reference_the_repository(const struct object_id *oid) { return lookup_commit_reference_gently(the_repository, oid, 0); } struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name) { - struct commit *c = lookup_commit_reference(oid); + struct commit *c = lookup_commit_reference(the_repository, oid); if (!c) die(_("could not parse %s"), ref_name); if (oidcmp(oid, &c->object.oid)) { @@ -68,7 +68,7 @@ struct commit *lookup_commit_reference_by_name(const char *name) if (get_oid_committish(name, &oid)) return NULL; - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (parse_commit(commit)) return NULL; return commit; diff --git a/commit.h b/commit.h index 000d194..2a41113 100644 --- a/commit.h +++ b/commit.h @@ -64,7 +64,9 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj const struct name_decoration *get_name_decoration(const struct object *obj); struct commit *lookup_commit(const struct object_id *oid); -struct commit *lookup_commit_reference(const struct object_id *oid); +#define lookup_commit_reference(r, o) \ + lookup_commit_reference_##r(o) +struct commit *lookup_commit_reference_the_repository(const struct object_id *oid); #define lookup_commit_reference_gently(r, o, q) \ lookup_commit_reference_gently_##r(o, q) struct commit *lookup_commit_reference_gently_the_repository( diff --git a/merge-recursive.c b/merge-recursive.c index fbb044e..41366e7 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1192,9 +1192,9 @@ static int merge_submodule(struct merge_options *o, return 0; } - if (!(commit_base = lookup_commit_reference(base)) || - !(commit_a = lookup_commit_reference(a)) || - !(commit_b = lookup_commit_reference(b))) { + if (!(commit_base = lookup_commit_reference(the_repository, base)) || + !(commit_a = lookup_commit_reference(the_repository, a)) || + !(commit_b = lookup_commit_reference(the_repository, b))) { output(o, 1, _("Failed to merge submodule %s (commits not present)"), path); return 0; } diff --git a/notes-merge.c b/notes-merge.c index 9cc2ee1..76ab19e 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -2,6 +2,7 @@ #include "commit.h" #include "refs.h" #include "object-store.h" +#include "repository.h" #include "diff.h" #include "diffcore.h" #include "xdiff-interface.h" @@ -553,7 +554,7 @@ int notes_merge(struct notes_merge_options *o, else if (!check_refname_format(o->local_ref, 0) && is_null_oid(&local_oid)) local = NULL; /* local_oid == null_oid indicates unborn ref */ - else if (!(local = lookup_commit_reference(&local_oid))) + else if (!(local = lookup_commit_reference(the_repository, &local_oid))) die("Could not parse local commit %s (%s)", oid_to_hex(&local_oid), o->local_ref); trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid)); @@ -571,7 +572,7 @@ int notes_merge(struct notes_merge_options *o, die("Failed to resolve remote notes ref '%s'", o->remote_ref); } - } else if (!(remote = lookup_commit_reference(&remote_oid))) { + } else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) { die("Could not parse remote commit %s (%s)", oid_to_hex(&remote_oid), o->remote_ref); } diff --git a/parse-options-cb.c b/parse-options-cb.c index 0f9f311..e823653 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -91,7 +91,7 @@ int parse_opt_commits(const struct option *opt, const char *arg, int unset) return -1; if (get_oid(arg, &oid)) return error("malformed object name %s", arg); - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (!commit) return error("no such commit %s", arg); commit_list_insert(commit, opt->value); diff --git a/remote.c b/remote.c index 0f1a84d..8c75c45 100644 --- a/remote.c +++ b/remote.c @@ -1865,13 +1865,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, /* Cannot stat if what we used to build on no longer exists */ if (read_ref(base, &oid)) return -1; - theirs = lookup_commit_reference(&oid); + theirs = lookup_commit_reference(the_repository, &oid); if (!theirs) return -1; if (read_ref(branch->refname, &oid)) return -1; - ours = lookup_commit_reference(&oid); + ours = lookup_commit_reference(the_repository, &oid); if (!ours) return -1; diff --git a/revision.c b/revision.c index 02e1296..4dbe406 100644 --- a/revision.c +++ b/revision.c @@ -1591,8 +1591,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot, struct commit *a, *b; struct commit_list *exclude; - a = lookup_commit_reference(&a_obj->oid); - b = lookup_commit_reference(&b_obj->oid); + a = lookup_commit_reference(the_repository, &a_obj->oid); + b = lookup_commit_reference(the_repository, &b_obj->oid); if (!a || !b) return dotdot_missing(arg, dotdot, revs, symmetric); diff --git a/sequencer.c b/sequencer.c index b4170b7..cc7b191 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1176,7 +1176,7 @@ static int parse_head(struct commit **head) if (get_oid("HEAD", &oid)) { current_head = NULL; } else { - current_head = lookup_commit_reference(&oid); + current_head = lookup_commit_reference(the_repository, &oid); if (!current_head) return error(_("could not parse HEAD")); if (oidcmp(&oid, ¤t_head->object.oid)) { @@ -1511,7 +1511,7 @@ static int update_squash_messages(enum todo_command command, if (get_oid("HEAD", &head)) return error(_("need a HEAD to fixup")); - if (!(head_commit = lookup_commit_reference(&head))) + if (!(head_commit = lookup_commit_reference(the_repository, &head))) return error(_("could not read HEAD")); if (!(head_message = get_commit_buffer(head_commit, NULL))) return error(_("could not read HEAD's commit message")); @@ -2009,7 +2009,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) if (status < 0) return -1; - item->commit = lookup_commit_reference(&commit_oid); + item->commit = lookup_commit_reference(the_repository, &commit_oid); return !item->commit; } diff --git a/sha1-name.c b/sha1-name.c index 4736118..325915f 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -844,7 +844,7 @@ static int get_parent(const char *name, int len, if (ret) return ret; - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (parse_commit(commit)) return -1; if (!idx) { @@ -872,7 +872,7 @@ static int get_nth_ancestor(const char *name, int len, ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH); if (ret) return ret; - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (!commit) return -1; diff --git a/submodule.c b/submodule.c index 0998ea2..6688dd5 100644 --- a/submodule.c +++ b/submodule.c @@ -517,8 +517,8 @@ static void show_submodule_header(struct diff_options *o, const char *path, * Attempt to lookup the commit references, and determine if this is * a fast forward or fast backwards update. */ - *left = lookup_commit_reference(one); - *right = lookup_commit_reference(two); + *left = lookup_commit_reference(the_repository, one); + *right = lookup_commit_reference(the_repository, two); /* * Warn about missing commits in the submodule project, but only if -- cgit v0.10.2-6-g49f6 From c1f5eb49620d4f287af28509621a364e3888cfe7 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:21:59 -0700 Subject: commit: add repository argument to lookup_commit Add a repository argument to allow callers of lookup_commit 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 Signed-off-by: Junio C Hamano diff --git a/builtin/am.c b/builtin/am.c index 72e928c..b6eeb46 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1633,7 +1633,8 @@ static void do_commit(const struct am_state *state) if (!get_oid_commit("HEAD", &parent)) { old_oid = &parent; - commit_list_insert(lookup_commit(&parent), &parents); + commit_list_insert(lookup_commit(the_repository, &parent), + &parents); } else { old_oid = NULL; say(state, stderr, _("applying to an empty history")); diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 9fbd352..9ec36a8 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -6,6 +6,7 @@ #include "cache.h" #include "config.h" #include "object-store.h" +#include "repository.h" #include "commit.h" #include "tree.h" #include "builtin.h" @@ -60,7 +61,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) if (get_oid_commit(argv[i], &oid)) die("Not a valid object name %s", argv[i]); assert_oid_type(&oid, OBJ_COMMIT); - new_parent(lookup_commit(&oid), &parents); + new_parent(lookup_commit(the_repository, &oid), + &parents); continue; } diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index a5718d9..91ba670 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -25,7 +25,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p) /* Graft the fake parents locally to the commit */ while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) { - struct commit *parent = lookup_commit(&oid); + struct commit *parent = lookup_commit(the_repository, &oid); if (!pptr) { /* Free the real parent list */ free_commit_list(commit->parents); diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 7d6b1d8..223499d 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -963,7 +963,7 @@ static void import_marks(char *input_file) /* only commits */ continue; - commit = lookup_commit(&oid); + commit = lookup_commit(the_repository, &oid); if (!commit) die("not a commit? can't happen: %s", oid_to_hex(&oid)); diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 5e44589..36318ef 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -572,7 +572,7 @@ static void find_merge_parents(struct merge_parents *result, commit_list_insert(parent, &parents); add_merge_parent(result, &obj->oid, &parent->object.oid); } - head_commit = lookup_commit(head); + head_commit = lookup_commit(the_repository, head); if (head_commit) commit_list_insert(head_commit, &parents); reduce_heads_replace(&parents); diff --git a/builtin/merge-base.c b/builtin/merge-base.c index bbead6f..08d91b1 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -124,7 +124,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs) if (is_null_oid(oid)) return; - commit = lookup_commit(oid); + commit = lookup_commit(the_repository, oid); if (!commit || (commit->object.flags & TMP_MARK) || parse_commit(commit)) diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index f6922da..7772c07 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -9,6 +9,7 @@ #include "config.h" #include "builtin.h" #include "object-store.h" +#include "repository.h" #include "commit.h" #include "run-command.h" #include @@ -27,7 +28,8 @@ static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned memset(&signature_check, 0, sizeof(signature_check)); - ret = check_commit_signature(lookup_commit(oid), &signature_check); + ret = check_commit_signature(lookup_commit(the_repository, oid), + &signature_check); print_signature_buffer(&signature_check, flags); signature_check_clear(&signature_check); diff --git a/commit-graph.c b/commit-graph.c index 7801b51..7f907b4 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -242,7 +242,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g, struct commit *c; struct object_id oid; hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos); - c = lookup_commit(&oid); + c = lookup_commit(the_repository, &oid); if (!c) die("could not find commit %s", oid_to_hex(&oid)); c->graph_pos = pos; @@ -568,7 +568,7 @@ static void close_reachable(struct packed_oid_list *oids) struct commit *commit; for (i = 0; i < oids->nr; i++) { - commit = lookup_commit(&oids->list[i]); + commit = lookup_commit(the_repository, &oids->list[i]); if (commit) commit->object.flags |= UNINTERESTING; } @@ -579,14 +579,14 @@ static void close_reachable(struct packed_oid_list *oids) * closure. */ for (i = 0; i < oids->nr; i++) { - commit = lookup_commit(&oids->list[i]); + commit = lookup_commit(the_repository, &oids->list[i]); if (commit && !parse_commit(commit)) add_missing_parents(oids, commit); } for (i = 0; i < oids->nr; i++) { - commit = lookup_commit(&oids->list[i]); + commit = lookup_commit(the_repository, &oids->list[i]); if (commit) commit->object.flags &= ~UNINTERESTING; @@ -737,7 +737,7 @@ void write_commit_graph(const char *obj_dir, if (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i])) continue; - commits.list[commits.nr] = lookup_commit(&oids.list[i]); + commits.list[commits.nr] = lookup_commit(the_repository, &oids.list[i]); parse_commit(commits.list[commits.nr]); for (parent = commits.list[commits.nr]->parents; diff --git a/commit.c b/commit.c index 5e50a07..4803c8b 100644 --- a/commit.c +++ b/commit.c @@ -52,7 +52,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref return c; } -struct commit *lookup_commit(const struct object_id *oid) +struct commit *lookup_commit_the_repository(const struct object_id *oid) { struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) @@ -402,7 +402,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s */ if (graft && (graft->nr_parent < 0 || grafts_replace_parents)) continue; - new_parent = lookup_commit(&parent); + new_parent = lookup_commit(the_repository, &parent); if (new_parent) pptr = &commit_list_insert(new_parent, pptr)->next; } @@ -410,7 +410,8 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s int i; struct commit *new_parent; for (i = 0; i < graft->nr_parent; i++) { - new_parent = lookup_commit(&graft->parent[i]); + new_parent = lookup_commit(the_repository, + &graft->parent[i]); if (!new_parent) continue; pptr = &commit_list_insert(new_parent, pptr)->next; diff --git a/commit.h b/commit.h index 2a41113..cd80dab 100644 --- a/commit.h +++ b/commit.h @@ -63,7 +63,8 @@ enum decoration_type { void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); const struct name_decoration *get_name_decoration(const struct object *obj); -struct commit *lookup_commit(const struct object_id *oid); +#define lookup_commit(r, o) lookup_commit_##r(o) +struct commit *lookup_commit_the_repository(const struct object_id *oid); #define lookup_commit_reference(r, o) \ lookup_commit_reference_##r(o) struct commit *lookup_commit_reference_the_repository(const struct object_id *oid); diff --git a/fetch-pack.c b/fetch-pack.c index 771eb8a..9f3aa4a 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -498,7 +498,8 @@ static int find_common(struct fetch_pack_args *args, case ACK_ready: case ACK_continue: { struct commit *commit = - lookup_commit(result_oid); + lookup_commit(the_repository, + result_oid); if (!commit) die(_("invalid commit %s"), oid_to_hex(result_oid)); if (args->stateless_rpc @@ -1278,7 +1279,7 @@ static int process_acks(struct packet_reader *reader, struct oidset *common) if (!get_oid_hex(arg, &oid)) { struct commit *commit; oidset_insert(common, &oid); - commit = lookup_commit(&oid); + commit = lookup_commit(the_repository, &oid); mark_common(commit, 0, 1); } continue; diff --git a/log-tree.c b/log-tree.c index 0eb7c60..abe67e8 100644 --- a/log-tree.c +++ b/log-tree.c @@ -134,7 +134,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) { - struct commit *commit = lookup_commit(&graft->oid); + struct commit *commit = lookup_commit(the_repository, &graft->oid); if (!commit) return 0; add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object); diff --git a/notes-utils.c b/notes-utils.c index 02407fe..14ea031 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -3,6 +3,7 @@ #include "commit.h" #include "refs.h" #include "notes-utils.h" +#include "repository.h" void create_notes_commit(struct notes_tree *t, struct commit_list *parents, const char *msg, size_t msg_len, @@ -19,7 +20,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents, /* Deduce parent commit from t->ref */ struct object_id parent_oid; if (!read_ref(t->ref, &parent_oid)) { - struct commit *parent = lookup_commit(&parent_oid); + struct commit *parent = lookup_commit(the_repository, + &parent_oid); if (parse_commit(parent)) die("Failed to find/parse commit %s", t->ref); commit_list_insert(parent, &parents); diff --git a/object.c b/object.c index 2acd3a0..530c55e 100644 --- a/object.c +++ b/object.c @@ -212,7 +212,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e } } } else if (type == OBJ_COMMIT) { - struct commit *commit = lookup_commit(oid); + struct commit *commit = lookup_commit(the_repository, oid); if (commit) { if (parse_commit_buffer(commit, buffer, size, 1)) return NULL; diff --git a/sequencer.c b/sequencer.c index cc7b191..d1d07be 100644 --- a/sequencer.c +++ b/sequencer.c @@ -594,7 +594,7 @@ static int is_index_unchanged(void) if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL)) return error(_("could not resolve HEAD commit")); - head_commit = lookup_commit(&head_oid); + head_commit = lookup_commit(the_repository, &head_oid); /* * If head_commit is NULL, check_commit, called from @@ -1101,7 +1101,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid, struct strbuf author_ident = STRBUF_INIT; struct strbuf committer_ident = STRBUF_INIT; - commit = lookup_commit(oid); + commit = lookup_commit(the_repository, oid); if (!commit) die(_("couldn't look up newly created commit")); if (parse_commit(commit)) diff --git a/sha1-name.c b/sha1-name.c index 325915f..98480ad 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -351,7 +351,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data) type = oid_object_info(the_repository, oid, NULL); if (type == OBJ_COMMIT) { - struct commit *commit = lookup_commit(oid); + struct commit *commit = lookup_commit(the_repository, oid); if (commit) { struct pretty_print_context pp = {0}; pp.date_mode.type = DATE_SHORT; diff --git a/shallow.c b/shallow.c index 40054b9..e9ce55b 100644 --- a/shallow.c +++ b/shallow.c @@ -31,7 +31,7 @@ int register_shallow(struct repository *r, const struct object_id *oid) { struct commit_graft *graft = xmalloc(sizeof(struct commit_graft)); - struct commit *commit = lookup_commit(oid); + struct commit *commit = lookup_commit(the_repository, oid); oidcpy(&graft->oid, oid); graft->nr_parent = -1; @@ -259,7 +259,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data) if (graft->nr_parent != -1) return 0; if (data->flags & SEEN_ONLY) { - struct commit *c = lookup_commit(&graft->oid); + struct commit *c = lookup_commit(the_repository, &graft->oid); if (!c || !(c->object.flags & SEEN)) { if (data->flags & VERBOSE) printf("Removing %s from .git/shallow\n", @@ -624,7 +624,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, /* Mark potential bottoms so we won't go out of bound */ for (i = 0; i < nr_shallow; i++) { - struct commit *c = lookup_commit(&oid[shallow[i]]); + struct commit *c = lookup_commit(the_repository, + &oid[shallow[i]]); c->object.flags |= BOTTOM; } @@ -635,7 +636,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, int bitmap_size = DIV_ROUND_UP(pi.nr_bits, 32) * sizeof(uint32_t); memset(used, 0, sizeof(*used) * info->shallow->nr); for (i = 0; i < nr_shallow; i++) { - const struct commit *c = lookup_commit(&oid[shallow[i]]); + const struct commit *c = lookup_commit(the_repository, + &oid[shallow[i]]); uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c); if (*map) used[shallow[i]] = xmemdupz(*map, bitmap_size); @@ -705,7 +707,7 @@ static void post_assign_shallow(struct shallow_info *info, for (i = dst = 0; i < info->nr_theirs; i++) { if (i != dst) info->theirs[dst] = info->theirs[i]; - c = lookup_commit(&oid[info->theirs[i]]); + c = lookup_commit(the_repository, &oid[info->theirs[i]]); bitmap = ref_bitmap_at(ref_bitmap, c); if (!*bitmap) continue; @@ -726,7 +728,7 @@ static void post_assign_shallow(struct shallow_info *info, for (i = dst = 0; i < info->nr_ours; i++) { if (i != dst) info->ours[dst] = info->ours[i]; - c = lookup_commit(&oid[info->ours[i]]); + c = lookup_commit(the_repository, &oid[info->ours[i]]); bitmap = ref_bitmap_at(ref_bitmap, c); if (!*bitmap) continue; @@ -748,7 +750,8 @@ static void post_assign_shallow(struct shallow_info *info, int delayed_reachability_test(struct shallow_info *si, int c) { if (si->need_reachability_test[c]) { - struct commit *commit = lookup_commit(&si->shallow->oid[c]); + struct commit *commit = lookup_commit(the_repository, + &si->shallow->oid[c]); if (!si->commits) { struct commit_array ca; diff --git a/tag.c b/tag.c index 3101021..5dcdf7b 100644 --- a/tag.c +++ b/tag.c @@ -158,7 +158,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) } else if (!strcmp(type, tree_type)) { item->tagged = (struct object *)lookup_tree(the_repository, &oid); } else if (!strcmp(type, commit_type)) { - item->tagged = (struct object *)lookup_commit(&oid); + item->tagged = (struct object *)lookup_commit(the_repository, &oid); } else if (!strcmp(type, tag_type)) { item->tagged = (struct object *)lookup_tag(&oid); } else { diff --git a/tree.c b/tree.c index 12b6960..45e89ff 100644 --- a/tree.c +++ b/tree.c @@ -101,7 +101,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, else if (S_ISGITLINK(entry.mode)) { struct commit *commit; - commit = lookup_commit(entry.oid); + commit = lookup_commit(the_repository, entry.oid); if (!commit) die("Commit %s in submodule path %s%s not found", oid_to_hex(entry.oid), -- cgit v0.10.2-6-g49f6 From 08f4f44501bef21e10a1a449b8ba2d2710835b48 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:00 -0700 Subject: commit: add repository argument to parse_commit_buffer Add a repository argument to allow the callers of parse_commit_buffer to be more specific about which repository to act on. 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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index 4803c8b..75d0bde 100644 --- a/commit.c +++ b/commit.c @@ -363,7 +363,7 @@ const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) return ret; } -int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size, int check_graph) +int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size, int check_graph) { const char *tail = buffer; const char *bufptr = buffer; @@ -448,7 +448,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing) return error("Object %s not a commit", oid_to_hex(&item->object.oid)); } - ret = parse_commit_buffer(item, buffer, size, 0); + ret = parse_commit_buffer(the_repository, item, buffer, size, 0); if (save_commit_buffer && !ret) { set_commit_buffer(item, buffer, size); return 0; diff --git a/commit.h b/commit.h index cd80dab..f326c13 100644 --- a/commit.h +++ b/commit.h @@ -82,7 +82,8 @@ struct commit *lookup_commit_reference_by_name(const char *name); */ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name); -int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size, int check_graph); +#define parse_commit_buffer(r, i, b, s, g) parse_commit_buffer_##r(i, b, s, g) +int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size, int check_graph); int parse_commit_gently(struct commit *item, int quiet_on_missing); static inline int parse_commit(struct commit *item) { diff --git a/object.c b/object.c index 530c55e..5494c0c 100644 --- a/object.c +++ b/object.c @@ -214,7 +214,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e } else if (type == OBJ_COMMIT) { struct commit *commit = lookup_commit(the_repository, oid); if (commit) { - if (parse_commit_buffer(commit, buffer, size, 1)) + if (parse_commit_buffer(the_repository, commit, buffer, size, 1)) return NULL; if (!get_cached_commit_buffer(commit, NULL)) { set_commit_buffer(commit, buffer, size); diff --git a/sha1-file.c b/sha1-file.c index de4839e..75ba30b 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -1801,7 +1801,7 @@ static void check_commit(const void *buf, size_t size) { struct commit c; memset(&c, 0, sizeof(c)); - if (parse_commit_buffer(&c, buf, size, 0)) + if (parse_commit_buffer(the_repository, &c, buf, size, 0)) die("corrupt commit"); } -- cgit v0.10.2-6-g49f6 From 5e0c63604dc1e5bb2e81f0f216cf31bd98f14210 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:01 -0700 Subject: commit: add repository argument to set_commit_buffer Add a repository argument to allow callers of set_commit_buffer 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 Signed-off-by: Junio C Hamano diff --git a/blame.c b/blame.c index 8a0655a..cf10227 100644 --- a/blame.c +++ b/blame.c @@ -158,7 +158,7 @@ static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb) { size_t len; void *buf = strbuf_detach(sb, &len); - set_commit_buffer(c, buf, len); + set_commit_buffer(the_repository, c, buf, len); } /* diff --git a/commit.c b/commit.c index 75d0bde..cdfb1a0 100644 --- a/commit.c +++ b/commit.c @@ -262,7 +262,7 @@ struct commit_buffer { define_commit_slab(buffer_slab, struct commit_buffer); static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab); -void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size) +void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size) { struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); v->buffer = buffer; @@ -450,7 +450,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing) } ret = parse_commit_buffer(the_repository, item, buffer, size, 0); if (save_commit_buffer && !ret) { - set_commit_buffer(item, buffer, size); + set_commit_buffer(the_repository, item, buffer, size); return 0; } free(buffer); diff --git a/commit.h b/commit.h index f326c13..7c14dfd 100644 --- a/commit.h +++ b/commit.h @@ -95,7 +95,8 @@ void parse_commit_or_die(struct commit *item); * Associate an object buffer with the commit. The ownership of the * memory is handed over to the commit, and must be free()-able. */ -void set_commit_buffer(struct commit *, void *buffer, unsigned long size); +#define set_commit_buffer(r, c, b, s) set_commit_buffer_##r(c, b, s) +void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned long size); /* * Get any cached object buffer associated with the commit. Returns NULL diff --git a/object.c b/object.c index 5494c0c..d1f7756 100644 --- a/object.c +++ b/object.c @@ -217,7 +217,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e if (parse_commit_buffer(the_repository, commit, buffer, size, 1)) return NULL; if (!get_cached_commit_buffer(commit, NULL)) { - set_commit_buffer(commit, buffer, size); + set_commit_buffer(the_repository, commit, buffer, size); *eaten_p = 1; } obj = &commit->object; -- cgit v0.10.2-6-g49f6 From 3ce85f7e5a41116145179f0fae2ce6d86558d099 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:02 -0700 Subject: commit: add repository argument to get_cached_commit_buffer Add a repository argument to allow callers of get_cached_commit_buffer 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 Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index cdfb1a0..9e2899b 100644 --- a/commit.c +++ b/commit.c @@ -269,7 +269,7 @@ void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsig v->size = size; } -const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep) +const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep) { struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); if (!v) { @@ -284,7 +284,7 @@ const void *get_cached_commit_buffer(const struct commit *commit, unsigned long const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep) { - const void *ret = get_cached_commit_buffer(commit, sizep); + const void *ret = get_cached_commit_buffer(the_repository, commit, sizep); if (!ret) { enum object_type type; unsigned long size; diff --git a/commit.h b/commit.h index 7c14dfd..237607d 100644 --- a/commit.h +++ b/commit.h @@ -102,7 +102,8 @@ void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned lo * Get any cached object buffer associated with the commit. Returns NULL * if none. The resulting memory should not be freed. */ -const void *get_cached_commit_buffer(const struct commit *, unsigned long *size); +#define get_cached_commit_buffer(r, c, s) get_cached_commit_buffer_##r(c, s) +const void *get_cached_commit_buffer_the_repository(const struct commit *, unsigned long *size); /* * Get the commit's object contents, either from cache or by reading the object diff --git a/object.c b/object.c index d1f7756..f08a887 100644 --- a/object.c +++ b/object.c @@ -216,7 +216,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e if (commit) { if (parse_commit_buffer(the_repository, commit, buffer, size, 1)) return NULL; - if (!get_cached_commit_buffer(commit, NULL)) { + if (!get_cached_commit_buffer(the_repository, commit, NULL)) { set_commit_buffer(the_repository, commit, buffer, size); *eaten_p = 1; } diff --git a/pretty.c b/pretty.c index cbd25b6..cde4fe0 100644 --- a/pretty.c +++ b/pretty.c @@ -630,7 +630,7 @@ const char *logmsg_reencode(const struct commit *commit, * the cached copy from get_commit_buffer, we need to duplicate it * to avoid munging the cached copy. */ - if (msg == get_cached_commit_buffer(commit, NULL)) + if (msg == get_cached_commit_buffer(the_repository, commit, NULL)) out = xstrdup(msg); else out = (char *)msg; -- cgit v0.10.2-6-g49f6 From ce71efb713f97f476a2d2ab541a0c73f684a5db3 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:03 -0700 Subject: tag: add repository argument to lookup_tag Add a repository argument to allow the callers of lookup_tag to be more specific about which repository to act on. 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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/builtin/describe.c b/builtin/describe.c index c8ff647..41606c8 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -93,13 +93,13 @@ static int replace_name(struct commit_name *e, struct tag *t; if (!e->tag) { - t = lookup_tag(&e->oid); + t = lookup_tag(the_repository, &e->oid); if (!t || parse_tag(t)) return 1; e->tag = t; } - t = lookup_tag(oid); + t = lookup_tag(the_repository, oid); if (!t || parse_tag(t)) return 0; *tag = t; @@ -267,7 +267,7 @@ static unsigned long finish_depth_computation( static void append_name(struct commit_name *n, struct strbuf *dst) { if (n->prio == 2 && !n->tag) { - n->tag = lookup_tag(&n->oid); + n->tag = lookup_tag(the_repository, &n->oid); if (!n->tag || parse_tag(n->tag)) die(_("annotated tag %s not available"), n->path); } diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 69d3d7b..6565c80 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2474,7 +2474,7 @@ static void add_tag_chain(const struct object_id *oid) if (packlist_find(&to_pack, oid->hash, NULL)) return; - tag = lookup_tag(oid); + tag = lookup_tag(the_repository, oid); while (1) { if (!tag || parse_tag(tag) || !tag->tagged) die("unable to pack objects reachable from tag %s", diff --git a/builtin/replace.c b/builtin/replace.c index 0232f98..0351b7c 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -402,7 +402,7 @@ static int check_one_mergetag(struct commit *commit, int i; hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &tag_oid); - tag = lookup_tag(&tag_oid); + tag = lookup_tag(the_repository, &tag_oid); if (!tag) return error(_("bad mergetag in commit '%s'"), ref); if (parse_tag_buffer(tag, extra->value, extra->len)) diff --git a/log-tree.c b/log-tree.c index abe67e8..840423c 100644 --- a/log-tree.c +++ b/log-tree.c @@ -498,7 +498,7 @@ static int show_one_mergetag(struct commit *commit, size_t payload_size, gpg_message_offset; hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &oid); - tag = lookup_tag(&oid); + tag = lookup_tag(the_repository, &oid); if (!tag) return -1; /* error message already given */ diff --git a/object.c b/object.c index f08a887..bcfcfd3 100644 --- a/object.c +++ b/object.c @@ -223,7 +223,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e obj = &commit->object; } } else if (type == OBJ_TAG) { - struct tag *tag = lookup_tag(oid); + struct tag *tag = lookup_tag(the_repository, oid); if (tag) { if (parse_tag_buffer(tag, buffer, size)) return NULL; diff --git a/sha1-name.c b/sha1-name.c index 98480ad..5854bc7 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -358,7 +358,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data) format_commit_message(commit, " %ad - %s", &desc, &pp); } } else if (type == OBJ_TAG) { - struct tag *tag = lookup_tag(oid); + struct tag *tag = lookup_tag(the_repository, oid); if (!parse_tag(tag) && tag->tag) strbuf_addf(&desc, " %s", tag->tag); } diff --git a/tag.c b/tag.c index 5dcdf7b..5b41fc7 100644 --- a/tag.c +++ b/tag.c @@ -92,7 +92,7 @@ struct object *deref_tag_noverify(struct object *o) return o; } -struct tag *lookup_tag(const struct object_id *oid) +struct tag *lookup_tag_the_repository(const struct object_id *oid) { struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) @@ -160,7 +160,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) } else if (!strcmp(type, commit_type)) { item->tagged = (struct object *)lookup_commit(the_repository, &oid); } else if (!strcmp(type, tag_type)) { - item->tagged = (struct object *)lookup_tag(&oid); + item->tagged = (struct object *)lookup_tag(the_repository, &oid); } else { error("Unknown type %s", type); item->tagged = NULL; diff --git a/tag.h b/tag.h index 9057d76..276c448 100644 --- a/tag.h +++ b/tag.h @@ -11,8 +11,8 @@ struct tag { char *tag; timestamp_t date; }; - -extern struct tag *lookup_tag(const struct object_id *oid); +#define lookup_tag(r, o) lookup_tag_##r(o) +extern struct tag *lookup_tag_the_repository(const struct object_id *oid); extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size); extern int parse_tag(struct tag *item); extern void release_tag_memory(struct tag *t); -- cgit v0.10.2-6-g49f6 From 0e740fed5dfd84bf0d136719d91a7764a3477d20 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:04 -0700 Subject: tag: add repository argument to parse_tag_buffer Add a repository argument to allow the callers of parse_tag_buffer to be more specific about which repository to act on. 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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/builtin/replace.c b/builtin/replace.c index 0351b7c..ef22d72 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -405,7 +405,7 @@ static int check_one_mergetag(struct commit *commit, tag = lookup_tag(the_repository, &tag_oid); if (!tag) return error(_("bad mergetag in commit '%s'"), ref); - if (parse_tag_buffer(tag, extra->value, extra->len)) + if (parse_tag_buffer(the_repository, tag, extra->value, extra->len)) return error(_("malformed mergetag in commit '%s'"), ref); /* iterate over new parents */ diff --git a/log-tree.c b/log-tree.c index 840423c..76475d0 100644 --- a/log-tree.c +++ b/log-tree.c @@ -503,7 +503,7 @@ static int show_one_mergetag(struct commit *commit, return -1; /* error message already given */ strbuf_init(&verify_message, 256); - if (parse_tag_buffer(tag, extra->value, extra->len)) + if (parse_tag_buffer(the_repository, tag, extra->value, extra->len)) strbuf_addstr(&verify_message, "malformed mergetag\n"); else if (is_common_merge(commit) && !oidcmp(&tag->tagged->oid, diff --git a/object.c b/object.c index bcfcfd3..e095d49 100644 --- a/object.c +++ b/object.c @@ -225,7 +225,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e } else if (type == OBJ_TAG) { struct tag *tag = lookup_tag(the_repository, oid); if (tag) { - if (parse_tag_buffer(tag, buffer, size)) + if (parse_tag_buffer(the_repository, tag, buffer, size)) return NULL; obj = &tag->object; } diff --git a/sha1-file.c b/sha1-file.c index 75ba30b..c75ef77 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -1809,7 +1809,7 @@ static void check_tag(const void *buf, size_t size) { struct tag t; memset(&t, 0, sizeof(t)); - if (parse_tag_buffer(&t, buf, size)) + if (parse_tag_buffer(the_repository, &t, buf, size)) die("corrupt tag"); } diff --git a/tag.c b/tag.c index 5b41fc7..4971fd4 100644 --- a/tag.c +++ b/tag.c @@ -126,7 +126,7 @@ void release_tag_memory(struct tag *t) t->date = 0; } -int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) +int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size) { struct object_id oid; char type[20]; @@ -203,7 +203,7 @@ int parse_tag(struct tag *item) return error("Object %s not a tag", oid_to_hex(&item->object.oid)); } - ret = parse_tag_buffer(item, data, size); + ret = parse_tag_buffer(the_repository, item, data, size); free(data); return ret; } diff --git a/tag.h b/tag.h index 276c448..149959c 100644 --- a/tag.h +++ b/tag.h @@ -13,7 +13,8 @@ struct tag { }; #define lookup_tag(r, o) lookup_tag_##r(o) extern struct tag *lookup_tag_the_repository(const struct object_id *oid); -extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size); +#define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s) +extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size); extern int parse_tag(struct tag *item); extern void release_tag_memory(struct tag *t); extern struct object *deref_tag(struct object *, const char *, int); -- cgit v0.10.2-6-g49f6 From a74093da5ed601a09fa158e5ba6f6f14c1142a3e Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:05 -0700 Subject: tag: add repository argument to deref_tag Add a repository argument to allow the callers of deref_tag to be more specific about which repository to act on. 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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/blame.c b/blame.c index cf10227..4229bcd 100644 --- a/blame.c +++ b/blame.c @@ -1674,7 +1674,7 @@ static struct commit *find_single_final(struct rev_info *revs, struct object *obj = revs->pending.objects[i].item; if (obj->flags & UNINTERESTING) continue; - obj = deref_tag(obj, NULL, 0); + obj = deref_tag(the_repository, obj, NULL, 0); if (obj->type != OBJ_COMMIT) die("Non commit %s?", revs->pending.objects[i].name); if (found) @@ -1705,7 +1705,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs, /* Is that sole rev a committish? */ obj = revs->pending.objects[0].item; - obj = deref_tag(obj, NULL, 0); + obj = deref_tag(the_repository, obj, NULL, 0); if (obj->type != OBJ_COMMIT) return NULL; @@ -1741,7 +1741,7 @@ static struct commit *find_single_initial(struct rev_info *revs, struct object *obj = revs->pending.objects[i].item; if (!(obj->flags & UNINTERESTING)) continue; - obj = deref_tag(obj, NULL, 0); + obj = deref_tag(the_repository, obj, NULL, 0); if (obj->type != OBJ_COMMIT) die("Non commit %s?", revs->pending.objects[i].name); if (found) diff --git a/builtin/diff.c b/builtin/diff.c index 7971530..361a3c3 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -402,7 +402,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) int flags = (obj->flags & UNINTERESTING); if (!obj->parsed) obj = parse_object(the_repository, &obj->oid); - obj = deref_tag(obj, NULL, 0); + obj = deref_tag(the_repository, obj, NULL, 0); if (!obj) die(_("invalid object '%s' given."), name); if (obj->type == OBJ_COMMIT) diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 36318ef..ff165c0 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -344,7 +344,8 @@ static void shortlog(const char *name, const struct object_id *oid = &origin_data->oid; int limit = opts->shortlog_len; - branch = deref_tag(parse_object(the_repository, oid), oid_to_hex(oid), + branch = deref_tag(the_repository, parse_object(the_repository, oid), + oid_to_hex(oid), GIT_SHA1_HEXSZ); if (!branch || branch->type != OBJ_COMMIT) return; diff --git a/builtin/grep.c b/builtin/grep.c index ee753a4..538a818 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -647,7 +647,8 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, for (i = 0; i < nr; i++) { struct object *real_obj; - real_obj = deref_tag(list->objects[i].item, NULL, 0); + real_obj = deref_tag(the_repository, list->objects[i].item, + NULL, 0); /* load the gitmodules file for this rev */ if (recurse_submodules) { diff --git a/builtin/name-rev.c b/builtin/name-rev.c index f6eb419..f1cb45c 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -455,7 +455,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) commit = NULL; object = parse_object(the_repository, &oid); if (object) { - struct object *peeled = deref_tag(object, *argv, 0); + struct object *peeled = deref_tag(the_repository, + object, *argv, 0); if (peeled && peeled->type == OBJ_COMMIT) commit = (struct commit *)peeled; } diff --git a/commit.c b/commit.c index 9e2899b..aa5557d 100644 --- a/commit.c +++ b/commit.c @@ -27,7 +27,8 @@ const char *commit_type = "commit"; struct commit *lookup_commit_reference_gently_the_repository( const struct object_id *oid, int quiet) { - struct object *obj = deref_tag(parse_object(the_repository, oid), + struct object *obj = deref_tag(the_repository, + parse_object(the_repository, oid), NULL, 0); if (!obj) diff --git a/fetch-pack.c b/fetch-pack.c index 9f3aa4a..d60d83f 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -126,7 +126,8 @@ static void rev_list_push(struct commit *commit, int mark) static int rev_list_insert_ref(const char *refname, const struct object_id *oid) { - struct object *o = deref_tag(parse_object(the_repository, oid), + struct object *o = deref_tag(the_repository, + parse_object(the_repository, oid), refname, 0); if (o && o->type == OBJ_COMMIT) @@ -144,7 +145,8 @@ static int rev_list_insert_ref_oid(const char *refname, const struct object_id * static int clear_marks(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - struct object *o = deref_tag(parse_object(the_repository, oid), + struct object *o = deref_tag(the_repository, + parse_object(the_repository, oid), refname, 0); if (o && o->type == OBJ_COMMIT) @@ -802,7 +804,8 @@ static int everything_local(struct fetch_pack_args *args, * Don't mark them common yet; the server has to be told so first. */ for (ref = *refs; ref; ref = ref->next) { - struct object *o = deref_tag(lookup_object(the_repository, + struct object *o = deref_tag(the_repository, + lookup_object(the_repository, ref->old_oid.hash), NULL, 0); diff --git a/http-backend.c b/http-backend.c index 50ba4d5..bd0442a 100644 --- a/http-backend.c +++ b/http-backend.c @@ -442,7 +442,7 @@ static int show_text_ref(const char *name, const struct object_id *oid, strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons); if (o->type == OBJ_TAG) { - o = deref_tag(o, name, 0); + o = deref_tag(the_repository, o, name, 0); if (!o) return 0; strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid), diff --git a/http-push.c b/http-push.c index f7b70c4..5eaf551 100644 --- a/http-push.c +++ b/http-push.c @@ -1477,7 +1477,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls) oid_to_hex(&ref->old_oid), ls->dentry_name); if (o->type == OBJ_TAG) { - o = deref_tag(o, ls->dentry_name, 0); + o = deref_tag(the_repository, o, ls->dentry_name, 0); if (o) strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid), ls->dentry_name); diff --git a/line-log.c b/line-log.c index fa9cfd5..7fa0f16 100644 --- a/line-log.c +++ b/line-log.c @@ -479,7 +479,7 @@ static struct commit *check_single_commit(struct rev_info *revs) struct object *obj = revs->pending.objects[i].item; if (obj->flags & UNINTERESTING) continue; - obj = deref_tag(obj, NULL, 0); + obj = deref_tag(the_repository, obj, NULL, 0); if (obj->type != OBJ_COMMIT) die("Non commit %s?", revs->pending.objects[i].name); if (commit) diff --git a/merge-recursive.c b/merge-recursive.c index 41366e7..1dd6ec3 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3467,7 +3467,8 @@ static struct commit *get_ref(const struct object_id *oid, const char *name) { struct object *object; - object = deref_tag(parse_object(the_repository, oid), name, + object = deref_tag(the_repository, parse_object(the_repository, oid), + name, strlen(name)); if (!object) return NULL; diff --git a/remote.c b/remote.c index 8c75c45..26b1fbd 100644 --- a/remote.c +++ b/remote.c @@ -1802,12 +1802,14 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid) * Both new_commit and old_commit must be commit-ish and new_commit is descendant of * old_commit. Otherwise we require --force. */ - o = deref_tag(parse_object(the_repository, old_oid), NULL, 0); + o = deref_tag(the_repository, parse_object(the_repository, old_oid), + NULL, 0); if (!o || o->type != OBJ_COMMIT) return 0; old_commit = (struct commit *) o; - o = deref_tag(parse_object(the_repository, new_oid), NULL, 0); + o = deref_tag(the_repository, parse_object(the_repository, new_oid), + NULL, 0); if (!o || o->type != OBJ_COMMIT) return 0; new_commit = (struct commit *) o; diff --git a/server-info.c b/server-info.c index 2abd0dc..41050c2 100644 --- a/server-info.c +++ b/server-info.c @@ -64,7 +64,7 @@ static int add_info_ref(const char *path, const struct object_id *oid, return -1; if (o->type == OBJ_TAG) { - o = deref_tag(o, path, 0); + o = deref_tag(the_repository, o, path, 0); if (o) if (fprintf(fp, "%s %s^{}\n", oid_to_hex(&o->oid), path) < 0) diff --git a/sha1-name.c b/sha1-name.c index 5854bc7..009faab 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -239,7 +239,8 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da return 0; /* We need to do this the hard way... */ - obj = deref_tag(parse_object(the_repository, oid), NULL, 0); + obj = deref_tag(the_repository, parse_object(the_repository, oid), + NULL, 0); if (obj && obj->type == OBJ_COMMIT) return 1; return 0; @@ -263,7 +264,8 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_ return 0; /* We need to do this the hard way... */ - obj = deref_tag(parse_object(the_repository, oid), NULL, 0); + obj = deref_tag(the_repository, parse_object(the_repository, oid), + NULL, 0); if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT)) return 1; return 0; @@ -968,7 +970,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid, if (!o) return -1; if (!expected_type) { - o = deref_tag(o, name, sp - name - 2); + o = deref_tag(the_repository, o, name, sp - name - 2); if (!o || (!o->parsed && !parse_object(the_repository, &o->oid))) return -1; oidcpy(oid, &o->oid); @@ -1100,7 +1102,8 @@ static int handle_one_ref(const char *path, const struct object_id *oid, if (!object) return 0; if (object->type == OBJ_TAG) { - object = deref_tag(object, path, strlen(path)); + object = deref_tag(the_repository, object, path, + strlen(path)); if (!object) return 0; } diff --git a/shallow.c b/shallow.c index e9ce55b..dbe8a2a 100644 --- a/shallow.c +++ b/shallow.c @@ -96,7 +96,9 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth, if (i < heads->nr) { int **depth_slot; commit = (struct commit *) - deref_tag(heads->objects[i++].item, NULL, 0); + deref_tag(the_repository, + heads->objects[i++].item, + NULL, 0); if (!commit || commit->object.type != OBJ_COMMIT) { commit = NULL; continue; diff --git a/tag.c b/tag.c index 4971fd4..fbb4659 100644 --- a/tag.c +++ b/tag.c @@ -64,7 +64,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report, return ret; } -struct object *deref_tag(struct object *o, const char *warn, int warnlen) +struct object *deref_tag_the_repository(struct object *o, const char *warn, int warnlen) { while (o && o->type == OBJ_TAG) if (((struct tag *)o)->tagged) diff --git a/tag.h b/tag.h index 149959c..45b0b08 100644 --- a/tag.h +++ b/tag.h @@ -17,7 +17,8 @@ extern struct tag *lookup_tag_the_repository(const struct object_id *oid); extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size); extern int parse_tag(struct tag *item); extern void release_tag_memory(struct tag *t); -extern struct object *deref_tag(struct object *, const char *, int); +#define deref_tag(r, o, w, l) deref_tag_##r(o, w, l) +extern struct object *deref_tag_the_repository(struct object *, const char *, int); extern struct object *deref_tag_noverify(struct object *); extern int gpg_verify_tag(const struct object_id *oid, const char *name_to_report, unsigned flags); diff --git a/upload-pack.c b/upload-pack.c index 45e3a94..4ca052d 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -380,7 +380,7 @@ static int ok_to_give_up(void) if (want->flags & COMMON_KNOWN) continue; - want = deref_tag(want, "a want line", 0); + want = deref_tag(the_repository, want, "a want line", 0); if (!want || want->type != OBJ_COMMIT) { /* no way to tell if this is reachable by * looking at the ancestry chain alone, so -- cgit v0.10.2-6-g49f6 From a962da1ef59c71b6b18f71aeb25f1edaa99769f6 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:06 -0700 Subject: object: allow object_as_type to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/object.c b/object.c index e095d49..f41f82c 100644 --- a/object.c +++ b/object.c @@ -158,13 +158,13 @@ void *create_object(struct repository *r, const unsigned char *sha1, void *o) return obj; } -void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet) +void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet) { if (obj->type == type) return obj; else if (obj->type == OBJ_NONE) { if (type == OBJ_COMMIT) - ((struct commit *)obj)->index = alloc_commit_index(the_repository); + ((struct commit *)obj)->index = alloc_commit_index(r); obj->type = type; return obj; } diff --git a/object.h b/object.h index 3faa895..6f3271e 100644 --- a/object.h +++ b/object.h @@ -114,8 +114,7 @@ struct object *lookup_object_the_repository(const unsigned char *sha1); extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj); -#define object_as_type(r, o, t, q) object_as_type_##r(o, t, q) -void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet); +void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet); /* * Returns the object, having parsed it to find out what it is. -- cgit v0.10.2-6-g49f6 From 94c09a7197cde15587318dbb60cdc591d443f45c Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:07 -0700 Subject: object: allow lookup_object to handle arbitrary repositories Signed-off-by: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/object.c b/object.c index f41f82c..9d74de9 100644 --- a/object.c +++ b/object.c @@ -84,21 +84,20 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i * Look up the record for the given sha1 in the hash map stored in * obj_hash. Return NULL if it was not found. */ -struct object *lookup_object_the_repository(const unsigned char *sha1) +struct object *lookup_object(struct repository *r, const unsigned char *sha1) { unsigned int i, first; struct object *obj; - if (!the_repository->parsed_objects->obj_hash) + if (!r->parsed_objects->obj_hash) return NULL; - first = i = hash_obj(sha1, - the_repository->parsed_objects->obj_hash_size); - while ((obj = the_repository->parsed_objects->obj_hash[i]) != NULL) { + first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size); + while ((obj = r->parsed_objects->obj_hash[i]) != NULL) { if (!hashcmp(sha1, obj->oid.hash)) break; i++; - if (i == the_repository->parsed_objects->obj_hash_size) + if (i == r->parsed_objects->obj_hash_size) i = 0; } if (obj && i != first) { @@ -107,8 +106,8 @@ struct object *lookup_object_the_repository(const unsigned char *sha1) * that we do not need to walk the hash table the next * time we look for it. */ - SWAP(the_repository->parsed_objects->obj_hash[i], - the_repository->parsed_objects->obj_hash[first]); + SWAP(r->parsed_objects->obj_hash[i], + r->parsed_objects->obj_hash[first]); } return obj; } diff --git a/object.h b/object.h index 6f3271e..0d7d741 100644 --- a/object.h +++ b/object.h @@ -109,8 +109,7 @@ extern struct object *get_indexed_object(unsigned int); * half-initialised objects, the caller is expected to initialize them * by calling parse_object() on them. */ -#define lookup_object(r, s) lookup_object_##r(s) -struct object *lookup_object_the_repository(const unsigned char *sha1); +struct object *lookup_object(struct repository *r, const unsigned char *sha1); extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj); -- cgit v0.10.2-6-g49f6 From 17126cdf78dc7b8cbe6b35bc44cb74d8d0fb11ee Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:08 -0700 Subject: blob: allow lookup_blob to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/blob.c b/blob.c index 17b9314..342bdbb 100644 --- a/blob.c +++ b/blob.c @@ -5,13 +5,13 @@ const char *blob_type = "blob"; -struct blob *lookup_blob_the_repository(const struct object_id *oid) +struct blob *lookup_blob(struct repository *r, const struct object_id *oid) { - struct object *obj = lookup_object(the_repository, oid->hash); + struct object *obj = lookup_object(r, oid->hash); if (!obj) - return create_object(the_repository, oid->hash, - alloc_blob_node(the_repository)); - return object_as_type(the_repository, obj, OBJ_BLOB, 0); + return create_object(r, oid->hash, + alloc_blob_node(r)); + return object_as_type(r, obj, OBJ_BLOB, 0); } int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size) diff --git a/blob.h b/blob.h index 08bc344..1664872 100644 --- a/blob.h +++ b/blob.h @@ -9,8 +9,7 @@ struct blob { struct object object; }; -#define lookup_blob(r, o) lookup_blob_##r(o) -struct blob *lookup_blob_the_repository(const struct object_id *oid); +struct blob *lookup_blob(struct repository *r, const struct object_id *oid); int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size); -- cgit v0.10.2-6-g49f6 From f58a6cb60222d32063437ae85859e6e7ac7ffc8e Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:09 -0700 Subject: tree: allow lookup_tree to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/tree.c b/tree.c index 45e89ff..78d440a 100644 --- a/tree.c +++ b/tree.c @@ -195,13 +195,13 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match, return 0; } -struct tree *lookup_tree_the_repository(const struct object_id *oid) +struct tree *lookup_tree(struct repository *r, const struct object_id *oid) { - struct object *obj = lookup_object(the_repository, oid->hash); + struct object *obj = lookup_object(r, oid->hash); if (!obj) - return create_object(the_repository, oid->hash, - alloc_tree_node(the_repository)); - return object_as_type(the_repository, obj, OBJ_TREE, 0); + return create_object(r, oid->hash, + alloc_tree_node(r)); + return object_as_type(r, obj, OBJ_TREE, 0); } int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size) diff --git a/tree.h b/tree.h index 2ea21ed..d4807dc 100644 --- a/tree.h +++ b/tree.h @@ -12,8 +12,7 @@ struct tree { unsigned long size; }; -#define lookup_tree(r, oid) lookup_tree_##r(oid) -struct tree *lookup_tree_the_repository(const struct object_id *oid); +struct tree *lookup_tree(struct repository *r, const struct object_id *oid); int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); -- cgit v0.10.2-6-g49f6 From bacf16874e0af1a34537d814274d66ae16d4cde8 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:10 -0700 Subject: commit: allow lookup_commit to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index aa5557d..8749e15 100644 --- a/commit.c +++ b/commit.c @@ -53,13 +53,13 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref return c; } -struct commit *lookup_commit_the_repository(const struct object_id *oid) +struct commit *lookup_commit(struct repository *r, const struct object_id *oid) { - struct object *obj = lookup_object(the_repository, oid->hash); + struct object *obj = lookup_object(r, oid->hash); if (!obj) - return create_object(the_repository, oid->hash, - alloc_commit_node(the_repository)); - return object_as_type(the_repository, obj, OBJ_COMMIT, 0); + return create_object(r, oid->hash, + alloc_commit_node(r)); + return object_as_type(r, obj, OBJ_COMMIT, 0); } struct commit *lookup_commit_reference_by_name(const char *name) diff --git a/commit.h b/commit.h index 237607d..27888d8 100644 --- a/commit.h +++ b/commit.h @@ -63,8 +63,7 @@ enum decoration_type { void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); const struct name_decoration *get_name_decoration(const struct object *obj); -#define lookup_commit(r, o) lookup_commit_##r(o) -struct commit *lookup_commit_the_repository(const struct object_id *oid); +struct commit *lookup_commit(struct repository *r, const struct object_id *oid); #define lookup_commit_reference(r, o) \ lookup_commit_reference_##r(o) struct commit *lookup_commit_reference_the_repository(const struct object_id *oid); -- cgit v0.10.2-6-g49f6 From 8bde69b974d20a030506d2de49b7cacfb17a63e7 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:11 -0700 Subject: tag: allow lookup_tag to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/tag.c b/tag.c index fbb4659..46b5882 100644 --- a/tag.c +++ b/tag.c @@ -92,13 +92,13 @@ struct object *deref_tag_noverify(struct object *o) return o; } -struct tag *lookup_tag_the_repository(const struct object_id *oid) +struct tag *lookup_tag(struct repository *r, const struct object_id *oid) { - struct object *obj = lookup_object(the_repository, oid->hash); + struct object *obj = lookup_object(r, oid->hash); if (!obj) - return create_object(the_repository, oid->hash, - alloc_tag_node(the_repository)); - return object_as_type(the_repository, obj, OBJ_TAG, 0); + return create_object(r, oid->hash, + alloc_tag_node(r)); + return object_as_type(r, obj, OBJ_TAG, 0); } static timestamp_t parse_tag_date(const char *buf, const char *tail) diff --git a/tag.h b/tag.h index 45b0b08..6a160c9 100644 --- a/tag.h +++ b/tag.h @@ -11,8 +11,7 @@ struct tag { char *tag; timestamp_t date; }; -#define lookup_tag(r, o) lookup_tag_##r(o) -extern struct tag *lookup_tag_the_repository(const struct object_id *oid); +extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid); #define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s) extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size); extern int parse_tag(struct tag *item); -- cgit v0.10.2-6-g49f6 From 84f80cd2db5daa71a68df9a71c13524700a4edc7 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:12 -0700 Subject: tag: allow parse_tag_buffer to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/tag.c b/tag.c index 46b5882..682e779 100644 --- a/tag.c +++ b/tag.c @@ -126,7 +126,7 @@ void release_tag_memory(struct tag *t) t->date = 0; } -int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size) +int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size) { struct object_id oid; char type[20]; @@ -154,13 +154,13 @@ int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned bufptr = nl + 1; if (!strcmp(type, blob_type)) { - item->tagged = (struct object *)lookup_blob(the_repository, &oid); + item->tagged = (struct object *)lookup_blob(r, &oid); } else if (!strcmp(type, tree_type)) { - item->tagged = (struct object *)lookup_tree(the_repository, &oid); + item->tagged = (struct object *)lookup_tree(r, &oid); } else if (!strcmp(type, commit_type)) { - item->tagged = (struct object *)lookup_commit(the_repository, &oid); + item->tagged = (struct object *)lookup_commit(r, &oid); } else if (!strcmp(type, tag_type)) { - item->tagged = (struct object *)lookup_tag(the_repository, &oid); + item->tagged = (struct object *)lookup_tag(r, &oid); } else { error("Unknown type %s", type); item->tagged = NULL; diff --git a/tag.h b/tag.h index 6a160c9..efd4c7d 100644 --- a/tag.h +++ b/tag.h @@ -12,8 +12,7 @@ struct tag { timestamp_t date; }; extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid); -#define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s) -extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size); +extern int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size); extern int parse_tag(struct tag *item); extern void release_tag_memory(struct tag *t); #define deref_tag(r, o, w, l) deref_tag_##r(o, w, l) -- cgit v0.10.2-6-g49f6 From fd8030c739522acf3f55879b29f4716b36f4d440 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:13 -0700 Subject: commit.c: allow parse_commit_buffer to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index 8749e15..41d2335 100644 --- a/commit.c +++ b/commit.c @@ -364,7 +364,7 @@ const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) return ret; } -int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size, int check_graph) +int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph) { const char *tail = buffer; const char *bufptr = buffer; @@ -384,11 +384,11 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, if (get_oid_hex(bufptr + 5, &parent) < 0) return error("bad tree pointer in commit %s", oid_to_hex(&item->object.oid)); - item->maybe_tree = lookup_tree(the_repository, &parent); + item->maybe_tree = lookup_tree(r, &parent); bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ pptr = &item->parents; - graft = lookup_commit_graft(the_repository, &item->object.oid); + graft = lookup_commit_graft(r, &item->object.oid); while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) { struct commit *new_parent; @@ -403,7 +403,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, */ if (graft && (graft->nr_parent < 0 || grafts_replace_parents)) continue; - new_parent = lookup_commit(the_repository, &parent); + new_parent = lookup_commit(r, &parent); if (new_parent) pptr = &commit_list_insert(new_parent, pptr)->next; } @@ -411,7 +411,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, int i; struct commit *new_parent; for (i = 0; i < graft->nr_parent; i++) { - new_parent = lookup_commit(the_repository, + new_parent = lookup_commit(r, &graft->parent[i]); if (!new_parent) continue; diff --git a/commit.h b/commit.h index 27888d8..e9cb5aa 100644 --- a/commit.h +++ b/commit.h @@ -81,8 +81,7 @@ struct commit *lookup_commit_reference_by_name(const char *name); */ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name); -#define parse_commit_buffer(r, i, b, s, g) parse_commit_buffer_##r(i, b, s, g) -int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size, int check_graph); +int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph); int parse_commit_gently(struct commit *item, int quiet_on_missing); static inline int parse_commit(struct commit *item) { -- cgit v0.10.2-6-g49f6 From 95bb9d4c326695553b9d5499752e24959e833f82 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:14 -0700 Subject: commit-slabs: remove realloc counter outside of slab struct The realloc counter is declared outside the struct for the given slabname, which makes it harder for a follow up patch to move the declaration of the struct around as then the counter variable would need special treatment. As the reallocation counter is currently unused we can just remove it. If we ever need to count the reallocations again, we can reintroduce the counter as part of 'struct slabname' in commit-slab-decl.h. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit-slab-impl.h b/commit-slab-impl.h index 87a9cad..ac1e6d4 100644 --- a/commit-slab-impl.h +++ b/commit-slab-impl.h @@ -11,8 +11,6 @@ #define implement_commit_slab(slabname, elemtype, scope) \ \ -static int stat_ ##slabname## realloc; \ - \ scope void init_ ##slabname## _with_stride(struct slabname *s, \ unsigned stride) \ { \ @@ -54,7 +52,6 @@ scope elemtype *slabname## _at_peek(struct slabname *s, \ if (!add_if_missing) \ return NULL; \ REALLOC_ARRAY(s->slab, nth_slab + 1); \ - stat_ ##slabname## realloc++; \ for (i = s->slab_count; i <= nth_slab; i++) \ s->slab[i] = NULL; \ s->slab_count = nth_slab + 1; \ -- cgit v0.10.2-6-g49f6 From 65ea9d4bec141295d34955b286c32725fe3b422d Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:15 -0700 Subject: commit.c: migrate the commit buffer to the parsed object store Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index 41d2335..1baac77 100644 --- a/commit.c +++ b/commit.c @@ -261,18 +261,32 @@ struct commit_buffer { unsigned long size; }; define_commit_slab(buffer_slab, struct commit_buffer); -static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab); + +struct buffer_slab *allocate_commit_buffer_slab(void) +{ + struct buffer_slab *bs = xmalloc(sizeof(*bs)); + init_buffer_slab(bs); + return bs; +} + +void free_commit_buffer_slab(struct buffer_slab *bs) +{ + clear_buffer_slab(bs); + free(bs); +} void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size) { - struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_at( + the_repository->parsed_objects->buffer_slab, commit); v->buffer = buffer; v->size = size; } const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep) { - struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek( + the_repository->parsed_objects->buffer_slab, commit); if (!v) { if (sizep) *sizep = 0; @@ -304,14 +318,16 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep) void unuse_commit_buffer(const struct commit *commit, const void *buffer) { - struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek( + the_repository->parsed_objects->buffer_slab, commit); if (!(v && v->buffer == buffer)) free((void *)buffer); } void free_commit_buffer(struct commit *commit) { - struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek( + the_repository->parsed_objects->buffer_slab, commit); if (v) { FREE_AND_NULL(v->buffer); v->size = 0; @@ -347,7 +363,8 @@ void release_commit_memory(struct commit *c) const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) { - struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek( + the_repository->parsed_objects->buffer_slab, commit); void *ret; if (!v) { diff --git a/commit.h b/commit.h index e9cb5aa..bea5e01 100644 --- a/commit.h +++ b/commit.h @@ -89,6 +89,10 @@ static inline int parse_commit(struct commit *item) } void parse_commit_or_die(struct commit *item); +struct buffer_slab; +struct buffer_slab *allocate_commit_buffer_slab(void); +void free_commit_buffer_slab(struct buffer_slab *bs); + /* * Associate an object buffer with the commit. The ownership of the * memory is handed over to the commit, and must be free()-able. diff --git a/object.c b/object.c index 9d74de9..9d58844 100644 --- a/object.c +++ b/object.c @@ -467,6 +467,8 @@ struct parsed_object_pool *parsed_object_pool_new(void) o->is_shallow = -1; o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat)); + o->buffer_slab = allocate_commit_buffer_slab(); + return o; } @@ -541,6 +543,9 @@ void parsed_object_pool_clear(struct parsed_object_pool *o) FREE_AND_NULL(o->obj_hash); o->obj_hash_size = 0; + free_commit_buffer_slab(o->buffer_slab); + o->buffer_slab = NULL; + clear_alloc_state(o->blob_state); clear_alloc_state(o->tree_state); clear_alloc_state(o->commit_state); diff --git a/object.h b/object.h index 0d7d741..f54a892 100644 --- a/object.h +++ b/object.h @@ -1,6 +1,8 @@ #ifndef OBJECT_H #define OBJECT_H +struct buffer_slab; + struct parsed_object_pool { struct object **obj_hash; int nr_objs, obj_hash_size; @@ -22,6 +24,8 @@ struct parsed_object_pool { char *alternate_shallow_file; int commit_graft_prepared; + + struct buffer_slab *buffer_slab; }; struct parsed_object_pool *parsed_object_pool_new(void); -- cgit v0.10.2-6-g49f6 From 1a40fc4509fb5369f089ed8774871e5e6974d3c2 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:16 -0700 Subject: commit.c: allow set_commit_buffer to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index 1baac77..dd8c9c1 100644 --- a/commit.c +++ b/commit.c @@ -275,10 +275,10 @@ void free_commit_buffer_slab(struct buffer_slab *bs) free(bs); } -void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size) +void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer, unsigned long size) { struct commit_buffer *v = buffer_slab_at( - the_repository->parsed_objects->buffer_slab, commit); + r->parsed_objects->buffer_slab, commit); v->buffer = buffer; v->size = size; } diff --git a/commit.h b/commit.h index bea5e01..7297af4 100644 --- a/commit.h +++ b/commit.h @@ -97,8 +97,7 @@ void free_commit_buffer_slab(struct buffer_slab *bs); * Associate an object buffer with the commit. The ownership of the * memory is handed over to the commit, and must be free()-able. */ -#define set_commit_buffer(r, c, b, s) set_commit_buffer_##r(c, b, s) -void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned long size); +void set_commit_buffer(struct repository *r, struct commit *, void *buffer, unsigned long size); /* * Get any cached object buffer associated with the commit. Returns NULL -- cgit v0.10.2-6-g49f6 From 4ff7e5c9362875b2296fd2e289dba487a38609f0 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:17 -0700 Subject: commit.c: allow get_cached_commit_buffer to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index dd8c9c1..15b0443 100644 --- a/commit.c +++ b/commit.c @@ -283,10 +283,10 @@ void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer v->size = size; } -const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep) +const void *get_cached_commit_buffer(struct repository *r, const struct commit *commit, unsigned long *sizep) { struct commit_buffer *v = buffer_slab_peek( - the_repository->parsed_objects->buffer_slab, commit); + r->parsed_objects->buffer_slab, commit); if (!v) { if (sizep) *sizep = 0; diff --git a/commit.h b/commit.h index 7297af4..d61585d 100644 --- a/commit.h +++ b/commit.h @@ -103,8 +103,7 @@ void set_commit_buffer(struct repository *r, struct commit *, void *buffer, unsi * Get any cached object buffer associated with the commit. Returns NULL * if none. The resulting memory should not be freed. */ -#define get_cached_commit_buffer(r, c, s) get_cached_commit_buffer_##r(c, s) -const void *get_cached_commit_buffer_the_repository(const struct commit *, unsigned long *size); +const void *get_cached_commit_buffer(struct repository *, const struct commit *, unsigned long *size); /* * Get the commit's object contents, either from cache or by reading the object -- cgit v0.10.2-6-g49f6 From 108ed1a3d88b04bb7a6d0b0a0e7c642a28a7845a Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:18 -0700 Subject: object.c: allow parse_object_buffer to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/object.c b/object.c index 9d58844..cd870fe 100644 --- a/object.c +++ b/object.c @@ -185,21 +185,21 @@ struct object *lookup_unknown_object(const unsigned char *sha1) return obj; } -struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p) +struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p) { struct object *obj; *eaten_p = 0; obj = NULL; if (type == OBJ_BLOB) { - struct blob *blob = lookup_blob(the_repository, oid); + struct blob *blob = lookup_blob(r, oid); if (blob) { if (parse_blob_buffer(blob, buffer, size)) return NULL; obj = &blob->object; } } else if (type == OBJ_TREE) { - struct tree *tree = lookup_tree(the_repository, oid); + struct tree *tree = lookup_tree(r, oid); if (tree) { obj = &tree->object; if (!tree->buffer) @@ -211,20 +211,20 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e } } } else if (type == OBJ_COMMIT) { - struct commit *commit = lookup_commit(the_repository, oid); + struct commit *commit = lookup_commit(r, oid); if (commit) { - if (parse_commit_buffer(the_repository, commit, buffer, size, 1)) + if (parse_commit_buffer(r, commit, buffer, size, 1)) return NULL; - if (!get_cached_commit_buffer(the_repository, commit, NULL)) { - set_commit_buffer(the_repository, commit, buffer, size); + if (!get_cached_commit_buffer(r, commit, NULL)) { + set_commit_buffer(r, commit, buffer, size); *eaten_p = 1; } obj = &commit->object; } } else if (type == OBJ_TAG) { - struct tag *tag = lookup_tag(the_repository, oid); + struct tag *tag = lookup_tag(r, oid); if (tag) { - if (parse_tag_buffer(the_repository, tag, buffer, size)) + if (parse_tag_buffer(r, tag, buffer, size)) return NULL; obj = &tag->object; } diff --git a/object.h b/object.h index f54a892..38198bb 100644 --- a/object.h +++ b/object.h @@ -138,8 +138,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name * parsing it. eaten_p indicates if the object has a borrowed copy * of buffer and the caller should not free() it. */ -#define parse_object_buffer(r, o, t, s, b, e) parse_object_buffer_##r(o, t, s, b, e) -struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p); +struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p); /** Returns the object, with potentially excess memory allocated. **/ struct object *lookup_unknown_object(const unsigned char *sha1); -- cgit v0.10.2-6-g49f6 From 8e4b0b6047e3cfbe627de6694c2eeae6904b41a1 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:19 -0700 Subject: object.c: allow parse_object to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/object.c b/object.c index cd870fe..b0faab8 100644 --- a/object.c +++ b/object.c @@ -245,28 +245,28 @@ struct object *parse_object_or_die(const struct object_id *oid, die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid)); } -struct object *parse_object_the_repository(const struct object_id *oid) +struct object *parse_object(struct repository *r, const struct object_id *oid) { unsigned long size; enum object_type type; int eaten; - const struct object_id *repl = lookup_replace_object(the_repository, oid); + const struct object_id *repl = lookup_replace_object(r, oid); void *buffer; struct object *obj; - obj = lookup_object(the_repository, oid->hash); + obj = lookup_object(r, oid->hash); if (obj && obj->parsed) return obj; if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) || (!obj && has_object_file(oid) && - oid_object_info(the_repository, oid, NULL) == OBJ_BLOB)) { + oid_object_info(r, oid, NULL) == OBJ_BLOB)) { if (check_object_signature(repl, NULL, 0, NULL) < 0) { error("sha1 mismatch %s", oid_to_hex(oid)); return NULL; } - parse_blob_buffer(lookup_blob(the_repository, oid), NULL, 0); - return lookup_object(the_repository, oid->hash); + parse_blob_buffer(lookup_blob(r, oid), NULL, 0); + return lookup_object(r, oid->hash); } buffer = read_object_file(oid, &type, &size); @@ -277,7 +277,7 @@ struct object *parse_object_the_repository(const struct object_id *oid) return NULL; } - obj = parse_object_buffer(the_repository, oid, type, size, + obj = parse_object_buffer(r, oid, type, size, buffer, &eaten); if (!eaten) free(buffer); diff --git a/object.h b/object.h index 38198bb..fa5ca97 100644 --- a/object.h +++ b/object.h @@ -124,8 +124,7 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type * * Returns NULL if the object is missing or corrupt. */ -#define parse_object(r, oid) parse_object_##r(oid) -struct object *parse_object_the_repository(const struct object_id *oid); +struct object *parse_object(struct repository *r, const struct object_id *oid); /* * Like parse_object, but will die() instead of returning NULL. If the -- cgit v0.10.2-6-g49f6 From 286d258d4f8b6f67676b1c50c2fd07a577450518 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:20 -0700 Subject: tag.c: allow deref_tag to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/tag.c b/tag.c index 682e779..94a89b2 100644 --- a/tag.c +++ b/tag.c @@ -64,12 +64,11 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report, return ret; } -struct object *deref_tag_the_repository(struct object *o, const char *warn, int warnlen) +struct object *deref_tag(struct repository *r, struct object *o, const char *warn, int warnlen) { while (o && o->type == OBJ_TAG) if (((struct tag *)o)->tagged) - o = parse_object(the_repository, - &((struct tag *)o)->tagged->oid); + o = parse_object(r, &((struct tag *)o)->tagged->oid); else o = NULL; if (!o && warn) { diff --git a/tag.h b/tag.h index efd4c7d..e669c3e 100644 --- a/tag.h +++ b/tag.h @@ -15,8 +15,7 @@ extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid) extern int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size); extern int parse_tag(struct tag *item); extern void release_tag_memory(struct tag *t); -#define deref_tag(r, o, w, l) deref_tag_##r(o, w, l) -extern struct object *deref_tag_the_repository(struct object *, const char *, int); +extern struct object *deref_tag(struct repository *r, struct object *, const char *, int); extern struct object *deref_tag_noverify(struct object *); extern int gpg_verify_tag(const struct object_id *oid, const char *name_to_report, unsigned flags); -- cgit v0.10.2-6-g49f6 From d9a05e74ec01bb59fccb70c005269d930cd60d9a Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:21 -0700 Subject: commit.c: allow lookup_commit_reference_gently to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index 15b0443..08b4602 100644 --- a/commit.c +++ b/commit.c @@ -24,16 +24,16 @@ int save_commit_buffer = 1; const char *commit_type = "commit"; -struct commit *lookup_commit_reference_gently_the_repository( +struct commit *lookup_commit_reference_gently(struct repository *r, const struct object_id *oid, int quiet) { - struct object *obj = deref_tag(the_repository, - parse_object(the_repository, oid), + struct object *obj = deref_tag(r, + parse_object(r, oid), NULL, 0); if (!obj) return NULL; - return object_as_type(the_repository, obj, OBJ_COMMIT, quiet); + return object_as_type(r, obj, OBJ_COMMIT, quiet); } struct commit *lookup_commit_reference_the_repository(const struct object_id *oid) diff --git a/commit.h b/commit.h index d61585d..f1f2595 100644 --- a/commit.h +++ b/commit.h @@ -67,9 +67,7 @@ struct commit *lookup_commit(struct repository *r, const struct object_id *oid); #define lookup_commit_reference(r, o) \ lookup_commit_reference_##r(o) struct commit *lookup_commit_reference_the_repository(const struct object_id *oid); -#define lookup_commit_reference_gently(r, o, q) \ - lookup_commit_reference_gently_##r(o, q) -struct commit *lookup_commit_reference_gently_the_repository( +struct commit *lookup_commit_reference_gently(struct repository *r, const struct object_id *oid, int quiet); struct commit *lookup_commit_reference_by_name(const char *name); -- cgit v0.10.2-6-g49f6 From 1f6c72fe55fded90cadcefffe5bd980a6f896579 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Jun 2018 18:22:22 -0700 Subject: commit.c: allow lookup_commit_reference to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/commit.c b/commit.c index 08b4602..b88ced5 100644 --- a/commit.c +++ b/commit.c @@ -36,9 +36,9 @@ struct commit *lookup_commit_reference_gently(struct repository *r, return object_as_type(r, obj, OBJ_COMMIT, quiet); } -struct commit *lookup_commit_reference_the_repository(const struct object_id *oid) +struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid) { - return lookup_commit_reference_gently(the_repository, oid, 0); + return lookup_commit_reference_gently(r, oid, 0); } struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name) diff --git a/commit.h b/commit.h index f1f2595..8b2cf96 100644 --- a/commit.h +++ b/commit.h @@ -64,9 +64,8 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj const struct name_decoration *get_name_decoration(const struct object *obj); struct commit *lookup_commit(struct repository *r, const struct object_id *oid); -#define lookup_commit_reference(r, o) \ - lookup_commit_reference_##r(o) -struct commit *lookup_commit_reference_the_repository(const struct object_id *oid); +struct commit *lookup_commit_reference(struct repository *r, + const struct object_id *oid); struct commit *lookup_commit_reference_gently(struct repository *r, const struct object_id *oid, int quiet); -- cgit v0.10.2-6-g49f6