提交 c1f5eb49 编写于 作者: S Stefan Beller 提交者: Junio C Hamano

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: NStefan Beller <sbeller@google.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 2122f675
...@@ -1633,7 +1633,8 @@ static void do_commit(const struct am_state *state) ...@@ -1633,7 +1633,8 @@ static void do_commit(const struct am_state *state)
if (!get_oid_commit("HEAD", &parent)) { if (!get_oid_commit("HEAD", &parent)) {
old_oid = &parent; old_oid = &parent;
commit_list_insert(lookup_commit(&parent), &parents); commit_list_insert(lookup_commit(the_repository, &parent),
&parents);
} else { } else {
old_oid = NULL; old_oid = NULL;
say(state, stderr, _("applying to an empty history")); say(state, stderr, _("applying to an empty history"));
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "object-store.h" #include "object-store.h"
#include "repository.h"
#include "commit.h" #include "commit.h"
#include "tree.h" #include "tree.h"
#include "builtin.h" #include "builtin.h"
...@@ -60,7 +61,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) ...@@ -60,7 +61,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
if (get_oid_commit(argv[i], &oid)) if (get_oid_commit(argv[i], &oid))
die("Not a valid object name %s", argv[i]); die("Not a valid object name %s", argv[i]);
assert_oid_type(&oid, OBJ_COMMIT); assert_oid_type(&oid, OBJ_COMMIT);
new_parent(lookup_commit(&oid), &parents); new_parent(lookup_commit(the_repository, &oid),
&parents);
continue; continue;
} }
......
...@@ -25,7 +25,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p) ...@@ -25,7 +25,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p)
/* Graft the fake parents locally to the commit */ /* Graft the fake parents locally to the commit */
while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) { 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) { if (!pptr) {
/* Free the real parent list */ /* Free the real parent list */
free_commit_list(commit->parents); free_commit_list(commit->parents);
......
...@@ -963,7 +963,7 @@ static void import_marks(char *input_file) ...@@ -963,7 +963,7 @@ static void import_marks(char *input_file)
/* only commits */ /* only commits */
continue; continue;
commit = lookup_commit(&oid); commit = lookup_commit(the_repository, &oid);
if (!commit) if (!commit)
die("not a commit? can't happen: %s", oid_to_hex(&oid)); die("not a commit? can't happen: %s", oid_to_hex(&oid));
......
...@@ -572,7 +572,7 @@ static void find_merge_parents(struct merge_parents *result, ...@@ -572,7 +572,7 @@ static void find_merge_parents(struct merge_parents *result,
commit_list_insert(parent, &parents); commit_list_insert(parent, &parents);
add_merge_parent(result, &obj->oid, &parent->object.oid); add_merge_parent(result, &obj->oid, &parent->object.oid);
} }
head_commit = lookup_commit(head); head_commit = lookup_commit(the_repository, head);
if (head_commit) if (head_commit)
commit_list_insert(head_commit, &parents); commit_list_insert(head_commit, &parents);
reduce_heads_replace(&parents); reduce_heads_replace(&parents);
......
...@@ -124,7 +124,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs) ...@@ -124,7 +124,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
if (is_null_oid(oid)) if (is_null_oid(oid))
return; return;
commit = lookup_commit(oid); commit = lookup_commit(the_repository, oid);
if (!commit || if (!commit ||
(commit->object.flags & TMP_MARK) || (commit->object.flags & TMP_MARK) ||
parse_commit(commit)) parse_commit(commit))
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"
#include "object-store.h" #include "object-store.h"
#include "repository.h"
#include "commit.h" #include "commit.h"
#include "run-command.h" #include "run-command.h"
#include <signal.h> #include <signal.h>
...@@ -27,7 +28,8 @@ static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned ...@@ -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)); 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); print_signature_buffer(&signature_check, flags);
signature_check_clear(&signature_check); signature_check_clear(&signature_check);
......
...@@ -242,7 +242,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g, ...@@ -242,7 +242,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
struct commit *c; struct commit *c;
struct object_id oid; struct object_id oid;
hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos); hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
c = lookup_commit(&oid); c = lookup_commit(the_repository, &oid);
if (!c) if (!c)
die("could not find commit %s", oid_to_hex(&oid)); die("could not find commit %s", oid_to_hex(&oid));
c->graph_pos = pos; c->graph_pos = pos;
...@@ -568,7 +568,7 @@ static void close_reachable(struct packed_oid_list *oids) ...@@ -568,7 +568,7 @@ static void close_reachable(struct packed_oid_list *oids)
struct commit *commit; struct commit *commit;
for (i = 0; i < oids->nr; i++) { for (i = 0; i < oids->nr; i++) {
commit = lookup_commit(&oids->list[i]); commit = lookup_commit(the_repository, &oids->list[i]);
if (commit) if (commit)
commit->object.flags |= UNINTERESTING; commit->object.flags |= UNINTERESTING;
} }
...@@ -579,14 +579,14 @@ static void close_reachable(struct packed_oid_list *oids) ...@@ -579,14 +579,14 @@ static void close_reachable(struct packed_oid_list *oids)
* closure. * closure.
*/ */
for (i = 0; i < oids->nr; i++) { 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)) if (commit && !parse_commit(commit))
add_missing_parents(oids, commit); add_missing_parents(oids, commit);
} }
for (i = 0; i < oids->nr; i++) { for (i = 0; i < oids->nr; i++) {
commit = lookup_commit(&oids->list[i]); commit = lookup_commit(the_repository, &oids->list[i]);
if (commit) if (commit)
commit->object.flags &= ~UNINTERESTING; commit->object.flags &= ~UNINTERESTING;
...@@ -737,7 +737,7 @@ void write_commit_graph(const char *obj_dir, ...@@ -737,7 +737,7 @@ void write_commit_graph(const char *obj_dir,
if (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i])) if (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i]))
continue; 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]); parse_commit(commits.list[commits.nr]);
for (parent = commits.list[commits.nr]->parents; for (parent = commits.list[commits.nr]->parents;
......
...@@ -52,7 +52,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref ...@@ -52,7 +52,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
return c; 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); struct object *obj = lookup_object(the_repository, oid->hash);
if (!obj) if (!obj)
...@@ -402,7 +402,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s ...@@ -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)) if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
continue; continue;
new_parent = lookup_commit(&parent); new_parent = lookup_commit(the_repository, &parent);
if (new_parent) if (new_parent)
pptr = &commit_list_insert(new_parent, pptr)->next; 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 ...@@ -410,7 +410,8 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
int i; int i;
struct commit *new_parent; struct commit *new_parent;
for (i = 0; i < graft->nr_parent; i++) { 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) if (!new_parent)
continue; continue;
pptr = &commit_list_insert(new_parent, pptr)->next; pptr = &commit_list_insert(new_parent, pptr)->next;
......
...@@ -63,7 +63,8 @@ enum decoration_type { ...@@ -63,7 +63,8 @@ enum decoration_type {
void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); 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); 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) \ #define lookup_commit_reference(r, o) \
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_the_repository(const struct object_id *oid);
......
...@@ -498,7 +498,8 @@ static int find_common(struct fetch_pack_args *args, ...@@ -498,7 +498,8 @@ static int find_common(struct fetch_pack_args *args,
case ACK_ready: case ACK_ready:
case ACK_continue: { case ACK_continue: {
struct commit *commit = struct commit *commit =
lookup_commit(result_oid); lookup_commit(the_repository,
result_oid);
if (!commit) if (!commit)
die(_("invalid commit %s"), oid_to_hex(result_oid)); die(_("invalid commit %s"), oid_to_hex(result_oid));
if (args->stateless_rpc if (args->stateless_rpc
...@@ -1278,7 +1279,7 @@ static int process_acks(struct packet_reader *reader, struct oidset *common) ...@@ -1278,7 +1279,7 @@ static int process_acks(struct packet_reader *reader, struct oidset *common)
if (!get_oid_hex(arg, &oid)) { if (!get_oid_hex(arg, &oid)) {
struct commit *commit; struct commit *commit;
oidset_insert(common, &oid); oidset_insert(common, &oid);
commit = lookup_commit(&oid); commit = lookup_commit(the_repository, &oid);
mark_common(commit, 0, 1); mark_common(commit, 0, 1);
} }
continue; continue;
......
...@@ -134,7 +134,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, ...@@ -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) 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) if (!commit)
return 0; return 0;
add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object); add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "commit.h" #include "commit.h"
#include "refs.h" #include "refs.h"
#include "notes-utils.h" #include "notes-utils.h"
#include "repository.h"
void create_notes_commit(struct notes_tree *t, struct commit_list *parents, void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
const char *msg, size_t msg_len, const char *msg, size_t msg_len,
...@@ -19,7 +20,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents, ...@@ -19,7 +20,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
/* Deduce parent commit from t->ref */ /* Deduce parent commit from t->ref */
struct object_id parent_oid; struct object_id parent_oid;
if (!read_ref(t->ref, &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)) if (parse_commit(parent))
die("Failed to find/parse commit %s", t->ref); die("Failed to find/parse commit %s", t->ref);
commit_list_insert(parent, &parents); commit_list_insert(parent, &parents);
......
...@@ -212,7 +212,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e ...@@ -212,7 +212,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e
} }
} }
} else if (type == OBJ_COMMIT) { } else if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(oid); struct commit *commit = lookup_commit(the_repository, oid);
if (commit) { if (commit) {
if (parse_commit_buffer(commit, buffer, size, 1)) if (parse_commit_buffer(commit, buffer, size, 1))
return NULL; return NULL;
......
...@@ -594,7 +594,7 @@ static int is_index_unchanged(void) ...@@ -594,7 +594,7 @@ static int is_index_unchanged(void)
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL)) if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
return error(_("could not resolve HEAD commit")); 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 * 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, ...@@ -1101,7 +1101,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,
struct strbuf author_ident = STRBUF_INIT; struct strbuf author_ident = STRBUF_INIT;
struct strbuf committer_ident = STRBUF_INIT; struct strbuf committer_ident = STRBUF_INIT;
commit = lookup_commit(oid); commit = lookup_commit(the_repository, oid);
if (!commit) if (!commit)
die(_("couldn't look up newly created commit")); die(_("couldn't look up newly created commit"));
if (parse_commit(commit)) if (parse_commit(commit))
......
...@@ -351,7 +351,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data) ...@@ -351,7 +351,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
type = oid_object_info(the_repository, oid, NULL); type = oid_object_info(the_repository, oid, NULL);
if (type == OBJ_COMMIT) { if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(oid); struct commit *commit = lookup_commit(the_repository, oid);
if (commit) { if (commit) {
struct pretty_print_context pp = {0}; struct pretty_print_context pp = {0};
pp.date_mode.type = DATE_SHORT; pp.date_mode.type = DATE_SHORT;
......
...@@ -31,7 +31,7 @@ int register_shallow(struct repository *r, const struct object_id *oid) ...@@ -31,7 +31,7 @@ int register_shallow(struct repository *r, const struct object_id *oid)
{ {
struct commit_graft *graft = struct commit_graft *graft =
xmalloc(sizeof(struct commit_graft)); xmalloc(sizeof(struct commit_graft));
struct commit *commit = lookup_commit(oid); struct commit *commit = lookup_commit(the_repository, oid);
oidcpy(&graft->oid, oid); oidcpy(&graft->oid, oid);
graft->nr_parent = -1; graft->nr_parent = -1;
...@@ -259,7 +259,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data) ...@@ -259,7 +259,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (graft->nr_parent != -1) if (graft->nr_parent != -1)
return 0; return 0;
if (data->flags & SEEN_ONLY) { 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 (!c || !(c->object.flags & SEEN)) {
if (data->flags & VERBOSE) if (data->flags & VERBOSE)
printf("Removing %s from .git/shallow\n", printf("Removing %s from .git/shallow\n",
...@@ -624,7 +624,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, ...@@ -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 */ /* Mark potential bottoms so we won't go out of bound */
for (i = 0; i < nr_shallow; i++) { 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; c->object.flags |= BOTTOM;
} }
...@@ -635,7 +636,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, ...@@ -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); int bitmap_size = DIV_ROUND_UP(pi.nr_bits, 32) * sizeof(uint32_t);
memset(used, 0, sizeof(*used) * info->shallow->nr); memset(used, 0, sizeof(*used) * info->shallow->nr);
for (i = 0; i < nr_shallow; i++) { 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); uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c);
if (*map) if (*map)
used[shallow[i]] = xmemdupz(*map, bitmap_size); used[shallow[i]] = xmemdupz(*map, bitmap_size);
...@@ -705,7 +707,7 @@ static void post_assign_shallow(struct shallow_info *info, ...@@ -705,7 +707,7 @@ static void post_assign_shallow(struct shallow_info *info,
for (i = dst = 0; i < info->nr_theirs; i++) { for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst) if (i != dst)
info->theirs[dst] = info->theirs[i]; 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); bitmap = ref_bitmap_at(ref_bitmap, c);
if (!*bitmap) if (!*bitmap)
continue; continue;
...@@ -726,7 +728,7 @@ static void post_assign_shallow(struct shallow_info *info, ...@@ -726,7 +728,7 @@ static void post_assign_shallow(struct shallow_info *info,
for (i = dst = 0; i < info->nr_ours; i++) { for (i = dst = 0; i < info->nr_ours; i++) {
if (i != dst) if (i != dst)
info->ours[dst] = info->ours[i]; 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); bitmap = ref_bitmap_at(ref_bitmap, c);
if (!*bitmap) if (!*bitmap)
continue; continue;
...@@ -748,7 +750,8 @@ static void post_assign_shallow(struct shallow_info *info, ...@@ -748,7 +750,8 @@ static void post_assign_shallow(struct shallow_info *info,
int delayed_reachability_test(struct shallow_info *si, int c) int delayed_reachability_test(struct shallow_info *si, int c)
{ {
if (si->need_reachability_test[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) { if (!si->commits) {
struct commit_array ca; struct commit_array ca;
......
...@@ -158,7 +158,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) ...@@ -158,7 +158,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
} else if (!strcmp(type, tree_type)) { } else if (!strcmp(type, tree_type)) {
item->tagged = (struct object *)lookup_tree(the_repository, &oid); item->tagged = (struct object *)lookup_tree(the_repository, &oid);
} else if (!strcmp(type, commit_type)) { } 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)) { } else if (!strcmp(type, tag_type)) {
item->tagged = (struct object *)lookup_tag(&oid); item->tagged = (struct object *)lookup_tag(&oid);
} else { } else {
......
...@@ -101,7 +101,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, ...@@ -101,7 +101,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
else if (S_ISGITLINK(entry.mode)) { else if (S_ISGITLINK(entry.mode)) {
struct commit *commit; struct commit *commit;
commit = lookup_commit(entry.oid); commit = lookup_commit(the_repository, entry.oid);
if (!commit) if (!commit)
die("Commit %s in submodule path %s%s not found", die("Commit %s in submodule path %s%s not found",
oid_to_hex(entry.oid), oid_to_hex(entry.oid),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册