git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-remote: make remote name optional for prune operation
@ 2009-05-06 14:37 Julien Danjou
  2009-05-06 14:49 ` Francis Galiegue
  2009-05-06 17:18 ` Junio C Hamano
  0 siblings, 2 replies; 9+ messages in thread
From: Julien Danjou @ 2009-05-06 14:37 UTC (permalink / raw)
  To: git, gitster; +Cc: Julien Danjou

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(-)

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-remote: make remote name optional for prune operation
  2009-05-06 14:37 [PATCH] git-remote: make remote name optional for prune operation Julien Danjou
@ 2009-05-06 14:49 ` Francis Galiegue
  2009-05-06 15:32   ` Julien Danjou
  2009-05-06 17:18 ` Junio C Hamano
  1 sibling, 1 reply; 9+ messages in thread
From: Francis Galiegue @ 2009-05-06 14:49 UTC (permalink / raw)
  To: Julien Danjou; +Cc: git, gitster

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
[...]
> @@ -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);
[...]
>  
>  	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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-remote: make remote name optional for prune operation
  2009-05-06 14:49 ` Francis Galiegue
@ 2009-05-06 15:32   ` Julien Danjou
  2009-05-06 15:46     ` Jacob Helwig
  0 siblings, 1 reply; 9+ messages in thread
From: Julien Danjou @ 2009-05-06 15:32 UTC (permalink / raw)
  To: Francis Galiegue; +Cc: git, gitster

[-- Attachment #1: Type: text/plain, Size: 327 bytes --]

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.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-remote: make remote name optional for prune operation
  2009-05-06 15:32   ` Julien Danjou
@ 2009-05-06 15:46     ` Jacob Helwig
  2009-05-06 16:15       ` Michael J Gruber
  0 siblings, 1 reply; 9+ messages in thread
From: Jacob Helwig @ 2009-05-06 15:46 UTC (permalink / raw)
  To: Julien Danjou; +Cc: Francis Galiegue, git, gitster

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
> // ᐰ <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?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-remote: make remote name optional for prune operation
  2009-05-06 15:46     ` Jacob Helwig
@ 2009-05-06 16:15       ` Michael J Gruber
  2009-05-06 16:58         ` Julien Danjou
  0 siblings, 1 reply; 9+ messages in thread
From: Michael J Gruber @ 2009-05-06 16:15 UTC (permalink / raw)
  To: Jacob Helwig; +Cc: Julien Danjou, Francis Galiegue, git, gitster

Jacob Helwig venit, vidit, dixit 06.05.2009 17:46:
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] git-remote: make remote name optional for prune operation
  2009-05-06 16:15       ` Michael J Gruber
@ 2009-05-06 16:58         ` Julien Danjou
  0 siblings, 0 replies; 9+ messages in thread
From: Julien Danjou @ 2009-05-06 16:58 UTC (permalink / raw)
  To: git, gitster; +Cc: Julien Danjou

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(-)

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-remote: make remote name optional for prune operation
  2009-05-06 14:37 [PATCH] git-remote: make remote name optional for prune operation Julien Danjou
  2009-05-06 14:49 ` Francis Galiegue
@ 2009-05-06 17:18 ` Junio C Hamano
  2009-05-06 17:54   ` Junio C Hamano
  2009-05-06 17:55   ` Finn Arne Gangstad
  1 sibling, 2 replies; 9+ messages in thread
From: Junio C Hamano @ 2009-05-06 17:18 UTC (permalink / raw)
  To: Julien Danjou; +Cc: git

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").

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-remote: make remote name optional for prune operation
  2009-05-06 17:18 ` Junio C Hamano
@ 2009-05-06 17:54   ` Junio C Hamano
  2009-05-06 17:55   ` Finn Arne Gangstad
  1 sibling, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2009-05-06 17:54 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Julien Danjou, git

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".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-remote: make remote name optional for prune operation
  2009-05-06 17:18 ` Junio C Hamano
  2009-05-06 17:54   ` Junio C Hamano
@ 2009-05-06 17:55   ` Finn Arne Gangstad
  1 sibling, 0 replies; 9+ messages in thread
From: Finn Arne Gangstad @ 2009-05-06 17:55 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Julien Danjou, git

On Wed, May 06, 2009 at 10:18:48AM -0700, Junio C Hamano wrote:
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-05-06 17:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-06 14:37 [PATCH] git-remote: make remote name optional for prune operation Julien Danjou
2009-05-06 14:49 ` Francis Galiegue
2009-05-06 15:32   ` Julien Danjou
2009-05-06 15:46     ` Jacob Helwig
2009-05-06 16:15       ` Michael J Gruber
2009-05-06 16:58         ` Julien Danjou
2009-05-06 17:18 ` Junio C Hamano
2009-05-06 17:54   ` Junio C Hamano
2009-05-06 17:55   ` Finn Arne Gangstad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).