(
self,
commit_index: Dict[GitCommitHash, ghstack.git.CommitHeader],
commits_to_submit: List[ghstack.git.CommitHeader],
commits_to_rebase: List[ghstack.git.CommitHeader],
)
| 680 | return commits_to_submit_and_boundary |
| 681 | |
| 682 | def prepare_updates( |
| 683 | self, |
| 684 | commit_index: Dict[GitCommitHash, ghstack.git.CommitHeader], |
| 685 | commits_to_submit: List[ghstack.git.CommitHeader], |
| 686 | commits_to_rebase: List[ghstack.git.CommitHeader], |
| 687 | ) -> Tuple[Dict[GitCommitHash, DiffMeta], Dict[GitCommitHash, GitCommitHash]]: |
| 688 | # Prepare diffs in reverse topological order. |
| 689 | # (Reverse here is important because we must have processed parents |
| 690 | # first.) |
| 691 | # NB: some parts of the algo (namely commit creation) could |
| 692 | # be done in parallel |
| 693 | submit_set = set(h.commit_id for h in commits_to_submit) |
| 694 | diff_meta_index: Dict[GitCommitHash, DiffMeta] = {} |
| 695 | rebase_index: Dict[GitCommitHash, GitCommitHash] = {} |
| 696 | for commit in reversed(commits_to_rebase): |
| 697 | submit = commit.commit_id in submit_set |
| 698 | parents = commit.parents |
| 699 | if len(parents) != 1: |
| 700 | raise RuntimeError( |
| 701 | "The commit {} has {} parents, which makes my head explode. " |
| 702 | "`git rebase -i` your diffs into a stack, then try again.".format( |
| 703 | commit.commit_id, len(parents) |
| 704 | ) |
| 705 | ) |
| 706 | parent = parents[0] |
| 707 | diff_meta = None |
| 708 | parent_commit = commit_index[parent] |
| 709 | parent_diff_meta = diff_meta_index.get(parent) |
| 710 | diff = ghstack.git.convert_header(commit, self.github_url) |
| 711 | diff_meta = self.process_commit( |
| 712 | parent_commit, |
| 713 | parent_diff_meta, |
| 714 | diff, |
| 715 | ( |
| 716 | self.elaborate_diff(diff) |
| 717 | if diff.pull_request_resolved is not None |
| 718 | else None |
| 719 | ), |
| 720 | submit, |
| 721 | ) |
| 722 | if diff_meta is not None: |
| 723 | diff_meta_index[commit.commit_id] = diff_meta |
| 724 | |
| 725 | # Check if we actually need to rebase it, or can use it as is |
| 726 | # NB: This is not in process_commit, because we may need |
| 727 | # to rebase a commit even if we didn't submit it |
| 728 | if parent in rebase_index or diff_meta is not None: |
| 729 | # Yes, we need to rebase it |
| 730 | |
| 731 | if diff_meta is not None: |
| 732 | # use the updated commit message, if it exists |
| 733 | commit_msg = diff_meta.commit_msg |
| 734 | else: |
| 735 | commit_msg = commit.commit_msg |
| 736 | |
| 737 | if rebase_id := rebase_index.get(commit.parents[0]): |
| 738 | # use the updated base, if it exists |
| 739 | base_commit_id = rebase_id |
no test coverage detected