]> git.ipfire.org Git - thirdparty/git.git/commitdiff
prune_remote(): use delete_refs()
authorMichael Haggerty <mhagger@alum.mit.edu>
Mon, 22 Jun 2015 14:02:58 +0000 (16:02 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Jun 2015 20:17:10 +0000 (13:17 -0700)
This slightly changes how errors are reported. The old and new code
both report errors that come from repack_without_refs() the same way.
But if an error occurs within delete_ref(), the old version only
emitted an error within delete_ref() without further comment. The new
version (in delete_refs()) still emits that error, but then follows it
up with

    error(_("could not remove reference %s"), refname)

The "could not remove reference" error originally came from a similar
message in remove_branches() (from builtin/remote.c).

This is an improvement, because the error from delete_ref() (which
usually comes from ref_transaction_commit()) can be pretty low-level,
like

    Cannot lock ref '%s': unable to resolve reference %s: %s

where the last "%s" is the original strerror.

In any case, I don't think we need to sweat the details too much,
because these errors should only ever be seen in the case of a broken
repository or a race between two processes; i.e., only in pretty rare
and anomalous situations.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/remote.c

index c8dc724956275a37d4defaebea07a61ddadacd27..cc3c7410f321af91da6af384aadf3dd4db536ce3 100644 (file)
@@ -1314,19 +1314,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/"));