Skip to content

Commit

Permalink
Merge branch 'sb/object-store-lookup'
Browse files Browse the repository at this point in the history
lookup_commit_reference() and friends have been updated to find
in-core object for a specific in-core repository instance.

* sb/object-store-lookup: (32 commits)
  commit.c: allow lookup_commit_reference to handle arbitrary repositories
  commit.c: allow lookup_commit_reference_gently to handle arbitrary repositories
  tag.c: allow deref_tag to handle arbitrary repositories
  object.c: allow parse_object to handle arbitrary repositories
  object.c: allow parse_object_buffer to handle arbitrary repositories
  commit.c: allow get_cached_commit_buffer to handle arbitrary repositories
  commit.c: allow set_commit_buffer to handle arbitrary repositories
  commit.c: migrate the commit buffer to the parsed object store
  commit-slabs: remove realloc counter outside of slab struct
  commit.c: allow parse_commit_buffer to handle arbitrary repositories
  tag: allow parse_tag_buffer to handle arbitrary repositories
  tag: allow lookup_tag to handle arbitrary repositories
  commit: allow lookup_commit to handle arbitrary repositories
  tree: allow lookup_tree to handle arbitrary repositories
  blob: allow lookup_blob to handle arbitrary repositories
  object: allow lookup_object to handle arbitrary repositories
  object: allow object_as_type to handle arbitrary repositories
  tag: add repository argument to deref_tag
  tag: add repository argument to parse_tag_buffer
  tag: add repository argument to lookup_tag
  ...
  • Loading branch information
gitster committed Aug 2, 2018
2 parents 6566a91 + 1f6c72f commit 3a2a1dc
Show file tree
Hide file tree
Showing 82 changed files with 487 additions and 361 deletions.
2 changes: 1 addition & 1 deletion archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1705,14 +1705,15 @@ 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;

/* 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;

Expand Down Expand Up @@ -1740,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)
Expand Down
10 changes: 5 additions & 5 deletions blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

const char *blob_type = "blob";

struct blob *lookup_blob(const struct object_id *oid)
struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
{
struct object *obj = lookup_object(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(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)
Expand Down
2 changes: 1 addition & 1 deletion blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct blob {
struct object object;
};

struct blob *lookup_blob(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);

Expand Down
2 changes: 1 addition & 1 deletion branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 6 additions & 3 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1631,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"));
Expand Down
7 changes: 4 additions & 3 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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;
Expand Down Expand Up @@ -155,7 +156,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;
Expand Down Expand Up @@ -209,7 +210,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"));
}
Expand Down
6 changes: 3 additions & 3 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,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;
Expand Down Expand Up @@ -831,7 +831,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;

Expand Down Expand Up @@ -1009,7 +1009,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);
Expand Down
3 changes: 2 additions & 1 deletion builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion builtin/commit-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 7 additions & 6 deletions builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions builtin/diff-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include "log-tree.h"
#include "builtin.h"
#include "submodule.h"
#include "repository.h"

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);
Expand All @@ -24,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);
Expand All @@ -45,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),
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions builtin/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -400,8 +401,8 @@ 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 = deref_tag(obj, NULL, 0);
obj = parse_object(the_repository, &obj->oid);
obj = deref_tag(the_repository, obj, NULL, 0);
if (!obj)
die(_("invalid object '%s' given."), name);
if (obj->type == OBJ_COMMIT)
Expand Down
14 changes: 8 additions & 6 deletions builtin/fast-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,22 @@ 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;

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);
if (!buf)
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)
Expand Down Expand Up @@ -402,7 +403,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));
}
Expand Down Expand Up @@ -801,7 +803,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;
}
Expand Down Expand Up @@ -961,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));

Expand Down
Loading

0 comments on commit 3a2a1dc

Please sign in to comment.