* Setup a new am session for applying patches */
| 991 | * Setup a new am session for applying patches |
| 992 | */ |
| 993 | static void am_setup(struct am_state *state, enum patch_format patch_format, |
| 994 | const char **paths, int keep_cr) |
| 995 | { |
| 996 | struct object_id curr_head; |
| 997 | const char *str; |
| 998 | struct strbuf sb = STRBUF_INIT; |
| 999 | |
| 1000 | if (!patch_format) |
| 1001 | patch_format = detect_patch_format(paths); |
| 1002 | |
| 1003 | if (!patch_format) { |
| 1004 | fprintf_ln(stderr, _("Patch format detection failed.")); |
| 1005 | die(NULL); |
| 1006 | } |
| 1007 | |
| 1008 | if (mkdir(state->dir, 0777) < 0 && errno != EEXIST) |
| 1009 | die_errno(_("failed to create directory '%s'"), state->dir); |
| 1010 | refs_delete_ref(get_main_ref_store(the_repository), NULL, |
| 1011 | "REBASE_HEAD", NULL, REF_NO_DEREF); |
| 1012 | |
| 1013 | if (split_mail(state, patch_format, paths, keep_cr) < 0) { |
| 1014 | am_destroy(state); |
| 1015 | die(_("Failed to split patches.")); |
| 1016 | } |
| 1017 | |
| 1018 | if (state->rebasing) |
| 1019 | state->threeway = 1; |
| 1020 | |
| 1021 | write_state_bool(state, "threeway", state->threeway); |
| 1022 | write_state_bool(state, "quiet", state->quiet); |
| 1023 | write_state_bool(state, "sign", state->signoff); |
| 1024 | write_state_bool(state, "utf8", state->utf8); |
| 1025 | |
| 1026 | if (state->allow_rerere_autoupdate) |
| 1027 | write_state_bool(state, "rerere-autoupdate", |
| 1028 | state->allow_rerere_autoupdate == RERERE_AUTOUPDATE); |
| 1029 | |
| 1030 | switch (state->keep) { |
| 1031 | case KEEP_FALSE: |
| 1032 | str = "f"; |
| 1033 | break; |
| 1034 | case KEEP_TRUE: |
| 1035 | str = "t"; |
| 1036 | break; |
| 1037 | case KEEP_NON_PATCH: |
| 1038 | str = "b"; |
| 1039 | break; |
| 1040 | default: |
| 1041 | BUG("invalid value for state->keep"); |
| 1042 | } |
| 1043 | |
| 1044 | write_state_text(state, "keep", str); |
| 1045 | write_state_bool(state, "messageid", state->message_id); |
| 1046 | |
| 1047 | switch (state->scissors) { |
| 1048 | case SCISSORS_UNSET: |
| 1049 | str = ""; |
| 1050 | break; |
no test coverage detected