|
23 | 23 | #include "merge-recursive.h"
|
24 | 24 | #include "revision.h"
|
25 | 25 | #include "log-tree.h"
|
| 26 | +#include "notes-utils.h" |
26 | 27 |
|
27 | 28 | /**
|
28 | 29 | * Returns 1 if the file is empty or does not exist, 0 otherwise.
|
@@ -478,6 +479,64 @@ static int run_post_rewrite_hook(const struct am_state *state)
|
478 | 479 | return ret;
|
479 | 480 | }
|
480 | 481 |
|
| 482 | +/** |
| 483 | + * Reads the state directory's "rewritten" file, and copies notes from the old |
| 484 | + * commits listed in the file to their rewritten commits. |
| 485 | + * |
| 486 | + * Returns 0 on success, -1 on failure. |
| 487 | + */ |
| 488 | +static int copy_notes_for_rebase(const struct am_state *state) |
| 489 | +{ |
| 490 | + struct notes_rewrite_cfg *c; |
| 491 | + struct strbuf sb = STRBUF_INIT; |
| 492 | + const char *invalid_line = _("Malformed input line: '%s'."); |
| 493 | + const char *msg = "Notes added by 'git rebase'"; |
| 494 | + FILE *fp; |
| 495 | + int ret = 0; |
| 496 | + |
| 497 | + assert(state->rebasing); |
| 498 | + |
| 499 | + c = init_copy_notes_for_rewrite("rebase"); |
| 500 | + if (!c) |
| 501 | + return 0; |
| 502 | + |
| 503 | + fp = xfopen(am_path(state, "rewritten"), "r"); |
| 504 | + |
| 505 | + while (!strbuf_getline(&sb, fp, '\n')) { |
| 506 | + unsigned char from_obj[GIT_SHA1_RAWSZ], to_obj[GIT_SHA1_RAWSZ]; |
| 507 | + |
| 508 | + if (sb.len != GIT_SHA1_HEXSZ * 2 + 1) { |
| 509 | + ret = error(invalid_line, sb.buf); |
| 510 | + goto finish; |
| 511 | + } |
| 512 | + |
| 513 | + if (get_sha1_hex(sb.buf, from_obj)) { |
| 514 | + ret = error(invalid_line, sb.buf); |
| 515 | + goto finish; |
| 516 | + } |
| 517 | + |
| 518 | + if (sb.buf[GIT_SHA1_HEXSZ] != ' ') { |
| 519 | + ret = error(invalid_line, sb.buf); |
| 520 | + goto finish; |
| 521 | + } |
| 522 | + |
| 523 | + if (get_sha1_hex(sb.buf + GIT_SHA1_HEXSZ + 1, to_obj)) { |
| 524 | + ret = error(invalid_line, sb.buf); |
| 525 | + goto finish; |
| 526 | + } |
| 527 | + |
| 528 | + if (copy_note_for_rewrite(c, from_obj, to_obj)) |
| 529 | + ret = error(_("Failed to copy notes from '%s' to '%s'"), |
| 530 | + sha1_to_hex(from_obj), sha1_to_hex(to_obj)); |
| 531 | + } |
| 532 | + |
| 533 | +finish: |
| 534 | + finish_copy_notes_for_rewrite(c, msg); |
| 535 | + fclose(fp); |
| 536 | + strbuf_release(&sb); |
| 537 | + return ret; |
| 538 | +} |
| 539 | + |
481 | 540 | /**
|
482 | 541 | * Determines if the file looks like a piece of RFC2822 mail by grabbing all
|
483 | 542 | * non-indented lines and checking if they look like they begin with valid
|
@@ -1405,6 +1464,7 @@ static void am_run(struct am_state *state, int resume)
|
1405 | 1464 |
|
1406 | 1465 | if (!is_empty_file(am_path(state, "rewritten"))) {
|
1407 | 1466 | assert(state->rebasing);
|
| 1467 | + copy_notes_for_rebase(state); |
1408 | 1468 | run_post_rewrite_hook(state);
|
1409 | 1469 | }
|
1410 | 1470 |
|
|
0 commit comments