Merge branch 'sb/perf-without-installed-git' into maint
[gitweb.git] / builtin / remote.c
index 5d3ab906bc7ef6cc8cc9c65a3b86cf4c1ff443fb..181668dedddef9bf79ab91d9740607cf31115a16 100644 (file)
@@ -509,11 +509,10 @@ struct branches_for_remote {
 };
 
 static int add_branch_for_removal(const char *refname,
-       const unsigned char *sha1, int flags, void *cb_data)
+       const struct object_id *oid, int flags, void *cb_data)
 {
        struct branches_for_remote *branches = cb_data;
        struct refspec refspec;
-       struct string_list_item *item;
        struct known_remote *kr;
 
        memset(&refspec, 0, sizeof(refspec));
@@ -543,9 +542,7 @@ static int add_branch_for_removal(const char *refname,
        if (flags & REF_ISSYMREF)
                return unlink(git_path("%s", refname));
 
-       item = string_list_append(branches->branches, refname);
-       item->util = xmalloc(20);
-       hashcpy(item->util, sha1);
+       string_list_append(branches->branches, refname);
 
        return 0;
 }
@@ -557,20 +554,20 @@ struct rename_info {
 };
 
 static int read_remote_branches(const char *refname,
-       const unsigned char *sha1, int flags, void *cb_data)
+       const struct object_id *oid, int flags, void *cb_data)
 {
        struct rename_info *rename = cb_data;
        struct strbuf buf = STRBUF_INIT;
        struct string_list_item *item;
        int flag;
-       unsigned char orig_sha1[20];
+       struct object_id orig_oid;
        const char *symref;
 
        strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
        if (starts_with(refname, buf.buf)) {
                item = string_list_append(rename->remote_branches, xstrdup(refname));
                symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
-                                           orig_sha1, &flag);
+                                           orig_oid.hash, &flag);
                if (flag & REF_ISSYMREF)
                        item->util = xstrdup(symref);
                else
@@ -584,7 +581,6 @@ static int migrate_file(struct remote *remote)
 {
        struct strbuf buf = STRBUF_INIT;
        int i;
-       char *path = NULL;
 
        strbuf_addf(&buf, "remote.%s.url", remote->name);
        for (i = 0; i < remote->url_nr; i++)
@@ -604,11 +600,9 @@ static int migrate_file(struct remote *remote)
                        return error(_("Could not append '%s' to '%s'"),
                                        remote->fetch_refspec[i], buf.buf);
        if (remote->origin == REMOTE_REMOTES)
-               path = git_path("remotes/%s", remote->name);
+               unlink_or_warn(git_path("remotes/%s", remote->name));
        else if (remote->origin == REMOTE_BRANCHES)
-               path = git_path("branches/%s", remote->name);
-       if (path)
-               unlink_or_warn(path);
+               unlink_or_warn(git_path("branches/%s", remote->name));
        return 0;
 }
 
@@ -704,9 +698,9 @@ static int mv(int argc, const char **argv)
        for (i = 0; i < remote_branches.nr; i++) {
                struct string_list_item *item = remote_branches.items + i;
                int flag = 0;
-               unsigned char sha1[20];
+               struct object_id oid;
 
-               read_ref_full(item->string, RESOLVE_REF_READING, sha1, &flag);
+               read_ref_full(item->string, RESOLVE_REF_READING, oid.hash, &flag);
                if (!(flag & REF_ISSYMREF))
                        continue;
                if (delete_ref(item->string, NULL, REF_NODEREF))
@@ -749,26 +743,6 @@ static int mv(int argc, const char **argv)
        return 0;
 }
 
-static int remove_branches(struct string_list *branches)
-{
-       struct strbuf err = STRBUF_INIT;
-       int i, result = 0;
-
-       if (repack_without_refs(branches, &err))
-               result |= error("%s", err.buf);
-       strbuf_release(&err);
-
-       for (i = 0; i < branches->nr; i++) {
-               struct string_list_item *item = branches->items + i;
-               const char *refname = item->string;
-
-               if (delete_ref(refname, NULL, 0))
-                       result |= error(_("Could not remove branch %s"), refname);
-       }
-
-       return result;
-}
-
 static int rm(int argc, const char **argv)
 {
        struct option options[] = {
@@ -825,8 +799,8 @@ static int rm(int argc, const char **argv)
        strbuf_release(&buf);
 
        if (!result)
-               result = remove_branches(&branches);
-       string_list_clear(&branches, 1);
+               result = delete_refs(&branches);
+       string_list_clear(&branches, 0);
 
        if (skipped.nr) {
                fprintf_ln(stderr,
@@ -867,7 +841,7 @@ static void free_remote_ref_states(struct ref_states *states)
 }
 
 static int append_ref_to_tracked_list(const char *refname,
-       const unsigned char *sha1, int flags, void *cb_data)
+       const struct object_id *oid, int flags, void *cb_data)
 {
        struct ref_states *states = cb_data;
        struct refspec refspec;
@@ -1337,19 +1311,12 @@ static int prune_remote(const char *remote, int dry_run)
                string_list_append(&refs_to_prune, item->util);
        string_list_sort(&refs_to_prune);
 
-       if (!dry_run) {
-               struct strbuf err = STRBUF_INIT;
-               if (repack_without_refs(&refs_to_prune, &err))
-                       result |= error("%s", err.buf);
-               strbuf_release(&err);
-       }
+       if (!dry_run)
+               result |= delete_refs(&refs_to_prune);
 
        for_each_string_list_item(item, &states.stale) {
                const char *refname = item->util;
 
-               if (!dry_run)
-                       result |= delete_ref(refname, NULL, 0);
-
                if (dry_run)
                        printf_ln(_(" * [would prune] %s"),
                               abbrev_ref(refname, "refs/remotes/"));