Skip to content

Commit

Permalink
Merge branch 'nd/the-index'
Browse files Browse the repository at this point in the history
More codepaths become aware of working with in-core repository
instance other than the default "the_repository".

* nd/the-index: (22 commits)
  rebase-interactive.c: remove the_repository references
  rerere.c: remove the_repository references
  pack-*.c: remove the_repository references
  pack-check.c: remove the_repository references
  notes-cache.c: remove the_repository references
  line-log.c: remove the_repository reference
  diff-lib.c: remove the_repository references
  delta-islands.c: remove the_repository references
  cache-tree.c: remove the_repository references
  bundle.c: remove the_repository references
  branch.c: remove the_repository reference
  bisect.c: remove the_repository reference
  blame.c: remove implicit dependency the_repository
  sequencer.c: remove implicit dependency on the_repository
  sequencer.c: remove implicit dependency on the_index
  transport.c: remove implicit dependency on the_index
  notes-merge.c: remove implicit dependency the_repository
  notes-merge.c: remove implicit dependency on the_index
  list-objects.c: reduce the_repository references
  list-objects-filter.c: remove implicit dependency on the_index
  ...
  • Loading branch information
gitster committed Jan 4, 2019
2 parents 3b2f8a0 + 36e7ed6 commit cde5554
Show file tree
Hide file tree
Showing 66 changed files with 652 additions and 491 deletions.
48 changes: 28 additions & 20 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,15 @@ static struct commit_list *managed_skipped(struct commit_list *list,
return skip_away(list, count);
}

static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
const char *prefix,
const char *bad_format, const char *good_format,
int read_paths)
{
struct argv_array rev_argv = ARGV_ARRAY_INIT;
int i;

repo_init_revisions(the_repository, revs, prefix);
repo_init_revisions(r, revs, prefix);
revs->abbrev = 0;
revs->commit_format = CMIT_FMT_UNSPECIFIED;

Expand Down Expand Up @@ -723,23 +724,25 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
}

static struct commit *get_commit_reference(const struct object_id *oid)
static struct commit *get_commit_reference(struct repository *r,
const struct object_id *oid)
{
struct commit *r = lookup_commit_reference(the_repository, oid);
if (!r)
struct commit *c = lookup_commit_reference(r, oid);
if (!c)
die(_("Not a valid commit name %s"), oid_to_hex(oid));
return r;
return c;
}

static struct commit **get_bad_and_good_commits(int *rev_nr)
static struct commit **get_bad_and_good_commits(struct repository *r,
int *rev_nr)
{
struct commit **rev;
int i, n = 0;

ALLOC_ARRAY(rev, 1 + good_revs.nr);
rev[n++] = get_commit_reference(current_bad_oid);
rev[n++] = get_commit_reference(r, current_bad_oid);
for (i = 0; i < good_revs.nr; i++)
rev[n++] = get_commit_reference(good_revs.oid + i);
rev[n++] = get_commit_reference(r, good_revs.oid + i);
*rev_nr = n;

return rev;
Expand Down Expand Up @@ -823,12 +826,13 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
free_commit_list(result);
}

