diff options
Diffstat (limited to 'submodule.c')
-rw-r--r-- | submodule.c | 57 |
1 files changed, 12 insertions, 45 deletions
diff --git a/submodule.c b/submodule.c index 1905d75b2b..d37d400b22 100644 --- a/submodule.c +++ b/submodule.c @@ -116,30 +116,7 @@ int remove_path_from_gitmodules(const char *path) void stage_updated_gitmodules(void) { - struct strbuf buf = STRBUF_INIT; - struct stat st; - int pos; - struct cache_entry *ce; - int namelen = strlen(".gitmodules"); - - pos = cache_name_pos(".gitmodules", namelen); - if (pos < 0) { - warning(_("could not find .gitmodules in index")); - return; - } - ce = active_cache[pos]; - ce->ce_flags = namelen; - if (strbuf_read_file(&buf, ".gitmodules", 0) < 0) - die(_("reading updated .gitmodules failed")); - if (lstat(".gitmodules", &st) < 0) - die_errno(_("unable to stat updated .gitmodules")); - fill_stat_cache_info(ce, &st); - ce->ce_mode = ce_mode_from_stat(ce, st.st_mode); - if (remove_cache_entry_at(pos) < 0) - die(_("unable to remove .gitmodules from index")); - if (write_sha1_file(buf.buf, buf.len, blob_type, ce->sha1)) - die(_("adding updated .gitmodules failed")); - if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE)) + if (add_file_to_cache(".gitmodules", 0)) die(_("staging updated .gitmodules failed")); } @@ -201,7 +178,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt, int submodule_config(const char *var, const char *value, void *cb) { - if (!prefixcmp(var, "submodule.")) + if (starts_with(var, "submodule.")) return parse_submodule_config_option(var, value); else if (!strcmp(var, "fetch.recursesubmodules")) { config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value); @@ -324,7 +301,7 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path, left->object.flags |= SYMMETRIC_LEFT; add_pending_object(rev, &left->object, path); add_pending_object(rev, &right->object, path); - merge_bases = get_merge_bases(left, right, 1); + merge_bases = get_merge_bases(left, right); if (merge_bases) { if (merge_bases->item == left) *fast_forward = 1; @@ -456,13 +433,12 @@ static int submodule_needs_pushing(const char *path, const unsigned char sha1[20 return 0; if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { - struct child_process cp; + struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = {"rev-list", NULL, "--not", "--remotes", "-n", "1" , NULL}; struct strbuf buf = STRBUF_INIT; int needs_pushing = 0; argv[1] = sha1_to_hex(sha1); - memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; @@ -547,10 +523,9 @@ static int push_submodule(const char *path) return 1; if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { - struct child_process cp; + struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = {"push", NULL}; - memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; @@ -567,10 +542,7 @@ static int push_submodule(const char *path) int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name) { int i, ret = 1; - struct string_list needs_pushing; - - memset(&needs_pushing, 0, sizeof(struct string_list)); - needs_pushing.strdup_strings = 1; + struct string_list needs_pushing = STRING_LIST_INIT_DUP; if (!find_unpushed_submodules(new_sha1, remotes_name, &needs_pushing)) return 1; @@ -595,12 +567,11 @@ static int is_submodule_commit_present(const char *path, unsigned char sha1[20]) if (!add_submodule_odb(path) && lookup_commit_reference(sha1)) { /* Even if the submodule is checked out and the commit is * present, make sure it is reachable from a ref. */ - struct child_process cp; + struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = {"rev-list", "-n", "1", NULL, "--not", "--all", NULL}; struct strbuf buf = STRBUF_INIT; argv[3] = sha1_to_hex(sha1); - memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; @@ -721,7 +692,7 @@ int fetch_populated_submodules(const struct argv_array *options, int quiet) { int i, result = 0; - struct child_process cp; + struct child_process cp = CHILD_PROCESS_INIT; struct argv_array argv = ARGV_ARRAY_INIT; struct string_list_item *name_for_path; const char *work_tree = get_git_work_tree(); @@ -737,7 +708,6 @@ int fetch_populated_submodules(const struct argv_array *options, argv_array_push(&argv, "--recurse-submodules-default"); /* default value, "--submodule-prefix" and its value are added later */ - memset(&cp, 0, sizeof(cp)); cp.env = local_repo_env; cp.git_cmd = 1; cp.no_stdin = 1; @@ -820,7 +790,7 @@ out: unsigned is_submodule_modified(const char *path, int ignore_untracked) { ssize_t len; - struct child_process cp; + struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = { "status", "--porcelain", @@ -847,7 +817,6 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) if (ignore_untracked) argv[2] = "-uno"; - memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; @@ -888,7 +857,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) int submodule_uses_gitfile(const char *path) { - struct child_process cp; + struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = { "submodule", "foreach", @@ -909,7 +878,6 @@ int submodule_uses_gitfile(const char *path) strbuf_release(&buf); /* Now test that all nested submodules use a gitfile too */ - memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; @@ -927,7 +895,7 @@ int ok_to_remove_submodule(const char *path) { struct stat st; ssize_t len; - struct child_process cp; + struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = { "status", "--porcelain", @@ -944,7 +912,6 @@ int ok_to_remove_submodule(const char *path) if (!submodule_uses_gitfile(path)) return 0; - memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; @@ -988,7 +955,7 @@ static int find_first_merges(struct object_array *result, const char *path, sha1_to_hex(a->object.sha1)); init_revisions(&revs, NULL); rev_opts.submodule = path; - setup_revisions(sizeof(rev_args)/sizeof(char *)-1, rev_args, &revs, &rev_opts); + setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts); /* save all revisions from the above list that contain b */ if (prepare_revision_walk(&revs)) |