@@ -877,6 +877,20 @@ static inline int push_mark(const char *string, int len)
return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
}
+static inline int tail_mark(const char *string, int len)
+{
+ const char *suffix[] = { "@{tail}", "@{t}" };
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(suffix); i++) {
+ int suffix_len = strlen(suffix[i]);
+ if (suffix_len <= len
+ && !memcmp(string, suffix[i], suffix_len))
+ return suffix_len;
+ }
+ return 0;
+}
+
static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);
static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
@@ -925,7 +939,8 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
continue;
}
if (!upstream_mark(str + at, len - at) &&
- !push_mark(str + at, len - at)) {
+ !push_mark(str + at, len - at) &&
+ !tail_mark(str + at, len - at)) {
reflog_len = (len-1) - (at+2);
len = at;
}
@@ -1608,6 +1623,13 @@ static int interpret_branch_mark(struct repository *r,
return len + at;
}
+const char *branch_get_tail(struct branch *branch, struct strbuf *err)
+{
+ static struct strbuf tmp = STRBUF_INIT; /* TODO: find a proper place */
+ strbuf_addf(&tmp, "refs/tails/%s", branch->name);
+ return tmp.buf;
+}
+
int repo_interpret_branch_name(struct repository *r,
const char *name, int namelen,
struct strbuf *buf,
@@ -1655,6 +1677,12 @@ int repo_interpret_branch_name(struct repository *r,
options);
if (len > 0)
return len;
+
+ len = interpret_branch_mark(r, name, namelen, at - name, buf,
+ tail_mark, branch_get_tail,
+ options);
+ if (len > 0)
+ return len;
}
return -1;
@@ -20,4 +20,10 @@ test_expect_success 'test tail creation' '
test_cmp expect actual
'
+test_expect_success 'test @{tail}' '
+ git rev-parse test@{tail} > actual &&
+ git rev-parse master > expect &&
+ test_cmp expect actual
+'
+
test_done
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- object-name.c | 30 +++++++++++++++++++++++++++++- t/t1514-rev-parse-tail.sh | 6 ++++++ 2 files changed, 35 insertions(+), 1 deletion(-)