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

Subsystems: documentation, the rest

STALE3731d

8 messages, 6 authors, 2016-06-15 · open the first message on its own page

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

From: Julien Danjou <hidden>
Date: 2016-06-15 22:46:42

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

Signed-off-by: Julien Danjou <redacted>
---
 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

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

From: Francis Galiegue <hidden>
Date: 2016-06-15 22:46:42

Le mercredi 06 mai 2009, Julien Danjou a écrit :

[...]

Didn't you forget a little something in your patch?

[...]
quoted hunk
diff --git a/builtin-remote.c b/builtin-remote.c
[...]
quoted hunk
@@ -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

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

From: Julien Danjou <hidden>
Date: 2016-06-15 22:46:42

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
// ᐰ [off-list ref]   http://julien.danjou.info
// 9A0D 5FD9 EB42 22F6 8974  C95C A462 B51E C2FE E5CD
// Tomorrow I was nothing, yesterday I'll be.

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

From: Jacob Helwig <hidden>
Date: 2016-06-15 22:46:42

On Wed, May 6, 2009 at 08:32, Julien Danjou [off-list ref] wrote:
At 1241621365 time_t, Francis Galiegue wrote:
quoted
Didn't you forget a little something in your patch?
If so, I really can't see what.

Cheers,
--
Julien Danjou
// ᐰ [off-list ref]   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?

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

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:46:43

Jacob Helwig venit, vidit, dixit 06.05.2009 17:46:
On Wed, May 6, 2009 at 08:32, Julien Danjou [off-list ref] wrote:
quoted
At 1241621365 time_t, Francis Galiegue wrote:
quoted
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

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

From: Julien Danjou <hidden>
Date: 2016-06-15 22:46:43

If `git remote prune` is called without a name, prune all remotes.

Signed-off-by: Julien Danjou <redacted>
---
 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

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:43

Julien Danjou [off-list ref] 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...
quoted hunk
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").

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

From: Finn Arne Gangstad <hidden>
Date: 2016-06-15 22:46:43

On Wed, May 06, 2009 at 10:18:48AM -0700, Junio C Hamano wrote:
Julien Danjou [off-list ref] writes:
quoted
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...
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help