diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2022-11-10 16:43:41 (GMT) |
---|---|---|
committer | Taylor Blau <me@ttaylorr.com> | 2022-11-11 04:36:24 (GMT) |
commit | 688d82f254f8fc5da019fc4962e6e8646767aba0 (patch) | |
tree | fed6e9326641804646a044c5a59a9fe59ddda03e /sequencer.c | |
parent | 82766b29611aea7c3fb42a99debfba1436852d38 (diff) | |
download | git-688d82f254f8fc5da019fc4962e6e8646767aba0.zip git-688d82f254f8fc5da019fc4962e6e8646767aba0.tar.gz git-688d82f254f8fc5da019fc4962e6e8646767aba0.tar.bz2 |
sequencer: tighten label lookups
The `label` command creates a ref refs/rewritten/<label> that the
`reset` and `merge` commands resolve by calling lookup_label(). That
uses lookup_commit_reference_by_name() to look up the label ref. As
lookup_commit_reference_by_name() uses the dwim rules when looking up
the label it will look for a branch named
refs/heads/refs/rewritten/<label> and return that instead of an error if
the branch exists and the label does not. Fix this by using read_ref()
followed by lookup_commit_object() when looking up labels.
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r-- | sequencer.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sequencer.c b/sequencer.c index f2d0667..7eec231 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3694,15 +3694,17 @@ static const char *reflog_message(struct replay_opts *opts, return buf.buf; } -static struct commit *lookup_label(const char *label, int len, - struct strbuf *buf) +static struct commit *lookup_label(struct repository *r, const char *label, + int len, struct strbuf *buf) { struct commit *commit; + struct object_id oid; strbuf_reset(buf); strbuf_addf(buf, "refs/rewritten/%.*s", len, label); - commit = lookup_commit_reference_by_name(buf->buf); - if (!commit) { + if (!read_ref(buf->buf, &oid)) { + commit = lookup_commit_object(r, &oid); + } else { /* fall back to non-rewritten ref or commit */ strbuf_splice(buf, 0, strlen("refs/rewritten/"), "", 0); commit = lookup_commit_reference_by_name(buf->buf); @@ -3753,7 +3755,7 @@ static int do_reset(struct repository *r, break; len = i; - commit = lookup_label(name, len, &ref_name); + commit = lookup_label(r, name, len, &ref_name); if (!commit) { ret = -1; goto cleanup; @@ -3852,7 +3854,7 @@ static int do_merge(struct repository *r, k = strcspn(p, " \t\n"); if (!k) continue; - merge_commit = lookup_label(p, k, &ref_name); + merge_commit = lookup_label(r, p, k, &ref_name); if (!merge_commit) { ret = error(_("unable to parse '%.*s'"), k, p); goto leave_merge; |