Teach `git remote` howto prune all remotes
cover Teach `git remote` howto prune all remotes
Lars Hjemli (2):
git remote: split part of prune() into prune_one() git remote: prune all remotes with prune -a
Documentation/git-remote.txt | 4 +- builtin-remote.c | 97 ++++++++++++++++++++++++++++------------- 2 files changed, 69 insertions(+), 32 deletions(-)
PATCH 1/2 git remote: move part of prune() into prune_one()
The new function will be reused by prune_all() in the next patch.
Signed-off-by Lars Hjemli <[email protected]>
--- builtin-remote.c | 67 +++++++++++++++++++++++++++++------------------------ 1 files changed, 37 insertions(+), 30 deletions(-)
builtin-remote.c +37 -30
@@ -537,6 +537,41 @@ static int show(int argc, const char **argv)return result; } +static int prune_one (const char *name,int dry_run) +{ +struct ref_states states; +int result =0 ; +int i; + +memset (&states,0 ,sizeof (states)); +get_remote_ref_states (name, &states,1 ); + +if (states.stale.nr) { +printf ("Pruning %s\n" , name); +printf ("URL: %s\n" , + states.remote->url_nr + ? 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 ); + +printf (" * [%s] %s\n" , dry_run ?"would prune" :"pruned" , +abbrev_ref (refname,"refs/remotes/" )); + } + +/* NEEDSWORK: free remote */ +string_list_clear (&states.new,0 ); +string_list_clear (&states.stale,0 ); +string_list_clear (&states.tracked,0 ); + +return result; +} +static int prune (int argc,const char **argv) {int dry_run =0 , result =0 ;
@@ -545,42 +580,14 @@ static int prune(int argc, const char **argv)OPT__DRY_RUN (&dry_run), OPT_END() }; -struct ref_states states; argc =parse_options (argc, argv, options, builtin_remote_usage,0 );if (argc <1 )usage_with_options (builtin_remote_usage, options); -memset (&states,0 ,sizeof (states)); -for (; argc; argc--, argv++) { -int i; - -get_remote_ref_states (*argv, &states,1 ); - -if (states.stale.nr) { -printf ("Pruning %s\n" , *argv); -printf ("URL: %s\n" , - states.remote->url_nr - ? 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 ); - -printf (" * [%s] %s\n" , dry_run ?"would prune" :"pruned" , -abbrev_ref (refname,"refs/remotes/" )); - } - -/* NEEDSWORK: free remote */ -string_list_clear (&states.new,0 ); -string_list_clear (&states.stale,0 ); -string_list_clear (&states.tracked,0 ); - } +for (; argc; argc--, argv++) + result |=prune_one (*argv, dry_run);return result; }
--
1.6.0.2.309.gc1f46
PATCH 2/2 git remote: prune all remotes with `prune -a`
This is handy when working with lots of remotes.
Signed-off-by Lars Hjemli <[email protected]>
--- Documentation/git-remote.txt | 4 +++- builtin-remote.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-)
Documentation/git-remote.txt +3 -1
@@ -13,7 +13,7 @@ SYNOPSIS 'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url> 'git remote rm' <name> 'git remote show' [-n] <name> -'git remote prune' [-n | --dry-run] <name> +'git remote prune' [-n | --dry-run] [-a | <name>] 'git remote update' [group] DESCRIPTION
@@ -82,6 +82,8 @@ referenced by <name>, but are still locally available in + With `--dry-run` option, report what branches will be pruned, but do no actually prune them. ++ +With `-a` option, prune all remotes. 'update'::
builtin-remote.c +30 -2
@@ -572,20 +572,48 @@ static int prune_one(const char *name, int dry_run)return result; } +struct prune_cbdata { +int result; +int dry_run; +}; + +static int prune_all_cb (struct remote *remote,void *cbdata) +{ +struct prune_cbdata *cb = cbdata; + + cb->result |=prune_one (remote->name, cb->dry_run); +return 0 ; +} + +static int prune_all (int dry_run) +{ +int result; +struct prune_cbdata cb; + + cb.result =0 ; + cb.dry_run = dry_run; + result =for_each_remote (prune_all_cb, &cb); +return (result | cb.result); +} +static int prune (int argc,const char **argv) { -int dry_run =0 , result =0 ; +int dry_run =0 , all =0 , result =0 ;struct option options[] = {OPT_GROUP ("prune specific options" ), +OPT_BOOLEAN ('a' ,NULL , &all,"prune all remotes" ),OPT__DRY_RUN (&dry_run),OPT_END () }; argc =parse_options (argc, argv, options, builtin_remote_usage,0 ); -if (argc <1 ) +if (!argc == !all)usage_with_options (builtin_remote_usage, options); +if (all) +return prune_all (dry_run); +for (; argc; argc--, argv++) result |=prune_one (*argv, dry_run);
Signature · 1 line
1.6.0.2.309.gc1f46