static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
static int check_ancestors(struct repository *r, int rev_nr,
struct commit **rev, const char *prefix)
{
struct rev_info revs;
int res;

bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
bisect_rev_setup(r, &revs, prefix, "^%s", "%s", 0);

bisect_common(&revs);
res = (revs.commits != NULL);
Expand All @@ -847,7 +851,9 @@ static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
* If a merge base must be tested by the user, its source code will be
* checked out to be tested by the user and we will exit.
*/
static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
static void check_good_are_ancestors_of_bad(struct repository *r,
const char *prefix,
int no_checkout)
{
char *filename = git_pathdup("BISECT_ANCESTORS_OK");
struct stat st;
Expand All @@ -866,8 +872,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
goto done;

/* Check if all good revs are ancestor of the bad rev. */
rev = get_bad_and_good_commits(&rev_nr);
if (check_ancestors(rev_nr, rev, prefix))
rev = get_bad_and_good_commits(r, &rev_nr);
if (check_ancestors(r, rev_nr, rev, prefix))
check_merge_bases(rev_nr, rev, no_checkout);
free(rev);

Expand All @@ -885,12 +891,14 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
/*
* This does "git diff-tree --pretty COMMIT" without one fork+exec.
*/
static void show_diff_tree(const char *prefix, struct commit *commit)
static void show_diff_tree(struct repository *r,
const char *prefix,
struct commit *commit)
{
struct rev_info opt;

/* diff-tree init */
repo_init_revisions(the_repository, &opt, prefix);
repo_init_revisions(r, &opt, prefix);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
opt.abbrev = 0;
opt.diff = 1;
Expand Down Expand Up @@ -945,7 +953,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
* If no_checkout is non-zero, the bisection process does not
* checkout the trial commit but instead simply updates BISECT_HEAD.
*/
int bisect_next_all(const char *prefix, int no_checkout)
int bisect_next_all(struct repository *r, const char *prefix, int no_checkout)
{
struct rev_info revs;
struct commit_list *tried;
Expand All @@ -957,9 +965,9 @@ int bisect_next_all(const char *prefix, int no_checkout)
if (read_bisect_refs())
die(_("reading bisect refs failed"));

check_good_are_ancestors_of_bad(prefix, no_checkout);
check_good_are_ancestors_of_bad(r, prefix, no_checkout);

bisect_rev_setup(&revs, prefix, "%s", "^%s", 1);
bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
revs.limited = 1;

bisect_common(&revs);
Expand Down Expand Up @@ -993,7 +1001,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
exit_if_skipped_commits(tried, current_bad_oid);
printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
term_bad);
show_diff_tree(prefix, revs.commits->item);
show_diff_tree(r, prefix, revs.commits->item);
/* This means the bisection process succeeded. */
exit(10);
}
Expand Down
5 changes: 4 additions & 1 deletion bisect.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define BISECT_H

struct commit_list;
struct repository;

/*
* Find bisection. If something is found, `reaches` will be the number of
Expand Down Expand Up @@ -30,7 +31,9 @@ struct rev_list_info {
const char *header_prefix;
};

extern int bisect_next_all(const char *prefix, int no_checkout);
extern int bisect_next_all(struct repository *r,
const char *prefix,
int no_checkout);

extern int estimate_bisect_steps(int all);

Expand Down
39 changes: 22 additions & 17 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,35 +116,38 @@ static void verify_working_tree_path(struct repository *r,
die("no such path '%s' in HEAD", path);
}

static struct commit_list **append_parent(struct commit_list **tail, const struct object_id *oid)
static struct commit_list **append_parent(struct repository *r,
struct commit_list **tail,
const struct object_id *oid)
{
struct commit *parent;

parent = lookup_commit_reference(the_repository, oid);
parent = lookup_commit_reference(r, oid);
if (!parent)
die("no such commit %s", oid_to_hex(oid));
return &commit_list_insert(parent, tail)->next;
}

static void append_merge_parents(struct commit_list **tail)
static void append_merge_parents(struct repository *r,
struct commit_list **tail)
{
int merge_head;
struct strbuf line = STRBUF_INIT;

merge_head = open(git_path_merge_head(the_repository), O_RDONLY);
merge_head = open(git_path_merge_head(r), O_RDONLY);
if (merge_head < 0) {
if (errno == ENOENT)
return;
die("cannot open '%s' for reading",
git_path_merge_head(the_repository));
git_path_merge_head(r));
}

while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
struct object_id oid;
if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
die("unknown line in '%s': %s",
git_path_merge_head(the_repository), line.buf);
tail = append_parent(tail, &oid);
git_path_merge_head(r), line.buf);
tail = append_parent(r, tail, &oid);
}
close(merge_head);
strbuf_release(&line);
Expand All @@ -155,11 +158,13 @@ static void append_merge_parents(struct commit_list **tail)
* want to transfer ownership of the buffer to the commit (so we
* must use detach).
*/
static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
static void set_commit_buffer_from_strbuf(struct repository *r,
struct commit *c,
struct strbuf *sb)
{
size_t len;
void *buf = strbuf_detach(sb, &len);
set_commit_buffer(the_repository, c, buf, len);
set_commit_buffer(r, c, buf, len);
}

/*
Expand All @@ -185,16 +190,16 @@ static struct commit *fake_working_tree_commit(struct repository *r,

read_index(r->index);
time(&now);
commit = alloc_commit_node(the_repository);
commit = alloc_commit_node(r);
commit->object.parsed = 1;
commit->date = now;
parent_tail = &commit->parents;

if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
die("no such ref: HEAD");

parent_tail = append_parent(parent_tail, &head_oid);
append_merge_parents(parent_tail);
parent_tail = append_parent(r, parent_tail, &head_oid);
append_merge_parents(r, parent_tail);
verify_working_tree_path(r, commit, path);

origin = make_origin(commit, path);
Expand All @@ -211,7 +216,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
ident, ident, path,
(!contents_from ? path :
(!strcmp(contents_from, "-") ? "standard input" : contents_from)));
set_commit_buffer_from_strbuf(commit, &msg);
set_commit_buffer_from_strbuf(r, commit, &msg);

if (!contents_from || strcmp("-", contents_from)) {
struct stat st;
Expand Down Expand Up @@ -1678,7 +1683,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(the_repository, obj, NULL, 0);
obj = deref_tag(revs->repo, obj, NULL, 0);
if (obj->type != OBJ_COMMIT)
die("Non commit %s?", revs->pending.objects[i].name);
if (found)
Expand Down Expand Up @@ -1709,14 +1714,14 @@ 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(the_repository, obj, NULL, 0);
obj = deref_tag(revs->repo, 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(the_repository,
head_commit = lookup_commit_reference_gently(revs->repo,
&head_oid, 1);
if (!head_commit)
return NULL;
Expand Down Expand Up @@ -1745,7 +1750,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(the_repository, obj, NULL, 0);
obj = deref_tag(revs->repo, obj, NULL, 0);
if (obj->type != OBJ_COMMIT)
die("Non commit %s?", revs->pending.objects[i].name);
if (found)
Expand Down
21 changes: 11 additions & 10 deletions branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ N_("\n"
"will track its remote counterpart, you may want to use\n"
"\"git push -u\" to set the upstream config as you push.");

void create_branch(const char *name, const char *start_name,
void create_branch(struct repository *r,
const char *name, const char *start_name,
int force, int clobber_head_ok, int reflog,
int quiet, enum branch_track track)
{
Expand Down Expand Up @@ -300,7 +301,7 @@ void create_branch(const char *name, const char *start_name,
break;
}

if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
if ((commit = lookup_commit_reference(r, &oid)) == NULL)
die(_("Not a valid branch point: '%s'."), start_name);
oidcpy(&oid, &commit->object.oid);

Expand Down Expand Up @@ -336,15 +337,15 @@ void create_branch(const char *name, const char *start_name,
free(real_ref);
}

void remove_branch_state(void)
void remove_branch_state(struct repository *r)
{
unlink(git_path_cherry_pick_head(the_repository));
unlink(git_path_revert_head(the_repository));
unlink(git_path_merge_head(the_repository));
unlink(git_path_merge_rr(the_repository));
unlink(git_path_merge_msg(the_repository));
unlink(git_path_merge_mode(the_repository));
unlink(git_path_squash_msg(the_repository));
unlink(git_path_cherry_pick_head(r));
unlink(git_path_revert_head(r));
unlink(git_path_merge_head(r));
unlink(git_path_merge_rr(r));
unlink(git_path_merge_msg(r));
unlink(git_path_merge_mode(r));
unlink(git_path_squash_msg(r));
}

void die_if_checked_out(const char *branch, int ignore_current_worktree)
Expand Down
8 changes: 6 additions & 2 deletions branch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BRANCH_H
#define BRANCH_H

struct repository;
struct strbuf;

enum branch_track {
Expand All @@ -19,6 +20,8 @@ extern enum branch_track git_branch_track;
/*
* Creates a new branch, where:
*
* - r is the repository to add a branch to
*
* - name is the new branch name
*
* - start_name is the name of the existing branch that the new branch should
Expand All @@ -37,7 +40,8 @@ extern enum branch_track git_branch_track;
* that start_name is a tracking branch for (if any).
*
*/
void create_branch(const char *name, const char *start_name,
void create_branch(struct repository *r,
const char *name, const char *start_name,
int force, int clobber_head_ok,
int reflog, int quiet, enum branch_track track);

Expand All @@ -60,7 +64,7 @@ extern int validate_new_branchname(const char *name, struct strbuf *ref, int for
* Remove information about the state of working on the current
* branch. (E.g., MERGE_HEAD)
*/
void remove_branch_state(void);
void remove_branch_state(struct repository *r);

/*
* Configure local branch "local" as downstream to branch "remote"
Expand Down
4 changes: 2 additions & 2 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
if (merge_tree(remote_tree))
return -1;

remove_branch_state();
remove_branch_state(the_repository);

return 0;
}
Expand All @@ -1981,7 +1981,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
static void am_rerere_clear(void)
{
struct string_list merge_rr = STRING_LIST_INIT_DUP;
rerere_clear(&merge_rr);
rerere_clear(the_repository, &merge_rr);
string_list_clear(&merge_rr, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion builtin/bisect--helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)

switch (cmdmode) {
case NEXT_ALL:
return bisect_next_all(prefix, no_checkout);
return bisect_next_all(the_repository, prefix, no_checkout);
case WRITE_TERMS:
if (argc != 2)
return error(_("--write-terms requires two arguments"));
Expand Down
Loading

0 comments on commit cde5554

Please sign in to comment.