diff options
-rw-r--r-- | builtin/rebase--helper.c | 40 | ||||
-rw-r--r-- | git-rebase--interactive.sh | 27 |
2 files changed, 38 insertions, 29 deletions
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c index acc71a6f99..0716bbfd78 100644 --- a/builtin/rebase--helper.c +++ b/builtin/rebase--helper.c @@ -10,7 +10,7 @@ static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto") static int get_revision_ranges(const char *upstream, const char *onto, const char **head_hash, - char **revisions) + char **revisions, char **shortrevisions) { const char *base_rev = upstream ? upstream : onto; struct object_id orig_head; @@ -19,7 +19,25 @@ static int get_revision_ranges(const char *upstream, const char *onto, return error(_("no HEAD?")); *head_hash = find_unique_abbrev(&orig_head, GIT_MAX_HEXSZ); - *revisions = xstrfmt("%s...%s", base_rev, *head_hash); + + if (revisions) + *revisions = xstrfmt("%s...%s", base_rev, *head_hash); + if (shortrevisions) { + const char *shorthead; + + shorthead = find_unique_abbrev(&orig_head, DEFAULT_ABBREV); + + if (upstream) { + const char *shortrev; + struct object_id rev_oid; + + get_oid(base_rev, &rev_oid); + shortrev = find_unique_abbrev(&rev_oid, DEFAULT_ABBREV); + + *shortrevisions = xstrfmt("%s..%s", shortrev, shorthead); + } else + *shortrevisions = xstrdup(shorthead); + } return 0; } @@ -116,7 +134,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix) if (!upstream && squash_onto) write_file(path_squash_onto(), "%s\n", squash_onto); - ret = get_revision_ranges(upstream, onto, &head_hash, &revisions); + ret = get_revision_ranges(upstream, onto, &head_hash, &revisions, NULL); if (ret) return ret; @@ -145,9 +163,19 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix) return !!edit_todo_list(flags); if (command == PREPARE_BRANCH && argc == 2) return !!prepare_branch_to_be_rebased(&opts, argv[1]); - if (command == COMPLETE_ACTION && argc == 6) - return !!complete_action(&opts, flags, argv[1], argv[2], argv[3], - argv[4], argv[5], autosquash); + if (command == COMPLETE_ACTION && argc == 3) { + char *shortrevisions = NULL; + + ret = get_revision_ranges(upstream, onto, &head_hash, NULL, &shortrevisions); + if (ret) + return ret; + + ret = complete_action(&opts, flags, shortrevisions, argv[1], onto, + head_hash, argv[2], autosquash); + + free(shortrevisions); + return !!ret; + } usage_with_options(builtin_rebase_helper_usage, options); } diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 4ca47aed1e..08e9a21c2f 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -60,23 +60,6 @@ init_basic_state () { write_basic_state } -init_revisions_and_shortrevisions () { - shorthead=$(git rev-parse --short $orig_head) - shortonto=$(git rev-parse --short $onto) - if test -z "$rebase_root" - # this is now equivalent to ! -z "$upstream" - then - shortupstream=$(git rev-parse --short $upstream) - revisions=$upstream...$orig_head - shortrevisions=$shortupstream..$shorthead - else - revisions=$onto...$orig_head - shortrevisions=$shorthead - test -z "$squash_onto" || - echo "$squash_onto" >"$state_dir"/squash-onto - fi -} - git_rebase__interactive () { initiate_action "$action" ret=$? @@ -87,8 +70,6 @@ git_rebase__interactive () { git rebase--helper --prepare-branch "$switch_to" ${verbose:+--verbose} init_basic_state - init_revisions_and_shortrevisions - git rebase--helper --make-script ${keep_empty:+--keep-empty} \ ${rebase_merges:+--rebase-merges} \ ${rebase_cousins:+--rebase-cousins} \ @@ -97,8 +78,8 @@ git_rebase__interactive () { ${restrict_revision:+--restrict-revision ^"$restrict_revision"} >"$todo" || die "$(gettext "Could not generate todo list")" - exec git rebase--helper --complete-action "$shortrevisions" "$onto_name" \ - "$shortonto" "$orig_head" "$cmd" $allow_empty_message \ - ${autosquash:+--autosquash} ${keep_empty:+--keep-empty} \ - ${verbose:+--verbose} ${force_rebase:+--no-ff} + exec git rebase--helper --complete-action "$onto_name" "$cmd" \ + $allow_empty_message ${autosquash:+--autosquash} ${verbose:+--verbose} \ + ${keep_empty:+--keep-empty} ${force_rebase:+--no-ff} \ + ${upstream:+--upstream "$upstream"} ${onto:+--onto "$onto"} } |