All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6/8] builtin-fetch: add --prune option
@ 2009-11-10  8:15 Björn Gustavsson
  2009-11-10  8:55 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Björn Gustavsson @ 2009-11-10  8:15 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

From: Jay Soffian <jaysoffian@gmail.com>

Teach fetch to cull stale remote tracking branches after fetching via --prune.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
---
 Documentation/fetch-options.txt |    4 ++++
 builtin-fetch.c                 |   32 ++++++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 8b0cf58..500637a 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -28,6 +28,10 @@ ifndef::git-pull[]
 --multiple::
 	Allow several <repository> and <group> arguments to be
 	specified. No <refspec>s may be specified.
+
+--prune::
+	After fetching, remove any remote tracking branches which
+	no longer exist	on the remote.
 endif::git-pull[]
 
 ifdef::git-pull[]
diff --git a/builtin-fetch.c b/builtin-fetch.c
index 945dfd8..fd31072 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -26,7 +26,7 @@ enum {
 	TAGS_SET = 2
 };
 
-static int all, append, force, keep, multiple, update_head_ok, verbosity;
+static int all, append, force, keep, multiple, prune, update_head_ok, verbosity;
 static int tags = TAGS_DEFAULT;
 static const char *depth;
 static const char *upload_pack;
@@ -49,6 +49,8 @@ static struct option builtin_fetch_options[] = {
 		    "fetch all tags and associated objects", TAGS_SET),
 	OPT_SET_INT('n', NULL, &tags,
 		    "do not fetch all tags (--no-tags)", TAGS_UNSET),
+	OPT_BOOLEAN('p', "prune", &prune,
+		    "prune tracking branches no longer on remote"),
 	OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
 	OPT_BOOLEAN('u', "update-head-ok", &update_head_ok,
 		    "allow updating of HEAD ref"),
@@ -492,6 +494,28 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
 	return ret;
 }
 
