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
  ...
This commit is contained in:
Junio C Hamano 2019-01-04 13:33:33 -08:00
Родитель 3b2f8a02fa 36e7ed69de
Коммит cde555480b
66 изменённых файлов: 652 добавлений и 491 удалений

Просмотреть файл

@ -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;
@ -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;
@ -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);
@ -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;
@ -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);
@ -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;
@ -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;
@ -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);
@ -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);
}

Просмотреть файл

@ -2,6 +2,7 @@
#define BISECT_H
struct commit_list;
struct repository;
/*
* Find bisection. If something is found, `reaches` will be the number of
@ -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);

39
blame.c
Просмотреть файл

@ -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);
@ -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);
}
/*
@ -185,7 +190,7 @@ 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;
@ -193,8 +198,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
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);
@ -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;
@ -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)
@ -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;
@ -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)

Просмотреть файл

@ -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)
{
@ -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);
@ -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)

Просмотреть файл

@ -1,6 +1,7 @@
#ifndef BRANCH_H
#define BRANCH_H
struct repository;
struct strbuf;
enum branch_track {
@ -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
@ -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);
@ -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"

Просмотреть файл

@ -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;
}
@ -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);
}

Просмотреть файл

@ -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"));

Просмотреть файл

@ -783,7 +783,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
* create_branch takes care of setting up the tracking
* info and making sure new_upstream is correct
*/
create_branch(branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
create_branch(the_repository, branch->name, new_upstream,
0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
} else if (unset_upstream) {
struct branch *branch = branch_get(argv[0]);
struct strbuf buf = STRBUF_INIT;
@ -814,7 +815,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (track == BRANCH_TRACK_OVERRIDE)
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));
create_branch(argv[0], (argc == 2) ? argv[1] : head,
create_branch(the_repository,
argv[0], (argc == 2) ? argv[1] : head,
force, 0, reflog, quiet, track);
} else

Просмотреть файл

@ -40,7 +40,7 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
usage(builtin_bundle_usage);
return 1;
}
if (verify_bundle(&header, 1))
if (verify_bundle(the_repository, &header, 1))
return 1;
fprintf(stderr, _("%s is okay\n"), bundle_file);
return 0;
@ -56,11 +56,12 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
}
if (!startup_info->have_repository)
die(_("Need a repository to create a bundle."));
return !!create_bundle(&header, bundle_file, argc, argv);
return !!create_bundle(the_repository, &header,
bundle_file, argc, argv);
} else if (!strcmp(cmd, "unbundle")) {
if (!startup_info->have_repository)
die(_("Need a repository to unbundle."));
return !!unbundle(&header, bundle_fd, 0) ||
return !!unbundle(the_repository, &header, bundle_fd, 0) ||
list_bundle_refs(&header, argc, argv);
} else
usage(builtin_bundle_usage);

Просмотреть файл

@ -753,7 +753,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
free(refname);
}
else
create_branch(opts->new_branch, new_branch_info->name,
create_branch(the_repository,
opts->new_branch, new_branch_info->name,
opts->new_branch_force ? 1 : 0,
opts->new_branch_force ? 1 : 0,
opts->new_branch_log,
@ -811,7 +812,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
delete_reflog(old_branch_info->path);
}
}
remove_branch_state();
remove_branch_state(the_repository);
strbuf_release(&msg);
if (!opts->quiet &&
(new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))

Просмотреть файл

@ -188,7 +188,7 @@ static void determine_whence(struct wt_status *s)
static void status_init_config(struct wt_status *s, config_fn_t fn)
{
wt_status_prepare(s);
wt_status_prepare(the_repository, s);
init_diff_ui_defaults();
git_config(fn, s);
determine_whence(s);
@ -911,7 +911,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (ignore_submodule_arg &&
!strcmp(ignore_submodule_arg, "all"))
flags.ignore_submodules = 1;
committable = index_differs_from(parent, &flags, 1);
committable = index_differs_from(the_repository,
parent, &flags, 1);
}
}
strbuf_release(&committer_ident);
@ -1682,7 +1683,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
flags |= SUMMARY_INITIAL_COMMIT;
if (author_date_is_interesting())
flags |= SUMMARY_SHOW_AUTHOR_DATE;
print_commit_summary(prefix, &oid, flags);
print_commit_summary(the_repository, prefix,
&oid, flags);
}
UNLEAK(err);

Просмотреть файл

@ -797,7 +797,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
for (p = get_all_packs(the_repository); p;
p = p->next) {
/* verify gives error messages itself */
if (verify_pack(p, fsck_obj_buffer,
if (verify_pack(the_repository,
p, fsck_obj_buffer,
progress, count))
errors_found |= ERROR_PACK;
count += p->num_objects;

Просмотреть файл

@ -26,7 +26,7 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)
*/
if (read_cache() < 0)
die_errno("read_cache failed");
if (index_differs_from("HEAD", NULL, 0))
if (index_differs_from(the_repository, "HEAD", NULL, 0))
exit(2);
exit(0);
}

Просмотреть файл

@ -897,7 +897,7 @@ static int suggest_conflicts(void)
filename = git_path_merge_msg(the_repository);
fp = xfopen(filename, "a");
append_conflicts_hint(&msgbuf);
append_conflicts_hint(&the_index, &msgbuf);
fputs(msgbuf.buf, fp);
strbuf_release(&msgbuf);
fclose(fp);

Просмотреть файл

@ -813,7 +813,7 @@ static int merge(int argc, const char **argv, const char *prefix)
usage_with_options(git_notes_merge_usage, options);
}
init_notes_merge_options(&o);
init_notes_merge_options(the_repository, &o);
o.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT;
if (do_abort)

Просмотреть файл

@ -2610,7 +2610,7 @@ static void prepare_pack(int window, int depth)
unsigned n;
if (use_delta_islands)
resolve_tree_islands(progress, &to_pack);
resolve_tree_islands(the_repository, progress, &to_pack);
get_object_details();
@ -3131,7 +3131,7 @@ static void get_object_list(int ac, const char **av)
return;
if (use_delta_islands)
load_delta_islands();
load_delta_islands(the_repository);
if (prepare_revision_walk(&revs))
die(_("revision walk setup failed"));
@ -3470,7 +3470,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
}
}
prepare_packing_data(&to_pack);
prepare_packing_data(the_repository, &to_pack);
if (progress)
progress_state = start_progress(_("Enumerating objects"), 0);

Просмотреть файл

@ -899,7 +899,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
die(_("Updating an unborn branch with changes added to the index."));
if (!autostash)
require_clean_work_tree(N_("pull with rebase"),
require_clean_work_tree(the_repository,
N_("pull with rebase"),
_("please commit or stash them."), 1, 0);
if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))

Просмотреть файл

