95
char *msg;
96
size_t msg_len;
97
98
+ /* when --rebasing, records the original commit the patch came from */
99
+ unsigned char orig_commit[GIT_SHA1_RAWSZ];
100
+
101
/* number of digits in patch filename */
102
int prec;
103
395
396
read_commit_msg(state);
397
398
+ if (read_state_file(&sb, state, "original-commit", 1) < 0)
399
+ hashclr(state->orig_commit);
400
+ else if (get_sha1_hex(sb.buf, state->orig_commit) < 0)
401
+ die(_("could not parse %s"), am_path(state, "original-commit"));
402
+
403
read_state_file(&sb, state, "threeway", 1);
404
state->threeway = !strcmp(sb.buf, "t");
405
454
strbuf_release(&sb);
455
}
456
457
+/**
458
+ * Runs post-rewrite hook. Returns it exit code.
459
+ */
460
+static int run_post_rewrite_hook(const struct am_state *state)
461
+{
462
+ struct child_process cp = CHILD_PROCESS_INIT;
463
+ const char *hook = find_hook("post-rewrite");
464
+ int ret;
465
+
466
+ if (!hook)
467
+ return 0;
468
+
469
+ argv_array_push(&cp.args, hook);
470
+ argv_array_push(&cp.args, "rebase");
471
+
472
+ cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
473
+ cp.stdout_to_stderr = 1;
474
+
475
+ ret = run_command(&cp);
476
+
477
+ close(cp.in);
478
+ return ret;
479
+}
480
+
481
/**
482
* Determines if the file looks like a piece of RFC2822 mail by grabbing all
483
* non-indented lines and checking if they look like they begin with valid
752
unlink(am_path(state, "author-script"));
753
unlink(am_path(state, "final-commit"));
754
755
+ hashclr(state->orig_commit);
756
+ unlink(am_path(state, "original-commit"));
757
+
758
if (!get_sha1("HEAD", head))
759
write_file(am_path(state, "abort-safety"), 1, "%s", sha1_to_hex(head));
760
else
1073
* directly. This is used in --rebasing mode to bypass git-mailinfo's munging
1074
* of patches.
1075
*
1076
+ * state->orig_commit will be set to the original commit ID.
1077
+ *
1078
* Will always return 0 as the patch should never be skipped.
1079
*/
1080
static int parse_mail_rebase(struct am_state *state, const char *mail)
1091
1092
write_commit_patch(state, commit);
1093
1094
+ hashcpy(state->orig_commit, commit_sha1);
1095
+ write_file(am_path(state, "original-commit"), 1, "%s",
1096
+ sha1_to_hex(commit_sha1));
1097
+
1098
return 0;
1099
}
1100
1286
1287
update_ref(sb.buf, "HEAD", commit, ptr, 0, UPDATE_REFS_DIE_ON_ERR);
1288
1289
+ if (state->rebasing) {
1290
+ FILE *fp = xfopen(am_path(state, "rewritten"), "a");
1291
+
1292
+ assert(!is_null_sha1(state->orig_commit));
1293
+ fprintf(fp, "%s ", sha1_to_hex(state->orig_commit));
1294
+ fprintf(fp, "%s\n", sha1_to_hex(commit));
1295
+ fclose(fp);
1296
+ }
1297
+
1298
strbuf_release(&sb);
1299
}
1300
1403
am_next(state);
1404
}
1405
1406
+ if (!is_empty_file(am_path(state, "rewritten"))) {
1407
+ assert(state->rebasing);
1408
+ run_post_rewrite_hook(state);
1409
+ }
1410
+
1411
/*
1412
* In rebasing mode, it's up to the caller to take care of
1413
* housekeeping.