+static int prune_refs(struct transport *transport, struct ref *ref_map)
+{
+	int result = 0;
+	struct ref *ref, *stale_refs = get_stale_heads(transport->remote, ref_map);
+	const char *dangling_msg = dry_run
+		? "   (%s will become dangling)\n"
+		: "   (%s has become dangling)\n";
+
+	for (ref = stale_refs; ref; ref = ref->next) {
+		if (!dry_run)
+			result |= delete_ref(ref->name, NULL, 0);
+		if (verbosity >= 0) {
+			fprintf(stderr, " x %-*s %-*s -> %s\n",
+				SUMMARY_WIDTH, "[deleted]",
+				REFCOL_WIDTH, "(none)", prettify_refname(ref->name));
+			warn_dangling_symref(stderr, dangling_msg, ref->name);
+		}
+	}
+	free_refs(stale_refs);
+	return result;
+}
+
 static int add_existing(const char *refname, const unsigned char *sha1,
 			int flag, void *cbdata)
 {
@@ -657,6 +681,8 @@ static int do_fetch(struct transport *transport,
 		free_refs(ref_map);
 		return 1;
 	}
+	if (prune)
+		prune_refs(transport, ref_map);
 	free_refs(ref_map);
 
 	/* if neither --no-tags nor --tags was specified, do automated tag
@@ -740,9 +766,11 @@ static int add_remote_or_group(const char *name, struct string_list *list)
 static int fetch_multiple(struct string_list *list)
 {
 	int i, result = 0;
-	const char *argv[] = { "fetch", NULL, NULL, NULL, NULL };
+	const char *argv[] = { "fetch", NULL, NULL, NULL, NULL, NULL };
 	int argc = 1;
 
+	if (prune)
+		argv[argc++] = "--prune";
 	if (verbosity >= 2)
 		argv[argc++] = "-v";
 	if (verbosity >= 1)
-- 
1.6.5.1.69.g36942

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

* Re: [PATCH 6/8] builtin-fetch: add --prune option
  2009-11-10  8:15 [PATCH 6/8] builtin-fetch: add --prune option Björn Gustavsson
@ 2009-11-10  8:55 ` Junio C Hamano
  2009-11-10  9:03   ` Junio C Hamano
  2009-11-10  9:43   ` Björn Gustavsson
  0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2009-11-10  8:55 UTC (permalink / raw)
  To: Björn Gustavsson; +Cc: git, Junio C Hamano

Björn Gustavsson <bgustavsson@gmail.com> writes:

> From: Jay Soffian <jaysoffian@gmail.com>

Thanks for being careful; it would be even better if you preserve the
author date by copying Date: from the original.

> Teach fetch to cull stale remote tracking branches after fetching via --prune.
>
> Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
> Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>

Yuck...

builtin-fetch.c: In function 'prune_refs':
builtin-fetch.c:500: error: implicit declaration of function 'get_stale_heads'
builtin-fetch.c:500: error: initialization makes pointer from integer without a cast
builtin-fetch.c:501: error: 'dry_run' undeclared (first use in this function)
builtin-fetch.c:501: error: (Each undeclared identifier is reported only once
builtin-fetch.c:501: error: for each function it appears in.)
make: *** [builtin-fetch.o] Error 1

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

* Re: [PATCH 6/8] builtin-fetch: add --prune option
  2009-11-10  8:55 ` Junio C Hamano
@ 2009-11-10  9:03   ` Junio C Hamano
  2009-11-10  9:49     ` Björn Gustavsson
  2009-11-10  9:43   ` Björn Gustavsson
  1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2009-11-10  9:03 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Björn Gustavsson, git

Junio C Hamano <gitster@pobox.com> writes:

> Björn Gustavsson <bgustavsson@gmail.com> writes:
>
>> From: Jay Soffian <jaysoffian@gmail.com>
>
> Thanks for being careful; it would be even better if you preserve the
> author date by copying Date: from the original.
>
>> Teach fetch to cull stale remote tracking branches after fetching via --prune.
>>
>> Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
>> Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
>
> Yuck...
>
> builtin-fetch.c: In function 'prune_refs':
> builtin-fetch.c:500: error: implicit declaration of function 'get_stale_heads'
> builtin-fetch.c:500: error: initialization makes pointer from integer without a cast
> builtin-fetch.c:501: error: 'dry_run' undeclared (first use in this function)
> builtin-fetch.c:501: error: (Each undeclared identifier is reported only once
> builtin-fetch.c:501: error: for each function it appears in.)
> make: *** [builtin-fetch.o] Error 1

Ah, I know.  You forgot the first one from Jay's series.

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

* Re: [PATCH 6/8] builtin-fetch: add --prune option
  2009-11-10  8:55 ` Junio C Hamano
  2009-11-10  9:03   ` Junio C Hamano
@ 2009-11-10  9:43   ` Björn Gustavsson
  1 sibling, 0 replies; 5+ messages in thread
From: Björn Gustavsson @ 2009-11-10  9:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

2009/11/10 Junio C Hamano <gitster@pobox.com>:
> Björn Gustavsson <bgustavsson@gmail.com> writes:
>
>> From: Jay Soffian <jaysoffian@gmail.com>
>
> Thanks for being careful; it would be even better if you preserve the
> author date by copying Date: from the original.

Thanks for the tip! Will do that next time.

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB

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

* Re: [PATCH 6/8] builtin-fetch: add --prune option
  2009-11-10  9:03   ` Junio C Hamano
@ 2009-11-10  9:49     ` Björn Gustavsson
  0 siblings, 0 replies; 5+ messages in thread
From: Björn Gustavsson @ 2009-11-10  9:49 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

2009/11/10 Junio C Hamano <gitster@pobox.com>:
>> Yuck...
>>
>> builtin-fetch.c: In function 'prune_refs':
>> builtin-fetch.c:500: error: implicit declaration of function 'get_stale_heads'
>> builtin-fetch.c:500: error: initialization makes pointer from integer without a cast
>> builtin-fetch.c:501: error: 'dry_run' undeclared (first use in this function)
>> builtin-fetch.c:501: error: (Each undeclared identifier is reported only once
>> builtin-fetch.c:501: error: for each function it appears in.)
>> make: *** [builtin-fetch.o] Error 1
>
> Ah, I know.  You forgot the first one from Jay's series.
>

Off-by-one error when I ran format-patch. Sorry for that.

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB

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

end of thread, other threads:[~2009-11-10  9:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-10  8:15 [PATCH 6/8] builtin-fetch: add --prune option Björn Gustavsson
2009-11-10  8:55 ` Junio C Hamano
2009-11-10  9:03   ` Junio C Hamano
2009-11-10  9:49     ` Björn Gustavsson
2009-11-10  9:43   ` Björn Gustavsson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.