summaryrefslogtreecommitdiff
path: root/builtin/remote.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2014-11-25 09:02:30 +0100
committerJunio C Hamano <gitster@pobox.com>2014-11-25 10:09:45 -0800
commit28d3f214d12af4a3d7e625faf4bb0af6c735fa8b (patch)
tree08c9a1ef176b1c34adabced7939c9f8d52efc13c /builtin/remote.c
parent16d4fa3d9667ca28a519c46c1b1c752a848a693c (diff)
downloadgit-28d3f214d12af4a3d7e625faf4bb0af6c735fa8b.tar.gz
prune_remote(): initialize both delete_refs lists in a single loop
Also free them together at the end of the function. In a moment, the array version will become redundant. Managing them together makes later steps more obvious. 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.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/builtin/remote.c b/builtin/remote.c
index d2b684cd24..d5a5a1663b 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1337,8 +1337,13 @@ static int prune_remote(const char *remote, int dry_run)
: _("(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;
+ for (i = 0; i < states.stale.nr; i++) {
+ const char *refname = states.stale.items[i].util;
+
+ delete_refs[i] = refname;
+ string_list_insert(&delete_refs_list, refname);
+ }
+
if (!dry_run) {
struct strbuf err = STRBUF_INIT;
if (repack_without_refs(delete_refs, states.stale.nr,
@@ -1346,13 +1351,10 @@ static int prune_remote(const char *remote, int dry_run)
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;
- string_list_insert(&delete_refs_list, refname);
-
if (!dry_run)
result |= delete_ref(refname, NULL, 0);
@@ -1365,8 +1367,9 @@ static int prune_remote(const char *remote, int dry_run)
}
warn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);
- string_list_clear(&delete_refs_list, 0);
+ free(delete_refs);
+ string_list_clear(&delete_refs_list, 0);
free_remote_ref_states(&states);
return result;
}