3694
return buf.buf;
3695
}
3696
3697
+static struct commit *lookup_label(const char *label, int len,
3698
+ struct strbuf *buf)
3699
+{
3700
+ struct commit *commit;
3701
+
3702
+ strbuf_reset(buf);
3703
+ strbuf_addf(buf, "refs/rewritten/%.*s", len, label);
3704
+ commit = lookup_commit_reference_by_name(buf->buf);
3705
+ if (!commit) {
3706
+ /* fall back to non-rewritten ref or commit */
3707
+ strbuf_splice(buf, 0, strlen("refs/rewritten/"), "", 0);
3708
+ commit = lookup_commit_reference_by_name(buf->buf);
3709
+ }
3710
+
3711
+ if (!commit)
3712
+ error(_("could not resolve '%s'"), buf->buf);
3713
+
3714
+ return commit;
3715
+}
3716
+
3717
static int do_reset(struct repository *r,
3718
const char *name, int len,
3719
struct replay_opts *opts)
3745
oidcpy(&oid, &opts->squash_onto);
3746
} else {
3747
int i;
3748
+ struct commit *commit;
3749
3750
/* Determine the length of the label */
3751
for (i = 0; i < len; i++)
3753
break;
3754
len = i;
3755
3735
- strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name);
3736
- if (get_oid(ref_name.buf, &oid) &&
3737
- get_oid(ref_name.buf + strlen("refs/rewritten/"), &oid)) {
3738
- ret = error(_("could not read '%s'"), ref_name.buf);
3756
+ commit = lookup_label(name, len, &ref_name);
3757
+ if (!commit) {
3758
+ ret = -1;
3759
goto cleanup;
3760
}
3761
+ oid = commit->object.oid;
3762
}
3763
3764
setup_unpack_trees_porcelain(&unpack_tree_opts, "reset");
3805
return ret;
3806
}
3807
3787
-static struct commit *lookup_label(const char *label, int len,
3788
- struct strbuf *buf)
3789
-{
3790
- struct commit *commit;
3791
-
3792
- strbuf_reset(buf);
3793
- strbuf_addf(buf, "refs/rewritten/%.*s", len, label);
3794
- commit = lookup_commit_reference_by_name(buf->buf);
3795
- if (!commit) {
3796
- /* fall back to non-rewritten ref or commit */
3797
- strbuf_splice(buf, 0, strlen("refs/rewritten/"), "", 0);
3798
- commit = lookup_commit_reference_by_name(buf->buf);
3799
- }
3800
-
3801
- if (!commit)
3802
- error(_("could not resolve '%s'"), buf->buf);
3803
-
3804
- return commit;
3805
-}
3806
-
3808
static int do_merge(struct repository *r,
3809
struct commit *commit,
3810
const char *arg, int arg_len,