From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: "Jay Soffian" <jaysoffian@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Björn Gustavsson" <bgustavsson@gmail.com>
Subject: [PATCH 3/4] builtin-fetch: add --prune option
Date: Mon, 9 Nov 2009 23:58:32 -0500 [thread overview]
Message-ID: <1257829113-52168-4-git-send-email-jaysoffian@gmail.com> (raw)
In-Reply-To: <1257829113-52168-3-git-send-email-jaysoffian@gmail.com>
Teach fetch to cull stale remote tracking branches after fetching via --prune.
We can now enable the "--prune" option to "remote update", which was recently
re-implemented as an invocation of git fetch.
---
Documentation/fetch-options.txt | 4 ++++
builtin-fetch.c | 32 ++++++++++++++++++++++++++++++--
builtin-remote.c | 4 +++-
t/t5505-remote.sh | 2 +-
4 files changed, 38 insertions(+), 4 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)
diff --git a/builtin-remote.c b/builtin-remote.c
index e67b89f..fb0d66d 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -1195,13 +1195,15 @@ static int update(int argc, const char **argv)
int fetch_argc = 0;
int default_defined = 0;
- fetch_argv = xmalloc(sizeof(char *) * (argc+4));
+ fetch_argv = xmalloc(sizeof(char *) * (argc+5));
argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
PARSE_OPT_KEEP_ARGV0);
fetch_argv[fetch_argc++] = "fetch";
+ if (prune)
+ fetch_argv[fetch_argc++] = "--prune";
if (verbose)
fetch_argv[fetch_argc++] = "-v";
if (argc < 2) {
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 562cca2..e931ce6 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -365,7 +365,7 @@ test_expect_success 'update with arguments' '
'
-test_expect_failure 'update --prune' '
+test_expect_success 'update --prune' '
(cd one &&
git branch -m side2 side3) &&
--
1.6.4.2
next prev parent reply other threads:[~2009-11-10 4:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-10 4:58 [PATCH 0/4] Teach fetch --prune and --dry run options Jay Soffian
2009-11-10 4:58 ` [PATCH 1/4] remote: refactor some logic into get_stale_heads() Jay Soffian
2009-11-10 4:58 ` [PATCH 2/4] teach warn_dangling_symref to take a FILE argument Jay Soffian
2009-11-10 4:58 ` Jay Soffian [this message]
2009-11-10 4:58 ` [PATCH 4/4] builtin-fetch: add --dry-run option Jay Soffian
-- strict thread matches above, loose matches on Subject: below --
2009-11-10 5:03 [PATCH 0/4] Teach fetch --prune and --dry run options Jay Soffian
2009-11-10 5:03 ` [PATCH 1/4] remote: refactor some logic into get_stale_heads() Jay Soffian
2009-11-10 5:03 ` [PATCH 2/4] teach warn_dangling_symref to take a FILE argument Jay Soffian
2009-11-10 5:03 ` [PATCH 3/4] builtin-fetch: add --prune option Jay Soffian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1257829113-52168-4-git-send-email-jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--cc=bgustavsson@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).