threads / patch / 19197

patchgit-remote: make remote name optional for prune operation

Subject: [PATCH] git-remote: make remote name optional for prune operation

## tl;dr

9 messages between May 6, 2009 and May 6, 2009. Diffs are folded; open one to read it.

replies: 8people: 6as markdown or json

Julien Danjou· May 6, 2009, 14:37 UTC · lore

We consider that if `git remote prune` is called without a name, we actually want to prune all remotes.

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 Documentation/git-remote.txt |    2 +-
 builtin-remote.c             |   26 +++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 6 deletions(-)
Show changes to 2 files +21 −5

Documentation/git-remote.txt, builtin-remote.c

diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 9e2b4ea..c566061 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -15,7 +15,7 @@ SYNOPSIS
 'git remote rm' <name>
 'git remote set-head' <name> [-a | -d | <branch>]
 'git remote show' [-n] <name>
-'git remote prune' [-n | --dry-run] <name>
+'git remote prune' [-n | --dry-run] [name]
 'git remote update' [-p | --prune] [group | remote]...
 
 DESCRIPTION
diff --git a/builtin-remote.c b/builtin-remote.c
index 2ed752c..053d886 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -14,7 +14,7 @@ static const char * const builtin_remote_usage[] = {
 	"git remote rm <name>",
 	"git remote set-head <name> [-a | -d | <branch>]",
 	"git remote show [-n] <name>",
-	"git remote prune [-n | --dry-run] <name>",
+	"git remote prune [-n | --dry-run] [name]",
 	"git remote [-v | --verbose] update [-p | --prune] [group]",
 	NULL
 };
@@ -25,6 +25,7 @@ static const char * const builtin_remote_usage[] = {
 
 static int verbose;
 
+static int get_one_entry(struct remote *remote, void *priv);
 static int show_all(void);
 static int prune_remote(const char *remote, int dry_run);
 
@@ -1133,10 +1134,25 @@ static int prune(int argc, const char **argv)
 	argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
 
 	if (argc < 1)
-		usage_with_options(builtin_remote_usage, options);
+	{
+		struct string_list list = { NULL, 0, 0 };
+		int result = for_each_remote(get_one_entry, &list);
+
+		if (!result) {
+			int i;
 
-	for (; argc; argc--, argv++)
-		result |= prune_remote(*argv, dry_run);
+			sort_string_list(&list);
+			for (i = 0; i < list.nr; i++) {
+				struct string_list_item *item = list.items + i;
+				if (i && !strcmp((item - 1)->string, item->string))
+				       continue;
+				result |= prune_remote(item->string, dry_run);
+			}
+		}
+	}
+	else
+		for (; argc; argc--, argv++)
+			result |= prune_remote(*argv, dry_run);
 
 	return result;
 }
-- 
1.6.2.4
Francis Galiegue· May 6, 2009, 14:49 UTC · re: Julien Danjou · lore

Re: [PATCH] git-remote: make remote name optional for prune operation

