builtin-am: don't parse mail when resuming
Since 271440e (git-am: make it easier after fixing up an unapplicable patch., 2005-10-25), when "git am" is run again after being paused, the current mail message will not be re-parsed, but instead the contents of the state directory's patch, msg and author-script files will be used as-is instead. Re-implement this in builtin/am.c. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Paul Tan committed
Aug 4, 2015 at 21:51 UTC
8c7b1563eeb2dd42eef0c5ab1a65b7a93300908c
1 file changed
+25
-9
builtin/am.c
+25
-9
@@ -776,8 +776,12 @@ static void validate_resume_state(const struct am_state *state)
776
777
/**
778
* Applies all queued mail.
779
+ *
780
+ * If `resume` is true, we are "resuming". The "msg" and authorship fields, as
781
+ * well as the state directory's "patch" file is used as-is for applying the
782
+ * patch and committing it.
783
*/
780
-static void am_run(struct am_state *state)
784
+static void am_run(struct am_state *state, int resume)
785
{
786
const char *argv_gc_auto[] = {"gc", "--auto", NULL};
787
struct strbuf sb = STRBUF_INIT;
@@ -795,11 +799,16 @@ static void am_run(struct am_state *state)
799
if (!file_exists(mail))
800
goto next;
801
798
- if (parse_mail(state, mail))
799
- goto next; /* mail should be skipped */
802
+ if (resume) {
803
+ validate_resume_state(state);
804
+ resume = 0;
805
+ } else {
806
+ if (parse_mail(state, mail))
807
+ goto next; /* mail should be skipped */
808
801
- write_author_script(state);
802
- write_commit_msg(state);
809
+ write_author_script(state);
810
+ write_commit_msg(state);
811
+ }
812
813
printf_ln(_("Applying: %.*s"), linelen(state->msg), state->msg);
814
@@ -855,7 +864,7 @@ static void am_resolve(struct am_state *state)
864
do_commit(state);
865
866
am_next(state);
858
- am_run(state);
867
+ am_run(state, 0);
868
}
869
870
/**
@@ -875,6 +884,7 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
884
885
enum resume_mode {
886
RESUME_FALSE = 0,
887
+ RESUME_APPLY,
888
RESUME_RESOLVED
889
};
890
@@ -927,9 +937,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)
937
if (read_index_preload(&the_index, NULL) < 0)
938
die(_("failed to read the index"));
939
930
- if (am_in_progress(&state))
940
+ if (am_in_progress(&state)) {
941
+ if (resume == RESUME_FALSE)
942
+ resume = RESUME_APPLY;
943
+
944
am_load(&state);
932
- else {
945
+ } else {
946
struct argv_array paths = ARGV_ARRAY_INIT;
947
int i;
948
@@ -950,7 +963,10 @@ int cmd_am(int argc, const char **argv, const char *prefix)
963
964
switch (resume) {
965
case RESUME_FALSE:
953
- am_run(&state);
966
+ am_run(&state, 0);
967
+ break;
968
+ case RESUME_APPLY:
969
+ am_run(&state, 1);
970
break;
971
case RESUME_RESOLVED:
972
am_resolve(&state);