summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9140804)
raw | patch | inline | side by side (parent: 9140804)
author | Junio C Hamano <gitster@pobox.com> | |
Sat, 21 Mar 2009 19:51:34 +0000 (12:51 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 23 Mar 2009 06:36:47 +0000 (23:36 -0700) |
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 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 | patch | blob | history | |
builtin-branch.c | patch | blob | history | |
builtin-checkout.c | patch | blob | history | |
builtin-merge.c | patch | blob | history | |
cache.h | patch | blob | history | |
sha1_name.c | patch | blob | history |
diff --git a/branch.c b/branch.c
index 5f889fee6b94d2aa517c1a694b20772b9fa20507..313bcf16342a956a4f4521c6835bfb382c449da6 100644 (file)
--- a/branch.c
+++ b/branch.c
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 14d4b917e5bb929f40efd3fc5e010cec5d3507de..cacd7daae7ce3ccb2171a557a52705473d7ff665 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
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 9fdfc58d1a198164727431352e083585d91f2d30..a8d9d97da202952eda503f28e006737ff34c7d5b 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
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 4c119359e74cc483c47a6031f6057ac2eb06ca76..e94ea7c35f73bd5e939cab93cf860039a757f9a9 100644 (file)
--- a/builtin-merge.c
+++ b/builtin-merge.c
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));
index 39789ee94a2f2e7dd1600115f4033ccf0e52c07b..d28fd74880c299fa61a1b47331e4359f46fdf8b8 100644 (file)
--- a/cache.h
+++ b/cache.h
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 2f75179f4c6c1d05bdd7594b23dcf77007c26751..904bcd96a54a1cc33386a56a16d07dce34cbb90b 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
* *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;
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;
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;
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);
* 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;