Le mercredi 06 mai 2009, Julien Danjou a écrit :
[...]
Didn't you forget a little something in your patch?
[...]
> diff --git a/builtin-remote.c b/builtin-remote.c
[...]
Show 6 quoted lines
> @@ -25,6 +25,7 @@ static const char * const builtin_remote_usage[] = {
>  
>  static int verbose;
>  
> +static int get_one_entry(struct remote *remote, void *priv);
>  static int show_all(void);
[...]
Show 6 quoted lines
>  
>  	if (argc < 1)
> -		usage_with_options(builtin_remote_usage, options);
> +	{
> +		struct string_list list = { NULL, 0, 0 };
> +		int result = for_each_remote(get_one_entry, &list);
-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris
Julien Danjou· May 6, 2009, 15:32 UTC · re: Francis Galiegue · lore

Re: [PATCH] git-remote: make remote name optional for prune operation

At 1241621365 time_t, Francis Galiegue wrote:
> Didn't you forget a little something in your patch?
If so, I really can't see what.
Cheers,
-- 
Julien Danjou
// ᐰ <julien@danjou.info>   http://julien.danjou.info
// 9A0D 5FD9 EB42 22F6 8974  C95C A462 B51E C2FE E5CD
// Tomorrow I was nothing, yesterday I'll be.
Jacob Helwig· May 6, 2009, 15:46 UTC · re: Julien Danjou · lore

Re: [PATCH] git-remote: make remote name optional for prune operation

On Wed, May 6, 2009 at 08:32, Julien Danjou <julien@danjou.info> wrote:
Show 21 quoted lines
> At 1241621365 time_t, Francis Galiegue wrote:
>> Didn't you forget a little something in your patch?
>
> If so, I really can't see what.
>
> Cheers,
> --
> Julien Danjou
> // ᐰ <julien@danjou.info>   http://julien.danjou.info
> // 9A0D 5FD9 EB42 22F6 8974  C95C A462 B51E C2FE E5CD
> // Tomorrow I was nothing, yesterday I'll be.
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkoBrXoACgkQpGK1HsL+5c1TdwCgltFTU6aZmLUWzXFzNkq7Dqo5
> FywAoJTEUtDJO2LrzQyu+jB0vf9XCbe2
> =pF1M
> -----END PGP SIGNATURE-----
>
>
I'm guessing, but perhaps Francis means a test for this behavior?
Michael J Gruber· May 6, 2009, 16:15 UTC · re: Jacob Helwig · lore

Re: [PATCH] git-remote: make remote name optional for prune operation

Jacob Helwig venit, vidit, dixit 06.05.2009 17:46:
Show 11 quoted lines
> On Wed, May 6, 2009 at 08:32, Julien Danjou <julien@danjou.info> wrote:
>> At 1241621365 time_t, Francis Galiegue wrote:
>>> Didn't you forget a little something in your patch?
>>
>> If so, I really can't see what.
>>
>> Cheers,
>> --
>> Julien Danjou
> 
> I'm guessing, but perhaps Francis means a test for this behavior?

Documentation (besides changing <> to []), test. Also, it looks as if a get_one_entry() declaration is added without a definition. But the definition is there already.

Michael
Julien Danjou· May 6, 2009, 16:58 UTC · re: Michael J Gruber · lore
If `git remote prune` is called without a name, prune all remotes.
Signed-off-by: Julien Danjou <julien@danjou.info>
---
 Documentation/git-remote.txt |    4 +++-
 builtin-remote.c             |   26 +++++++++++++++++++++-----
 t/t5505-remote.sh            |   21 +++++++++++++++++++++
 3 files changed, 45 insertions(+), 6 deletions(-)
Show changes to 3 files +44 −5

Documentation/git-remote.txt, builtin-remote.c, t/t5505-remote.sh

diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 9e2b4ea..5c8477e 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -15,7 +15,7 @@ SYNOPSIS
 'git remote rm' <name>
 'git remote set-head' <name> [-a | -d | <branch>]
 'git remote show' [-n] <name>
-'git remote prune' [-n | --dry-run] <name>
+'git remote prune' [-n | --dry-run] [name]
 'git remote update' [-p | --prune] [group | remote]...
 
 DESCRIPTION
@@ -116,6 +116,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.
+If <name> is not set, all stale branches from all remote repositories will
+be deleted.
 
 'update'::
 
diff --git a/builtin-remote.c b/builtin-remote.c
index 2ed752c..053d886 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -14,7 +14,7 @@ static const char * const builtin_remote_usage[] = {
 	"git remote rm <name>",
 	"git remote set-head <name> [-a | -d | <branch>]",
 	"git remote show [-n] <name>",
-	"git remote prune [-n | --dry-run] <name>",
+	"git remote prune [-n | --dry-run] [name]",
 	"git remote [-v | --verbose] update [-p | --prune] [group]",
 	NULL
 };
@@ -25,6 +25,7 @@ static const char * const builtin_remote_usage[] = {
 
 static int verbose;
 
+static int get_one_entry(struct remote *remote, void *priv);
 static int show_all(void);
 static int prune_remote(const char *remote, int dry_run);
 
@@ -1133,10 +1134,25 @@ static int prune(int argc, const char **argv)
 	argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
 
 	if (argc < 1)
-		usage_with_options(builtin_remote_usage, options);
+	{
+		struct string_list list = { NULL, 0, 0 };
+		int result = for_each_remote(get_one_entry, &list);
+
+		if (!result) {
+			int i;
 
-	for (; argc; argc--, argv++)
-		result |= prune_remote(*argv, dry_run);
+			sort_string_list(&list);
+			for (i = 0; i < list.nr; i++) {
+				struct string_list_item *item = list.items + i;
+				if (i && !strcmp((item - 1)->string, item->string))
+				       continue;
+				result |= prune_remote(item->string, dry_run);
+			}
+		}
+	}
+	else
+		for (; argc; argc--, argv++)
+			result |= prune_remote(*argv, dry_run);
 
 	return result;
 }
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 5ec668d..cfb7922 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -223,6 +223,27 @@ test_expect_success 'prune' '
 	 test_must_fail git rev-parse refs/remotes/origin/side)
 '
 
+test_expect_success 'prune-all' '
+	(cd one &&
+	 git branch side3 side2) &&
+        (cd test &&
+         git fetch origin) &&
+        (cd one &&
+         git branch -D side3) &&
+        (cd two &&
+         git branch side2 side) &&
+        (cd test &&
+         git fetch two) &&
+        (cd two &&
+         git branch -D side2) &&
+	(cd test &&
+	 git fetch origin &&
+         git fetch two &&
+	 git remote prune &&
+	 test_must_fail git rev-parse refs/remotes/origin/side3 &&
+	 test_must_fail git rev-parse refs/remotes/two/side2)
+'
+
 test_expect_success 'set-head --delete' '
 	(cd test &&
 	 git symbolic-ref refs/remotes/origin/HEAD &&
-- 
1.6.2.4
Junio C Hamano· May 6, 2009, 17:18 UTC · re: Julien Danjou · lore

Re: [PATCH] git-remote: make remote name optional for prune operation

Julien Danjou <julien@danjou.info> writes:
> We consider that if `git remote prune` is called without a name, we
> actually want to prune all remotes.

I think we try to make an opearation that discards information from many things at once by mistake, and it feels that this patch goes against it.

In what situation does this new short-cut make things convenient, and how often does such a situation come up? The only one I can think of is when you are interacting with many volatile remotes that create and delete branches all the time, and when you are trying to repack/pack-ref your local repository with as much cruft removed, but in such a set-up, next time you interact with your remotes, you will get their "branch of the day" in your remote tracking namespace that will disappear shortly, and it does not sound like it is such a big deal if you did not run "remote prune" to all of them at once anyway.

Having said all that...
Show 11 quoted lines
> diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
> index 9e2b4ea..c566061 100644
> --- a/Documentation/git-remote.txt
> +++ b/Documentation/git-remote.txt
> @@ -15,7 +15,7 @@ SYNOPSIS
>  'git remote rm' <name>
>  'git remote set-head' <name> [-a | -d | <branch>]
>  'git remote show' [-n] <name>
> -'git remote prune' [-n | --dry-run] <name>
> +'git remote prune' [-n | --dry-run] [name]
>  'git remote update' [-p | --prune] [group | remote]...

I think you would want to say [<name>] here, but looking at this list, I wonder if it would be more appropriate to allow "remote group" to be given to "prune" (and perhaps "show").

Junio C Hamano· May 6, 2009, 17:54 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-remote: make remote name optional for prune operation

Junio C Hamano <gitster@pobox.com> writes:
> I think we try to make an opearation that discards information from many
> things at once by mistake, and it feels that this patch goes against it.
Sorry, "by mistake" should have read "harder to trigger by mistake".
Finn Arne Gangstad· May 6, 2009, 17:55 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-remote: make remote name optional for prune operation

On Wed, May 06, 2009 at 10:18:48AM -0700, Junio C Hamano wrote:
Show 35 quoted lines
> Julien Danjou <julien@danjou.info> writes:
> 
> > We consider that if `git remote prune` is called without a name, we
> > actually want to prune all remotes.
> 
> I think we try to make an opearation that discards information from many
> things at once by mistake, and it feels that this patch goes against it.
> 
> In what situation does this new short-cut make things convenient, and how
> often does such a situation come up?  The only one I can think of is when
> you are interacting with many volatile remotes that create and delete
> branches all the time, and when you are trying to repack/pack-ref your
> local repository with as much cruft removed, but in such a set-up, next
> time you interact with your remotes, you will get their "branch of the
> day" in your remote tracking namespace that will disappear shortly, and it
> does not sound like it is such a big deal if you did not run "remote
> prune" to all of them at once anyway.
> 
> Having said all that...
> 
> > diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
> > index 9e2b4ea..c566061 100644
> > --- a/Documentation/git-remote.txt
> > +++ b/Documentation/git-remote.txt
> > @@ -15,7 +15,7 @@ SYNOPSIS
> >  'git remote rm' <name>
> >  'git remote set-head' <name> [-a | -d | <branch>]
> >  'git remote show' [-n] <name>
> > -'git remote prune' [-n | --dry-run] <name>
> > +'git remote prune' [-n | --dry-run] [name]
> >  'git remote update' [-p | --prune] [group | remote]...
> 
> I think you would want to say [<name>] here, but looking at this list, I
> wonder if it would be more appropriate to allow "remote group" to be given
> to "prune" (and perhaps "show").

I also think that if we want to change prune, we should change it to interpret its parameters identically to update. This means that no argument will not expand to "all remotes", but rather to the possibly configured "default" group.

In other words: I think "git remote update -p" and "git remote prune" should prune the same remotes (both with and without additional arguments).

- Finn Arne

← back to recent threads