Skip to content

Commit

Permalink
Merge branch 'sb/more-repo-in-api'
Browse files Browse the repository at this point in the history
The in-core repository instances are passed through more codepaths.

* sb/more-repo-in-api: (23 commits)
  t/helper/test-repository: celebrate independence from the_repository
  path.h: make REPO_GIT_PATH_FUNC repository agnostic
  commit: prepare free_commit_buffer and release_commit_memory for any repo
  commit-graph: convert remaining functions to handle any repo
  submodule: don't add submodule as odb for push
  submodule: use submodule repos for object lookup
  pretty: prepare format_commit_message to handle arbitrary repositories
  commit: prepare logmsg_reencode to handle arbitrary repositories
  commit: prepare repo_unuse_commit_buffer to handle any repo
  commit: prepare get_commit_buffer to handle any repo
  commit-reach: prepare in_merge_bases[_many] to handle any repo
  commit-reach: prepare get_merge_bases to handle any repo
  commit-reach.c: allow get_merge_bases_many_0 to handle any repo
  commit-reach.c: allow remove_redundant to handle any repo
  commit-reach.c: allow merge_bases_many to handle any repo
  commit-reach.c: allow paint_down_to_common to handle any repo
  commit: allow parse_commit* to handle any repo
  object: parse_object to honor its repository argument
  object-store: prepare has_{sha1, object}_file to handle any repo
  object-store: prepare read_object_file to deal with any repo
  ...
  • Loading branch information
gitster committed Feb 5, 2019
2 parents b5101f9 + ff509c5 commit b99a579
Show file tree
Hide file tree
Showing 20 changed files with 452 additions and 150 deletions.
3 changes: 2 additions & 1 deletion builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
if (obj->type == OBJ_TREE)
free_tree_buffer((struct tree *)obj);
if (obj->type == OBJ_COMMIT)
free_commit_buffer((struct commit *)obj);
free_commit_buffer(the_repository->parsed_objects,
(struct commit *)obj);
return err;
}

Expand Down
6 changes: 4 additions & 2 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ static int cmd_log_walk(struct rev_info *rev)
* We may show a given commit multiple times when
* walking the reflogs.
*/
free_commit_buffer(commit);
free_commit_buffer(the_repository->parsed_objects,
commit);
free_commit_list(commit->parents);
commit->parents = NULL;
}
Expand Down Expand Up @@ -1940,7 +1941,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
die(_("Failed to create output files"));
shown = log_tree_commit(&rev, commit);
free_commit_buffer(commit);
free_commit_buffer(the_repository->parsed_objects,
commit);

