builtin-remote.c: Split out prune_remote as a separate function.
prune_remote will be used in update(), so this function was split out to avoid code duplication. Signed-off-by: Finn Arne Gangstad <finnag@pvv.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e96f3689ec
commit
b92c5f228a
@ -26,6 +26,7 @@ static const char * const builtin_remote_usage[] = {
|
|||||||
static int verbose;
|
static int verbose;
|
||||||
|
|
||||||
static int show_all(void);
|
static int show_all(void);
|
||||||
|
static int prune_remote(const char *remote, int dry_run);
|
||||||
|
|
||||||
static inline int postfixcmp(const char *string, const char *postfix)
|
static inline int postfixcmp(const char *string, const char *postfix)
|
||||||
{
|
{
|
||||||
@ -1128,46 +1129,49 @@ static int prune(int argc, const char **argv)
|
|||||||
OPT__DRY_RUN(&dry_run),
|
OPT__DRY_RUN(&dry_run),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
struct ref_states states;
|
|
||||||
const char *dangling_msg;
|
|
||||||
|
|
||||||
argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
|
argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
|
||||||
|
|
||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
usage_with_options(builtin_remote_usage, options);
|
usage_with_options(builtin_remote_usage, options);
|
||||||
|
|
||||||
dangling_msg = (dry_run
|
for (; argc; argc--, argv++)
|
||||||
? " %s will become dangling!\n"
|
result |= prune_remote(*argv, dry_run);
|
||||||
: " %s has become dangling!\n");
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int prune_remote(const char *remote, int dry_run)
|
||||||
|
{
|
||||||
|
int result = 0, i;
|
||||||
|
struct ref_states states;
|
||||||
|
const char *dangling_msg = dry_run
|
||||||
|
? " %s will become dangling!\n"
|
||||||
|
: " %s has become dangling!\n";
|
||||||
|
|
||||||
memset(&states, 0, sizeof(states));
|
memset(&states, 0, sizeof(states));
|
||||||
for (; argc; argc--, argv++) {
|
get_remote_ref_states(remote, &states, GET_REF_STATES);
|
||||||
int i;
|
|
||||||
|
|
||||||
get_remote_ref_states(*argv, &states, GET_REF_STATES);
|
if (states.stale.nr) {
|
||||||
|
printf("Pruning %s\n", remote);
|
||||||
if (states.stale.nr) {
|
printf("URL: %s\n",
|
||||||
printf("Pruning %s\n", *argv);
|
states.remote->url_nr
|
||||||
printf("URL: %s\n",
|
? states.remote->url[0]
|
||||||
states.remote->url_nr
|
: "(no URL)");
|
||||||
? states.remote->url[0]
|
|
||||||
: "(no URL)");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < states.stale.nr; i++) {
|
|
||||||
const char *refname = states.stale.items[i].util;
|
|
||||||
|
|
||||||
if (!dry_run)
|
|
||||||
result |= delete_ref(refname, NULL, 0);
|
|
||||||
|
|
||||||
printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned",
|
|
||||||
abbrev_ref(refname, "refs/remotes/"));
|
|
||||||
warn_dangling_symref(dangling_msg, refname);
|
|
||||||
}
|
|
||||||
|
|
||||||
free_remote_ref_states(&states);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < states.stale.nr; i++) {
|
||||||
|
const char *refname = states.stale.items[i].util;
|
||||||
|
|
||||||
|
if (!dry_run)
|
||||||
|
result |= delete_ref(refname, NULL, 0);
|
||||||
|
|
||||||
|
printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned",
|
||||||
|
abbrev_ref(refname, "refs/remotes/"));
|
||||||
|
warn_dangling_symref(dangling_msg, refname);
|
||||||
|
}
|
||||||
|
|
||||||
|
free_remote_ref_states(&states);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user