4 * Based on git-am.sh by Junio C Hamano.
9 #include "parse-options.h"
11 #include "run-command.h"
14 #include "cache-tree.h"
19 #include "unpack-trees.h"
21 #include "sequencer.h"
23 #include "merge-recursive.h"
28 * Returns 1 if the file is empty or does not exist, 0 otherwise.
30 static int is_empty_file(const char *filename
)
34 if (stat(filename
, &st
) < 0) {
37 die_errno(_("could not stat %s"), filename
);
44 * Like strbuf_getline(), but treats both '\n' and "\r\n" as line terminators.
46 static int strbuf_getline_crlf(struct strbuf
*sb
, FILE *fp
)
48 if (strbuf_getwholeline(sb
, fp
, '\n'))
50 if (sb
->buf
[sb
->len
- 1] == '\n') {
51 strbuf_setlen(sb
, sb
->len
- 1);
52 if (sb
->len
> 0 && sb
->buf
[sb
->len
- 1] == '\r')
53 strbuf_setlen(sb
, sb
->len
- 1);
59 * Returns the length of the first line of msg.
61 static int linelen(const char *msg
)
63 return strchrnul(msg
, '\n') - msg
;
67 PATCH_FORMAT_UNKNOWN
= 0,
73 KEEP_TRUE
, /* pass -k flag to git-mailinfo */
74 KEEP_NON_PATCH
/* pass -b flag to git-mailinfo */
79 SCISSORS_FALSE
= 0, /* pass --no-scissors to git-mailinfo */
80 SCISSORS_TRUE
/* pass --scissors to git-mailinfo */
84 /* state directory path */
87 /* current and last patch numbers, 1-indexed */
91 /* commit metadata and message */
98 /* number of digits in patch filename */
101 /* various operating modes and command line options */
106 int keep
; /* enum keep_type */
108 int scissors
; /* enum scissors_type */
109 struct argv_array git_apply_opts
;
110 const char *resolvemsg
;
116 * Initializes am_state with the default values. The state directory is set to
119 static void am_state_init(struct am_state
*state
, const char *dir
)
121 memset(state
, 0, sizeof(*state
));
124 state
->dir
= xstrdup(dir
);
130 git_config_get_bool("am.messageid", &state
->message_id
);
132 state
->scissors
= SCISSORS_UNSET
;
134 argv_array_init(&state
->git_apply_opts
);
138 * Releases memory allocated by an am_state.
140 static void am_state_release(struct am_state
*state
)
143 free(state
->author_name
);
144 free(state
->author_email
);
145 free(state
->author_date
);
147 argv_array_clear(&state
->git_apply_opts
);
151 * Returns path relative to the am_state directory.
153 static inline const char *am_path(const struct am_state
*state
, const char *path
)
155 return mkpath("%s/%s", state
->dir
, path
);
159 * If state->quiet is false, calls fprintf(fp, fmt, ...), and appends a newline
162 static void say(const struct am_state
*state
, FILE *fp
, const char *fmt
, ...)
168 vfprintf(fp
, fmt
, ap
);
175 * Returns 1 if there is an am session in progress, 0 otherwise.
177 static int am_in_progress(const struct am_state
*state
)
181 if (lstat(state
->dir
, &st
) < 0 || !S_ISDIR(st
.st_mode
))
183 if (lstat(am_path(state
, "last"), &st
) || !S_ISREG(st
.st_mode
))
185 if (lstat(am_path(state
, "next"), &st
) || !S_ISREG(st
.st_mode
))
191 * Reads the contents of `file` in the `state` directory into `sb`. Returns the
192 * number of bytes read on success, -1 if the file does not exist. If `trim` is
193 * set, trailing whitespace will be removed.
195 static int read_state_file(struct strbuf
*sb
, const struct am_state
*state
,
196 const char *file
, int trim
)
200 if (strbuf_read_file(sb
, am_path(state
, file
), 0) >= 0) {
210 die_errno(_("could not read '%s'"), am_path(state
, file
));
214 * Reads a KEY=VALUE shell variable assignment from `fp`, returning the VALUE
215 * as a newly-allocated string. VALUE must be a quoted string, and the KEY must
216 * match `key`. Returns NULL on failure.
218 * This is used by read_author_script() to read the GIT_AUTHOR_* variables from
221 static char *read_shell_var(FILE *fp
, const char *key
)
223 struct strbuf sb
= STRBUF_INIT
;
226 if (strbuf_getline(&sb
, fp
, '\n'))
229 if (!skip_prefix(sb
.buf
, key
, &str
))
232 if (!skip_prefix(str
, "=", &str
))
235 strbuf_remove(&sb
, 0, str
- sb
.buf
);
237 str
= sq_dequote(sb
.buf
);
241 return strbuf_detach(&sb
, NULL
);
249 * Reads and parses the state directory's "author-script" file, and sets
250 * state->author_name, state->author_email and state->author_date accordingly.
251 * Returns 0 on success, -1 if the file could not be parsed.
253 * The author script is of the format:
255 * GIT_AUTHOR_NAME='$author_name'
256 * GIT_AUTHOR_EMAIL='$author_email'
257 * GIT_AUTHOR_DATE='$author_date'
259 * where $author_name, $author_email and $author_date are quoted. We are strict
260 * with our parsing, as the file was meant to be eval'd in the old git-am.sh
261 * script, and thus if the file differs from what this function expects, it is
262 * better to bail out than to do something that the user does not expect.
264 static int read_author_script(struct am_state
*state
)
266 const char *filename
= am_path(state
, "author-script");
269 assert(!state
->author_name
);
270 assert(!state
->author_email
);
271 assert(!state
->author_date
);
273 fp
= fopen(filename
, "r");
277 die_errno(_("could not open '%s' for reading"), filename
);
280 state
->author_name
= read_shell_var(fp
, "GIT_AUTHOR_NAME");
281 if (!state
->author_name
) {
286 state
->author_email
= read_shell_var(fp
, "GIT_AUTHOR_EMAIL");
287 if (!state
->author_email
) {
292 state
->author_date
= read_shell_var(fp
, "GIT_AUTHOR_DATE");
293 if (!state
->author_date
) {
298 if (fgetc(fp
) != EOF
) {
308 * Saves state->author_name, state->author_email and state->author_date in the
309 * state directory's "author-script" file.
311 static void write_author_script(const struct am_state
*state
)
313 struct strbuf sb
= STRBUF_INIT
;
315 strbuf_addstr(&sb
, "GIT_AUTHOR_NAME=");
316 sq_quote_buf(&sb
, state
->author_name
);
317 strbuf_addch(&sb
, '\n');
319 strbuf_addstr(&sb
, "GIT_AUTHOR_EMAIL=");
320 sq_quote_buf(&sb
, state
->author_email
);
321 strbuf_addch(&sb
, '\n');
323 strbuf_addstr(&sb
, "GIT_AUTHOR_DATE=");
324 sq_quote_buf(&sb
, state
->author_date
);
325 strbuf_addch(&sb
, '\n');
327 write_file(am_path(state
, "author-script"), 1, "%s", sb
.buf
);
333 * Reads the commit message from the state directory's "final-commit" file,
334 * setting state->msg to its contents and state->msg_len to the length of its
337 * Returns 0 on success, -1 if the file does not exist.
339 static int read_commit_msg(struct am_state
*state
)
341 struct strbuf sb
= STRBUF_INIT
;
345 if (read_state_file(&sb
, state
, "final-commit", 0) < 0) {
350 state
->msg
= strbuf_detach(&sb
, &state
->msg_len
);
355 * Saves state->msg in the state directory's "final-commit" file.
357 static void write_commit_msg(const struct am_state
*state
)
360 const char *filename
= am_path(state
, "final-commit");
362 fd
= xopen(filename
, O_WRONLY
| O_CREAT
, 0666);
363 if (write_in_full(fd
, state
->msg
, state
->msg_len
) < 0)
364 die_errno(_("could not write to %s"), filename
);
369 * Loads state from disk.
371 static void am_load(struct am_state
*state
)
373 struct strbuf sb
= STRBUF_INIT
;
375 if (read_state_file(&sb
, state
, "next", 1) < 0)
376 die("BUG: state file 'next' does not exist");
377 state
->cur
= strtol(sb
.buf
, NULL
, 10);
379 if (read_state_file(&sb
, state
, "last", 1) < 0)
380 die("BUG: state file 'last' does not exist");
381 state
->last
= strtol(sb
.buf
, NULL
, 10);
383 if (read_author_script(state
) < 0)
384 die(_("could not parse author script"));
386 read_commit_msg(state
);
388 read_state_file(&sb
, state
, "threeway", 1);
389 state
->threeway
= !strcmp(sb
.buf
, "t");
391 read_state_file(&sb
, state
, "quiet", 1);
392 state
->quiet
= !strcmp(sb
.buf
, "t");
394 read_state_file(&sb
, state
, "sign", 1);
395 state
->signoff
= !strcmp(sb
.buf
, "t");
397 read_state_file(&sb
, state
, "utf8", 1);
398 state
->utf8
= !strcmp(sb
.buf
, "t");
400 read_state_file(&sb
, state
, "keep", 1);
401 if (!strcmp(sb
.buf
, "t"))
402 state
->keep
= KEEP_TRUE
;
403 else if (!strcmp(sb
.buf
, "b"))
404 state
->keep
= KEEP_NON_PATCH
;
406 state
->keep
= KEEP_FALSE
;
408 read_state_file(&sb
, state
, "messageid", 1);
409 state
->message_id
= !strcmp(sb
.buf
, "t");
411 read_state_file(&sb
, state
, "scissors", 1);
412 if (!strcmp(sb
.buf
, "t"))
413 state
->scissors
= SCISSORS_TRUE
;
414 else if (!strcmp(sb
.buf
, "f"))
415 state
->scissors
= SCISSORS_FALSE
;
417 state
->scissors
= SCISSORS_UNSET
;
419 read_state_file(&sb
, state
, "apply-opt", 1);
420 argv_array_clear(&state
->git_apply_opts
);
421 if (sq_dequote_to_argv_array(sb
.buf
, &state
->git_apply_opts
) < 0)
422 die(_("could not parse %s"), am_path(state
, "apply-opt"));
424 state
->rebasing
= !!file_exists(am_path(state
, "rebasing"));
430 * Removes the am_state directory, forcefully terminating the current am
433 static void am_destroy(const struct am_state
*state
)
435 struct strbuf sb
= STRBUF_INIT
;
437 strbuf_addstr(&sb
, state
->dir
);
438 remove_dir_recursively(&sb
, 0);
443 * Determines if the file looks like a piece of RFC2822 mail by grabbing all
444 * non-indented lines and checking if they look like they begin with valid
445 * header field names.
447 * Returns 1 if the file looks like a piece of mail, 0 otherwise.
449 static int is_mail(FILE *fp
)
451 const char *header_regex
= "^[!-9;-~]+:";
452 struct strbuf sb
= STRBUF_INIT
;
456 if (fseek(fp
, 0L, SEEK_SET
))
457 die_errno(_("fseek failed"));
459 if (regcomp(®ex
, header_regex
, REG_NOSUB
| REG_EXTENDED
))
460 die("invalid pattern: %s", header_regex
);
462 while (!strbuf_getline_crlf(&sb
, fp
)) {
464 break; /* End of header */
466 /* Ignore indented folded lines */
467 if (*sb
.buf
== '\t' || *sb
.buf
== ' ')
470 /* It's a header if it matches header_regex */
471 if (regexec(®ex
, sb
.buf
, 0, NULL
, 0)) {
484 * Attempts to detect the patch_format of the patches contained in `paths`,
485 * returning the PATCH_FORMAT_* enum value. Returns PATCH_FORMAT_UNKNOWN if
488 static int detect_patch_format(const char **paths
)
490 enum patch_format ret
= PATCH_FORMAT_UNKNOWN
;
491 struct strbuf l1
= STRBUF_INIT
;
495 * We default to mbox format if input is from stdin and for directories
497 if (!*paths
|| !strcmp(*paths
, "-") || is_directory(*paths
))
498 return PATCH_FORMAT_MBOX
;
501 * Otherwise, check the first few lines of the first patch, starting
502 * from the first non-blank line, to try to detect its format.
505 fp
= xfopen(*paths
, "r");
507 while (!strbuf_getline_crlf(&l1
, fp
)) {
512 if (starts_with(l1
.buf
, "From ") || starts_with(l1
.buf
, "From: ")) {
513 ret
= PATCH_FORMAT_MBOX
;
517 if (l1
.len
&& is_mail(fp
)) {
518 ret
= PATCH_FORMAT_MBOX
;
529 * Splits out individual email patches from `paths`, where each path is either
530 * a mbox file or a Maildir. Returns 0 on success, -1 on failure.
532 static int split_mail_mbox(struct am_state
*state
, const char **paths
, int keep_cr
)
534 struct child_process cp
= CHILD_PROCESS_INIT
;
535 struct strbuf last
= STRBUF_INIT
;
538 argv_array_push(&cp
.args
, "mailsplit");
539 argv_array_pushf(&cp
.args
, "-d%d", state
->prec
);
540 argv_array_pushf(&cp
.args
, "-o%s", state
->dir
);
541 argv_array_push(&cp
.args
, "-b");
543 argv_array_push(&cp
.args
, "--keep-cr");
544 argv_array_push(&cp
.args
, "--");
545 argv_array_pushv(&cp
.args
, paths
);
547 if (capture_command(&cp
, &last
, 8))
551 state
->last
= strtol(last
.buf
, NULL
, 10);
557 * Splits a list of files/directories into individual email patches. Each path
558 * in `paths` must be a file/directory that is formatted according to
561 * Once split out, the individual email patches will be stored in the state
562 * directory, with each patch's filename being its index, padded to state->prec
565 * state->cur will be set to the index of the first mail, and state->last will
566 * be set to the index of the last mail.
568 * Set keep_cr to 0 to convert all lines ending with \r\n to end with \n, 1
569 * to disable this behavior, -1 to use the default configured setting.
571 * Returns 0 on success, -1 on failure.
573 static int split_mail(struct am_state
*state
, enum patch_format patch_format
,
574 const char **paths
, int keep_cr
)
578 git_config_get_bool("am.keepcr", &keep_cr
);
581 switch (patch_format
) {
582 case PATCH_FORMAT_MBOX
:
583 return split_mail_mbox(state
, paths
, keep_cr
);
585 die("BUG: invalid patch_format");
591 * Setup a new am session for applying patches
593 static void am_setup(struct am_state
*state
, enum patch_format patch_format
,
594 const char **paths
, int keep_cr
)
596 unsigned char curr_head
[GIT_SHA1_RAWSZ
];
598 struct strbuf sb
= STRBUF_INIT
;
601 patch_format
= detect_patch_format(paths
);
604 fprintf_ln(stderr
, _("Patch format detection failed."));
608 if (mkdir(state
->dir
, 0777) < 0 && errno
!= EEXIST
)
609 die_errno(_("failed to create directory '%s'"), state
->dir
);
611 if (split_mail(state
, patch_format
, paths
, keep_cr
) < 0) {
613 die(_("Failed to split patches."));
619 write_file(am_path(state
, "threeway"), 1, state
->threeway
? "t" : "f");
621 write_file(am_path(state
, "quiet"), 1, state
->quiet
? "t" : "f");
623 write_file(am_path(state
, "sign"), 1, state
->signoff
? "t" : "f");
625 write_file(am_path(state
, "utf8"), 1, state
->utf8
? "t" : "f");
627 switch (state
->keep
) {
638 die("BUG: invalid value for state->keep");
641 write_file(am_path(state
, "keep"), 1, "%s", str
);
643 write_file(am_path(state
, "messageid"), 1, state
->message_id
? "t" : "f");
645 switch (state
->scissors
) {
656 die("BUG: invalid value for state->scissors");
659 write_file(am_path(state
, "scissors"), 1, "%s", str
);
661 sq_quote_argv(&sb
, state
->git_apply_opts
.argv
, 0);
662 write_file(am_path(state
, "apply-opt"), 1, "%s", sb
.buf
);
665 write_file(am_path(state
, "rebasing"), 1, "%s", "");
667 write_file(am_path(state
, "applying"), 1, "%s", "");
669 if (!get_sha1("HEAD", curr_head
)) {
670 write_file(am_path(state
, "abort-safety"), 1, "%s", sha1_to_hex(curr_head
));
671 if (!state
->rebasing
)
672 update_ref("am", "ORIG_HEAD", curr_head
, NULL
, 0,
673 UPDATE_REFS_DIE_ON_ERR
);
675 write_file(am_path(state
, "abort-safety"), 1, "%s", "");
676 if (!state
->rebasing
)
677 delete_ref("ORIG_HEAD", NULL
, 0);
681 * NOTE: Since the "next" and "last" files determine if an am_state
682 * session is in progress, they should be written last.
685 write_file(am_path(state
, "next"), 1, "%d", state
->cur
);
687 write_file(am_path(state
, "last"), 1, "%d", state
->last
);
693 * Increments the patch pointer, and cleans am_state for the application of the
696 static void am_next(struct am_state
*state
)
698 unsigned char head
[GIT_SHA1_RAWSZ
];
700 free(state
->author_name
);
701 state
->author_name
= NULL
;
703 free(state
->author_email
);
704 state
->author_email
= NULL
;
706 free(state
->author_date
);
707 state
->author_date
= NULL
;
713 unlink(am_path(state
, "author-script"));
714 unlink(am_path(state
, "final-commit"));
716 if (!get_sha1("HEAD", head
))
717 write_file(am_path(state
, "abort-safety"), 1, "%s", sha1_to_hex(head
));
719 write_file(am_path(state
, "abort-safety"), 1, "%s", "");
722 write_file(am_path(state
, "next"), 1, "%d", state
->cur
);
726 * Returns the filename of the current patch email.
728 static const char *msgnum(const struct am_state
*state
)
730 static struct strbuf sb
= STRBUF_INIT
;
733 strbuf_addf(&sb
, "%0*d", state
->prec
, state
->cur
);
739 * Refresh and write index.
741 static void refresh_and_write_cache(void)
743 struct lock_file
*lock_file
= xcalloc(1, sizeof(struct lock_file
));
745 hold_locked_index(lock_file
, 1);
746 refresh_cache(REFRESH_QUIET
);
747 if (write_locked_index(&the_index
, lock_file
, COMMIT_LOCK
))
748 die(_("unable to write index file"));
752 * Returns 1 if the index differs from HEAD, 0 otherwise. When on an unborn
753 * branch, returns 1 if there are entries in the index, 0 otherwise. If an
754 * strbuf is provided, the space-separated list of files that differ will be
757 static int index_has_changes(struct strbuf
*sb
)
759 unsigned char head
[GIT_SHA1_RAWSZ
];
762 if (!get_sha1_tree("HEAD", head
)) {
763 struct diff_options opt
;
766 DIFF_OPT_SET(&opt
, EXIT_WITH_STATUS
);
768 DIFF_OPT_SET(&opt
, QUICK
);
769 do_diff_cache(head
, &opt
);
771 for (i
= 0; sb
&& i
< diff_queued_diff
.nr
; i
++) {
773 strbuf_addch(sb
, ' ');
774 strbuf_addstr(sb
, diff_queued_diff
.queue
[i
]->two
->path
);
777 return DIFF_OPT_TST(&opt
, HAS_CHANGES
) != 0;
779 for (i
= 0; sb
&& i
< active_nr
; i
++) {
781 strbuf_addch(sb
, ' ');
782 strbuf_addstr(sb
, active_cache
[i
]->name
);
789 * Dies with a user-friendly message on how to proceed after resolving the
790 * problem. This message can be overridden with state->resolvemsg.
792 static void NORETURN
die_user_resolve(const struct am_state
*state
)
794 if (state
->resolvemsg
) {
795 printf_ln("%s", state
->resolvemsg
);
797 const char *cmdline
= "git am";
799 printf_ln(_("When you have resolved this problem, run \"%s --continue\"."), cmdline
);
800 printf_ln(_("If you prefer to skip this patch, run \"%s --skip\" instead."), cmdline
);
801 printf_ln(_("To restore the original branch and stop patching, run \"%s --abort\"."), cmdline
);
808 * Parses `mail` using git-mailinfo, extracting its patch and authorship info.
809 * state->msg will be set to the patch message. state->author_name,
810 * state->author_email and state->author_date will be set to the patch author's
811 * name, email and date respectively. The patch body will be written to the
812 * state directory's "patch" file.
814 * Returns 1 if the patch should be skipped, 0 otherwise.
816 static int parse_mail(struct am_state
*state
, const char *mail
)
819 struct child_process cp
= CHILD_PROCESS_INIT
;
820 struct strbuf sb
= STRBUF_INIT
;
821 struct strbuf msg
= STRBUF_INIT
;
822 struct strbuf author_name
= STRBUF_INIT
;
823 struct strbuf author_date
= STRBUF_INIT
;
824 struct strbuf author_email
= STRBUF_INIT
;
828 cp
.in
= xopen(mail
, O_RDONLY
, 0);
829 cp
.out
= xopen(am_path(state
, "info"), O_WRONLY
| O_CREAT
, 0777);
831 argv_array_push(&cp
.args
, "mailinfo");
832 argv_array_push(&cp
.args
, state
->utf8
? "-u" : "-n");
834 switch (state
->keep
) {
838 argv_array_push(&cp
.args
, "-k");
841 argv_array_push(&cp
.args
, "-b");
844 die("BUG: invalid value for state->keep");
847 if (state
->message_id
)
848 argv_array_push(&cp
.args
, "-m");
850 switch (state
->scissors
) {
854 argv_array_push(&cp
.args
, "--no-scissors");
857 argv_array_push(&cp
.args
, "--scissors");
860 die("BUG: invalid value for state->scissors");
863 argv_array_push(&cp
.args
, am_path(state
, "msg"));
864 argv_array_push(&cp
.args
, am_path(state
, "patch"));
866 if (run_command(&cp
) < 0)
867 die("could not parse patch");
872 /* Extract message and author information */
873 fp
= xfopen(am_path(state
, "info"), "r");
874 while (!strbuf_getline(&sb
, fp
, '\n')) {
877 if (skip_prefix(sb
.buf
, "Subject: ", &x
)) {
879 strbuf_addch(&msg
, '\n');
880 strbuf_addstr(&msg
, x
);
881 } else if (skip_prefix(sb
.buf
, "Author: ", &x
))
882 strbuf_addstr(&author_name
, x
);
883 else if (skip_prefix(sb
.buf
, "Email: ", &x
))
884 strbuf_addstr(&author_email
, x
);
885 else if (skip_prefix(sb
.buf
, "Date: ", &x
))
886 strbuf_addstr(&author_date
, x
);
890 /* Skip pine's internal folder data */
891 if (!strcmp(author_name
.buf
, "Mail System Internal Data")) {
896 if (is_empty_file(am_path(state
, "patch"))) {
897 printf_ln(_("Patch is empty. Was it split wrong?"));
898 die_user_resolve(state
);
901 strbuf_addstr(&msg
, "\n\n");
902 if (strbuf_read_file(&msg
, am_path(state
, "msg"), 0) < 0)
903 die_errno(_("could not read '%s'"), am_path(state
, "msg"));
907 append_signoff(&msg
, 0, 0);
909 assert(!state
->author_name
);
910 state
->author_name
= strbuf_detach(&author_name
, NULL
);
912 assert(!state
->author_email
);
913 state
->author_email
= strbuf_detach(&author_email
, NULL
);
915 assert(!state
->author_date
);
916 state
->author_date
= strbuf_detach(&author_date
, NULL
);
919 state
->msg
= strbuf_detach(&msg
, &state
->msg_len
);
922 strbuf_release(&msg
);
923 strbuf_release(&author_date
);
924 strbuf_release(&author_email
);
925 strbuf_release(&author_name
);
931 * Sets commit_id to the commit hash where the mail was generated from.
932 * Returns 0 on success, -1 on failure.
934 static int get_mail_commit_sha1(unsigned char *commit_id
, const char *mail
)
936 struct strbuf sb
= STRBUF_INIT
;
937 FILE *fp
= xfopen(mail
, "r");
940 if (strbuf_getline(&sb
, fp
, '\n'))
943 if (!skip_prefix(sb
.buf
, "From ", &x
))
946 if (get_sha1_hex(x
, commit_id
) < 0)
955 * Sets state->msg, state->author_name, state->author_email, state->author_date
956 * to the commit's respective info.
958 static void get_commit_info(struct am_state
*state
, struct commit
*commit
)
960 const char *buffer
, *ident_line
, *author_date
, *msg
;
962 struct ident_split ident_split
;
963 struct strbuf sb
= STRBUF_INIT
;
965 buffer
= logmsg_reencode(commit
, NULL
, get_commit_output_encoding());
967 ident_line
= find_commit_header(buffer
, "author", &ident_len
);
969 if (split_ident_line(&ident_split
, ident_line
, ident_len
) < 0) {
970 strbuf_add(&sb
, ident_line
, ident_len
);
971 die(_("invalid ident line: %s"), sb
.buf
);
974 assert(!state
->author_name
);
975 if (ident_split
.name_begin
) {
976 strbuf_add(&sb
, ident_split
.name_begin
,
977 ident_split
.name_end
- ident_split
.name_begin
);
978 state
->author_name
= strbuf_detach(&sb
, NULL
);
980 state
->author_name
= xstrdup("");
982 assert(!state
->author_email
);
983 if (ident_split
.mail_begin
) {
984 strbuf_add(&sb
, ident_split
.mail_begin
,
985 ident_split
.mail_end
- ident_split
.mail_begin
);
986 state
->author_email
= strbuf_detach(&sb
, NULL
);
988 state
->author_email
= xstrdup("");
990 author_date
= show_ident_date(&ident_split
, DATE_MODE(NORMAL
));
991 strbuf_addstr(&sb
, author_date
);
992 assert(!state
->author_date
);
993 state
->author_date
= strbuf_detach(&sb
, NULL
);
996 msg
= strstr(buffer
, "\n\n");
998 die(_("unable to parse commit %s"), sha1_to_hex(commit
->object
.sha1
));
999 state
->msg
= xstrdup(msg
+ 2);
1000 state
->msg_len
= strlen(state
->msg
);
1004 * Writes `commit` as a patch to the state directory's "patch" file.
1006 static void write_commit_patch(const struct am_state
*state
, struct commit
*commit
)
1008 struct rev_info rev_info
;
1011 fp
= xfopen(am_path(state
, "patch"), "w");
1012 init_revisions(&rev_info
, NULL
);
1014 rev_info
.abbrev
= 0;
1015 rev_info
.disable_stdin
= 1;
1016 rev_info
.show_root_diff
= 1;
1017 rev_info
.diffopt
.output_format
= DIFF_FORMAT_PATCH
;
1018 rev_info
.no_commit_id
= 1;
1019 DIFF_OPT_SET(&rev_info
.diffopt
, BINARY
);
1020 DIFF_OPT_SET(&rev_info
.diffopt
, FULL_INDEX
);
1021 rev_info
.diffopt
.use_color
= 0;
1022 rev_info
.diffopt
.file
= fp
;
1023 rev_info
.diffopt
.close_file
= 1;
1024 add_pending_object(&rev_info
, &commit
->object
, "");
1025 diff_setup_done(&rev_info
.diffopt
);
1026 log_tree_commit(&rev_info
, commit
);
1030 * Like parse_mail(), but parses the mail by looking up its commit ID
1031 * directly. This is used in --rebasing mode to bypass git-mailinfo's munging
1034 * Will always return 0 as the patch should never be skipped.
1036 static int parse_mail_rebase(struct am_state
*state
, const char *mail
)
1038 struct commit
*commit
;
1039 unsigned char commit_sha1
[GIT_SHA1_RAWSZ
];
1041 if (get_mail_commit_sha1(commit_sha1
, mail
) < 0)
1042 die(_("could not parse %s"), mail
);
1044 commit
= lookup_commit_or_die(commit_sha1
, mail
);
1046 get_commit_info(state
, commit
);
1048 write_commit_patch(state
, commit
);
1054 * Applies current patch with git-apply. Returns 0 on success, -1 otherwise. If
1055 * `index_file` is not NULL, the patch will be applied to that index.
1057 static int run_apply(const struct am_state
*state
, const char *index_file
)
1059 struct child_process cp
= CHILD_PROCESS_INIT
;
1064 argv_array_pushf(&cp
.env_array
, "GIT_INDEX_FILE=%s", index_file
);
1067 * If we are allowed to fall back on 3-way merge, don't give false
1068 * errors during the initial attempt.
1070 if (state
->threeway
&& !index_file
) {
1075 argv_array_push(&cp
.args
, "apply");
1077 argv_array_pushv(&cp
.args
, state
->git_apply_opts
.argv
);
1080 argv_array_push(&cp
.args
, "--cached");
1082 argv_array_push(&cp
.args
, "--index");
1084 argv_array_push(&cp
.args
, am_path(state
, "patch"));
1086 if (run_command(&cp
))
1089 /* Reload index as git-apply will have modified it. */
1091 read_cache_from(index_file
? index_file
: get_index_file());
1097 * Builds an index that contains just the blobs needed for a 3way merge.
1099 static int build_fake_ancestor(const struct am_state
*state
, const char *index_file
)
1101 struct child_process cp
= CHILD_PROCESS_INIT
;
1104 argv_array_push(&cp
.args
, "apply");
1105 argv_array_pushv(&cp
.args
, state
->git_apply_opts
.argv
);
1106 argv_array_pushf(&cp
.args
, "--build-fake-ancestor=%s", index_file
);
1107 argv_array_push(&cp
.args
, am_path(state
, "patch"));
1109 if (run_command(&cp
))
1116 * Attempt a threeway merge, using index_path as the temporary index.
1118 static int fall_back_threeway(const struct am_state
*state
, const char *index_path
)
1120 unsigned char orig_tree
[GIT_SHA1_RAWSZ
], his_tree
[GIT_SHA1_RAWSZ
],
1121 our_tree
[GIT_SHA1_RAWSZ
];
1122 const unsigned char *bases
[1] = {orig_tree
};
1123 struct merge_options o
;
1124 struct commit
*result
;
1125 char *his_tree_name
;
1127 if (get_sha1("HEAD", our_tree
) < 0)
1128 hashcpy(our_tree
, EMPTY_TREE_SHA1_BIN
);
1130 if (build_fake_ancestor(state
, index_path
))
1131 return error("could not build fake ancestor");
1134 read_cache_from(index_path
);
1136 if (write_index_as_tree(orig_tree
, &the_index
, index_path
, 0, NULL
))
1137 return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
1139 say(state
, stdout
, _("Using index info to reconstruct a base tree..."));
1141 if (!state
->quiet
) {
1143 * List paths that needed 3-way fallback, so that the user can
1144 * review them with extra care to spot mismerges.
1146 struct rev_info rev_info
;
1147 const char *diff_filter_str
= "--diff-filter=AM";
1149 init_revisions(&rev_info
, NULL
);
1150 rev_info
.diffopt
.output_format
= DIFF_FORMAT_NAME_STATUS
;
1151 diff_opt_parse(&rev_info
.diffopt
, &diff_filter_str
, 1);
1152 add_pending_sha1(&rev_info
, "HEAD", our_tree
, 0);
1153 diff_setup_done(&rev_info
.diffopt
);
1154 run_diff_index(&rev_info
, 1);
1157 if (run_apply(state
, index_path
))
1158 return error(_("Did you hand edit your patch?\n"
1159 "It does not apply to blobs recorded in its index."));
1161 if (write_index_as_tree(his_tree
, &the_index
, index_path
, 0, NULL
))
1162 return error("could not write tree");
1164 say(state
, stdout
, _("Falling back to patching base and 3-way merge..."));
1170 * This is not so wrong. Depending on which base we picked, orig_tree
1171 * may be wildly different from ours, but his_tree has the same set of
1172 * wildly different changes in parts the patch did not touch, so
1173 * recursive ends up canceling them, saying that we reverted all those
1177 init_merge_options(&o
);
1180 his_tree_name
= xstrfmt("%.*s", linelen(state
->msg
), state
->msg
);
1181 o
.branch2
= his_tree_name
;
1186 if (merge_recursive_generic(&o
, our_tree
, his_tree
, 1, bases
, &result
)) {
1187 free(his_tree_name
);
1188 return error(_("Failed to merge in the changes."));
1191 free(his_tree_name
);
1196 * Commits the current index with state->msg as the commit message and
1197 * state->author_name, state->author_email and state->author_date as the author
1200 static void do_commit(const struct am_state
*state
)
1202 unsigned char tree
[GIT_SHA1_RAWSZ
], parent
[GIT_SHA1_RAWSZ
],
1203 commit
[GIT_SHA1_RAWSZ
];
1205 struct commit_list
*parents
= NULL
;
1206 const char *reflog_msg
, *author
;
1207 struct strbuf sb
= STRBUF_INIT
;
1209 if (write_cache_as_tree(tree
, 0, NULL
))
1210 die(_("git write-tree failed to write a tree"));
1212 if (!get_sha1_commit("HEAD", parent
)) {
1214 commit_list_insert(lookup_commit(parent
), &parents
);
1217 say(state
, stderr
, _("applying to an empty history"));
1220 author
= fmt_ident(state
->author_name
, state
->author_email
,
1221 state
->ignore_date
? NULL
: state
->author_date
,
1224 if (commit_tree(state
->msg
, state
->msg_len
, tree
, parents
, commit
,
1226 die(_("failed to write commit object"));
1228 reflog_msg
= getenv("GIT_REFLOG_ACTION");
1232 strbuf_addf(&sb
, "%s: %.*s", reflog_msg
, linelen(state
->msg
),
1235 update_ref(sb
.buf
, "HEAD", commit
, ptr
, 0, UPDATE_REFS_DIE_ON_ERR
);
1237 strbuf_release(&sb
);
1241 * Validates the am_state for resuming -- the "msg" and authorship fields must
1244 static void validate_resume_state(const struct am_state
*state
)
1247 die(_("cannot resume: %s does not exist."),
1248 am_path(state
, "final-commit"));
1250 if (!state
->author_name
|| !state
->author_email
|| !state
->author_date
)
1251 die(_("cannot resume: %s does not exist."),
1252 am_path(state
, "author-script"));
1256 * Applies all queued mail.
1258 * If `resume` is true, we are "resuming". The "msg" and authorship fields, as
1259 * well as the state directory's "patch" file is used as-is for applying the
1260 * patch and committing it.
1262 static void am_run(struct am_state
*state
, int resume
)
1264 const char *argv_gc_auto
[] = {"gc", "--auto", NULL
};
1265 struct strbuf sb
= STRBUF_INIT
;
1267 unlink(am_path(state
, "dirtyindex"));
1269 refresh_and_write_cache();
1271 if (index_has_changes(&sb
)) {
1272 write_file(am_path(state
, "dirtyindex"), 1, "t");
1273 die(_("Dirty index: cannot apply patches (dirty: %s)"), sb
.buf
);
1276 strbuf_release(&sb
);
1278 while (state
->cur
<= state
->last
) {
1279 const char *mail
= am_path(state
, msgnum(state
));
1282 if (!file_exists(mail
))
1286 validate_resume_state(state
);
1291 if (state
->rebasing
)
1292 skip
= parse_mail_rebase(state
, mail
);
1294 skip
= parse_mail(state
, mail
);
1297 goto next
; /* mail should be skipped */
1299 write_author_script(state
);
1300 write_commit_msg(state
);
1303 say(state
, stdout
, _("Applying: %.*s"), linelen(state
->msg
), state
->msg
);
1305 apply_status
= run_apply(state
, NULL
);
1307 if (apply_status
&& state
->threeway
) {
1308 struct strbuf sb
= STRBUF_INIT
;
1310 strbuf_addstr(&sb
, am_path(state
, "patch-merge-index"));
1311 apply_status
= fall_back_threeway(state
, sb
.buf
);
1312 strbuf_release(&sb
);
1315 * Applying the patch to an earlier tree and merging
1316 * the result may have produced the same tree as ours.
1318 if (!apply_status
&& !index_has_changes(NULL
)) {
1319 say(state
, stdout
, _("No changes -- Patch already applied."));
1325 int advice_amworkdir
= 1;
1327 printf_ln(_("Patch failed at %s %.*s"), msgnum(state
),
1328 linelen(state
->msg
), state
->msg
);
1330 git_config_get_bool("advice.amworkdir", &advice_amworkdir
);
1332 if (advice_amworkdir
)
1333 printf_ln(_("The copy of the patch that failed is found in: %s"),
1334 am_path(state
, "patch"));
1336 die_user_resolve(state
);
1346 * In rebasing mode, it's up to the caller to take care of
1349 if (!state
->rebasing
) {
1351 run_command_v_opt(argv_gc_auto
, RUN_GIT_CMD
);
1356 * Resume the current am session after patch application failure. The user did
1357 * all the hard work, and we do not have to do any patch application. Just
1358 * trust and commit what the user has in the index and working tree.
1360 static void am_resolve(struct am_state
*state
)
1362 validate_resume_state(state
);
1364 say(state
, stdout
, _("Applying: %.*s"), linelen(state
->msg
), state
->msg
);
1366 if (!index_has_changes(NULL
)) {
1367 printf_ln(_("No changes - did you forget to use 'git add'?\n"
1368 "If there is nothing left to stage, chances are that something else\n"
1369 "already introduced the same changes; you might want to skip this patch."));
1370 die_user_resolve(state
);
1373 if (unmerged_cache()) {
1374 printf_ln(_("You still have unmerged paths in your index.\n"
1375 "Did you forget to use 'git add'?"));
1376 die_user_resolve(state
);
1386 * Performs a checkout fast-forward from `head` to `remote`. If `reset` is
1387 * true, any unmerged entries will be discarded. Returns 0 on success, -1 on
1390 static int fast_forward_to(struct tree
*head
, struct tree
*remote
, int reset
)
1392 struct lock_file
*lock_file
;
1393 struct unpack_trees_options opts
;
1394 struct tree_desc t
[2];
1396 if (parse_tree(head
) || parse_tree(remote
))
1399 lock_file
= xcalloc(1, sizeof(struct lock_file
));
1400 hold_locked_index(lock_file
, 1);
1402 refresh_cache(REFRESH_QUIET
);
1404 memset(&opts
, 0, sizeof(opts
));
1406 opts
.src_index
= &the_index
;
1407 opts
.dst_index
= &the_index
;
1411 opts
.fn
= twoway_merge
;
1412 init_tree_desc(&t
[0], head
->buffer
, head
->size
);
1413 init_tree_desc(&t
[1], remote
->buffer
, remote
->size
);
1415 if (unpack_trees(2, t
, &opts
)) {
1416 rollback_lock_file(lock_file
);
1420 if (write_locked_index(&the_index
, lock_file
, COMMIT_LOCK
))
1421 die(_("unable to write new index file"));
1427 * Clean the index without touching entries that are not modified between
1428 * `head` and `remote`.
1430 static int clean_index(const unsigned char *head
, const unsigned char *remote
)
1432 struct lock_file
*lock_file
;
1433 struct tree
*head_tree
, *remote_tree
, *index_tree
;
1434 unsigned char index
[GIT_SHA1_RAWSZ
];
1435 struct pathspec pathspec
;
1437 head_tree
= parse_tree_indirect(head
);
1439 return error(_("Could not parse object '%s'."), sha1_to_hex(head
));
1441 remote_tree
= parse_tree_indirect(remote
);
1443 return error(_("Could not parse object '%s'."), sha1_to_hex(remote
));
1445 read_cache_unmerged();
1447 if (fast_forward_to(head_tree
, head_tree
, 1))
1450 if (write_cache_as_tree(index
, 0, NULL
))
1453 index_tree
= parse_tree_indirect(index
);
1455 return error(_("Could not parse object '%s'."), sha1_to_hex(index
));
1457 if (fast_forward_to(index_tree
, remote_tree
, 0))
1460 memset(&pathspec
, 0, sizeof(pathspec
));
1462 lock_file
= xcalloc(1, sizeof(struct lock_file
));
1463 hold_locked_index(lock_file
, 1);
1465 if (read_tree(remote_tree
, 0, &pathspec
)) {
1466 rollback_lock_file(lock_file
);
1470 if (write_locked_index(&the_index
, lock_file
, COMMIT_LOCK
))
1471 die(_("unable to write new index file"));
1473 remove_branch_state();
1479 * Resume the current am session by skipping the current patch.
1481 static void am_skip(struct am_state
*state
)
1483 unsigned char head
[GIT_SHA1_RAWSZ
];
1485 if (get_sha1("HEAD", head
))
1486 hashcpy(head
, EMPTY_TREE_SHA1_BIN
);
1488 if (clean_index(head
, head
))
1489 die(_("failed to clean index"));
1496 * Returns true if it is safe to reset HEAD to the ORIG_HEAD, false otherwise.
1498 * It is not safe to reset HEAD when:
1499 * 1. git-am previously failed because the index was dirty.
1500 * 2. HEAD has moved since git-am previously failed.
1502 static int safe_to_abort(const struct am_state
*state
)
1504 struct strbuf sb
= STRBUF_INIT
;
1505 unsigned char abort_safety
[GIT_SHA1_RAWSZ
], head
[GIT_SHA1_RAWSZ
];
1507 if (file_exists(am_path(state
, "dirtyindex")))
1510 if (read_state_file(&sb
, state
, "abort-safety", 1) > 0) {
1511 if (get_sha1_hex(sb
.buf
, abort_safety
))
1512 die(_("could not parse %s"), am_path(state
, "abort_safety"));
1514 hashclr(abort_safety
);
1516 if (get_sha1("HEAD", head
))
1519 if (!hashcmp(head
, abort_safety
))
1522 error(_("You seem to have moved HEAD since the last 'am' failure.\n"
1523 "Not rewinding to ORIG_HEAD"));
1529 * Aborts the current am session if it is safe to do so.
1531 static void am_abort(struct am_state
*state
)
1533 unsigned char curr_head
[GIT_SHA1_RAWSZ
], orig_head
[GIT_SHA1_RAWSZ
];
1534 int has_curr_head
, has_orig_head
;
1537 if (!safe_to_abort(state
)) {
1542 curr_branch
= resolve_refdup("HEAD", 0, curr_head
, NULL
);
1543 has_curr_head
= !is_null_sha1(curr_head
);
1545 hashcpy(curr_head
, EMPTY_TREE_SHA1_BIN
);
1547 has_orig_head
= !get_sha1("ORIG_HEAD", orig_head
);
1549 hashcpy(orig_head
, EMPTY_TREE_SHA1_BIN
);
1551 clean_index(curr_head
, orig_head
);
1554 update_ref("am --abort", "HEAD", orig_head
,
1555 has_curr_head
? curr_head
: NULL
, 0,
1556 UPDATE_REFS_DIE_ON_ERR
);
1557 else if (curr_branch
)
1558 delete_ref(curr_branch
, NULL
, REF_NODEREF
);
1565 * parse_options() callback that validates and sets opt->value to the
1566 * PATCH_FORMAT_* enum value corresponding to `arg`.
1568 static int parse_opt_patchformat(const struct option
*opt
, const char *arg
, int unset
)
1570 int *opt_value
= opt
->value
;
1572 if (!strcmp(arg
, "mbox"))
1573 *opt_value
= PATCH_FORMAT_MBOX
;
1575 return error(_("Invalid value for --patch-format: %s"), arg
);
1587 int cmd_am(int argc
, const char **argv
, const char *prefix
)
1589 struct am_state state
;
1591 int patch_format
= PATCH_FORMAT_UNKNOWN
;
1592 enum resume_mode resume
= RESUME_FALSE
;
1594 const char * const usage
[] = {
1595 N_("git am [options] [(<mbox>|<Maildir>)...]"),
1596 N_("git am [options] (--continue | --skip | --abort)"),
1600 struct option options
[] = {
1601 OPT_BOOL('3', "3way", &state
.threeway
,
1602 N_("allow fall back on 3way merging if needed")),
1603 OPT__QUIET(&state
.quiet
, N_("be quiet")),
1604 OPT_BOOL('s', "signoff", &state
.signoff
,
1605 N_("add a Signed-off-by line to the commit message")),
1606 OPT_BOOL('u', "utf8", &state
.utf8
,
1607 N_("recode into utf8 (default)")),
1608 OPT_SET_INT('k', "keep", &state
.keep
,
1609 N_("pass -k flag to git-mailinfo"), KEEP_TRUE
),
1610 OPT_SET_INT(0, "keep-non-patch", &state
.keep
,
1611 N_("pass -b flag to git-mailinfo"), KEEP_NON_PATCH
),
1612 OPT_BOOL('m', "message-id", &state
.message_id
,
1613 N_("pass -m flag to git-mailinfo")),
1614 { OPTION_SET_INT
, 0, "keep-cr", &keep_cr
, NULL
,
1615 N_("pass --keep-cr flag to git-mailsplit for mbox format"),
1616 PARSE_OPT_NOARG
| PARSE_OPT_NONEG
, NULL
, 1},
1617 { OPTION_SET_INT
, 0, "no-keep-cr", &keep_cr
, NULL
,
1618 N_("do not pass --keep-cr flag to git-mailsplit independent of am.keepcr"),
1619 PARSE_OPT_NOARG
| PARSE_OPT_NONEG
, NULL
, 0},
1620 OPT_BOOL('c', "scissors", &state
.scissors
,
1621 N_("strip everything before a scissors line")),
1622 OPT_PASSTHRU_ARGV(0, "whitespace", &state
.git_apply_opts
, N_("action"),
1623 N_("pass it through git-apply"),
1625 OPT_PASSTHRU_ARGV(0, "ignore-space-change", &state
.git_apply_opts
, NULL
,
1626 N_("pass it through git-apply"),
1628 OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &state
.git_apply_opts
, NULL
,
1629 N_("pass it through git-apply"),
1631 OPT_PASSTHRU_ARGV(0, "directory", &state
.git_apply_opts
, N_("root"),
1632 N_("pass it through git-apply"),
1634 OPT_PASSTHRU_ARGV(0, "exclude", &state
.git_apply_opts
, N_("path"),
1635 N_("pass it through git-apply"),
1637 OPT_PASSTHRU_ARGV(0, "include", &state
.git_apply_opts
, N_("path"),
1638 N_("pass it through git-apply"),
1640 OPT_PASSTHRU_ARGV('C', NULL
, &state
.git_apply_opts
, N_("n"),
1641 N_("pass it through git-apply"),
1643 OPT_PASSTHRU_ARGV('p', NULL
, &state
.git_apply_opts
, N_("num"),
1644 N_("pass it through git-apply"),
1646 OPT_CALLBACK(0, "patch-format", &patch_format
, N_("format"),
1647 N_("format the patch(es) are in"),
1648 parse_opt_patchformat
),
1649 OPT_PASSTHRU_ARGV(0, "reject", &state
.git_apply_opts
, NULL
,
1650 N_("pass it through git-apply"),
1652 OPT_STRING(0, "resolvemsg", &state
.resolvemsg
, NULL
,
1653 N_("override error message when patch failure occurs")),
1654 OPT_CMDMODE(0, "continue", &resume
,
1655 N_("continue applying patches after resolving a conflict"),
1657 OPT_CMDMODE('r', "resolved", &resume
,
1658 N_("synonyms for --continue"),
1660 OPT_CMDMODE(0, "skip", &resume
,
1661 N_("skip the current patch"),
1663 OPT_CMDMODE(0, "abort", &resume
,
1664 N_("restore the original branch and abort the patching operation."),
1666 OPT_BOOL(0, "ignore-date", &state
.ignore_date
,
1667 N_("use current timestamp for author date")),
1668 OPT_HIDDEN_BOOL(0, "rebasing", &state
.rebasing
,
1669 N_("(internal use for git-rebase)")),
1674 * NEEDSWORK: Once all the features of git-am.sh have been
1675 * re-implemented in builtin/am.c, this preamble can be removed.
1677 if (!getenv("_GIT_USE_BUILTIN_AM")) {
1678 const char *path
= mkpath("%s/git-am", git_exec_path());
1680 if (sane_execvp(path
, (char **)argv
) < 0)
1681 die_errno("could not exec %s", path
);
1683 prefix
= setup_git_directory();
1684 trace_repo_setup(prefix
);
1688 git_config(git_default_config
, NULL
);
1690 am_state_init(&state
, git_path("rebase-apply"));
1692 argc
= parse_options(argc
, argv
, prefix
, options
, usage
, 0);
1694 if (read_index_preload(&the_index
, NULL
) < 0)
1695 die(_("failed to read the index"));
1697 if (am_in_progress(&state
)) {
1699 * Catch user error to feed us patches when there is a session
1702 * 1. mbox path(s) are provided on the command-line.
1703 * 2. stdin is not a tty: the user is trying to feed us a patch
1704 * from standard input. This is somewhat unreliable -- stdin
1705 * could be /dev/null for example and the caller did not
1706 * intend to feed us a patch but wanted to continue
1709 if (argc
|| (resume
== RESUME_FALSE
&& !isatty(0)))
1710 die(_("previous rebase directory %s still exists but mbox given."),
1713 if (resume
== RESUME_FALSE
)
1714 resume
= RESUME_APPLY
;
1718 struct argv_array paths
= ARGV_ARRAY_INIT
;
1722 * Handle stray state directory in the independent-run case. In
1723 * the --rebasing case, it is up to the caller to take care of
1724 * stray directories.
1726 if (file_exists(state
.dir
) && !state
.rebasing
) {
1727 if (resume
== RESUME_ABORT
) {
1729 am_state_release(&state
);
1733 die(_("Stray %s directory found.\n"
1734 "Use \"git am --abort\" to remove it."),
1739 die(_("Resolve operation not in progress, we are not resuming."));
1741 for (i
= 0; i
< argc
; i
++) {
1742 if (is_absolute_path(argv
[i
]) || !prefix
)
1743 argv_array_push(&paths
, argv
[i
]);
1745 argv_array_push(&paths
, mkpath("%s/%s", prefix
, argv
[i
]));
1748 am_setup(&state
, patch_format
, paths
.argv
, keep_cr
);
1750 argv_array_clear(&paths
);
1760 case RESUME_RESOLVED
:
1770 die("BUG: invalid resume value");
1773 am_state_release(&state
);