summaryrefslogtreecommitdiff
path: root/builtin/remote.c
diff options
context:
space:
mode:
authorRonnie Sahlberg <sahlberg@google.com>2014-11-20 10:04:26 -0800
committerJunio C Hamano <gitster@pobox.com>2014-11-20 11:12:40 -0800
commita8739c210bda544077278de6790f4da39fe6befc (patch)
tree957ad32ad43d9a69f913385549cd220bf981676c /builtin/remote.c
parente69b1ce000e6c530ac8bf06470742456277e2a36 (diff)
downloadgit-sb/simplify-repack-without-refs.tar.gz
refs.c: use a string_list for repack_without_refssb/simplify-repack-without-refs
This patch doesn't intend any functional changes. It is just a refactoring, which replaces a char** array by a string_list in the function repack_without_refs. This is easier to read and maintain as it delivers the same functionality with less lines of code and more lines of documentation. [sb: ported this patch from a larger patch series to the master branch, added documentary comments in refs.h] Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Stefan Beller <sbeller@google.com> 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.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/builtin/remote.c b/builtin/remote.c
index 7f28f92a37..364350af21 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -750,16 +750,11 @@ static int mv(int argc, const char **argv)
static int remove_branches(struct string_list *branches)
{
struct strbuf err = STRBUF_INIT;
- const char **branch_names;
int i, result = 0;
- branch_names = xmalloc(branches->nr * sizeof(*branch_names));
- for (i = 0; i < branches->nr; i++)
- branch_names[i] = branches->items[i].string;
- if (repack_without_refs(branch_names, branches->nr, &err))
+ if (repack_without_refs(branches, &err))
result |= error("%s", err.buf);
strbuf_release(&err);
- free(branch_names);
for (i = 0; i < branches->nr; i++) {
struct string_list_item *item = branches->items + i;
@@ -1316,8 +1311,8 @@ static int prune_remote(const char *remote, int dry_run)
{
int result = 0, i;
struct ref_states states;
- struct string_list delete_refs_list = STRING_LIST_INIT_NODUP;
- const char **delete_refs;
+ struct string_list delete_refs = STRING_LIST_INIT_NODUP;
+ struct string_list_item *ref;
const char *dangling_msg = dry_run
? _(" %s will become dangling!")
: _(" %s has become dangling!");
@@ -1325,6 +1320,9 @@ static int prune_remote(const char *remote, int dry_run)
memset(&states, 0, sizeof(states));
get_remote_ref_states(remote, &states, GET_REF_STATES);
+ for (i = 0; i < states.stale.nr; i++)
+ string_list_append(&delete_refs, states.stale.items[i].util);
+
if (states.stale.nr) {
printf_ln(_("Pruning %s"), remote);
printf_ln(_("URL: %s"),
@@ -1332,23 +1330,16 @@ static int prune_remote(const char *remote, int dry_run)
? 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))
+ if (repack_without_refs(&delete_refs, &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;
-
- string_list_insert(&delete_refs_list, refname);
+ for_each_string_list_item(ref, &delete_refs) {
+ const char *refname = ref->string;
if (!dry_run)
result |= delete_ref(refname, NULL, 0);
@@ -1361,9 +1352,10 @@ static int prune_remote(const char *remote, int dry_run)
abbrev_ref(refname, "refs/remotes/"));
}
- warn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);
- string_list_clear(&delete_refs_list, 0);
+ sort_string_list(&delete_refs);
+ warn_dangling_symrefs(stdout, dangling_msg, &delete_refs);
+ string_list_clear(&delete_refs, 0);
free_remote_ref_states(&states);
return result;
}