Skip to content

Commit cec98c6

Browse files
dschojamill
authored andcommitted
Merge branch 'make-builtin-stash-and-rebase-opt-ins'
This branch adds back the scripted versions, then adds the option to use the builtin versions of `stash` and `rebase` by setting `stash.useBuiltin=true` and `rebase.useBuiltin=true`, respectively, (the latter already worked for the top-level `git rebase` command and the `--am` backend, and now it also works for the interactive backend). Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 0bccc7f + 50b06c8 commit cec98c6

12 files changed

+1139
-37
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
/git-interpret-trailers
8080
/git-instaweb
8181
/git-legacy-rebase
82+
/git-legacy-rebase--interactive
83+
/git-legacy-stash
8284
/git-log
8385
/git-ls-files
8486
/git-ls-remote

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,13 @@ SCRIPT_SH += git-merge-resolve.sh
615615
SCRIPT_SH += git-mergetool.sh
616616
SCRIPT_SH += git-quiltimport.sh
617617
SCRIPT_SH += git-legacy-rebase.sh
618+
SCRIPT_SH += git-legacy-stash.sh
618619
SCRIPT_SH += git-remote-testgit.sh
619620
SCRIPT_SH += git-request-pull.sh
620621
SCRIPT_SH += git-submodule.sh
621622
SCRIPT_SH += git-web--browse.sh
622623

624+
SCRIPT_LIB += git-legacy-rebase--interactive
623625
SCRIPT_LIB += git-mergetool--lib
624626
SCRIPT_LIB += git-parse-remote
625627
SCRIPT_LIB += git-rebase--am

builtin/rebase--interactive.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
141141
char *raw_strategies = NULL;
142142
enum {
143143
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH,
144-
SHORTEN_OIDS, EXPAND_OIDS, CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC
144+
SHORTEN_OIDS, EXPAND_OIDS, CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC,
145+
MAKE_SCRIPT, SKIP_UNNECESSARY_PICKS,
145146
} command = 0;
146147
struct option options[] = {
147148
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -191,6 +192,10 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
191192
OPT_STRING(0, "onto-name", &onto_name, N_("onto-name"), N_("onto name")),
192193
OPT_STRING(0, "cmd", &cmd, N_("cmd"), N_("the command to run")),
193194
OPT_RERERE_AUTOUPDATE(&opts.allow_rerere_auto),
195+
OPT_CMDMODE(0, "make-script", &command,
196+
N_("make rebase script"), MAKE_SCRIPT),
197+
OPT_CMDMODE(0, "skip-unnecessary-picks", &command,
198+
N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
194199
OPT_END()
195200
};
196201

@@ -262,6 +267,17 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
262267
case ADD_EXEC:
263268
ret = sequencer_add_exec_commands(cmd);
264269
break;
270+
case MAKE_SCRIPT:
271+
ret = sequencer_make_script(stdout, argc, argv, flags);
272+
break;
273+
case SKIP_UNNECESSARY_PICKS: {
274+
struct object_id oid;
275+
276+
ret = skip_unnecessary_picks(&oid);
277+
if (!ret)
278+
printf("%s\n", oid_to_hex(&oid));
279+
break;
280+
}
265281
default:
266282
BUG("invalid command '%d'", command);
267283
}

builtin/rebase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int use_builtin_rebase(void)
5454
cp.git_cmd = 1;
5555
if (capture_command(&cp, &out, 6)) {
5656
strbuf_release(&out);
57-
return 1;
57+
return 0;
5858
}
5959

6060
strbuf_trim(&out);

builtin/stash.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "revision.h"
1414
#include "log-tree.h"
1515
#include "diffcore.h"
16+
#include "exec-cmd.h"
1617

1718
static const char * const git_stash_usage[] = {
1819
N_("git stash list [<options>]"),
@@ -1476,6 +1477,26 @@ static int save_stash(int argc, const char **argv, const char *prefix)
14761477
return ret;
14771478
}
14781479

1480+
static int use_builtin_stash(void)
1481+
{
1482+
struct child_process cp = CHILD_PROCESS_INIT;
1483+
struct strbuf out = STRBUF_INIT;
1484+
int ret;
1485+
1486+
argv_array_pushl(&cp.args,
1487+
"config", "--bool", "stash.usebuiltin", NULL);
1488+
cp.git_cmd = 1;
1489+
if (capture_command(&cp, &out, 6)) {
1490+
strbuf_release(&out);
1491+
return 0;
1492+
}
1493+
1494+
strbuf_trim(&out);
1495+
ret = !strcmp("true", out.buf);
1496+
strbuf_release(&out);
1497+
return ret;
1498+
}
1499+
14791500
int cmd_stash(int argc, const char **argv, const char *prefix)
14801501
{
14811502
int i = -1;
@@ -1487,6 +1508,20 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
14871508
OPT_END()
14881509
};
14891510

1511+
if (!use_builtin_stash()) {
1512+
const char *path = mkpath("%s/git-legacy-stash",
1513+
git_exec_path());
1514+
1515+
if (sane_execvp(path, (char **)argv) < 0)
1516+
die_errno(_("could not exec %s"), path);
1517+
else
1518+
BUG("sane_execvp() returned???");
1519+
}
1520+
1521+
prefix = setup_git_directory();
1522+
trace_repo_setup(prefix);
1523+
setup_work_tree();
1524+
14901525
git_config(git_default_config, NULL);
14911526

14921527
argc = parse_options(argc, argv, prefix, options, git_stash_usage,

0 commit comments

Comments
 (0)