From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v2 1/7] Rename interpret/substitute nth_last_branch functions
Date: Mon, 23 Mar 2009 00:58:34 -0700 [thread overview]
Message-ID: <431b1969fcde69959a23355fba6894fb69c8fa0c.1237791716.git.gitster@pobox.com> (raw)
In-Reply-To: <cover.1237791716.git.gitster@pobox.com>
In-Reply-To: <cover.1237791716.git.gitster@pobox.com>
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 <gitster@pobox.com>
---
branch.c | 2 +-
builtin-branch.c | 2 +-
builtin-checkout.c | 2 +-
builtin-merge.c | 2 +-
cache.h | 2 +-
sha1_name.c | 12 ++++++------
6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/branch.c b/branch.c
index 5f889fe..313bcf1 100644
--- a/branch.c
+++ b/branch.c
@@ -137,7 +137,7 @@ void create_branch(const char *head,
int len;
len = strlen(name);
- if (interpret_nth_last_branch(name, &ref) != len) {
+ if (interpret_branch_name(name, &ref) != len) {
strbuf_reset(&ref);
strbuf_add(&ref, name, len);
}
diff --git a/builtin-branch.c b/builtin-branch.c
index 14d4b91..cacd7da 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -123,7 +123,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
for (i = 0; i < argc; i++, strbuf_release(&bname)) {
int len = strlen(argv[i]);
- if (interpret_nth_last_branch(argv[i], &bname) != len)
+ if (interpret_branch_name(argv[i], &bname) != len)
strbuf_add(&bname, argv[i], len);
if (kinds == REF_LOCAL_BRANCH && !strcmp(head, bname.buf)) {
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 9fdfc58..a8d9d97 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);
diff --git a/builtin-merge.c b/builtin-merge.c
index 4c11935..e94ea7c 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -361,7 +361,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
int len, early;
len = strlen(remote);
- if (interpret_nth_last_branch(remote, &bname) == len)
+ if (interpret_branch_name(remote, &bname) == len)
remote = bname.buf;
memset(branch_head, 0, sizeof(branch_head));
diff --git a/cache.h b/cache.h
index 39789ee..d28fd74 100644
--- a/cache.h
+++ b/cache.h
@@ -671,7 +671,7 @@ extern int read_ref(const char *filename, unsigned char *sha1);
extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *);
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
-extern int interpret_nth_last_branch(const char *str, struct strbuf *);
+extern int interpret_branch_name(const char *str, struct strbuf *);
extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules);
extern const char *ref_rev_parse_rules[];
diff --git a/sha1_name.c b/sha1_name.c
index 2f75179..904bcd9 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -242,10 +242,10 @@ static int ambiguous_path(const char *path, int len)
* *string and *len will only be substituted, and *string returned (for
* later free()ing) if the string passed in is of the form @{-<n>}.
*/
-static char *substitute_nth_last_branch(const char **string, int *len)
+static char *substitute_branch_name(const char **string, int *len)
{
struct strbuf buf = STRBUF_INIT;
- int ret = interpret_nth_last_branch(*string, &buf);
+ int ret = interpret_branch_name(*string, &buf);
if (ret == *len) {
size_t size;
@@ -259,7 +259,7 @@ static char *substitute_nth_last_branch(const char **string, int *len)
int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
{
- char *last_branch = substitute_nth_last_branch(&str, &len);
+ char *last_branch = substitute_branch_name(&str, &len);
const char **p, *r;
int refs_found = 0;
@@ -288,7 +288,7 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
{
- char *last_branch = substitute_nth_last_branch(&str, &len);
+ char *last_branch = substitute_branch_name(&str, &len);
const char **p;
int logs_found = 0;
@@ -355,7 +355,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
struct strbuf buf = STRBUF_INIT;
int ret;
/* try the @{-N} syntax for n-th checkout */
- ret = interpret_nth_last_branch(str+at, &buf);
+ ret = interpret_branch_name(str+at, &buf);
if (ret > 0) {
/* substitute this branch name and restart */
return get_sha1_1(buf.buf, buf.len, sha1);
@@ -750,7 +750,7 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
* If the input was ok but there are not N branch switches in the
* reflog, it returns 0.
*/
-int interpret_nth_last_branch(const char *name, struct strbuf *buf)
+int interpret_branch_name(const char *name, struct strbuf *buf)
{
long nth;
int i, retval;
--
1.6.2.1.349.ga64c
next prev parent reply other threads:[~2009-03-23 8:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-23 7:58 [PATCH v2 0/7] Clean up interpret_nth_last_branch feature Junio C Hamano
2009-03-23 7:58 ` Junio C Hamano [this message]
2009-03-23 7:58 ` [PATCH v2 2/7] strbuf_branchname(): a wrapper for branch name shorthands Junio C Hamano
2009-03-23 7:58 ` [PATCH v2 3/7] check-ref-format --branch: give Porcelain a way to grok branch shorthand Junio C Hamano
2009-03-23 7:58 ` [PATCH v2 4/7] Fix branch -m @{-1} newname Junio C Hamano
2009-03-23 7:58 ` [PATCH v2 5/7] strbuf_check_branch_ref(): a helper to check a refname for a branch Junio C Hamano
2009-03-23 7:58 ` [PATCH v2 6/7] check_ref_format(): tighten refname rules Junio C Hamano
2009-03-23 7:58 ` [PATCH v2 7/7] checkout -: make "-" to mean "previous branch" everywhere Junio C Hamano
2009-03-23 13:59 ` [PATCH v2 6/7] check_ref_format(): tighten refname rules Shawn O. Pearce
2009-03-23 16:03 ` Junio C Hamano
2009-03-23 8:10 ` [PATCH v2 0/7] Clean up interpret_nth_last_branch feature 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=431b1969fcde69959a23355fba6894fb69c8fa0c.1237791716.git.gitster@pobox.com \
--to=gitster@pobox.com \
--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).