git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: bonzini@gnu.org
Cc: git@vger.kernel.org, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH, nitpickingly final version] git-branch, git-checkout: autosetup for remote branch tracking
Date: Thu, 08 Mar 2007 13:59:24 -0800	[thread overview]
Message-ID: <7vr6rz8khv.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7vabyo9gr6.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Thu, 08 Mar 2007 02:22:37 -0800")

Junio C Hamano <junkio@cox.net> writes:

> Paolo Bonzini <paolo.bonzini@lu.unisi.ch> writes:
>
>> 	This fixes all the nits you pointed out. :-D
>> 	Now, this was an experience to make...
>
> Thanks.
>
> Will apply after reviewing once more tomorrow, with fix-ups
> locally if needed.  No need to resend.

Gaah.

The new create_branch() is totally borked, and I did not notice
it while exchanging review e-mails.

The problem is that we have:

	if (real_ref == NULL)
        	die();

which is completely bogus.  We do "checkout -b temp v2.6.20~15"
all the time, and in that case dwim_ref(v2.6.20~15) rightfully
would say "nope, that's not a branch tip".  We have no right to
die there.

I think your new tests should have caught this kind of breakage,
but now I notice that there is no such test that makes sure that
no auto set-up is made when the original branch is not a remote
tracking branch (your new tests are only interested in testing
to see if the new feature works, and it does not test that there
is no regression to old usage).  The breakage was caught by an
unrelated test, t3900.

The appended is on top of your "final".  This is what I am
considering to apply currently.


Grumble....

---

diff --git a/builtin-branch.c b/builtin-branch.c
index 011a2fc..1d6f0cb 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -409,7 +409,6 @@ static void set_branch_defaults(const char *name, const char *real_ref)
 }
 
 static void create_branch(const char *name, const char *start_name,
-			  unsigned char *start_sha1,
 			  int force, int reflog, int track)
 {
 	struct ref_lock *lock;
@@ -430,15 +429,22 @@ static void create_branch(const char *name, const char *start_name,
 		forcing = 1;
 	}
 
-	if (start_sha1) {
-		/* detached HEAD */
-		hashcpy(sha1, start_sha1);
+	real_ref = NULL;
+	if (get_sha1(start_name, sha1))
+		die("Not a valid object name: '%s'.", start_name);
+
+	switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
+	case 0:
+		/* Not branching from any existing branch */
 		real_ref = NULL;
-	}
-	else if (dwim_ref(start_name, strlen(start_name), sha1, &real_ref) > 1)
+		break;
+	case 1:
+		/* Unique completion -- good */
+		break;
+	default:
 		die("Ambiguous object name: '%s'.", start_name);
-	else if (real_ref == NULL)
-		die("Not a valid object name: '%s'.", start_name);
+		break;
+	}
 
 	if ((commit = lookup_commit_reference(sha1)) == NULL)
 		die("Not a valid branch point: '%s'.", start_name);
@@ -619,12 +625,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		rename_branch(head, argv[i], force_rename);
 	else if (rename && (i == argc - 2))
 		rename_branch(argv[i], argv[i + 1], force_rename);
-	else if (i == argc - 1)
-		create_branch(argv[i], head, head_sha1, force_create, reflog,
-			      track);
-	else if (i == argc - 2)
-		create_branch(argv[i], argv[i+1], NULL, force_create, reflog,
-			      track);
+	else if (i == argc - 1 || i == argc - 2)
+		create_branch(argv[i], (i == argc - 2) ? argv[i+1] : head,
+			      force_create, reflog, track);
 	else
 		usage(builtin_branch_usage);
 

  reply	other threads:[~2007-03-08 21:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-08  6:49 [PATCH, final version] git-branch, git-checkout: autosetup for remote branch tracking Paolo Bonzini
2007-03-08  9:47 ` Junio C Hamano
2007-03-08  9:58   ` [PATCH, nitpickingly " Paolo Bonzini
2007-03-08 10:22     ` Junio C Hamano
2007-03-08 21:59       ` Junio C Hamano [this message]
2007-03-08 22:10         ` [PATCH] git-branch: rename nor delete should not work when HEAD is detached Junio C Hamano
2007-03-10  0:59         ` [PATCH, nitpickingly final version] git-branch, git-checkout: autosetup for remote branch tracking Junio C Hamano

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=7vr6rz8khv.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=bonzini@gnu.org \
    --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;
as well as URLs for NNTP newsgroup(s).