From 431b1969fcde69959a23355fba6894fb69c8fa0c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Mar 2009 12:51:34 -0700 Subject: Rename interpret/substitute nth_last_branch functions These allow you to say "git checkout @{-2}" to switch to the branch two "branch switching" ago by pretending as if you typed the name of that branch. As it is likely that we will be introducing more short-hands to write the name of a branch without writing it explicitly, rename the functions from "nth_last_branch" to more generic "branch_name", to prepare for different semantics. Signed-off-by: Junio C Hamano --- builtin-checkout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-checkout.c') diff --git a/builtin-checkout.c b/builtin-checkout.c index 9fdfc58d1a..a8d9d97da2 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -355,7 +355,7 @@ static void setup_branch_path(struct branch_info *branch) struct strbuf buf = STRBUF_INIT; int ret; - if ((ret = interpret_nth_last_branch(branch->name, &buf)) + if ((ret = interpret_branch_name(branch->name, &buf)) && ret == strlen(branch->name)) { branch->name = xstrdup(buf.buf); strbuf_splice(&buf, 0, 0, "refs/heads/", 11); -- cgit v1.2.1 From a552de75eb01f78046feaf7dc88e5e4833624ad5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Mar 2009 13:17:30 -0700 Subject: strbuf_branchname(): a wrapper for branch name shorthands The function takes a user-supplied string that is supposed to be a branch name, and puts it in a strbuf after expanding possible shorthand notation. A handful of open coded sequence to do this in the existing code have been changed to use this helper function. Signed-off-by: Junio C Hamano --- builtin-checkout.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'builtin-checkout.c') diff --git a/builtin-checkout.c b/builtin-checkout.c index a8d9d97da2..b2680466d8 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -353,16 +353,11 @@ struct branch_info { static void setup_branch_path(struct branch_info *branch) { struct strbuf buf = STRBUF_INIT; - int ret; - if ((ret = interpret_branch_name(branch->name, &buf)) - && ret == strlen(branch->name)) { + strbuf_branchname(&buf, branch->name); + if (strcmp(buf.buf, branch->name)) branch->name = xstrdup(buf.buf); - strbuf_splice(&buf, 0, 0, "refs/heads/", 11); - } else { - strbuf_addstr(&buf, "refs/heads/"); - strbuf_addstr(&buf, branch->name); - } + strbuf_splice(&buf, 0, 0, "refs/heads/", 11); branch->path = strbuf_detach(&buf, NULL); } -- cgit v1.2.1 From a2fab531bbb00ff64335906e22854365be2eb5c7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Mar 2009 14:35:51 -0700 Subject: strbuf_check_branch_ref(): a helper to check a refname for a branch This allows a common calling sequence strbuf_branchname(&ref, name); strbuf_splice(&ref, 0, 0, "refs/heads/", 11); if (check_ref_format(ref.buf)) die(...); to be refactored into if (strbuf_check_branch_ref(&ref, name)) die(...); Signed-off-by: Junio C Hamano --- builtin-checkout.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'builtin-checkout.c') diff --git a/builtin-checkout.c b/builtin-checkout.c index b2680466d8..66df0c072c 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -733,12 +733,11 @@ no_reference: if (opts.new_branch) { struct strbuf buf = STRBUF_INIT; - strbuf_addstr(&buf, "refs/heads/"); - strbuf_addstr(&buf, opts.new_branch); + if (strbuf_check_branch_ref(&buf, opts.new_branch)) + die("git checkout: we do not like '%s' as a branch name.", + opts.new_branch); if (!get_sha1(buf.buf, rev)) die("git checkout: branch %s already exists", opts.new_branch); - if (check_ref_format(buf.buf)) - die("git checkout: we do not like '%s' as a branch name.", opts.new_branch); strbuf_release(&buf); } -- cgit v1.2.1