[RFC PATCH 2/3] sha1-name: add @{tail} helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 object-name.c             | 30 +++++++++++++++++++++++++++++-
 t/t1514-rev-parse-tail.sh |  6 ++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/object-name.c b/object-name.c
index 2dd1a0f56e..a0f845c927 100644
--- a/object-name.c
+++ b/object-name.c
@@ -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;
diff --git a/t/t1514-rev-parse-tail.sh b/t/t1514-rev-parse-tail.sh
index da8e9ceef1..6024b4276c 100755
--- a/t/t1514-rev-parse-tail.sh
+++ b/t/t1514-rev-parse-tail.sh
@@ -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
-- 
2.40.0.rc2.1.gf652911b76.dirty




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux