git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 3/3] Make "git-remote rm" delete refs acccording to fetch specs
Date: Sat, 31 May 2008 23:59:01 -0400	[thread overview]
Message-ID: <20080601035901.GC32176@spearce.org> (raw)

A remote may be configured to fetch into tracking branches that
don't match its name.  A user may have created a remote by hand
that will fetch to a different tracking branch namespace:

  [remote "alt"]
    url = git://repo.or.cz/alt-git.git
    fetch = refs/heads/*:refs/remotes/origin/*

When deleting remote alt we should clean up the refs whose names
start with "refs/remotes/origin/", even though the remote itself
was named alt by the user.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---

 I'm not sure this is the right thing to do here.  If another
 remote is still using these tracking refs (such as the example
 in my prior patch of this series) we may not want to remove these
 when we remove the remote.

 builtin-remote.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/builtin-remote.c b/builtin-remote.c
index e5cfc88..6dbc3d4 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -268,7 +268,7 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
 }
 
 struct branches_for_remote {
-	const char *prefix;
+	struct remote *remote;
 	struct path_list *branches;
 };
 
@@ -276,8 +276,11 @@ static int add_branch_for_removal(const char *refname,
 	const unsigned char *sha1, int flags, void *cb_data)
 {
 	struct branches_for_remote *branches = cb_data;
+	struct refspec refspec;
 
-	if (!prefixcmp(refname, branches->prefix)) {
+	memset(&refspec, 0, sizeof(refspec));
+	refspec.dst = (char *)refname;
+	if (!remote_find_tracking(branches->remote, &refspec)) {
 		struct path_list_item *item;
 
 		/* make sure that symrefs are deleted */
@@ -352,9 +355,7 @@ static int rm(int argc, const char **argv)
 	 * the branches one by one, since for_each_ref() relies on cached
 	 * refs, which are invalidated when deleting a branch.
 	 */
-	strbuf_reset(&buf);
-	strbuf_addf(&buf, "refs/remotes/%s/", remote->name);
-	cb_data.prefix = buf.buf;
+	cb_data.remote = remote;
 	i = for_each_ref(add_branch_for_removal, &cb_data);
 	strbuf_release(&buf);
 
-- 
1.5.6.rc0.158.g7c7a1

             reply	other threads:[~2008-06-01  3:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-01  3:59 Shawn O. Pearce [this message]
2008-06-01  4:28 ` [PATCH 3/3 v2] Make "git-remote rm" delete refs acccording to fetch specs Shawn O. Pearce
2008-06-01  4:40   ` Shawn O. Pearce
2008-06-01  5:29   ` Junio C Hamano
2008-06-01  6:30     ` Shawn O. Pearce
2008-06-01  8:28       ` Junio C Hamano
2008-06-02 17:10       ` Jon Loeliger

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=20080601035901.GC32176@spearce.org \
    --to=spearce@spearce.org \
    --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.
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).