Skip to content

Commit 35bdcc5

Browse files
pyokagangitster
authored andcommitted
builtin-am: implement --rebasing mode
Since 3041c32 (am: --rebasing, 2008-03-04), git-am.sh supported the --rebasing option, which is used internally by git-rebase to tell git-am that it is being used for its purpose. It would create the empty file $state_dir/rebasing to help "completion" scripts tell if the ongoing operation is am or rebase. As of 0fbb95d (am: don't call mailinfo if $rebasing, 2012-06-26), --rebasing also implies --3way as well. Since a1549e1 (am: return control to caller, for housekeeping, 2013-05-12), git-am.sh would only clean up the state directory when it is not --rebasing, instead deferring cleanup to git-rebase.sh. Re-implement the above in builtin/am.c. Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 84f3de2 commit 35bdcc5

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

builtin/am.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct am_state {
8989
int quiet;
9090
int signoff;
9191
const char *resolvemsg;
92+
int rebasing;
9293
};
9394

9495
/**
@@ -364,6 +365,8 @@ static void am_load(struct am_state *state)
364365
read_state_file(&sb, state, "sign", 1);
365366
state->signoff = !strcmp(sb.buf, "t");
366367

368+
state->rebasing = !!file_exists(am_path(state, "rebasing"));
369+
367370
strbuf_release(&sb);
368371
}
369372

@@ -542,18 +545,29 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
542545
die(_("Failed to split patches."));
543546
}
544547

548+
if (state->rebasing)
549+
state->threeway = 1;
550+
545551
write_file(am_path(state, "threeway"), 1, state->threeway ? "t" : "f");
546552

547553
write_file(am_path(state, "quiet"), 1, state->quiet ? "t" : "f");
548554

549555
write_file(am_path(state, "sign"), 1, state->signoff ? "t" : "f");
550556

557+
if (state->rebasing)
558+
write_file(am_path(state, "rebasing"), 1, "%s", "");
559+
else
560+
write_file(am_path(state, "applying"), 1, "%s", "");
561+
551562
if (!get_sha1("HEAD", curr_head)) {
552563
write_file(am_path(state, "abort-safety"), 1, "%s", sha1_to_hex(curr_head));
553-
update_ref("am", "ORIG_HEAD", curr_head, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
564+
if (!state->rebasing)
565+
update_ref("am", "ORIG_HEAD", curr_head, NULL, 0,
566+
UPDATE_REFS_DIE_ON_ERR);
554567
} else {
555568
write_file(am_path(state, "abort-safety"), 1, "%s", "");
556-
delete_ref("ORIG_HEAD", NULL, 0);
569+
if (!state->rebasing)
570+
delete_ref("ORIG_HEAD", NULL, 0);
557571
}
558572

559573
/*
@@ -1054,8 +1068,14 @@ static void am_run(struct am_state *state, int resume)
10541068
am_next(state);
10551069
}
10561070

1057-
am_destroy(state);
1058-
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
1071+
/*
1072+
* In rebasing mode, it's up to the caller to take care of
1073+
* housekeeping.
1074+
*/
1075+
if (!state->rebasing) {
1076+
am_destroy(state);
1077+
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
1078+
}
10591079
}
10601080

10611081
/**
@@ -1325,6 +1345,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
13251345
OPT_CMDMODE(0, "abort", &resume,
13261346
N_("restore the original branch and abort the patching operation."),
13271347
RESUME_ABORT),
1348+
OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing,
1349+
N_("(internal use for git-rebase)")),
13281350
OPT_END()
13291351
};
13301352

0 commit comments

Comments
 (0)