rebase -i: rewrite the rest of init_revisions_and_shortrevisions() in C
This rewrites the part of init_revisions_and_shortrevisions() needed by `--complete-action` (which initialize $shortrevisions) from shell to C. When `upstream` is empty, it means that the user launched a `rebase --root`, and `onto` contains the ID of an empty commit. As a range between an empty commit and `head` is not really meaningful, `onto` is not used to initialize `shortrevisions` in this case. The corresponding arguments passed to `--complete-action` are then dropped, and init_revisions_and_shortrevisions() is stripped from git-rebase--interactive.sh Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6ab54d17be
commit
f22e4e1a3c
@ -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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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"}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user