Skip to content

Commit

Permalink
Merge branch 'nd/submodule-unused-vars' into next
Browse files Browse the repository at this point in the history
Code clean-up.

* nd/submodule-unused-vars:
  submodule.c: remove some of the_repository references
  • Loading branch information
gitster committed Oct 29, 2018
2 parents de51b60 + 6245b98 commit 33641dc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion builtin/pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
int ret = 0;
if ((recurse_submodules == RECURSE_SUBMODULES_ON ||
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) &&
submodule_touches_in_range(&the_index, &rebase_fork_point, &curr_head))
submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head))
die(_("cannot rebase with locally recorded submodule modifications"));
if (!autostash) {
struct commit_list *list = NULL;
Expand Down
57 changes: 32 additions & 25 deletions submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ static struct oid_array *submodule_commits(struct string_list *submodules,
}

struct collect_changed_submodules_cb_data {
struct repository *repo;
struct string_list *changed;
const struct object_id *commit_oid;
};
Expand Down Expand Up @@ -733,15 +734,15 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
if (!S_ISGITLINK(p->two->mode))
continue;

submodule = submodule_from_path(the_repository,
submodule = submodule_from_path(me->repo,
commit_oid, p->two->path);
if (submodule)
name = submodule->name;
else {
name = default_name_or_path(p->two->path);
/* make sure name does not collide with existing one */
if (name)
submodule = submodule_from_name(the_repository,
submodule = submodule_from_name(me->repo,
commit_oid, name);
if (submodule) {
warning("Submodule in commit %s at path: "
Expand All @@ -766,25 +767,26 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
* have a corresponding 'struct oid_array' (in the 'util' field) which lists
* what the submodule pointers were updated to during the change.
*/
static void collect_changed_submodules(struct index_state *istate,
static void collect_changed_submodules(struct repository *r,
struct string_list *changed,
struct argv_array *argv)
{
struct rev_info rev;
const struct commit *commit;

repo_init_revisions(the_repository, &rev, NULL);
repo_init_revisions(r, &rev, NULL);
setup_revisions(argv->argc, argv->argv, &rev, NULL);
if (prepare_revision_walk(&rev))
die("revision walk setup failed");

while ((commit = get_revision(&rev))) {
struct rev_info diff_rev;
struct collect_changed_submodules_cb_data data;
data.repo = r;
data.changed = changed;
data.commit_oid = &commit->object.oid;

repo_init_revisions(the_repository, &diff_rev, NULL);
repo_init_revisions(r, &diff_rev, NULL);
diff_rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
diff_rev.diffopt.format_callback = collect_changed_submodules_cb;
diff_rev.diffopt.format_callback_data = &data;
Expand Down Expand Up @@ -816,6 +818,7 @@ static int append_oid_to_argv(const struct object_id *oid, void *data)
}

struct has_commit_data {
struct repository *repo;
int result;
const char *path;
};
Expand All @@ -824,7 +827,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
{
struct has_commit_data *cb = data;

enum object_type type = oid_object_info(the_repository, oid, NULL);
enum object_type type = oid_object_info(cb->repo, oid, NULL);

switch (type) {
case OBJ_COMMIT:
Expand All @@ -842,9 +845,11 @@ static int check_has_commit(const struct object_id *oid, void *data)
}
}

static int submodule_has_commits(const char *path, struct oid_array *commits)
static int submodule_has_commits(struct repository *r,
const char *path,
struct oid_array *commits)
{
struct has_commit_data has_commit = { 1, path };
struct has_commit_data has_commit = { r, 1, path };

/*
* Perform a cheap, but incorrect check for the existence of 'commits'.
Expand Down Expand Up @@ -887,9 +892,11 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)
return has_commit.result;
}

static int submodule_needs_pushing(const char *path, struct oid_array *commits)
static int submodule_needs_pushing(struct repository *r,
const char *path,
struct oid_array *commits)
{
if (!submodule_has_commits(path, commits))
if (!submodule_has_commits(r, path, commits))
/*
* NOTE: We do consider it safe to return "no" here. The
* correct answer would be "We do not know" instead of
Expand Down Expand Up @@ -931,7 +938,7 @@ static int submodule_needs_pushing(const char *path, struct oid_array *commits)
return 0;
}

int find_unpushed_submodules(struct index_state *istate,
int find_unpushed_submodules(struct repository *r,
struct oid_array *commits,
const char *remotes_name,
struct string_list *needs_pushing)
Expand All @@ -946,14 +953,14 @@ int find_unpushed_submodules(struct index_state *istate,
argv_array_push(&argv, "--not");
argv_array_pushf(&argv, "--remotes=%s", remotes_name);

collect_changed_submodules(istate, &submodules, &argv);
collect_changed_submodules(r, &submodules, &argv);

for_each_string_list_item(name, &submodules) {
struct oid_array *commits = name->util;
const struct submodule *submodule;
const char *path = NULL;

submodule = submodule_from_name(the_repository, &null_oid, name->string);
submodule = submodule_from_name(r, &null_oid, name->string);
if (submodule)
path = submodule->path;
else
Expand All @@ -962,7 +969,7 @@ int find_unpushed_submodules(struct index_state *istate,
if (!path)
continue;

if (submodule_needs_pushing(path, commits))
if (submodule_needs_pushing(r, path, commits))
string_list_insert(needs_pushing, path);
}

Expand Down Expand Up @@ -1047,7 +1054,7 @@ static void submodule_push_check(const char *path, const char *head,
die("process for submodule '%s' failed", path);
}

int push_unpushed_submodules(struct index_state *istate,
int push_unpushed_submodules(struct repository *r,
struct oid_array *commits,
const struct remote *remote,
const struct refspec *rs,
Expand All @@ -1057,7 +1064,7 @@ int push_unpushed_submodules(struct index_state *istate,
int i, ret = 1;
struct string_list needs_pushing = STRING_LIST_INIT_DUP;

if (!find_unpushed_submodules(istate, commits,
if (!find_unpushed_submodules(r, commits,
remote->name, &needs_pushing))
return 1;

Expand Down Expand Up @@ -1115,14 +1122,14 @@ void check_for_new_submodule_commits(struct object_id *oid)
oid_array_append(&ref_tips_after_fetch, oid);
}

static void calculate_changed_submodule_paths(struct index_state *istate)
static void calculate_changed_submodule_paths(struct repository *r)
{
struct argv_array argv = ARGV_ARRAY_INIT;
struct string_list changed_submodules = STRING_LIST_INIT_DUP;
const struct string_list_item *name;

/* No need to check if there are no submodules configured */
if (!submodule_from_path(the_repository, NULL, NULL))
if (!submodule_from_path(r, NULL, NULL))
return;

argv_array_push(&argv, "--"); /* argv[0] program name */
Expand All @@ -1136,14 +1143,14 @@ static void calculate_changed_submodule_paths(struct index_state *istate)
* Collect all submodules (whether checked out or not) for which new
* commits have been recorded upstream in "changed_submodule_names".
*/
collect_changed_submodules(istate, &changed_submodules, &argv);
collect_changed_submodules(r, &changed_submodules, &argv);

for_each_string_list_item(name, &changed_submodules) {
struct oid_array *commits = name->util;
const struct submodule *submodule;
const char *path = NULL;

submodule = submodule_from_name(the_repository, &null_oid, name->string);
submodule = submodule_from_name(r, &null_oid, name->string);
if (submodule)
path = submodule->path;
else
Expand All @@ -1152,7 +1159,7 @@ static void calculate_changed_submodule_paths(struct index_state *istate)
if (!path)
continue;

if (!submodule_has_commits(path, commits))
if (!submodule_has_commits(r, path, commits))
string_list_append(&changed_submodule_names, name->string);
}

Expand All @@ -1163,7 +1170,7 @@ static void calculate_changed_submodule_paths(struct index_state *istate)
initialized_fetch_ref_tips = 0;
}

int submodule_touches_in_range(struct index_state *istate,
int submodule_touches_in_range(struct repository *r,
struct object_id *excl_oid,
struct object_id *incl_oid)
{
Expand All @@ -1172,7 +1179,7 @@ int submodule_touches_in_range(struct index_state *istate,
int ret;

/* No need to check if there are no submodules configured */
if (!submodule_from_path(the_repository, NULL, NULL))
if (!submodule_from_path(r, NULL, NULL))
return 0;

argv_array_push(&args, "--"); /* args[0] program name */
Expand All @@ -1182,7 +1189,7 @@ int submodule_touches_in_range(struct index_state *istate,
argv_array_push(&args, oid_to_hex(excl_oid));
}

collect_changed_submodules(istate, &subs, &args);
collect_changed_submodules(r, &subs, &args);
ret = subs.nr;

argv_array_clear(&args);
Expand Down Expand Up @@ -1352,7 +1359,7 @@ int fetch_populated_submodules(struct repository *r,
argv_array_push(&spf.args, "--recurse-submodules-default");
/* default value, "--submodule-prefix" and its value are added later */

calculate_changed_submodule_paths(r->index);
calculate_changed_submodule_paths(r);
run_processes_parallel(max_parallel_jobs,
get_next_submodule,
fetch_start_failure,
Expand Down
6 changes: 3 additions & 3 deletions submodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ int add_submodule_odb(const char *path);
* Checks if there are submodule changes in a..b. If a is the null OID,
* checks b and all its ancestors instead.
*/
int submodule_touches_in_range(struct index_state *istate,
int submodule_touches_in_range(struct repository *r,
struct object_id *a,
struct object_id *b);
int find_unpushed_submodules(struct index_state *istate,
int find_unpushed_submodules(struct repository *r,
struct oid_array *commits,
const char *remotes_name,
struct string_list *needs_pushing);
struct refspec;
int push_unpushed_submodules(struct index_state *istate,
int push_unpushed_submodules(struct repository *r,
struct oid_array *commits,
const struct remote *remote,
const struct refspec *rs,
Expand Down
4 changes: 2 additions & 2 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ int transport_push(struct transport *transport,
oid_array_append(&commits,
&ref->new_oid);

if (!push_unpushed_submodules(&the_index,
if (!push_unpushed_submodules(the_repository,
&commits,
transport->remote,
rs,
Expand All @@ -1197,7 +1197,7 @@ int transport_push(struct transport *transport,
oid_array_append(&commits,
&ref->new_oid);

if (find_unpushed_submodules(&the_index,
if (find_unpushed_submodules(the_repository,
&commits,
transport->remote->name,
&needs_pushing)) {
Expand Down

0 comments on commit 33641dc

Please sign in to comment.