config: rename git_config_set to git_config_set_gently
[gitweb.git] / builtin / clone.c
index 3e14491a340cdce70308b31cdf96612344644c15..a46d3d0f81da93924c8d47b98976942479944cc7 100644 (file)
@@ -559,7 +559,7 @@ static void write_remote_refs(const struct ref *local_refs)
        for (r = local_refs; r; r = r->next) {
                if (!r->peer_ref)
                        continue;
-               if (ref_transaction_create(t, r->peer_ref->name, r->old_sha1,
+               if (ref_transaction_create(t, r->peer_ref->name, r->old_oid.hash,
                                           0, NULL, &err))
                        die("%s", err.buf);
        }
@@ -579,9 +579,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
                        continue;
                if (ends_with(ref->name, "^{}"))
                        continue;
-               if (!has_sha1_file(ref->old_sha1))
+               if (!has_object_file(&ref->old_oid))
                        continue;
-               update_ref(msg, ref->name, ref->old_sha1,
+               update_ref(msg, ref->name, ref->old_oid.hash,
                           NULL, 0, UPDATE_REFS_DIE_ON_ERR);
        }
 }
@@ -601,7 +601,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
        if (!ref)
                return -1;
 
-       hashcpy(sha1, ref->old_sha1);
+       hashcpy(sha1, ref->old_oid.hash);
        *rm = ref->next;
        return 0;
 }
@@ -650,14 +650,14 @@ static void update_head(const struct ref *our, const struct ref *remote,
                /* Local default branch link */
                create_symref("HEAD", our->name, NULL);
                if (!option_bare) {
-                       update_ref(msg, "HEAD", our->old_sha1, NULL, 0,
+                       update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
                                   UPDATE_REFS_DIE_ON_ERR);
                        install_branch_config(0, head, option_origin, our->name);
                }
        } else if (our) {
-               struct commit *c = lookup_commit_reference(our->old_sha1);
+               struct commit *c = lookup_commit_reference(our->old_oid.hash);
                /* --branch specifies a non-branch (i.e. tags), detach HEAD */
-               update_ref(msg, "HEAD", c->object.sha1,
+               update_ref(msg, "HEAD", c->object.oid.hash,
                           NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
        } else if (remote) {
                /*
@@ -665,7 +665,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
                 * HEAD points to a branch but we don't know which one.
                 * Detach HEAD in all these cases.
                 */
-               update_ref(msg, "HEAD", remote->old_sha1,
+               update_ref(msg, "HEAD", remote->old_oid.hash,
                           NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
        }
 }
@@ -732,7 +732,7 @@ static int checkout(void)
 
 static int write_one_config(const char *key, const char *value, void *data)
 {
-       return git_config_set_multivar(key, value ? value : "true", "^$", 0);
+       return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0);
 }
 
 static void write_config(struct string_list *config)
@@ -783,12 +783,12 @@ static void write_refspec_config(const char *src_ref_prefix,
                /* Configure the remote */
                if (value.len) {
                        strbuf_addf(&key, "remote.%s.fetch", option_origin);
-                       git_config_set_multivar(key.buf, value.buf, "^$", 0);
+                       git_config_set_multivar_or_die(key.buf, value.buf, "^$", 0);
                        strbuf_reset(&key);
 
                        if (option_mirror) {
                                strbuf_addf(&key, "remote.%s.mirror", option_origin);
-                               git_config_set(key.buf, "true");
+                               git_config_set_or_die(key.buf, "true");
                                strbuf_reset(&key);
                        }
                }
@@ -801,11 +801,15 @@ static void write_refspec_config(const char *src_ref_prefix,
 static void dissociate_from_references(void)
 {
        static const char* argv[] = { "repack", "-a", "-d", NULL };
+       char *alternates = git_pathdup("objects/info/alternates");
 
-       if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))
-               die(_("cannot repack to clean up"));
-       if (unlink(git_path("objects/info/alternates")) && errno != ENOENT)
-               die_errno(_("cannot unlink temporary alternates file"));
+       if (!access(alternates, F_OK)) {
+               if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))
+                       die(_("cannot repack to clean up"));
+               if (unlink(alternates) && errno != ENOENT)
+                       die_errno(_("cannot unlink temporary alternates file"));
+       }
+       free(alternates);
 }
 
 int cmd_clone(int argc, const char **argv, const char *prefix)
@@ -942,22 +946,18 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        src_ref_prefix = "refs/";
                strbuf_addstr(&branch_top, src_ref_prefix);
 
-               git_config_set("core.bare", "true");
+               git_config_set_or_die("core.bare", "true");
        } else {
                strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
        }
 
        strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
        strbuf_addf(&key, "remote.%s.url", option_origin);
-       git_config_set(key.buf, repo);
+       git_config_set_or_die(key.buf, repo);
        strbuf_reset(&key);
 
        if (option_reference.nr)
                setup_reference();
-       else if (option_dissociate) {
-               warning(_("--dissociate given, but there is no --reference"));
-               option_dissociate = 0;
-       }
 
        fetch_pattern = value.buf;
        refspec = parse_fetch_refspec(1, &fetch_pattern);
@@ -1016,7 +1016,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                 * remote HEAD check.
                 */
                for (ref = refs; ref; ref = ref->next)
-                       if (is_null_sha1(ref->old_sha1)) {
+                       if (is_null_oid(&ref->old_oid)) {
                                complete_refs_before_fetch = 0;
                                break;
                        }
@@ -1071,8 +1071,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        transport_unlock_pack(transport);
        transport_disconnect(transport);
 
-       if (option_dissociate)
+       if (option_dissociate) {
+               close_all_packs();
                dissociate_from_references();
+       }
 
        junk_mode = JUNK_LEAVE_REPO;
        err = checkout();