/* We put one extra blank line between formatted
* patches and this flag is used by log-tree code
Expand Down
3 changes: 2 additions & 1 deletion builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ static void finish_commit(struct commit *commit, void *data)
free_commit_list(commit->parents);
commit->parents = NULL;
}
free_commit_buffer(commit);
free_commit_buffer(the_repository->parsed_objects,
commit);
}

static inline void finish_object__ma(struct object *obj)
Expand Down
40 changes: 24 additions & 16 deletions commit-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t
g->chunk_oid_lookup, g->hash_len, pos);
}

static struct commit_list **insert_parent_or_die(struct commit_graph *g,
static struct commit_list **insert_parent_or_die(struct repository *r,
struct commit_graph *g,
uint64_t pos,
struct commit_list **pptr)
{
Expand All @@ -299,7 +300,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
die("invalid parent position %"PRIu64, pos);

hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
c = lookup_commit(the_repository, &oid);
c = lookup_commit(r, &oid);
if (!c)
die(_("could not find commit %s"), oid_to_hex(&oid));
c->graph_pos = pos;
Expand All @@ -313,7 +314,9 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
}

static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t pos)
static int fill_commit_in_graph(struct repository *r,
struct commit *item,
struct commit_graph *g, uint32_t pos)
{
uint32_t edge_value;
uint32_t *parent_data_ptr;
Expand All @@ -337,21 +340,21 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
edge_value = get_be32(commit_data + g->hash_len);
if (edge_value == GRAPH_PARENT_NONE)
return 1;
pptr = insert_parent_or_die(g, edge_value, pptr);
pptr = insert_parent_or_die(r, g, edge_value, pptr);

edge_value = get_be32(commit_data + g->hash_len + 4);
if (edge_value == GRAPH_PARENT_NONE)
return 1;
if (!(edge_value & GRAPH_OCTOPUS_EDGES_NEEDED)) {
pptr = insert_parent_or_die(g, edge_value, pptr);
pptr = insert_parent_or_die(r, g, edge_value, pptr);
return 1;
}

parent_data_ptr = (uint32_t*)(g->chunk_large_edges +
4 * (uint64_t)(edge_value & GRAPH_EDGE_LAST_MASK));
do {
edge_value = get_be32(parent_data_ptr);
pptr = insert_parent_or_die(g,
pptr = insert_parent_or_die(r, g,
edge_value & GRAPH_EDGE_LAST_MASK,
pptr);
parent_data_ptr++;
Expand All @@ -370,15 +373,17 @@ static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uin
}
}

static int parse_commit_in_graph_one(struct commit_graph *g, struct commit *item)
static int parse_commit_in_graph_one(struct repository *r,
struct commit_graph *g,
struct commit *item)
{
uint32_t pos;

if (item->object.parsed)
return 1;

if (find_commit_in_graph(item, g, &pos))
return fill_commit_in_graph(item, g, pos);
return fill_commit_in_graph(r, item, g, pos);

return 0;
}
Expand All @@ -387,7 +392,7 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
{
if (!prepare_commit_graph(r))
return 0;
return parse_commit_in_graph_one(r->objects->commit_graph, item);
return parse_commit_in_graph_one(r, r->objects->commit_graph, item);
}

void load_commit_graph_info(struct repository *r, struct commit *item)
Expand All @@ -399,32 +404,35 @@ void load_commit_graph_info(struct repository *r, struct commit *item)
fill_commit_graph_info(item, r->objects->commit_graph, pos);
}

static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *c)
static struct tree *load_tree_for_commit(struct repository *r,
struct commit_graph *g,
struct commit *c)
{
struct object_id oid;
const unsigned char *commit_data = g->chunk_commit_data +
GRAPH_DATA_WIDTH * (c->graph_pos);

hashcpy(oid.hash, commit_data);
c->maybe_tree = lookup_tree(the_repository, &oid);
c->maybe_tree = lookup_tree(r, &oid);

return c->maybe_tree;
}

static struct tree *get_commit_tree_in_graph_one(struct commit_graph *g,
static struct tree *get_commit_tree_in_graph_one(struct repository *r,
struct commit_graph *g,
const struct commit *c)
{
if (c->maybe_tree)
return c->maybe_tree;
if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");

return load_tree_for_commit(g, (struct commit *)c);
return load_tree_for_commit(r, g, (struct commit *)c);
}

struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit *c)
{
return get_commit_tree_in_graph_one(r->objects->commit_graph, c);
return get_commit_tree_in_graph_one(r, r->objects->commit_graph, c);
}

static void write_graph_chunk_fanout(struct hashfile *f,
Expand Down Expand Up @@ -1035,7 +1043,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
}

graph_commit = lookup_commit(r, &cur_oid);
if (!parse_commit_in_graph_one(g, graph_commit))
if (!parse_commit_in_graph_one(r, g, graph_commit))
graph_report("failed to parse %s from commit-graph",
oid_to_hex(&cur_oid));
}
Expand Down Expand Up @@ -1071,7 +1079,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
continue;
}

if (!oideq(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,
if (!oideq(&get_commit_tree_in_graph_one(r, g, graph_commit)->object.oid,
get_commit_tree_oid(odb_commit)))
graph_report("root tree OID for commit %s in commit-graph is %s != %s",
oid_to_hex(&cur_oid),
Expand Down
73 changes: 43 additions & 30 deletions commit-reach.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ static int queue_has_nonstale(struct prio_queue *queue)
}

/* all input commits in one and twos[] must have been parsed! */
static struct commit_list *paint_down_to_common(struct commit *one, int n,
static struct commit_list *paint_down_to_common(struct repository *r,
struct commit *one, int n,
struct commit **twos,
int min_generation)
{
Expand Down Expand Up @@ -83,7 +84,7 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n,
parents = parents->next;
if ((p->object.flags & flags) == flags)
continue;
if (parse_commit(p))
if (repo_parse_commit(r, p))
return NULL;
p->object.flags |= flags;
prio_queue_put(&queue, p);
Expand All @@ -94,7 +95,9 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n,
return result;
}

static struct commit_list *merge_bases_many(struct commit *one, int n, struct commit **twos)
static struct commit_list *merge_bases_many(struct repository *r,
struct commit *one, int n,
struct commit **twos)
{
struct commit_list *list = NULL;
struct commit_list *result = NULL;
Expand All @@ -109,14 +112,14 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
return commit_list_insert(one, &result);
}

if (parse_commit(one))
if (repo_parse_commit(r, one))
return NULL;
for (i = 0; i < n; i++) {
if (parse_commit(twos[i]))
if (repo_parse_commit(r, twos[i]))
return NULL;
}

list = paint_down_to_common(one, n, twos, 0);
list = paint_down_to_common(r, one, n, twos, 0);

while (list) {
struct commit *commit = pop_commit(&list);
Expand Down Expand Up @@ -153,7 +156,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
return ret;
}

static int remove_redundant(struct commit **array, int cnt)
static int remove_redundant(struct repository *r, struct commit **array, int cnt)
{
/*
* Some commit in the array may be an ancestor of
Expand All @@ -171,7 +174,7 @@ static int remove_redundant(struct commit **array, int cnt)
ALLOC_ARRAY(filled_index, cnt - 1);

for (i = 0; i < cnt; i++)
parse_commit(array[i]);
repo_parse_commit(r, array[i]);
for (i = 0; i < cnt; i++) {
struct commit_list *common;
uint32_t min_generation = array[i]->generation;
Expand All @@ -187,8 +190,8 @@ static int remove_redundant(struct commit **array, int cnt)
if (array[j]->generation < min_generation)
min_generation = array[j]->generation;
}
common = paint_down_to_common(array[i], filled, work,
min_generation);
common = paint_down_to_common(r, array[i], filled,
work, min_generation);
if (array[i]->object.flags & PARENT2)
redundant[i] = 1;
for (j = 0; j < filled; j++)
Expand All @@ -213,7 +216,8 @@ static int remove_redundant(struct commit **array, int cnt)
return filled;
}

static struct commit_list *get_merge_bases_many_0(struct commit *one,
static struct commit_list *get_merge_bases_many_0(struct repository *r,
struct commit *one,
int n,
struct commit **twos,
int cleanup)
Expand All @@ -223,7 +227,7 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
struct commit_list *result;
int cnt, i;

result = merge_bases_many(one, n, twos);
result = merge_bases_many(r, one, n, twos);
for (i = 0; i < n; i++) {
if (one == twos[i])
return result;
Expand All @@ -246,31 +250,35 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
clear_commit_marks(one, all_flags);
clear_commit_marks_many(n, twos, all_flags);

cnt = remove_redundant(rslt, cnt);
cnt = remove_redundant(r, rslt, cnt);
result = NULL;
for (i = 0; i < cnt; i++)
commit_list_insert_by_date(rslt[i], &result);
free(rslt);
return result;
}

struct commit_list *get_merge_bases_many(struct commit *one,
int n,
struct commit **twos)
struct commit_list *repo_get_merge_bases_many(struct repository *r,
struct commit *one,
int n,
struct commit **twos)
{
return get_merge_bases_many_0(one, n, twos, 1);
return get_merge_bases_many_0(r, one, n, twos, 1);
}

struct commit_list *get_merge_bases_many_dirty(struct commit *one,
int n,
struct commit **twos)
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
struct commit *one,
int n,
struct commit **twos)
{
return get_merge_bases_many_0(one, n, twos, 0);
return get_merge_bases_many_0(r, one, n, twos, 0);
}

struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
struct commit_list *repo_get_merge_bases(struct repository *r,
struct commit *one,
struct commit *two)
{
return get_merge_bases_many_0(one, 1, &two, 1);
return get_merge_bases_many_0(r, one, 1, &two, 1);
}

/*
Expand Down Expand Up @@ -304,16 +312,17 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
/*
* Is "commit" an ancestor of one of the "references"?
*/
int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)
int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
int nr_reference, struct commit **reference)
{
struct commit_list *bases;
int ret = 0, i;
uint32_t min_generation = GENERATION_NUMBER_INFINITY;

if (parse_commit(commit))
if (repo_parse_commit(r, commit))
return ret;
for (i = 0; i < nr_reference; i++) {
if (parse_commit(reference[i]))
if (repo_parse_commit(r, reference[i]))
return ret;
if (reference[i]->generation < min_generation)
min_generation = reference[i]->generation;
Expand All @@ -322,7 +331,9 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
if (commit->generation > min_generation)
return ret;

bases = paint_down_to_common(commit, nr_reference, reference, commit->generation);
bases = paint_down_to_common(r, commit,
nr_reference, reference,
commit->generation);
if (commit->object.flags & PARENT2)
ret = 1;
clear_commit_marks(commit, all_flags);
Expand All @@ -334,9 +345,11 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
/*
* Is "commit" an ancestor of (i.e. reachable from) the "reference"?
*/
int in_merge_bases(struct commit *commit, struct commit *reference)
int repo_in_merge_bases(struct repository *r,
struct commit *commit,
struct commit *reference)
{
return in_merge_bases_many(commit, 1, &reference);
return repo_in_merge_bases_many(r, commit, 1, &reference);
}

struct commit_list *reduce_heads(struct commit_list *heads)
Expand Down Expand Up @@ -365,7 +378,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
p->item->object.flags &= ~STALE;
}
}
num_head = remove_redundant(array, num_head);
num_head = remove_redundant(the_repository, array, num_head);
for (i = 0; i < num_head; i++)
tail = &commit_list_insert(array[i], tail)->next;
free(array);
Expand Down
Loading

0 comments on commit b99a579

Please sign in to comment.