diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2014-11-25 09:02:29 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-11-25 10:07:45 -0800 |
commit | 16d4fa3d9667ca28a519c46c1b1c752a848a693c (patch) | |
tree | c2dd0b111e2cdb661ce09962cad2bf4513f5f3cd /builtin/remote.c | |
parent | e69b1ce000e6c530ac8bf06470742456277e2a36 (diff) | |
download | git-16d4fa3d9667ca28a519c46c1b1c752a848a693c.tar.gz |
prune_remote(): exit early if there are no stale references
Aside from making the logic clearer, this avoids a call to
warn_dangling_symrefs(), which always does a for_each_rawref()
iteration.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/remote.c')
-rw-r--r-- | builtin/remote.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/builtin/remote.c b/builtin/remote.c index 7f28f92a37..d2b684cd24 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1325,25 +1325,28 @@ static int prune_remote(const char *remote, int dry_run) memset(&states, 0, sizeof(states)); get_remote_ref_states(remote, &states, GET_REF_STATES); - if (states.stale.nr) { - printf_ln(_("Pruning %s"), remote); - printf_ln(_("URL: %s"), - states.remote->url_nr - ? states.remote->url[0] - : _("(no URL)")); - - delete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs)); - for (i = 0; i < states.stale.nr; i++) - delete_refs[i] = states.stale.items[i].util; - if (!dry_run) { - struct strbuf err = STRBUF_INIT; - if (repack_without_refs(delete_refs, states.stale.nr, - &err)) - result |= error("%s", err.buf); - strbuf_release(&err); - } - free(delete_refs); + if (!states.stale.nr) { + free_remote_ref_states(&states); + return 0; + } + + printf_ln(_("Pruning %s"), remote); + printf_ln(_("URL: %s"), + states.remote->url_nr + ? states.remote->url[0] + : _("(no URL)")); + + delete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs)); + for (i = 0; i < states.stale.nr; i++) + delete_refs[i] = states.stale.items[i].util; + if (!dry_run) { + struct strbuf err = STRBUF_INIT; + if (repack_without_refs(delete_refs, states.stale.nr, + &err)) + result |= error("%s", err.buf); + strbuf_release(&err); } + free(delete_refs); for (i = 0; i < states.stale.nr; i++) { const char *refname = states.stale.items[i].util; |