git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junio@pobox.com>
To: Teemu Likonen <tlikonen@iki.fi>
Cc: git@vger.kernel.org
Subject: Re: [PATCH/RFC] Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEAD
Date: Fri, 07 Mar 2008 17:46:28 -0800	[thread overview]
Message-ID: <7vlk4uyoln.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 1204923732-29141-1-git-send-email-tlikonen@iki.fi

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

> I think "update-ref -d" should remove the ref without dereferencing
> anyway.  How about not doing your patch at all (you would need to manually
> remove the symref in "prune" codepath as well), and instead doing this?
>
> I do not know how this reacts when the tracked HEAD points at a ref that
> lexicographically sorts earlier, say branch "A".

And it turns out it does not react very well.  You would want to do
something like this on top of that one.

-- >8 --
"remote rm": first remove symbolic and then real refs

This teaches a new %(reftype) to for-each-ref that returns "symref",
"packed", or "plain" (we never pack symrefs, so this is the complete
enumeration), and updates "git remote rm" to first remove the symrefs and
then the actual refs.

Signed-off-by: Junio C Hamano <junio@pobox.com>
---

 builtin-for-each-ref.c |   13 +++++++++++++
 git-remote.perl        |   14 ++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 07d9c57..50e9eed 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -31,6 +31,7 @@ struct ref_sort {
 
 struct refinfo {
 	char *refname;
+	int reftype;
 	unsigned char objectname[20];
 	struct atom_value *value;
 };
@@ -40,6 +41,7 @@ static struct {
 	cmp_type cmp_type;
 } valid_atom[] = {
 	{ "refname" },
+	{ "reftype" },
 	{ "objecttype" },
 	{ "objectsize", FIELD_ULONG },
 	{ "objectname" },
@@ -568,6 +570,16 @@ static void populate_value(struct refinfo *ref)
 			char *s = xmalloc(len + 4);
 			sprintf(s, "%s^{}", ref->refname);
 			v->s = s;
+		} else if (!strcmp(name, "reftype")) {
+			char *s = xmalloc(20);
+			/* We do not pack symrefs */
+			if (ref->reftype & REF_ISSYMREF)
+				strcpy(s, "symref");
+			else if (ref->reftype & REF_ISPACKED)
+				strcpy(s, "packed");
+			else
+				strcpy(s, "plain");
+			v->s = s;
 		}
 	}
 
@@ -658,6 +670,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
 	 */
 	ref = xcalloc(1, sizeof(*ref));
 	ref->refname = xstrdup(refname);
+	ref->reftype = flag;
 	hashcpy(ref->objectname, sha1);
 
 	cnt = cb->grab_cnt;
diff --git a/git-remote.perl b/git-remote.perl
index b30ed73..c57e29d 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -341,9 +341,19 @@ sub rm_remote {
 	};
 
 	my @refs = $git->command('for-each-ref',
-		'--format=%(refname) %(objectname)', "refs/remotes/$name");
+				 '--format=%(refname) %(reftype) %(objectname)',
+				 "refs/remotes/$name");
+	my @nonsym = ();
 	for (@refs) {
-		my ($ref, $object) = split;
+		my ($ref, $type, $object) = split;
+		if ($type !~ /symref/) {
+			push @nonsym, $_;
+		} else {
+			$git->command(qw(update-ref -d), $ref, $object);
+		}
+	}
+	for (@nonsym) {
+		my ($ref, $type, $object) = split;
 		$git->command(qw(update-ref -d), $ref, $object);
 	}
 	return 0;


  parent reply	other threads:[~2008-03-08  1:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-05 11:38 error: refs/remotes/origin/HEAD points nowhere! Teemu Likonen
2008-03-05 21:24 ` Junio C Hamano
2008-03-06  7:50   ` Teemu Likonen
2008-03-08 22:40   ` [PATCH] builtin remote rm: remove symbolic refs, too Johannes Schindelin
2008-03-09 10:24     ` Junio C Hamano
2008-03-07 21:02 ` [PATCH/RFC] Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEAD Teemu Likonen
2008-03-07 22:18   ` Teemu Likonen
2008-03-08  1:45   ` Junio C Hamano
2008-03-08  1:46   ` Junio C Hamano [this message]
2008-03-08  6:16     ` Teemu Likonen

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=7vlk4uyoln.fsf@gitster.siamese.dyndns.org \
    --to=junio@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=tlikonen@iki.fi \
    /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).