@ -355,7 +355,8 @@ static int push_with_options(struct transport *transport, struct refspec *rs,
if (verbosity > 0)
fprintf(stderr, _("Pushing to %s\n"), transport->url);
err = transport_push(transport, rs, flags, &reject_reasons);
err = transport_push(the_repository, transport,
rs, flags, &reject_reasons);
if (err != 0) {
fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
error(_("failed to push some refs to '%s'"), transport->url);

Просмотреть файл

@ -258,7 +258,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
* what came from the tree.
*/
if (nr_trees == 1 && !opts.prefix)
prime_cache_tree(&the_index, trees[0]);
prime_cache_tree(the_repository,
the_repository->index,
trees[0]);
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
die("unable to write new index file");

Просмотреть файл

@ -105,7 +105,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
if (restrict_revision)
argv_array_push(&make_script_args, restrict_revision);
ret = sequencer_make_script(todo_list,
ret = sequencer_make_script(the_repository, todo_list,
make_script_args.argc, make_script_args.argv,
flags);
fclose(todo_list);
@ -114,7 +114,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
error(_("could not generate todo list"));
else {
discard_cache();
ret = complete_action(opts, flags, shortrevisions, onto_name, onto,
ret = complete_action(the_repository, opts, flags,
shortrevisions, onto_name, onto,
head_hash, cmd, autosquash);
}
@ -232,14 +233,14 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
case SKIP: {
struct string_list merge_rr = STRING_LIST_INIT_DUP;
rerere_clear(&merge_rr);
rerere_clear(the_repository, &merge_rr);
/* fallthrough */
case CONTINUE:
ret = sequencer_continue(&opts);
ret = sequencer_continue(the_repository, &opts);
break;
}
case EDIT_TODO:
ret = edit_todo_list(flags);
ret = edit_todo_list(the_repository, flags);
break;
case SHOW_CURRENT_PATCH: {
struct child_process cmd = CHILD_PROCESS_INIT;
@ -252,16 +253,16 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
}
case SHORTEN_OIDS:
case EXPAND_OIDS:
ret = transform_todos(flags);
ret = transform_todos(the_repository, flags);
break;
case CHECK_TODO_LIST:
ret = check_todo_list();
ret = check_todo_list(the_repository);
break;
case REARRANGE_SQUASH:
ret = rearrange_squash();
ret = rearrange_squash(the_repository);
break;
case ADD_EXEC:
ret = sequencer_add_exec_commands(cmd);
ret = sequencer_add_exec_commands(the_repository, cmd);
break;
default:
BUG("invalid command '%d'", command);

Просмотреть файл

@ -598,7 +598,7 @@ static int reset_head(struct object_id *oid, const char *action,
}
tree = parse_tree_indirect(oid);
prime_cache_tree(the_repository->index, tree);
prime_cache_tree(the_repository, the_repository->index, tree);
if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) {
ret = error(_("could not write index"));
@ -1024,7 +1024,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
&lock_file);
rollback_lock_file(&lock_file);
if (has_unstaged_changes(1)) {
if (has_unstaged_changes(the_repository, 1)) {
puts(_("You must edit all merge conflicts and then\n"
"mark them as resolved using git add"));
exit(1);
@ -1039,13 +1039,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
options.action = "skip";
set_reflog_action(&options);
rerere_clear(&merge_rr);
rerere_clear(the_repository, &merge_rr);
string_list_clear(&merge_rr, 1);
if (reset_head(NULL, "reset", NULL, RESET_HEAD_HARD,
NULL, NULL) < 0)
die(_("could not discard worktree changes"));
remove_branch_state();
remove_branch_state(the_repository);
if (read_basic_state(&options))
exit(1);
goto run_rebase;
@ -1055,7 +1055,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
options.action = "abort";
set_reflog_action(&options);
rerere_clear(&merge_rr);
rerere_clear(the_repository, &merge_rr);
string_list_clear(&merge_rr, 1);
if (read_basic_state(&options))
@ -1065,7 +1065,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
NULL, NULL) < 0)
die(_("could not move back to %s"),
oid_to_hex(&options.orig_head));
remove_branch_state();
remove_branch_state(the_repository);
ret = finish_rebase(&options);
goto cleanup;
}
@ -1381,7 +1381,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
update_index_if_able(&the_index, &lock_file);
rollback_lock_file(&lock_file);
if (has_unstaged_changes(1) || has_uncommitted_changes(1)) {
if (has_unstaged_changes(the_repository, 1) ||
has_uncommitted_changes(the_repository, 1)) {
const char *autostash =
state_dir_path("autostash", &options);
struct child_process stash = CHILD_PROCESS_INIT;
@ -1427,7 +1428,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
}
}
if (require_clean_work_tree("rebase",
if (require_clean_work_tree(the_repository, "rebase",
_("Please commit or stash them."), 1, 1)) {
ret = 1;
goto cleanup;

Просмотреть файл

@ -83,11 +83,12 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
}
if (!strcmp(argv[0], "clear")) {
rerere_clear(&merge_rr);
rerere_clear(the_repository, &merge_rr);
} else if (!strcmp(argv[0], "gc"))
rerere_gc(&merge_rr);
rerere_gc(the_repository, &merge_rr);
else if (!strcmp(argv[0], "status")) {
if (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)
if (setup_rerere(the_repository, &merge_rr,
flags | RERERE_READONLY) < 0)
return 0;
for (i = 0; i < merge_rr.nr; i++)
printf("%s\n", merge_rr.items[i].string);
@ -102,7 +103,8 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
merge_rr.items[i].util = NULL;
}
} else if (!strcmp(argv[0], "diff")) {
if (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)
if (setup_rerere(the_repository, &merge_rr,
flags | RERERE_READONLY) < 0)
return 0;
for (i = 0; i < merge_rr.nr; i++) {
const char *path = merge_rr.items[i].string;

Просмотреть файл

@ -95,7 +95,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
if (reset_type == MIXED || reset_type == HARD) {
tree = parse_tree_indirect(oid);
prime_cache_tree(&the_index, tree);
prime_cache_tree(the_repository, the_repository->index, tree);
}
ret = 0;
@ -413,7 +413,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
print_new_head_line(lookup_commit_reference(the_repository, &oid));
}
if (!pathspec.nr)
remove_branch_state();
remove_branch_state(the_repository);
return update_ref_status;
}

Просмотреть файл

@ -196,14 +196,14 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
if (cmd == 'q') {
int ret = sequencer_remove_state(opts);
if (!ret)
remove_branch_state();
remove_branch_state(the_repository);
return ret;
}
if (cmd == 'c')
return sequencer_continue(opts);
return sequencer_continue(the_repository, opts);
if (cmd == 'a')
return sequencer_rollback(opts);
return sequencer_pick_revisions(opts);
return sequencer_rollback(the_repository, opts);
return sequencer_pick_revisions(the_repository, opts);
}
int cmd_revert(int argc, const char **argv, const char *prefix)

Просмотреть файл

@ -127,7 +127,9 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
/* Remember to update object flag allocation in object.h */
#define PREREQ_MARK (1u<<16)
int verify_bundle(struct bundle_header *header, int verbose)
int verify_bundle(struct repository *r,
struct bundle_header *header,
int verbose)
{
/*
* Do fast check, then if any prereqs are missing then go line by line
@ -140,10 +142,10 @@ int verify_bundle(struct bundle_header *header, int verbose)
int i, ret = 0, req_nr;
const char *message = _("Repository lacks these prerequisite commits:");
repo_init_revisions(the_repository, &revs, NULL);
repo_init_revisions(r, &revs, NULL);
for (i = 0; i < p->nr; i++) {
struct ref_list_entry *e = p->list + i;
struct object *o = parse_object(the_repository, &e->oid);
struct object *o = parse_object(r, &e->oid);
if (o) {
o->flags |= PREREQ_MARK;
add_pending_object(&revs, o, e->name);
@ -168,7 +170,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(the_repository, &e->oid);
struct object *o = parse_object(r, &e->oid);
assert(o); /* otherwise we'd have returned early */
if (o->flags & SHOWN)
continue;
@ -180,7 +182,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(the_repository, &e->oid, 1);
commit = lookup_commit_reference_gently(r, &e->oid, 1);
if (commit)
clear_commit_marks(commit, ALL_REV_FLAGS);
}
@ -389,8 +391,7 @@ 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(the_repository,
&oid);
struct commit *one = lookup_commit_reference(revs->repo, &oid);
struct object *obj;
if (e->item == &(one->object)) {
@ -423,8 +424,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
return ref_count;
}
int create_bundle(struct bundle_header *header, const char *path,
int argc, const char **argv)
int create_bundle(struct repository *r, struct bundle_header *header,
const char *path, int argc, const char **argv)
{
struct lock_file lock = LOCK_INIT;
int bundle_fd = -1;
@ -444,7 +445,7 @@ int create_bundle(struct bundle_header *header, const char *path,
/* init revs to list objects for pack-objects later */
save_commit_buffer = 0;
repo_init_revisions(the_repository, &revs, NULL);
repo_init_revisions(r, &revs, NULL);
/* write prerequisites */
if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv))
@ -479,7 +480,8 @@ err:
return -1;
}
int unbundle(struct bundle_header *header, int bundle_fd, int flags)
int unbundle(struct repository *r, struct bundle_header *header,
int bundle_fd, int flags)
{
const char *argv_index_pack[] = {"index-pack",
"--fix-thin", "--stdin", NULL, NULL};
@ -488,7 +490,7 @@ int unbundle(struct bundle_header *header, int bundle_fd, int flags)
if (flags & BUNDLE_VERBOSE)
argv_index_pack[3] = "-v";
if (verify_bundle(header, 0))
if (verify_bundle(r, header, 0))
return -1;
ip.argv = argv_index_pack;
ip.in = bundle_fd;

Просмотреть файл

@ -18,11 +18,12 @@ struct bundle_header {
int is_bundle(const char *path, int quiet);
int read_bundle_header(const char *path, struct bundle_header *header);
int create_bundle(struct bundle_header *header, const char *path,
int argc, const char **argv);
int verify_bundle(struct bundle_header *header, int verbose);
int create_bundle(struct repository *r, struct bundle_header *header,
const char *path, int argc, const char **argv);
int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
#define BUNDLE_VERBOSE 1
int unbundle(struct bundle_header *header, int bundle_fd, int flags);
int unbundle(struct repository *r, struct bundle_header *header,
int bundle_fd, int flags);
int list_bundle_refs(struct bundle_header *header,
int argc, const char **argv);

Просмотреть файл

@ -659,7 +659,9 @@ out:
return ret;
}
static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
static void prime_cache_tree_rec(struct repository *r,
struct cache_tree *it,
struct tree *tree)
{
struct tree_desc desc;
struct name_entry entry;
@ -673,24 +675,25 @@ 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(the_repository,
entry.oid);
struct tree *subtree = lookup_tree(r, entry.oid);
if (!subtree->object.parsed)
parse_tree(subtree);
sub = cache_tree_sub(it, entry.path);
sub->cache_tree = cache_tree();
prime_cache_tree_rec(sub->cache_tree, subtree);
prime_cache_tree_rec(r, sub->cache_tree, subtree);
cnt += sub->cache_tree->entry_count;
}
}
it->entry_count = cnt;
}
void prime_cache_tree(struct index_state *istate, struct tree *tree)
void prime_cache_tree(struct repository *r,
struct index_state *istate,
struct tree *tree)
{
cache_tree_free(&istate->cache_tree);
istate->cache_tree = cache_tree();
prime_cache_tree_rec(istate->cache_tree, tree);
prime_cache_tree_rec(r, istate->cache_tree, tree);
istate->cache_changed |= CACHE_TREE_CHANGED;
}
@ -726,7 +729,8 @@ int cache_tree_matches_traversal(struct cache_tree *root,
return 0;
}
static void verify_one(struct index_state *istate,
static void verify_one(struct repository *r,
struct index_state *istate,
struct cache_tree *it,
struct strbuf *path)
{
@ -736,13 +740,13 @@ static void verify_one(struct index_state *istate,
for (i = 0; i < it->subtree_nr; i++) {
strbuf_addf(path, "%s/", it->down[i]->name);
verify_one(istate, it->down[i]->cache_tree, path);
verify_one(r, istate, it->down[i]->cache_tree, path);
strbuf_setlen(path, len);
}
if (it->entry_count < 0 ||
/* no verification on tests (t7003) that replace trees */
lookup_replace_object(the_repository, &it->oid) != &it->oid)
lookup_replace_object(r, &it->oid) != &it->oid)
return;
if (path->len) {
@ -793,12 +797,12 @@ static void verify_one(struct index_state *istate,
strbuf_release(&tree_buf);
}
void cache_tree_verify(struct index_state *istate)
void cache_tree_verify(struct repository *r, struct index_state *istate)
{
struct strbuf path = STRBUF_INIT;
if (!istate->cache_tree)
return;
verify_one(istate, istate->cache_tree, &path);
verify_one(r, istate, istate->cache_tree, &path);
strbuf_release(&path);
}

Просмотреть файл

@ -32,7 +32,7 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
int cache_tree_fully_valid(struct cache_tree *);
int cache_tree_update(struct index_state *, int);
void cache_tree_verify(struct index_state *);
void cache_tree_verify(struct repository *, struct index_state *);
/* bitmasks to write_cache_as_tree flags */
#define WRITE_TREE_MISSING_OK 1
@ -47,7 +47,7 @@ void cache_tree_verify(struct index_state *);
#define WRITE_TREE_PREFIX_ERROR (-3)
int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
void prime_cache_tree(struct index_state *, struct tree *);
void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);

Просмотреть файл

@ -996,7 +996,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
if (!userdiff)
userdiff = userdiff_find_by_name("default");
if (opt->flags.allow_textconv)
textconv = userdiff_get_textconv(userdiff);
textconv = userdiff_get_textconv(opt->repo, userdiff);
/* Read the result of merge first */
if (!working_tree_file)

Просмотреть файл

@ -190,13 +190,15 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks)
island_bitmap_or(b, marks);
}
static void mark_remote_island_1(struct remote_island *rl, int is_core_island)
static void mark_remote_island_1(struct repository *r,
struct remote_island *rl,
int is_core_island)
{
uint32_t i;
for (i = 0; i < rl->oids.nr; ++i) {
struct island_bitmap *marks;
struct object *obj = parse_object(the_repository, &rl->oids.oid[i]);
struct object *obj = parse_object(r, &rl->oids.oid[i]);
if (!obj)
continue;
@ -211,7 +213,7 @@ static void mark_remote_island_1(struct remote_island *rl, int is_core_island)
while (obj && obj->type == OBJ_TAG) {
obj = ((struct tag *)obj)->tagged;
if (obj) {
parse_object(the_repository, &obj->oid);
parse_object(r, &obj->oid);
marks = create_or_get_island_marks(obj);
island_bitmap_set(marks, island_counter);
}
@ -237,7 +239,9 @@ static int tree_depth_compare(const void *a, const void *b)
return todo_a->depth - todo_b->depth;
}
void resolve_tree_islands(int progress, struct packing_data *to_pack)
void resolve_tree_islands(struct repository *r,
int progress,
struct packing_data *to_pack)
{
struct progress *progress_state = NULL;
struct tree_islands_todo *todo;
@ -281,7 +285,7 @@ void resolve_tree_islands(int progress, struct packing_data *to_pack)
root_marks = kh_value(island_marks, pos);
tree = lookup_tree(the_repository, &ent->idx.oid);
tree = lookup_tree(r, &ent->idx.oid);
if (!tree || parse_tree(tree) < 0)
die(_("bad tree object %s"), oid_to_hex(&ent->idx.oid));
@ -292,7 +296,7 @@ void resolve_tree_islands(int progress, struct packing_data *to_pack)
if (S_ISGITLINK(entry.mode))
continue;
obj = lookup_object(the_repository, entry.oid->hash);
obj = lookup_object(r, entry.oid->hash);
if (!obj)
continue;
@ -415,7 +419,7 @@ static struct remote_island *get_core_island(void)
return NULL;
}
static void deduplicate_islands(void)
static void deduplicate_islands(struct repository *r)
{
struct remote_island *island, *core = NULL, **list;
unsigned int island_count, dst, src, ref, i = 0;
@ -444,20 +448,20 @@ static void deduplicate_islands(void)
core = get_core_island();
for (i = 0; i < island_count; ++i) {
mark_remote_island_1(list[i], core && list[i]->hash == core->hash);
mark_remote_island_1(r, list[i], core && list[i]->hash == core->hash);
}
free(list);
}
void load_delta_islands(void)
void load_delta_islands(struct repository *r)
{
island_marks = kh_init_sha1();
remote_islands = kh_init_str();
git_config(island_config_callback, NULL);
for_each_ref(find_island_for_ref, NULL);
deduplicate_islands();
deduplicate_islands(r);
fprintf(stderr, _("Marked %d islands, done.\n"), island_counter);
}

Просмотреть файл

@ -1,14 +1,17 @@
#ifndef DELTA_ISLANDS_H
#define DELTA_ISLANDS_H
struct commit;
struct object_id;
struct packing_data;
struct commit;
struct repository;
int island_delta_cmp(const struct object_id *a, const struct object_id *b);
int in_same_island(const struct object_id *, const struct object_id *);
void resolve_tree_islands(int progress, struct packing_data *to_pack);
void load_delta_islands(void);
void resolve_tree_islands(struct repository *r,
int progress,
struct packing_data *to_pack);
void load_delta_islands(struct repository *r);
void propagate_island_marks(struct commit *commit);
int compute_pack_layers(struct packing_data *to_pack);

Просмотреть файл

@ -542,7 +542,7 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
{
struct rev_info revs;
repo_init_revisions(the_repository, &revs, NULL);
repo_init_revisions(opt->repo, &revs, NULL);
copy_pathspec(&revs.prune_data, &opt->pathspec);
revs.diffopt = *opt;
@ -551,13 +551,14 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
return 0;
}
int index_differs_from(const char *def, const struct diff_flags *flags,
int index_differs_from(struct repository *r,
const char *def, const struct diff_flags *flags,
int ita_invisible_in_index)
{
struct rev_info rev;
struct setup_revision_opt opt;
repo_init_revisions(the_repository, &rev, NULL);
repo_init_revisions(r, &rev, NULL);
memset(&opt, 0, sizeof(opt));
opt.def = def;
setup_revisions(0, NULL, &rev, &opt);

12
diff.c
Просмотреть файл

@ -3313,14 +3313,14 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const
options->b_prefix = b;
}
struct userdiff_driver *get_textconv(struct index_state *istate,
struct userdiff_driver *get_textconv(struct repository *r,
struct diff_filespec *one)
{
if (!DIFF_FILE_VALID(one))
return NULL;
diff_filespec_load_driver(one, istate);
return userdiff_get_textconv(one->driver);
diff_filespec_load_driver(one, r->index);
return userdiff_get_textconv(r, one->driver);
}
static void builtin_diff(const char *name_a,
@ -3369,8 +3369,8 @@ static void builtin_diff(const char *name_a,
}
if (o->flags.allow_textconv) {
textconv_one = get_textconv(o->repo->index, one);
textconv_two = get_textconv(o->repo->index, two);
textconv_one = get_textconv(o->repo, one);
textconv_two = get_textconv(o->repo, two);
}
/* Never use a non-valid filename anywhere if at all possible */
@ -6434,7 +6434,7 @@ int textconv_object(struct repository *r,
df = alloc_filespec(path);
fill_filespec(df, oid, oid_valid, mode);
textconv = get_textconv(r->index, df);
textconv = get_textconv(r, df);
if (!textconv) {
free_filespec(df);
return 0;

5
diff.h
Просмотреть файл

@ -436,7 +436,8 @@ int diff_result_code(struct diff_options *, int);
void diff_no_index(struct repository *, struct rev_info *, int, const char **);
int index_differs_from(const char *def, const struct diff_flags *flags,
int index_differs_from(struct repository *r, const char *def,
const struct diff_flags *flags,
int ita_invisible_in_index);
/*
@ -460,7 +461,7 @@ size_t fill_textconv(struct repository *r,
* and only if it has textconv enabled (otherwise return NULL). The result
* can be passed to fill_textconv().
*/
struct userdiff_driver *get_textconv(struct index_state *istate,
struct userdiff_driver *get_textconv(struct repository *r,
struct diff_filespec *one);
/*

Просмотреть файл

@ -140,8 +140,8 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
return 0;
if (o->flags.allow_textconv) {
textconv_one = get_textconv(o->repo->index, p->one);
textconv_two = get_textconv(o->repo->index, p->two);
textconv_one = get_textconv(o->repo, p->one);
textconv_two = get_textconv(o->repo, p->two);
}
/*

2
grep.c
Просмотреть файл

@ -1805,7 +1805,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
* is not thread-safe.
*/
grep_attr_lock();
textconv = userdiff_get_textconv(gs->driver);
textconv = userdiff_get_textconv(opt->repo, gs->driver);
grep_attr_unlock();
}

Просмотреть файл

@ -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(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 (commit)

Просмотреть файл

@ -34,6 +34,7 @@ struct filter_blobs_none_data {
};
static enum list_objects_filter_result filter_blobs_none(
struct repository *r,
enum list_objects_filter_situation filter_situation,
struct object *obj,
const char *pathname,
@ -88,6 +89,7 @@ struct filter_trees_none_data {
};
static enum list_objects_filter_result filter_trees_none(
struct repository *r,
enum list_objects_filter_situation filter_situation,
struct object *obj,
const char *pathname,
@ -144,6 +146,7 @@ struct filter_blobs_limit_data {
};
static enum list_objects_filter_result filter_blobs_limit(
struct repository *r,
enum list_objects_filter_situation filter_situation,
struct object *obj,
const char *pathname,
@ -171,7 +174,7 @@ static enum list_objects_filter_result filter_blobs_limit(
assert(obj->type == OBJ_BLOB);
assert((obj->flags & SEEN) == 0);
t = oid_object_info(the_repository, &obj->oid, &object_length);
t = oid_object_info(r, &obj->oid, &object_length);
if (t != OBJ_BLOB) { /* probably OBJ_NONE */
/*
* We DO NOT have the blob locally, so we cannot
@ -249,6 +252,7 @@ struct filter_sparse_data {
};
static enum list_objects_filter_result filter_sparse(
struct repository *r,
enum list_objects_filter_situation filter_situation,
struct object *obj,
const char *pathname,
@ -268,7 +272,7 @@ static enum list_objects_filter_result filter_sparse(
dtype = DT_DIR;
val = is_excluded_from_list(pathname, strlen(pathname),
filename, &dtype, &filter_data->el,
&the_index);
r->index);
if (val < 0)
val = filter_data->array_frame[filter_data->nr].defval;
@ -331,7 +335,7 @@ static enum list_objects_filter_result filter_sparse(
dtype = DT_REG;
val = is_excluded_from_list(pathname, strlen(pathname),
filename, &dtype, &filter_data->el,
&the_index);
r->index);
if (val < 0)
val = frame->defval;
if (val > 0) {

Просмотреть файл

@ -4,6 +4,7 @@
struct list_objects_filter_options;
struct object;
struct oidset;
struct repository;
/*
* During list-object traversal we allow certain objects to be
@ -60,6 +61,7 @@ enum list_objects_filter_situation {
};
typedef enum list_objects_filter_result (*filter_object_fn)(
struct repository *r,
enum list_objects_filter_situation filter_situation,
struct object *obj,
const char *pathname,

Просмотреть файл

@ -55,7 +55,8 @@ static void process_blob(struct traversal_context *ctx,
pathlen = path->len;
strbuf_addstr(path, name);
if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)
r = ctx->filter_fn(LOFS_BLOB, obj,
r = ctx->filter_fn(ctx->revs->repo,
LOFS_BLOB, obj,
path->buf, &path->buf[pathlen],
ctx->filter_data);
if (r & LOFR_MARK_SEEN)
@ -122,7 +123,7 @@ static void process_tree_contents(struct traversal_context *ctx,
}
if (S_ISDIR(entry.mode)) {
struct tree *t = lookup_tree(the_repository, entry.oid);
struct tree *t = lookup_tree(ctx->revs->repo, entry.oid);
t->object.flags |= NOT_USER_GIVEN;
process_tree(ctx, t, base, entry.path);
}
@ -130,7 +131,7 @@ static void process_tree_contents(struct traversal_context *ctx,
process_gitlink(ctx, entry.oid->hash,
base, entry.path);
else {
struct blob *b = lookup_blob(the_repository, entry.oid);
struct blob *b = lookup_blob(ctx->revs->repo, entry.oid);
b->object.flags |= NOT_USER_GIVEN;
process_blob(ctx, b, base, entry.path);
}
@ -175,7 +176,8 @@ static void process_tree(struct traversal_context *ctx,
strbuf_addstr(base, name);
if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)
r = ctx->filter_fn(LOFS_BEGIN_TREE, obj,
r = ctx->filter_fn(ctx->revs->repo,
LOFS_BEGIN_TREE, obj,
base->buf, &base->buf[baselen],
ctx->filter_data);
if (r & LOFR_MARK_SEEN)
@ -191,7 +193,8 @@ static void process_tree(struct traversal_context *ctx,
process_tree_contents(ctx, tree, base);
if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn) {
r = ctx->filter_fn(LOFS_END_TREE, obj,
r = ctx->filter_fn(ctx->revs->repo,
LOFS_END_TREE, obj,
base->buf, &base->buf[baselen],
ctx->filter_data);
if (r & LOFR_MARK_SEEN)

Просмотреть файл

@ -5,7 +5,9 @@
#include "commit.h"
#include "refs.h"
static int notes_cache_match_validity(const char *ref, const char *validity)
static int notes_cache_match_validity(struct repository *r,
const char *ref,
const char *validity)
{
struct object_id oid;
struct commit *commit;
@ -16,7 +18,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(the_repository, &oid, 1);
commit = lookup_commit_reference_gently(r, &oid, 1);
if (!commit)
return 0;
@ -30,8 +32,8 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
return ret;
}
void notes_cache_init(struct notes_cache *c, const char *name,
const char *validity)
void notes_cache_init(struct repository *r, struct notes_cache *c,
const char *name, const char *validity)
{
struct strbuf ref = STRBUF_INIT;
int flags = NOTES_INIT_WRITABLE;
@ -40,7 +42,7 @@ void notes_cache_init(struct notes_cache *c, const char *name,
c->validity = xstrdup(validity);
strbuf_addf(&ref, "refs/notes/%s", name);
if (!notes_cache_match_validity(ref.buf, validity))
if (!notes_cache_match_validity(r, ref.buf, validity))
flags |= NOTES_INIT_EMPTY;
init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
strbuf_release(&ref);

Просмотреть файл

@ -3,13 +3,15 @@
#include "notes.h"
struct repository;
struct notes_cache {
struct notes_tree tree;
char *validity;
};
void notes_cache_init(struct notes_cache *c, const char *name,
const char *validity);
void notes_cache_init(struct repository *r, struct notes_cache *c,
const char *name, const char *validity);
int notes_cache_write(struct notes_cache *c);
char *notes_cache_get(struct notes_cache *c, struct object_id *oid, size_t

Просмотреть файл

@ -18,11 +18,13 @@ struct notes_merge_pair {
struct object_id obj, base, local, remote;
};
void init_notes_merge_options(struct notes_merge_options *o)
void init_notes_merge_options(struct repository *r,
struct notes_merge_options *o)
{
memset(o, 0, sizeof(struct notes_merge_options));
strbuf_init(&(o->commit_msg), 0);
o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT;
o->repo = r;
}
static int path_to_oid(const char *path, struct object_id *oid)
@ -127,7 +129,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n",
oid_to_hex(base), oid_to_hex(remote));
repo_diff_setup(the_repository, &opt);
repo_diff_setup(o->repo, &opt);
opt.flags.recursive = 1;
opt.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_setup_done(&opt);
@ -190,7 +192,7 @@ static void diff_tree_local(struct notes_merge_options *o,
trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n",
len, oid_to_hex(base), oid_to_hex(local));
repo_diff_setup(the_repository, &opt);
repo_diff_setup(o->repo, &opt);
opt.flags.recursive = 1;
opt.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_setup_done(&opt);
@ -350,7 +352,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,
&local, o->local_ref, &remote, o->remote_ref,
&the_index, NULL);
o->repo->index, NULL);
free(base.ptr);
free(local.ptr);
@ -556,7 +558,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(the_repository, &local_oid)))
else if (!(local = lookup_commit_reference(o->repo, &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));
@ -574,7 +576,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(the_repository, &remote_oid))) {
} else if (!(remote = lookup_commit_reference(o->repo, &remote_oid))) {
die("Could not parse remote commit %s (%s)",
oid_to_hex(&remote_oid), o->remote_ref);
}
@ -711,7 +713,7 @@ int notes_merge_commit(struct notes_merge_options *o,
/* write file as blob, and add to partial_tree */
if (stat(path.buf, &st))
die_errno("Failed to stat '%s'", path.buf);
if (index_path(&the_index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT))
if (index_path(o->repo->index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT))
die("Failed to write blob object from '%s'", path.buf);
if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))
die("Failed to add resolved note '%s' to notes tree",

Просмотреть файл

@ -6,6 +6,7 @@
struct commit;
struct object_id;
struct repository;
#define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE"
@ -15,6 +16,7 @@ enum notes_merge_verbosity {
};
struct notes_merge_options {
struct repository *repo;
const char *local_ref;
const char *remote_ref;
struct strbuf commit_msg;
@ -23,7 +25,8 @@ struct notes_merge_options {
unsigned has_worktree:1;
};
void init_notes_merge_options(struct notes_merge_options *o);
void init_notes_merge_options(struct repository *r,
struct notes_merge_options *o);
/*
* Merge notes from o->remote_ref into o->local_ref

Просмотреть файл

@ -77,7 +77,7 @@ void bitmap_writer_build_type_index(struct packing_data *to_pack,
break;
default:
real_type = oid_object_info(the_repository,
real_type = oid_object_info(to_pack->repo,
&entry->idx.oid, NULL);
break;
}
@ -262,7 +262,7 @@ void bitmap_writer_build(struct packing_data *to_pack)
if (writer.show_progress)
writer.progress = start_progress("Building bitmaps", writer.selected_nr);
repo_init_revisions(the_repository, &revs, NULL);
repo_init_revisions(to_pack->repo, &revs, NULL);
revs.tag_objects = 1;
revs.tree_objects = 1;
revs.blob_objects = 1;
@ -363,7 +363,7 @@ static int date_compare(const void *_a, const void *_b)
void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)
{
struct bitmap_index *bitmap_git;
if (!(bitmap_git = prepare_bitmap_git()))
if (!(bitmap_git = prepare_bitmap_git(to_pack->repo)))
return;
writer.reused = kh_init_sha1();

Просмотреть файл

@ -328,14 +328,15 @@ failed:
return -1;
}
static int open_pack_bitmap(struct bitmap_index *bitmap_git)
static int open_pack_bitmap(struct repository *r,
struct bitmap_index *bitmap_git)
{
struct packed_git *p;
int ret = -1;
assert(!bitmap_git->map);
for (p = get_all_packs(the_repository); p; p = p->next) {
for (p = get_all_packs(r); p; p = p->next) {
if (open_pack_bitmap_1(bitmap_git, p) == 0)
ret = 0;
}
@ -343,11 +344,11 @@ static int open_pack_bitmap(struct bitmap_index *bitmap_git)
return ret;
}
struct bitmap_index *prepare_bitmap_git(void)
struct bitmap_index *prepare_bitmap_git(struct repository *r)
{
struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
if (!open_pack_bitmap(bitmap_git) && !load_pack_bitmap(bitmap_git))
if (!open_pack_bitmap(r, bitmap_git) && !load_pack_bitmap(bitmap_git))
return bitmap_git;
free_bitmap_index(bitmap_git);
@ -690,7 +691,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
/* try to open a bitmapped pack, but don't parse it yet
* because we may not need to use it */
if (open_pack_bitmap(bitmap_git) < 0)
if (open_pack_bitmap(revs->repo, bitmap_git) < 0)
goto cleanup;
for (i = 0; i < revs->pending.nr; ++i) {
@ -955,7 +956,7 @@ void test_bitmap_walk(struct rev_info *revs)
struct bitmap_test_data tdata;
struct bitmap_index *bitmap_git;
if (!(bitmap_git = prepare_bitmap_git()))
if (!(bitmap_git = prepare_bitmap_git(revs->repo)))
die("failed to load bitmap indexes");
if (revs->pending.nr != 1)

Просмотреть файл

@ -6,6 +6,7 @@
#include "pack-objects.h"
struct commit;
struct repository;
struct rev_info;
struct bitmap_disk_header {
@ -39,7 +40,7 @@ typedef int (*show_reachable_fn)(
struct bitmap_index;
struct bitmap_index *prepare_bitmap_git(void);
struct bitmap_index *prepare_bitmap_git(struct repository *r);
void count_bitmap_commit_list(struct bitmap_index *, uint32_t *commits,
uint32_t *trees, uint32_t *blobs, uint32_t *tags);
void traverse_bitmap_commit_list(struct bitmap_index *,

Просмотреть файл

@ -48,7 +48,8 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
return data_crc != ntohl(*index_crc);
}
static int verify_packfile(struct packed_git *p,
static int verify_packfile(struct repository *r,
struct packed_git *p,
struct pack_window **w_curs,
verify_fn fn,
struct progress *progress, uint32_t base_count)
@ -135,7 +136,7 @@ static int verify_packfile(struct packed_git *p,
data = NULL;
data_valid = 0;
} else {
data = unpack_entry(the_repository, p, entries[i].offset, &type, &size);
data = unpack_entry(r, p, entries[i].offset, &type, &size);
data_valid = 1;
}
@ -186,7 +187,7 @@ int verify_pack_index(struct packed_git *p)
return err;
}
int verify_pack(struct packed_git *p, verify_fn fn,
int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn,
struct progress *progress, uint32_t base_count)
{
int err = 0;
@ -196,7 +197,7 @@ int verify_pack(struct packed_git *p, verify_fn fn,
if (!p->index_data)
return -1;
err |= verify_packfile(p, &w_curs, fn, progress, base_count);
err |= verify_packfile(r, p, &w_curs, fn, progress, base_count);
unuse_pack(&w_curs);
return err;

Просмотреть файл

@ -99,7 +99,7 @@ static void prepare_in_pack_by_idx(struct packing_data *pdata)
* (i.e. in_pack_idx also zero) should return NULL.
*/
mapping[cnt++] = NULL;
for (p = get_all_packs(the_repository); p; p = p->next, cnt++) {
for (p = get_all_packs(pdata->repo); p; p = p->next, cnt++) {
if (cnt == nr) {
free(mapping);
return;
@ -133,8 +133,10 @@ void oe_map_new_pack(struct packing_data *pack,
}
/* assume pdata is already zero'd by caller */
void prepare_packing_data(struct packing_data *pdata)
void prepare_packing_data(struct repository *r, struct packing_data *pdata)
{
pdata->repo = r;
if (git_env_bool("GIT_TEST_FULL_IN_PACK_ARRAY", 0)) {
/*
* do not initialize in_pack_by_idx[] to force the

Просмотреть файл

@ -5,6 +5,8 @@
#include "thread-utils.h"
#include "pack.h"
struct repository;
#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)
#define OE_DFS_STATE_BITS 2
@ -127,6 +129,7 @@ struct object_entry {
};
struct packing_data {
struct repository *repo;
struct object_entry *objects;
uint32_t nr_objects, nr_alloc;
@ -163,7 +166,7 @@ struct packing_data {
unsigned char *layer;
};
void prepare_packing_data(struct packing_data *pdata);
void prepare_packing_data(struct repository *r, struct packing_data *pdata);
static inline void packing_data_lock(struct packing_data *pdata)
{

4
pack.h
Просмотреть файл

@ -4,6 +4,8 @@
#include "object.h"
#include "csum-file.h"
struct repository;
/*
* Packed object header
*/
@ -80,7 +82,7 @@ typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned lo
extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *, const unsigned char *sha1);
extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
extern int verify_pack_index(struct packed_git *);
extern int verify_pack(struct packed_git *, verify_fn fn, struct progress *, uint32_t);
extern int verify_pack(struct repository *, struct packed_git *, verify_fn fn, struct progress *, uint32_t);
extern off_t write_pack_header(struct hashfile *f, uint32_t);
extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
extern char *index_pack_lockfile(int fd);

Просмотреть файл

@ -3147,7 +3147,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
struct split_index *si = istate->split_index;
if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
cache_tree_verify(istate);
cache_tree_verify(the_repository, istate);
if ((flags & SKIP_IF_UNCHANGED) && !istate->cache_changed) {
if (flags & COMMIT_LOCK)

Просмотреть файл

@ -53,7 +53,7 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,
}
}
int edit_todo_list(unsigned flags)
int edit_todo_list(struct repository *r, unsigned flags)
{
struct strbuf buf = STRBUF_INIT;
const char *todo_file = rebase_path_todo();
@ -69,7 +69,7 @@ int edit_todo_list(unsigned flags)
strbuf_release(&buf);
transform_todos(flags | TODO_LIST_SHORTEN_IDS);
transform_todos(r, flags | TODO_LIST_SHORTEN_IDS);
if (strbuf_read_file(&buf, todo_file, 0) < 0)
return error_errno(_("could not read '%s'."), todo_file);
@ -85,7 +85,7 @@ int edit_todo_list(unsigned flags)
if (launch_sequence_editor(todo_file, NULL, NULL))
return -1;
transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS));
transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS));
return 0;
}

Просмотреть файл

@ -1,8 +1,11 @@
#ifndef REBASE_INTERACTIVE_H
#define REBASE_INTERACTIVE_H
struct strbuf;
struct repository;
void append_todo_help(unsigned edit_todo, unsigned keep_empty,
struct strbuf *buf);
int edit_todo_list(unsigned flags);
int edit_todo_list(struct repository *r, unsigned flags);
#endif

Просмотреть файл

@ -1417,7 +1417,7 @@ char *get_head_description(void)
struct strbuf desc = STRBUF_INIT;
struct wt_status_state state;
memset(&state, 0, sizeof(state));
wt_status_get_state(&state, 1);
wt_status_get_state(the_repository, &state, 1);
if (state.rebase_in_progress ||
state.rebase_interactive_in_progress) {
if (state.branch)

Просмотреть файл

@ -198,10 +198,10 @@ static struct rerere_id *new_rerere_id(unsigned char *sha1)
* work on (i.e. what is left by the previous invocation of "git
* rerere" during the current conflict resolution session).
*/
static void read_rr(struct string_list *rr)
static void read_rr(struct repository *r, struct string_list *rr)
{
struct strbuf buf = STRBUF_INIT;
FILE *in = fopen_or_warn(git_path_merge_rr(the_repository), "r");
FILE *in = fopen_or_warn(git_path_merge_rr(r), "r");
if (!in)
return;
@ -593,7 +593,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)
{
int i;
if (setup_rerere(merge_rr, RERERE_READONLY))
if (setup_rerere(r, merge_rr, RERERE_READONLY))
return 0;
if (read_index(r->index) < 0)
return error(_("index file corrupt"));
@ -882,7 +882,7 @@ static int is_rerere_enabled(void)
return 1;
}
int setup_rerere(struct string_list *merge_rr, int flags)
int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)
{
int fd;
@ -896,9 +896,9 @@ int setup_rerere(struct string_list *merge_rr, int flags)
fd = 0;
else
fd = hold_lock_file_for_update(&write_lock,
git_path_merge_rr(the_repository),
git_path_merge_rr(r),
LOCK_DIE_ON_ERROR);
read_rr(merge_rr);
read_rr(r, merge_rr);
return fd;
}
@ -912,7 +912,7 @@ int repo_rerere(struct repository *r, int flags)
struct string_list merge_rr = STRING_LIST_INIT_DUP;
int fd, status;
fd = setup_rerere(&merge_rr, flags);
fd = setup_rerere(r, &merge_rr, flags);
if (fd < 0)
return 0;
status = do_plain_rerere(r, &merge_rr, fd);
@ -1110,7 +1110,7 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)
if (read_index(r->index) < 0)
return error(_("index file corrupt"));
fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);
fd = setup_rerere(r, &merge_rr, RERERE_NOAUTOUPDATE);
if (fd < 0)
return 0;
@ -1178,7 +1178,7 @@ static void prune_one(struct rerere_id *id,
unlink_rr_item(id);
}
void rerere_gc(struct string_list *rr)
void rerere_gc(struct repository *r, struct string_list *rr)
{
struct string_list to_remove = STRING_LIST_INIT_DUP;
DIR *dir;
@ -1188,7 +1188,7 @@ void rerere_gc(struct string_list *rr)
timestamp_t cutoff_noresolve = now - 15 * 86400;
timestamp_t cutoff_resolve = now - 60 * 86400;
if (setup_rerere(rr, 0) < 0)
if (setup_rerere(r, rr, 0) < 0)
return;
git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now);
@ -1236,11 +1236,11 @@ void rerere_gc(struct string_list *rr)
*
* NEEDSWORK: shouldn't we be calling this from "reset --hard"?
*/
void rerere_clear(struct string_list *merge_rr)
void rerere_clear(struct repository *r, struct string_list *merge_rr)
{
int i;
if (setup_rerere(merge_rr, 0) < 0)
if (setup_rerere(r, merge_rr, 0) < 0)
return;
for (i = 0; i < merge_rr->nr; i++) {
@ -1250,6 +1250,6 @@ void rerere_clear(struct string_list *merge_rr)
rmdir(rerere_path(id, NULL));
}
}
unlink_or_warn(git_path_merge_rr(the_repository));
unlink_or_warn(git_path_merge_rr(r));
rollback_lock_file(&write_lock);
}

Просмотреть файл

@ -23,7 +23,7 @@ struct rerere_id {
int variant;
};
int setup_rerere(struct string_list *, int);
int setup_rerere(struct repository *,struct string_list *, int);
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
#define rerere(flags) repo_rerere(the_repository, flags)
#endif
@ -37,8 +37,8 @@ int repo_rerere(struct repository *, int);
const char *rerere_path(const struct rerere_id *, const char *file);
int rerere_forget(struct repository *, struct pathspec *);
int rerere_remaining(struct repository *, struct string_list *);
void rerere_clear(struct string_list *);
void rerere_gc(struct string_list *);
void rerere_clear(struct repository *, struct string_list *);
void rerere_gc(struct repository *, struct string_list *);
#define OPT_RERERE_AUTOUPDATE(v) OPT_UYN(0, "rerere-autoupdate", (v), \
N_("update the index with reused conflict resolution if possible"))

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -5,6 +5,7 @@
#include "strbuf.h"
struct commit;
struct repository;
const char *git_path_commit_editmsg(void);
const char *git_path_seq_dir(void);
@ -74,9 +75,10 @@ int write_message(const void *buf, size_t len, const char *filename,
/* Call this to setup defaults before parsing command line options */
void sequencer_init_config(struct replay_opts *opts);
int sequencer_pick_revisions(struct replay_opts *opts);
int sequencer_continue(struct replay_opts *opts);
int sequencer_rollback(struct replay_opts *opts);
int sequencer_pick_revisions(struct repository *repo,
struct replay_opts *opts);
int sequencer_continue(struct repository *repo, struct replay_opts *opts);
int sequencer_rollback(struct repository *repo, struct replay_opts *opts);
int sequencer_remove_state(struct replay_opts *opts);
#define TODO_LIST_KEEP_EMPTY (1U << 0)
@ -89,18 +91,19 @@ int sequencer_remove_state(struct replay_opts *opts);
* commits should be rebased onto the new base, this flag needs to be passed.
*/
#define TODO_LIST_REBASE_COUSINS (1U << 4)
int sequencer_make_script(FILE *out, int argc, const char **argv,
int sequencer_make_script(struct repository *repo, FILE *out,
int argc, const char **argv,
unsigned flags);
int sequencer_add_exec_commands(const char *command);
int transform_todos(unsigned flags);
int sequencer_add_exec_commands(struct repository *r, const char *command);
int transform_todos(struct repository *r, unsigned flags);
enum missing_commit_check_level get_missing_commit_check_level(void);
int check_todo_list(void);
int complete_action(struct replay_opts *opts, unsigned flags,
int check_todo_list(struct repository *r);
int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
const char *shortrevisions, const char *onto_name,
const char *onto, const char *orig_head, const char *cmd,
unsigned autosquash);
int rearrange_squash(void);
int rearrange_squash(struct repository *r);
extern const char sign_off_header[];
@ -112,7 +115,7 @@ extern const char sign_off_header[];
*/
void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag);
void append_conflicts_hint(struct strbuf *msgbuf);
void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf);
int message_is_empty(const struct strbuf *sb,
enum commit_msg_cleanup_mode cleanup_mode);
int template_untouched(const struct strbuf *sb, const char *template_file,
@ -128,7 +131,9 @@ int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);
#define SUMMARY_INITIAL_COMMIT (1 << 0)
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)
void print_commit_summary(const char *prefix, const struct object_id *oid,
void print_commit_summary(struct repository *repo,
const char *prefix,
const struct object_id *oid,
unsigned int flags);
int read_author_script(const char *path, char **name, char **email, char **date,

Просмотреть файл

@ -154,7 +154,7 @@ static int fetch_refs_from_bundle(struct transport *transport,
int nr_heads, struct ref **to_fetch)
{
struct bundle_transport_data *data = transport->data;
return unbundle(&data->header, data->fd,
return unbundle(the_repository, &data->header, data->fd,
transport->progress ? BUNDLE_VERBOSE : 0);
}
@ -1105,7 +1105,8 @@ static int run_pre_push_hook(struct transport *transport,
return ret;
}
int transport_push(struct transport *transport,
int transport_push(struct repository *r,
struct transport *transport,
struct refspec *rs, int flags,
unsigned int *reject_reasons)
{
@ -1172,7 +1173,7 @@ int transport_push(struct transport *transport,
oid_array_append(&commits,
&ref->new_oid);
if (!push_unpushed_submodules(the_repository,
if (!push_unpushed_submodules(r,
&commits,
transport->remote,
rs,
@ -1197,7 +1198,7 @@ int transport_push(struct transport *transport,
oid_array_append(&commits,
&ref->new_oid);
if (find_unpushed_submodules(the_repository,
if (find_unpushed_submodules(r,
&commits,
transport->remote->name,
&needs_pushing)) {

Просмотреть файл

@ -223,7 +223,8 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
#define REJECT_FETCH_FIRST 0x08
#define REJECT_NEEDS_FORCE 0x10
int transport_push(struct transport *connection,
int transport_push(struct repository *repo,
struct transport *connection,
struct refspec *rs, int flags,
unsigned int * reject_reasons);

Просмотреть файл

@ -1630,7 +1630,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
move_index_extensions(&o->result, o->src_index);
if (!ret) {
if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
cache_tree_verify(&o->result);
cache_tree_verify(the_repository, &o->result);
if (!o->result.cache_tree)
o->result.cache_tree = cache_tree();
if (!cache_tree_fully_valid(o->result.cache_tree))

Просмотреть файл

@ -290,7 +290,8 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
return userdiff_find_by_name(check->items[0].value);
}
struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
struct userdiff_driver *userdiff_get_textconv(struct repository *r,
struct userdiff_driver *driver)
{
if (!driver->textconv)
return NULL;
@ -300,7 +301,7 @@ struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
struct strbuf name = STRBUF_INIT;
strbuf_addf(&name, "textconv/%s", driver->name);
notes_cache_init(c, name.buf, driver->textconv);
notes_cache_init(r, c, name.buf, driver->textconv);
driver->textconv_cache = c;
strbuf_release(&name);
}

Просмотреть файл

@ -4,6 +4,7 @@
#include "notes-cache.h"
struct index_state;
struct repository;
struct userdiff_funcname {
const char *pattern;
@ -30,6 +31,7 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
* Initialize any textconv-related fields in the driver and return it, or NULL
* if it does not have textconv enabled at all.
*/
struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver);
struct userdiff_driver *userdiff_get_textconv(struct repository *r,
struct userdiff_driver *driver);
#endif /* USERDIFF */

Просмотреть файл

@ -119,9 +119,10 @@ static void status_printf_more(struct wt_status *s, const char *color,
va_end(ap);
}
void wt_status_prepare(struct wt_status *s)
void wt_status_prepare(struct repository *r, struct wt_status *s)
{
memset(s, 0, sizeof(*s));
s->repo = r;
memcpy(s->color_palette, default_wt_status_colors,
sizeof(default_wt_status_colors));
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
@ -494,19 +495,19 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
}
}
static int unmerged_mask(const char *path)
static int unmerged_mask(struct index_state *istate, const char *path)
{
int pos, mask;
const struct cache_entry *ce;
pos = cache_name_pos(path, strlen(path));
pos = index_name_pos(istate, path, strlen(path));
if (0 <= pos)
return 0;
mask = 0;
pos = -pos-1;
while (pos < active_nr) {
ce = active_cache[pos++];
while (pos < istate->cache_nr) {
ce = istate->cache[pos++];
if (strcmp(ce->name, path) || !ce_stage(ce))
break;
mask |= (1 << (ce_stage(ce) - 1));
@ -566,7 +567,8 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
s->committable = 1;
break;
case DIFF_STATUS_UNMERGED:
d->stagemask = unmerged_mask(p->two->path);
d->stagemask = unmerged_mask(s->repo->index,
p->two->path);
/*
* Don't bother setting {mode,oid}_{head,index} since the print
* code will output the stage values directly and not use the
@ -585,7 +587,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
{
struct rev_info rev;
repo_init_revisions(the_repository, &rev, NULL);
repo_init_revisions(s->repo, &rev, NULL);
setup_revisions(0, NULL, &rev, NULL);
rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
rev.diffopt.flags.dirty_submodules = 1;
@ -610,7 +612,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
struct rev_info rev;
struct setup_revision_opt opt;
repo_init_revisions(the_repository, &rev, NULL);
repo_init_revisions(s->repo, &rev, NULL);
memset(&opt, 0, sizeof(opt));
opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
setup_revisions(0, NULL, &rev, &opt);
@ -643,14 +645,15 @@ static void wt_status_collect_changes_index(struct wt_status *s)
static void wt_status_collect_changes_initial(struct wt_status *s)
{
struct index_state *istate = s->repo->index;
int i;
for (i = 0; i < active_nr; i++) {
for (i = 0; i < istate->cache_nr; i++) {
struct string_list_item *it;
struct wt_status_change_data *d;
const struct cache_entry *ce = active_cache[i];
const struct cache_entry *ce = istate->cache[i];
if (!ce_path_match(&the_index, ce, &s->pathspec, NULL))
if (!ce_path_match(istate, ce, &s->pathspec, NULL))
continue;
if (ce_intent_to_add(ce))
continue;
@ -684,6 +687,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
int i;
struct dir_struct dir;
uint64_t t_begin = getnanotime();
struct index_state *istate = s->repo->index;
if (!s->show_untracked_files)
return;
@ -698,25 +702,25 @@ static void wt_status_collect_untracked(struct wt_status *s)
if (s->show_ignored_mode == SHOW_MATCHING_IGNORED)
dir.flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING;
} else {
dir.untracked = the_index.untracked;
dir.untracked = istate->untracked;
}
setup_standard_excludes(&dir);
fill_directory(&dir, &the_index, &s->pathspec);
fill_directory(&dir, istate, &s->pathspec);
for (i = 0; i < dir.nr; i++) {
struct dir_entry *ent = dir.entries[i];
if (cache_name_is_other(ent->name, ent->len) &&
dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))
if (index_name_is_other(istate, ent->name, ent->len) &&
dir_path_match(istate, ent, &s->pathspec, 0, NULL))
string_list_insert(&s->untracked, ent->name);
free(ent);
}
for (i = 0; i < dir.ignored_nr; i++) {
struct dir_entry *ent = dir.ignored[i];
if (cache_name_is_other(ent->name, ent->len) &&
dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))
if (index_name_is_other(istate, ent->name, ent->len) &&
dir_path_match(istate, ent, &s->pathspec, 0, NULL))
string_list_insert(&s->ignored, ent->name);
free(ent);
}
@ -751,7 +755,7 @@ void wt_status_collect(struct wt_status *s)
wt_status_collect_changes_index(s);
wt_status_collect_untracked(s);
wt_status_get_state(&s->state, s->branch && !strcmp(s->branch, "HEAD"));
wt_status_get_state(s->repo, &s->state, s->branch && !strcmp(s->branch, "HEAD"));
if (s->state.merge_in_progress && !has_unmerged(s))
s->committable = 1;
}
@ -1009,7 +1013,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
int dirty_submodules;
const char *c = color(WT_STATUS_HEADER, s);
repo_init_revisions(the_repository, &rev, NULL);
repo_init_revisions(s->repo, &rev, NULL);
rev.diffopt.flags.allow_textconv = 1;
rev.diffopt.ita_invisible_in_index = 1;
@ -1326,7 +1330,7 @@ static void show_rebase_in_progress(struct wt_status *s,
_(" (use \"git rebase --abort\" to check out the original branch)"));
}
} else if (s->state.rebase_in_progress ||
!stat(git_path_merge_msg(the_repository), &st)) {
!stat(git_path_merge_msg(s->repo), &st)) {
print_rebase_state(s, color);
if (s->hints)
status_printf_ln(s, color,
@ -1478,7 +1482,8 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
return 1;
}
static void wt_status_get_detached_from(struct wt_status_state *state)
static void wt_status_get_detached_from(struct repository *r,
struct wt_status_state *state)
{
struct grab_1st_switch_cbdata cb;
struct commit *commit;
@ -1495,7 +1500,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
/* sha1 is a commit? match without further lookup */
(oideq(&cb.noid, &oid) ||
/* perhaps sha1 is a tag, try to dereference to a commit */
((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&
((commit = lookup_commit_reference_gently(r, &oid, 1)) != NULL &&
oideq(&cb.noid, &commit->object.oid)))) {
const char *from = ref;
if (!skip_prefix(from, "refs/tags/", &from))
@ -1552,31 +1557,32 @@ int wt_status_check_bisect(const struct worktree *wt,
return 0;
}
void wt_status_get_state(struct wt_status_state *state,
void wt_status_get_state(struct repository *r,
struct wt_status_state *state,
int get_detached_from)
{
struct stat st;
struct object_id oid;
if (!stat(git_path_merge_head(the_repository), &st)) {
if (!stat(git_path_merge_head(r), &st)) {
wt_status_check_rebase(NULL, state);
state->merge_in_progress = 1;
} else if (wt_status_check_rebase(NULL, state)) {
; /* all set */
} else if (!stat(git_path_cherry_pick_head(the_repository), &st) &&
} else if (!stat(git_path_cherry_pick_head(r), &st) &&
!get_oid("CHERRY_PICK_HEAD", &oid)) {
state->cherry_pick_in_progress = 1;
oidcpy(&state->cherry_pick_head_oid, &oid);
}
wt_status_check_bisect(NULL, state);
if (!stat(git_path_revert_head(the_repository), &st) &&
if (!stat(git_path_revert_head(r), &st) &&
!get_oid("REVERT_HEAD", &oid)) {
state->revert_in_progress = 1;
oidcpy(&state->revert_head_oid, &oid);
}
if (get_detached_from)
wt_status_get_detached_from(state);
wt_status_get_detached_from(r, state);
}
static void wt_longstatus_print_state(struct wt_status *s)
@ -2140,6 +2146,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
struct wt_status *s)
{
struct wt_status_change_data *d = it->util;
struct index_state *istate = s->repo->index;
const struct cache_entry *ce;
struct strbuf buf_index = STRBUF_INIT;
const char *path_index = NULL;
@ -2178,11 +2185,11 @@ static void wt_porcelain_v2_print_unmerged_entry(
*/
memset(stages, 0, sizeof(stages));
sum = 0;
pos = cache_name_pos(it->string, strlen(it->string));
pos = index_name_pos(istate, it->string, strlen(it->string));
assert(pos < 0);
pos = -pos-1;
while (pos < active_nr) {
ce = active_cache[pos++];
while (pos < istate->cache_nr) {
ce = istate->cache[pos++];
stage = ce_stage(ce);
if (strcmp(ce->name, it->string) || !stage)
break;
@ -2307,12 +2314,12 @@ void wt_status_print(struct wt_status *s)
/**
* Returns 1 if there are unstaged changes, 0 otherwise.
*/
int has_unstaged_changes(int ignore_submodules)
int has_unstaged_changes(struct repository *r, int ignore_submodules)
{
struct rev_info rev_info;
int result;
repo_init_revisions(the_repository, &rev_info, NULL);
repo_init_revisions(r, &rev_info, NULL);
if (ignore_submodules) {
rev_info.diffopt.flags.ignore_submodules = 1;
rev_info.diffopt.flags.override_submodule_config = 1;
@ -2326,15 +2333,16 @@ int has_unstaged_changes(int ignore_submodules)
/**
* Returns 1 if there are uncommitted changes, 0 otherwise.
*/
int has_uncommitted_changes(int ignore_submodules)
int has_uncommitted_changes(struct repository *r,
int ignore_submodules)
{
struct rev_info rev_info;
int result;
if (is_cache_unborn())
if (is_index_unborn(r->index))
return 0;
repo_init_revisions(the_repository, &rev_info, NULL);
repo_init_revisions(r, &rev_info, NULL);
if (ignore_submodules)
rev_info.diffopt.flags.ignore_submodules = 1;
rev_info.diffopt.flags.quick = 1;
@ -2345,7 +2353,7 @@ int has_uncommitted_changes(int ignore_submodules)
* We have no head (or it's corrupt); use the empty tree,
* which will complain if the index is non-empty.
*/
struct tree *tree = lookup_tree(the_repository, the_hash_algo->empty_tree);
struct tree *tree = lookup_tree(r, the_hash_algo->empty_tree);
add_pending_object(&rev_info, &tree->object, "");
}
@ -2358,24 +2366,28 @@ int has_uncommitted_changes(int ignore_submodules)
* If the work tree has unstaged or uncommitted changes, dies with the
* appropriate message.
*/
int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently)
int require_clean_work_tree(struct repository *r,
const char *action,
const char *hint,
int ignore_submodules,
int gently)
{
struct lock_file lock_file = LOCK_INIT;
int err = 0, fd;
fd = hold_locked_index(&lock_file, 0);
refresh_cache(REFRESH_QUIET);
refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
if (0 <= fd)
update_index_if_able(&the_index, &lock_file);
update_index_if_able(r->index, &lock_file);
rollback_lock_file(&lock_file);
if (has_unstaged_changes(ignore_submodules)) {
if (has_unstaged_changes(r, ignore_submodules)) {
/* TRANSLATORS: the action is e.g. "pull with rebase" */
error(_("cannot %s: You have unstaged changes."), _(action));
err = 1;
}
if (has_uncommitted_changes(ignore_submodules)) {
if (has_uncommitted_changes(r, ignore_submodules)) {
if (err)
error(_("additionally, your index contains uncommitted changes."));
else

Просмотреть файл

@ -7,6 +7,7 @@
#include "pathspec.h"
#include "remote.h"
struct repository;
struct worktree;
enum color_wt_status {
@ -83,6 +84,7 @@ struct wt_status_state {
};
struct wt_status {
struct repository *repo;
int is_initial;
char *branch;
const char *reference;
@ -128,11 +130,13 @@ struct wt_status {
size_t wt_status_locate_end(const char *s, size_t len);
void wt_status_add_cut_line(FILE *fp);
void wt_status_prepare(struct wt_status *s);
void wt_status_prepare(struct repository *r, struct wt_status *s);
void wt_status_print(struct wt_status *s);
void wt_status_collect(struct wt_status *s);
void wt_status_collect_free_buffers(struct wt_status *s);
void wt_status_get_state(struct wt_status_state *state, int get_detached_from);
void wt_status_get_state(struct repository *repo,
struct wt_status_state *state,
int get_detached_from);
int wt_status_check_rebase(const struct worktree *wt,
struct wt_status_state *state);
int wt_status_check_bisect(const struct worktree *wt,
@ -144,9 +148,14 @@ __attribute__((format (printf, 3, 4)))
void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
/* The following functions expect that the caller took care of reading the index. */
int has_unstaged_changes(int ignore_submodules);
int has_uncommitted_changes(int ignore_submodules);
int require_clean_work_tree(const char *action, const char *hint,
int ignore_submodules, int gently);
int has_unstaged_changes(struct repository *repo,
int ignore_submodules);
int has_uncommitted_changes(struct repository *repo,
int ignore_submodules);
int require_clean_work_tree(struct repository *repo,
const char *action,
const char *hint,
int ignore_submodules,
int gently);
#endif /* STATUS_H */