From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: "Antoine Beaupré" <anarcat@debian.org>,
"Phillip Wood" <phillip.wood@dunelm.org.uk>,
"Felipe Contreras" <felipe.contreras@gmail.com>
Subject: [RFC PATCH 2/3] sha1-name: add @{tail} helpers
Date: Fri, 10 Mar 2023 15:45:14 -0600 [thread overview]
Message-ID: <20230310214515.39154-3-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20230310214515.39154-1-felipe.contreras@gmail.com>
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(-)
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
next prev parent reply other threads:[~2023-03-10 21:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 21:45 [RFC PATCH 0/3] Support for tail (branch point) experiment Felipe Contreras
2023-03-10 21:45 ` [RFC PATCH 1/3] branch: add new 'tail' concept Felipe Contreras
2023-03-10 21:45 ` Felipe Contreras [this message]
2023-03-10 21:45 ` [RFC PATCH 3/3] rebase: update branch tail after rebasing Felipe Contreras
2023-03-11 0:04 ` [RFC PATCH 0/3] Support for tail (branch point) experiment Junio C Hamano
2023-03-11 3:26 ` Felipe Contreras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230310214515.39154-3-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=anarcat@debian.org \
--cc=git@vger.kernel.org \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).