rebase: start implementing it as a builtin
This commit imitates the strategy that was used to convert the difftool to a builtin. We start by renaming the shell script `git-rebase.sh` to `git-legacy-rebase.sh` and introduce a `builtin/rebase.c` that simply executes the shell script version, unless the config setting `rebase.useBuiltin` is set to `true`. The motivation behind this is to rewrite all the functionality of the shell script version in the aforementioned `rebase.c`, one by one and be able to conveniently test new features by configuring `rebase.useBuiltin`. In the original difftool conversion, if sane_execvp() that attempts to run the legacy scripted version returned with non-negative status, the command silently exited without doing anything with success, but sane_execvp() should not return with non-negative status in the first place, so we use die() to notice such an abnormal case. We intentionally avoid reading the config directly to avoid messing up the GIT_* environment variables when we need to fall back to exec()ing the shell script. The test of builtin rebase can be done by `git -c rebase.useBuiltin=true rebase ...` Signed-off-by: Pratik Karki <predatoramigo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1d89318c48
commit
55071ea248
1
.gitignore
vendored
1
.gitignore
vendored
@ -78,6 +78,7 @@
|
|||||||
/git-init-db
|
/git-init-db
|
||||||
/git-interpret-trailers
|
/git-interpret-trailers
|
||||||
/git-instaweb
|
/git-instaweb
|
||||||
|
/git-legacy-rebase
|
||||||
/git-log
|
/git-log
|
||||||
/git-ls-files
|
/git-ls-files
|
||||||
/git-ls-remote
|
/git-ls-remote
|
||||||
|
3
Makefile
3
Makefile
@ -609,7 +609,7 @@ SCRIPT_SH += git-merge-one-file.sh
|
|||||||
SCRIPT_SH += git-merge-resolve.sh
|
SCRIPT_SH += git-merge-resolve.sh
|
||||||
SCRIPT_SH += git-mergetool.sh
|
SCRIPT_SH += git-mergetool.sh
|
||||||
SCRIPT_SH += git-quiltimport.sh
|
SCRIPT_SH += git-quiltimport.sh
|
||||||
SCRIPT_SH += git-rebase.sh
|
SCRIPT_SH += git-legacy-rebase.sh
|
||||||
SCRIPT_SH += git-remote-testgit.sh
|
SCRIPT_SH += git-remote-testgit.sh
|
||||||
SCRIPT_SH += git-request-pull.sh
|
SCRIPT_SH += git-request-pull.sh
|
||||||
SCRIPT_SH += git-stash.sh
|
SCRIPT_SH += git-stash.sh
|
||||||
@ -1063,6 +1063,7 @@ BUILTIN_OBJS += builtin/prune.o
|
|||||||
BUILTIN_OBJS += builtin/pull.o
|
BUILTIN_OBJS += builtin/pull.o
|
||||||
BUILTIN_OBJS += builtin/push.o
|
BUILTIN_OBJS += builtin/push.o
|
||||||
BUILTIN_OBJS += builtin/read-tree.o
|
BUILTIN_OBJS += builtin/read-tree.o
|
||||||
|
BUILTIN_OBJS += builtin/rebase.o
|
||||||
BUILTIN_OBJS += builtin/rebase--helper.o
|
BUILTIN_OBJS += builtin/rebase--helper.o
|
||||||
BUILTIN_OBJS += builtin/receive-pack.o
|
BUILTIN_OBJS += builtin/receive-pack.o
|
||||||
BUILTIN_OBJS += builtin/reflog.o
|
BUILTIN_OBJS += builtin/reflog.o
|
||||||
|
@ -202,6 +202,7 @@ extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
|
|||||||
extern int cmd_pull(int argc, const char **argv, const char *prefix);
|
extern int cmd_pull(int argc, const char **argv, const char *prefix);
|
||||||
extern int cmd_push(int argc, const char **argv, const char *prefix);
|
extern int cmd_push(int argc, const char **argv, const char *prefix);
|
||||||
extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
|
extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
|
||||||
|
extern int cmd_rebase(int argc, const char **argv, const char *prefix);
|
||||||
extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
|
extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
|
||||||
extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
|
extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
|
||||||
extern int cmd_reflog(int argc, const char **argv, const char *prefix);
|
extern int cmd_reflog(int argc, const char **argv, const char *prefix);
|
||||||
|
58
builtin/rebase.c
Normal file
58
builtin/rebase.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* "git rebase" builtin command
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 Pratik Karki
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "builtin.h"
|
||||||
|
#include "run-command.h"
|
||||||
|
#include "exec-cmd.h"
|
||||||
|
#include "argv-array.h"
|
||||||
|
#include "dir.h"
|
||||||
|
|
||||||
|
static int use_builtin_rebase(void)
|
||||||
|
{
|
||||||
|
struct child_process cp = CHILD_PROCESS_INIT;
|
||||||
|
struct strbuf out = STRBUF_INIT;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
argv_array_pushl(&cp.args,
|
||||||
|
"config", "--bool", "rebase.usebuiltin", NULL);
|
||||||
|
cp.git_cmd = 1;
|
||||||
|
if (capture_command(&cp, &out, 6)) {
|
||||||
|
strbuf_release(&out);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
strbuf_trim(&out);
|
||||||
|
ret = !strcmp("true", out.buf);
|
||||||
|
strbuf_release(&out);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* NEEDSWORK: Once the builtin rebase has been tested enough
|
||||||
|
* and git-legacy-rebase.sh is retired to contrib/, this preamble
|
||||||
|
* can be removed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!use_builtin_rebase()) {
|
||||||
|
const char *path = mkpath("%s/git-legacy-rebase",
|
||||||
|
git_exec_path());
|
||||||
|
|
||||||
|
if (sane_execvp(path, (char **)argv) < 0)
|
||||||
|
die_errno(_("could not exec %s"), path);
|
||||||
|
else
|
||||||
|
BUG("sane_execvp() returned???");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc != 2)
|
||||||
|
die(_("Usage: %s <base>"), argv[0]);
|
||||||
|
prefix = setup_git_directory();
|
||||||
|
trace_repo_setup(prefix);
|
||||||
|
setup_work_tree();
|
||||||
|
|
||||||
|
die("TODO");
|
||||||
|
}
|
6
git.c
6
git.c
@ -521,6 +521,12 @@ static struct cmd_struct commands[] = {
|
|||||||
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
|
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
|
||||||
{ "push", cmd_push, RUN_SETUP },
|
{ "push", cmd_push, RUN_SETUP },
|
||||||
{ "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX},
|
{ "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX},
|
||||||
|
/*
|
||||||
|
* NEEDSWORK: Until the rebase is independent and needs no redirection
|
||||||
|
* to rebase shell script this is kept as is, then should be changed to
|
||||||
|
* RUN_SETUP | NEED_WORK_TREE
|
||||||
|
*/
|
||||||
|
{ "rebase", cmd_rebase },
|
||||||
{ "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
|
{ "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
|
||||||
{ "receive-pack", cmd_receive_pack },
|
{ "receive-pack", cmd_receive_pack },
|
||||||
{ "reflog", cmd_reflog, RUN_SETUP },
|
{ "reflog", cmd_reflog, RUN_SETUP },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user