send-pack: isolate sigpipe in demuxer thread
[gitweb.git] / submodule.c
index a458100ed2c2c70e80fd8c4f1cebc23a5ac1c08e..2a6cc9e8bab8f8ac198d7621131bcd70b38956a3 100644 (file)
@@ -68,7 +68,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
        strbuf_addstr(&entry, "submodule.");
        strbuf_addstr(&entry, submodule->name);
        strbuf_addstr(&entry, ".path");
-       if (git_config_set_in_file(".gitmodules", entry.buf, newpath) < 0) {
+       if (git_config_set_in_file_gently(".gitmodules", entry.buf, newpath) < 0) {
                /* Maybe the user already did that, don't error out here */
                warning(_("Could not update .gitmodules entry %s"), entry.buf);
                strbuf_release(&entry);
@@ -122,6 +122,7 @@ static int add_submodule_odb(const char *path)
        struct strbuf objects_directory = STRBUF_INIT;
        struct alternate_object_database *alt_odb;
        int ret = 0;
+       size_t alloc;
 
        strbuf_git_path_submodule(&objects_directory, path, "objects/");
        if (!is_directory(objects_directory.buf)) {
@@ -136,9 +137,10 @@ static int add_submodule_odb(const char *path)
                                        objects_directory.len))
                        goto done;
 
-       alt_odb = xmalloc(objects_directory.len + 42 + sizeof(*alt_odb));
+       alloc = st_add(objects_directory.len, 42); /* for "12/345..." sha1 */
+       alt_odb = xmalloc(st_add(sizeof(*alt_odb), alloc));
        alt_odb->next = alt_odb_list;
-       strcpy(alt_odb->base, objects_directory.buf);
+       xsnprintf(alt_odb->base, alloc, "%s", objects_directory.buf);
        alt_odb->name = alt_odb->base + objects_directory.len;
        alt_odb->name[2] = '/';
        alt_odb->name[40] = '\0';
@@ -247,7 +249,7 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
        for (list = merge_bases; list; list = list->next) {
                list->item->object.flags |= UNINTERESTING;
                add_pending_object(rev, &list->item->object,
-                       sha1_to_hex(list->item->object.sha1));
+                       oid_to_hex(&list->item->object.oid));
        }
        return prepare_revision_walk(rev);
 }
@@ -595,7 +597,7 @@ static void calculate_changed_submodule_paths(void)
                        diff_opts.output_format |= DIFF_FORMAT_CALLBACK;
                        diff_opts.format_callback = submodule_collect_changed_cb;
                        diff_setup_done(&diff_opts);
-                       diff_tree_sha1(parent->item->object.sha1, commit->object.sha1, "", &diff_opts);
+                       diff_tree_sha1(parent->item->object.oid.hash, commit->object.oid.hash, "", &diff_opts);
                        diffcore_std(&diff_opts);
                        diff_flush(&diff_opts);
                        parent = parent->next;
@@ -873,7 +875,7 @@ static int find_first_merges(struct object_array *result, const char *path,
 
        /* get all revisions that merge commit a */
        snprintf(merged_revision, sizeof(merged_revision), "^%s",
-                       sha1_to_hex(a->object.sha1));
+                       oid_to_hex(&a->object.oid));
        init_revisions(&revs, NULL);
        rev_opts.submodule = path;
        setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
@@ -1004,7 +1006,7 @@ int merge_submodule(unsigned char result[20], const char *path,
                        "by using:\n\n"
                        "  git update-index --cacheinfo 160000 %s \"%s\"\n\n"
                        "which will accept this suggestion.\n",
-                       sha1_to_hex(merges.objects[0].item->sha1), path);
+                       oid_to_hex(&merges.objects[0].item->oid), path);
                break;
 
        default:
@@ -1032,11 +1034,9 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
        /* Update core.worktree setting */
        strbuf_reset(&file_name);
        strbuf_addf(&file_name, "%s/config", git_dir);
-       if (git_config_set_in_file(file_name.buf, "core.worktree",
-                                  relative_path(real_work_tree, git_dir,
-                                                &rel_path)))
-               die(_("Could not set core.worktree in %s"),
-                   file_name.buf);
+       git_config_set_in_file(file_name.buf, "core.worktree",
+                              relative_path(real_work_tree, git_dir,
+                                            &rel_path));
 
        strbuf_release(&file_name);
        strbuf_release(&rel_path);