Skip to content

Commit a5e0606

Browse files
agrngitster
authored andcommitted
rebase -i: rewrite init_basic_state() in C
This rewrites init_basic_state() from shell to C. The call to write_basic_state() in cmd_rebase__helper() is replaced by a call to the new function. The shell version is then stripped from git-rebase--interactive.sh. Signed-off-by: Alban Gruin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e702468 commit a5e0606

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

builtin/rebase--helper.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
#include "sequencer.h"
66
#include "rebase-interactive.h"
77
#include "argv-array.h"
8+
#include "refs.h"
89
#include "rerere.h"
910
#include "alias.h"
1011

12+
static GIT_PATH_FUNC(path_state_dir, "rebase-merge/")
1113
static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto")
14+
static GIT_PATH_FUNC(path_interactive, "rebase-merge/interactive")
1215

1316
static int get_revision_ranges(const char *upstream, const char *onto,
1417
const char **head_hash,
@@ -44,6 +47,24 @@ static int get_revision_ranges(const char *upstream, const char *onto,
4447
return 0;
4548
}
4649

50+
static int init_basic_state(struct replay_opts *opts, const char *head_name,
51+
const char *onto, const char *orig_head)
52+
{
53+
FILE *interactive;
54+
55+
if (!is_directory(path_state_dir()) && mkdir_in_gitdir(path_state_dir()))
56+
return error_errno(_("could not create temporary %s"), path_state_dir());
57+
58+
delete_reflog("REBASE_HEAD");
59+
60+
interactive = fopen(path_interactive(), "w");
61+
if (!interactive)
62+
return error_errno(_("could not mark as interactive"));
63+
fclose(interactive);
64+
65+
return write_basic_state(opts, head_name, onto, orig_head);
66+
}
67+
4768
static const char * const builtin_rebase_helper_usage[] = {
4869
N_("git rebase--helper [<options>]"),
4970
NULL
@@ -198,7 +219,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
198219
if (ret)
199220
return ret;
200221

201-
return !!write_basic_state(&opts, head_name, onto, head_hash);
222+
return !!init_basic_state(&opts, head_name, onto, head_hash);
202223
}
203224

204225
usage_with_options(builtin_rebase_helper_usage, options);

git-rebase--interactive.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ initiate_action () {
5151
esac
5252
}
5353

54-
init_basic_state () {
55-
orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
56-
mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
57-
rm -f "$(git rev-parse --git-path REBASE_HEAD)"
58-
59-
: > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
60-
}
61-
6254
git_rebase__interactive () {
6355
initiate_action "$action"
6456
ret=$?
@@ -67,7 +59,6 @@ git_rebase__interactive () {
6759
fi
6860

6961
git rebase--helper --prepare-branch "$switch_to" ${verbose:+--verbose}
70-
init_basic_state
7162

7263
git rebase--helper --init-basic-state ${upstream:+--upstream "$upstream"} \
7364
${onto:+--onto "$onto"} ${head_name:+--head-name "$head_name"} \

0 commit comments

Comments
 (0)