builtin rebase: support `git rebase --onto A...B`

This commit implements support for an --onto argument that is actually a "symmetric range" i.e. `<rev1>...<rev2>`. The equivalent shell script version of the code offers two different error messages for the cases where there is no merge base vs more than one merge base. Though it would be nice to retain this distinction, dropping it makes it possible to simply use the `get_oid_mb()` function. Besides, it happens rarely in real-world scenarios. Therefore, in the interest of keeping the code less complex, let's just use that function, and live with an error message that does not distinguish between those two error conditions. Signed-off-by: Pratik Karki <predatoramigo@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pratik Karki committed Sep 4, 2018 at 14:27 UTC 075bc8527c7e162e1131ac42443637dbe3bef16a
1 file changed +7 -1
builtin/rebase.c
+7 -1
@@ -17,6 +17,7 @@
17 #include "unpack-trees.h"
18 #include "lockfile.h"
19 #include "parse-options.h"
20 +#include "commit.h"
21
22 static char const * const builtin_rebase_usage[] = {
23 N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
@@ -311,6 +312,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
312 int ret, flags;
313 struct strbuf msg = STRBUF_INIT;
314 struct strbuf revisions = STRBUF_INIT;
315 + struct object_id merge_base;
316 struct option builtin_rebase_options[] = {
317 OPT_STRING(0, "onto", &options.onto_name,
318 N_("revision"),
@@ -387,7 +389,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
389 if (!options.onto_name)
390 options.onto_name = options.upstream_name;
391 if (strstr(options.onto_name, "...")) {
390 - die("TODO");
392 + if (get_oid_mb(options.onto_name, &merge_base) < 0)
393 + die(_("'%s': need exactly one merge base"),
394 + options.onto_name);
395 + options.onto = lookup_commit_or_die(&merge_base,
396 + options.onto_name);
397 } else {
398 options.onto = peel_committish(options.onto_name);
399 if (!options.onto)