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 <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alban Gruin committed
Aug 28, 2018 at 14:10 UTC
d59cd14de8e05111f45ad55a507493225cd849bc
2 files changed
+22
-10
builtin/rebase--helper.c
+22
-1
@@ -5,10 +5,13 @@
5
#include "sequencer.h"
6
#include "rebase-interactive.h"
7
#include "argv-array.h"
8
+#include "refs.h"
9
#include "rerere.h"
10
#include "alias.h"
11
12
+static GIT_PATH_FUNC(path_state_dir, "rebase-merge/")
13
static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto")
14
+static GIT_PATH_FUNC(path_interactive, "rebase-merge/interactive")
15
16
static int get_revision_ranges(const char *upstream, const char *onto,
17
const char **head_hash,
@@ -44,6 +47,24 @@ static int get_revision_ranges(const char *upstream, const char *onto,
47
return 0;
48
}
49
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
+
68
static const char * const builtin_rebase_helper_usage[] = {
69
N_("git rebase--helper [<options>]"),
70
NULL
@@ -198,7 +219,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
219
if (ret)
220
return ret;
221
201
- return !!write_basic_state(&opts, head_name, onto, head_hash);
222
+ return !!init_basic_state(&opts, head_name, onto, head_hash);
223
}
224
225
usage_with_options(builtin_rebase_helper_usage, options);
git-rebase--interactive.sh
-9
@@ -51,14 +51,6 @@ initiate_action () {
51
esac
52
}
53
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
-
54
git_rebase__interactive () {
55
initiate_action "$action"
56
ret=$?
@@ -67,7 +59,6 @@ git_rebase__interactive () {
59
fi
60
61
git rebase--helper --prepare-branch "$switch_to" ${verbose:+--verbose}
70
- init_basic_state
62
63
git rebase--helper --init-basic-state ${upstream:+--upstream "$upstream"} \
64
${onto:+--onto "$onto"} ${head_name:+--head-name "$head_name"} \