From: Sam Vilain <sam@vilain.net>
To: git@vger.kernel.org
Cc: Sam Vilain <sam@vilain.net>
Subject: [PATCH 4/4] fetch: cleanup refs with --use-mirror
Date: Wed, 25 Nov 2009 23:06:57 +1300 [thread overview]
Message-ID: <1259143617-26580-5-git-send-email-sam@vilain.net> (raw)
In-Reply-To: <1259143617-26580-4-git-send-email-sam@vilain.net>
Remove identical refs after a successful fetch. The ref under
'refs/mirrors/HOST/XXX' is compared with 'refs/XXX', and if matched,
then the 'refs/mirrors/' version is removed.
Signed-off-by: Sam Vilain <sam@vilain.net>
---
This is a simple mechanism for removing stale mirror refs; a more
sophisticated approach would use the revision walker.
builtin-fetch.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/builtin-fetch.c b/builtin-fetch.c
index daa287a..0c52f23 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -211,6 +211,57 @@ struct ref *mirror_refmap(struct transport* transport,
return rv;
}
+int clean_up_mirror_ref(const char *refname,
+ const unsigned char *sha1,
+ int flags,
+ void *leading)
+{
+ char *orig_refname;
+ char *target_refname;
+ char *x;
+ unsigned char found_sha1[20];
+
+ orig_refname = xmalloc(strlen(refname)+strlen(leading)+1);
+ x = strchr(refname, '/');
+ if (!x)
+ return 0;
+ target_refname = xmalloc(strlen(x)+strlen("refs/remotes/")+1);
+
+ strcpy(orig_refname, leading);
+ x = orig_refname + strlen(leading);
+ strcpy(x, refname);
+
+ warning("cleaning up mirror ref: %s (%s)",
+ orig_refname, sha1_to_hex(sha1));
+
+ strcpy(target_refname, "refs/remotes/");
+ strcpy(target_refname+5, strchr(refname, '/')+1);
+
+ warning("target ref is %s", target_refname);
+
+ if (resolve_ref(target_refname, found_sha1, 1, NULL)) {
+ if (!hashcmp(found_sha1, sha1)) {
+ warning("deleting ref %s", orig_refname);
+ delete_ref(orig_refname, sha1, REF_NODEREF);
+ }
+ }
+}
+
+void clean_up_mirror_refs(struct remote* remote)
+{
+ int rem_l = strlen(remote->name);
+ char *dst_name = xmalloc(rem_l+14);
+ char *x;
+ strcpy(dst_name, "refs/mirrors/");
+ x = dst_name + 13;
+ strcpy(x, remote->name);
+ x += rem_l;
+ *x++ = '/';
+
+ warning("cleaning up mirror refs for remote %s", remote->name);
+ for_each_ref_in(dst_name, clean_up_mirror_ref,
+ (void *)dst_name);
+}
static struct ref *get_ref_map(struct transport *transport,
struct refspec *refs, int ref_count, int tags,
@@ -884,9 +935,14 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
transport = NULL;
urls_remaining--;
if (use_mirror) {
- if (!exit_code && urls_remaining >= 1) {
- warning("successful fetch from mirror");
- urls_remaining = 1;
+ if (!exit_code) {
+ if (urls_remaining >= 1) {
+ warning("successful fetch from mirror");
+ urls_remaining = 1;
+ }
+ else {
+ clean_up_mirror_refs(remote);
+ }
}
if (urls_remaining == 1) {
transport = real_transport;
--
1.6.3.3
next prev parent reply other threads:[~2009-11-25 10:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-25 10:06 Client-side mirroring patches (v0) Sam Vilain
2009-11-25 10:06 ` [PATCH 1/4] remote: allow mirroring to be specified, and document settings Sam Vilain
2009-11-25 10:06 ` [PATCH 2/4] fetch: try mirrors if selected Sam Vilain
2009-11-25 10:06 ` [PATCH 3/4] fetch --use-mirror: don't fetch with 'autotags' for actual fetch Sam Vilain
2009-11-25 10:06 ` Sam Vilain [this message]
2009-11-26 1:20 ` [PATCH 2/4] fetch: try mirrors if selected Shawn O. Pearce
2009-11-26 0:58 ` Client-side mirroring patches (v0) Shawn O. Pearce
2010-01-01 0:05 ` Nanako Shiraishi
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=1259143617-26580-5-git-send-email-sam@vilain.net \
--to=sam@vilain.net \
--cc=git@vger.kernel.org \
/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