@matheusbsbs / matheus-bagliano / commits / 431b1969fc
Fork 0

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 <gitster@pobox.com>

Junio C Hamano committed Mar 21, 2009 at 12:51 UTC 431b1969fcde69959a23355fba6894fb69c8fa0c
6 files changed +11 -11
branch.c
+1 -1
@@ -137,7 +137,7 @@ void create_branch(const char *head,
137 int len;
138
139 len = strlen(name);
140 - if (interpret_nth_last_branch(name, &ref) != len) {
140 + if (interpret_branch_name(name, &ref) != len) {
141 strbuf_reset(&ref);
142 strbuf_add(&ref, name, len);
143 }
builtin-branch.c
+1 -1
@@ -123,7 +123,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
123 for (i = 0; i < argc; i++, strbuf_release(&bname)) {
124 int len = strlen(argv[i]);
125
126 - if (interpret_nth_last_branch(argv[i], &bname) != len)
126 + if (interpret_branch_name(argv[i], &bname) != len)
127 strbuf_add(&bname, argv[i], len);
128
129 if (kinds == REF_LOCAL_BRANCH && !strcmp(head, bname.buf)) {
builtin-checkout.c
+1 -1
@@ -355,7 +355,7 @@ static void setup_branch_path(struct branch_info *branch)
355 struct strbuf buf = STRBUF_INIT;
356 int ret;
357
358 - if ((ret = interpret_nth_last_branch(branch->name, &buf))
358 + if ((ret = interpret_branch_name(branch->name, &buf))
359 && ret == strlen(branch->name)) {
360 branch->name = xstrdup(buf.buf);
361 strbuf_splice(&buf, 0, 0, "refs/heads/", 11);
builtin-merge.c
+1 -1
@@ -361,7 +361,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
361 int len, early;
362
363 len = strlen(remote);
364 - if (interpret_nth_last_branch(remote, &bname) == len)
364 + if (interpret_branch_name(remote, &bname) == len)
365 remote = bname.buf;
366
367 memset(branch_head, 0, sizeof(branch_head));
cache.h
+1 -1
@@ -671,7 +671,7 @@ extern int read_ref(const char *filename, unsigned char *sha1);
671 extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *);
672 extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
673 extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
674 -extern int interpret_nth_last_branch(const char *str, struct strbuf *);
674 +extern int interpret_branch_name(const char *str, struct strbuf *);
675
676 extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules);
677 extern const char *ref_rev_parse_rules[];
sha1_name.c
+6 -6
@@ -242,10 +242,10 @@ static int ambiguous_path(const char *path, int len)
242 * *string and *len will only be substituted, and *string returned (for
243 * later free()ing) if the string passed in is of the form @{-<n>}.
244 */
245 -static char *substitute_nth_last_branch(const char **string, int *len)
245 +static char *substitute_branch_name(const char **string, int *len)
246 {
247 struct strbuf buf = STRBUF_INIT;
248 - int ret = interpret_nth_last_branch(*string, &buf);
248 + int ret = interpret_branch_name(*string, &buf);
249
250 if (ret == *len) {
251 size_t size;
@@ -259,7 +259,7 @@ static char *substitute_nth_last_branch(const char **string, int *len)
259
260 int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
261 {
262 - char *last_branch = substitute_nth_last_branch(&str, &len);
262 + char *last_branch = substitute_branch_name(&str, &len);
263 const char **p, *r;
264 int refs_found = 0;
265
@@ -288,7 +288,7 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
288
289 int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
290 {
291 - char *last_branch = substitute_nth_last_branch(&str, &len);
291 + char *last_branch = substitute_branch_name(&str, &len);
292 const char **p;
293 int logs_found = 0;
294
@@ -355,7 +355,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
355 struct strbuf buf = STRBUF_INIT;
356 int ret;
357 /* try the @{-N} syntax for n-th checkout */
358 - ret = interpret_nth_last_branch(str+at, &buf);
358 + ret = interpret_branch_name(str+at, &buf);
359 if (ret > 0) {
360 /* substitute this branch name and restart */
361 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,
750 * If the input was ok but there are not N branch switches in the
751 * reflog, it returns 0.
752 */
753 -int interpret_nth_last_branch(const char *name, struct strbuf *buf)
753 +int interpret_branch_name(const char *name, struct strbuf *buf)
754 {
755 long nth;
756 int i, retval;