From: "Carlos Martín Nieto" <cmn@elego.de>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
mathstuf@gmail.com
Subject: [PATCH 4/4] fetch: treat --tags like refs/tags/*:refs/tags/* when pruning
Date: Sat, 8 Oct 2011 00:51:09 +0200 [thread overview]
Message-ID: <1318027869-4037-5-git-send-email-cmn@elego.de> (raw)
In-Reply-To: <1318027869-4037-1-git-send-email-cmn@elego.de>
If --tags is specified, add that refspec to the list given to
prune_refs so it knows to treat it as a filter on what refs to
should consider for prunning. This way
git fetch --prune --tags origin
only prunes tags and doesn't delete the branch refs.
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
---
builtin/fetch.c | 23 +++++++++++++++++++++--
t/t5510-fetch.sh | 4 ++--
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 041f79e..0f8170c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -700,10 +700,29 @@ static int do_fetch(struct transport *transport,
return 1;
}
if (prune) {
- if (ref_count)
+ /* If --tags was specified, pretend the user gave us the canonical tags refspec */
+ if (tags == TAGS_SET) {
+ const char *tags_str = "refs/tags/*:refs/tags/*";
+ struct refspec *tags_refspec, *refspec;
+
+ /* Copy the refspec and add the tags to it */
+ refspec = xcalloc(ref_count + 1, sizeof(struct refspec));
+ tags_refspec = parse_fetch_refspec(1, &tags_str);
+ memcpy(refspec, refs, ref_count * sizeof(struct refspec));
+ memcpy(&refspec[ref_count], tags_refspec, sizeof(struct refspec));
+ ref_count++;
+
+ prune_refs(refspec, ref_count, ref_map);
+
+ ref_count--;
+ /* The rest of the strings belong to fetch_one */
+ free_refspec(1, tags_refspec);
+ free(refspec);
+ } else if (ref_count) {
prune_refs(refs, ref_count, ref_map);
- else
+ } else {
prune_refs(transport->remote->fetch, transport->remote->fetch_refspec_nr, ref_map);
+ }
}
free_refs(ref_map);
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 581049b..e0af4c4 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -105,7 +105,7 @@ test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
git rev-parse origin/master
'
-test_expect_failure 'fetch --prune --tags does not delete the remote-tracking branches' '
+test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' '
cd "$D" &&
git clone . prune-tags &&
cd prune-tags &&
@@ -116,7 +116,7 @@ test_expect_failure 'fetch --prune --tags does not delete the remote-tracking br
test_must_fail git rev-parse somebranch
'
-test_expect_failure 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
+test_expect_success 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
cd "$D" &&
git clone . prune-tags-branch &&
cd prune-tags-branch &&
--
1.7.5.2.354.g349bf
prev parent reply other threads:[~2011-10-07 22:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-07 22:51 [PATCHv3 0/4] Be more careful when prunning Carlos Martín Nieto
2011-10-07 22:51 ` [PATCH 1/4] fetch: free all the additional refspecs Carlos Martín Nieto
2011-10-07 22:51 ` [PATCH 2/4] t5510: add tests for fetch --prune Carlos Martín Nieto
2011-10-07 22:51 ` [PATCH 3/4] fetch: honor the user-provided refspecs when pruning refs Carlos Martín Nieto
2011-10-12 21:39 ` Junio C Hamano
2011-10-12 23:18 ` Carlos Martín Nieto
2011-10-07 22:51 ` Carlos Martín Nieto [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1318027869-4037-5-git-send-email-cmn@elego.de \
--to=cmn@elego.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mathstuf@gmail.com \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).