Merge branch 'jh/trace2'
[gitweb.git] / builtin / am.c
index ad913ef20e18b177055a0d10895b267b9128b82f..86e33495b039bd44d4b59625388d55cd624ccd26 100644 (file)
 #include "packfile.h"
 #include "repository.h"
 
-/**
- * Returns 1 if the file is empty or does not exist, 0 otherwise.
- */
-static int is_empty_file(const char *filename)
-{
-       struct stat st;
-
-       if (stat(filename, &st) < 0) {
-               if (errno == ENOENT)
-                       return 1;
-               die_errno(_("could not stat %s"), filename);
-       }
-
-       return !st.st_size;
-}
-
 /**
  * Returns the length of the first line of msg.
  */
@@ -469,6 +453,7 @@ static int run_post_rewrite_hook(const struct am_state *state)
 
        cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
        cp.stdout_to_stderr = 1;
+       cp.trace2_hook_name = "post-rewrite";
 
        ret = run_command(&cp);
 
@@ -1221,7 +1206,7 @@ static int parse_mail(struct am_state *state, const char *mail)
                goto finish;
        }
 
-       if (is_empty_file(am_path(state, "patch"))) {
+       if (is_empty_or_missing_file(am_path(state, "patch"))) {
                printf_ln(_("Patch is empty."));
                die_user_resolve(state);
        }
@@ -1595,6 +1580,7 @@ static void do_commit(const struct am_state *state)
        }
 
        author = fmt_ident(state->author_name, state->author_email,
+               WANT_AUTHOR_IDENT,
                        state->ignore_date ? NULL : state->author_date,
                        IDENT_STRICT);
 
@@ -1804,7 +1790,7 @@ static void am_run(struct am_state *state, int resume)
                resume = 0;
        }
 
-       if (!is_empty_file(am_path(state, "rewritten"))) {
+       if (!is_empty_or_missing_file(am_path(state, "rewritten"))) {
                assert(state->rebasing);
                copy_notes_for_rebase(state);
                run_post_rewrite_hook(state);
@@ -2001,6 +1987,15 @@ static void am_skip(struct am_state *state)
        if (clean_index(&head, &head))
                die(_("failed to clean index"));
 
+       if (state->rebasing) {
+               FILE *fp = xfopen(am_path(state, "rewritten"), "a");
+
+               assert(!is_null_oid(&state->orig_commit));
+               fprintf(fp, "%s ", oid_to_hex(&state->orig_commit));
+               fprintf(fp, "%s\n", oid_to_hex(&head));
+               fclose(fp);
+       }
+
        am_next(state);
        am_load(state);
        am_run(state, 0);