Skip to content

Commit 431b196

Browse files
committed
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 <[email protected]>
1 parent 9140804 commit 431b196

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void create_branch(const char *head,
137137
int len;
138138

139139
len = strlen(name);
140-
if (interpret_nth_last_branch(name, &ref) != len) {
140+
if (interpret_branch_name(name, &ref) != len) {
141141
strbuf_reset(&ref);
142142
strbuf_add(&ref, name, len);
143143
}

builtin-branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
123123
for (i = 0; i < argc; i++, strbuf_release(&bname)) {
124124
int len = strlen(argv[i]);
125125

126-
if (interpret_nth_last_branch(argv[i], &bname) != len)
126+
if (interpret_branch_name(argv[i], &bname) != len)
127127
strbuf_add(&bname, argv[i], len);
128128

129129
if (kinds == REF_LOCAL_BRANCH && !strcmp(head, bname.buf)) {

builtin-checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static void setup_branch_path(struct branch_info *branch)
355355
struct strbuf buf = STRBUF_INIT;
356356
int ret;
357357

358-
if ((ret = interpret_nth_last_branch(branch->name, &buf))
358+
if ((ret = interpret_branch_name(branch->name, &buf))
359359
&& ret == strlen(branch->name)) {
360360
branch->name = xstrdup(buf.buf);
361361
strbuf_splice(&buf, 0, 0, "refs/heads/", 11);

builtin-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
361361
int len, early;
362362

363363
len = strlen(remote);
364-
if (interpret_nth_last_branch(remote, &bname) == len)
364+
if (interpret_branch_name(remote, &bname) == len)
365365
remote = bname.buf;
366366

367367
memset(branch_head, 0, sizeof(branch_head));

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ extern int read_ref(const char *filename, unsigned char *sha1);
671671
extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *);
672672
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
673673
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 *);
675675

676676
extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules);
677677
extern const char *ref_rev_parse_rules[];

sha1_name.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ static int ambiguous_path(const char *path, int len)
242242
* *string and *len will only be substituted, and *string returned (for
243243
* later free()ing) if the string passed in is of the form @{-<n>}.
244244
*/
245-
static char *substitute_nth_last_branch(const char **string, int *len)
245+
static char *substitute_branch_name(const char **string, int *len)
246246
{
247247
struct strbuf buf = STRBUF_INIT;
248-
int ret = interpret_nth_last_branch(*string, &buf);
248+
int ret = interpret_branch_name(*string, &buf);
249249

250250
if (ret == *len) {
251251
size_t size;
@@ -259,7 +259,7 @@ static char *substitute_nth_last_branch(const char **string, int *len)
259259

260260
int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
261261
{
262-
char *last_branch = substitute_nth_last_branch(&str, &len);
262+
char *last_branch = substitute_branch_name(&str, &len);
263263
const char **p, *r;
264264
int refs_found = 0;
265265

@@ -288,7 +288,7 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
288288

289289
int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
290290
{
291-
char *last_branch = substitute_nth_last_branch(&str, &len);
291+
char *last_branch = substitute_branch_name(&str, &len);
292292
const char **p;
293293
int logs_found = 0;
294294

@@ -355,7 +355,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
355355
struct strbuf buf = STRBUF_INIT;
356356
int ret;
357357
/* 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);
359359
if (ret > 0) {
360360
/* substitute this branch name and restart */
361361
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,
750750
* If the input was ok but there are not N branch switches in the
751751
* reflog, it returns 0.
752752
*/
753-
int interpret_nth_last_branch(const char *name, struct strbuf *buf)
753+
int interpret_branch_name(const char *name, struct strbuf *buf)
754754
{
755755
long nth;
756756
int i, retval;

0 commit comments

Comments
 (0)