(self)
| 429 | # The main algorithm |
| 430 | |
| 431 | def run(self) -> List[DiffMeta]: |
| 432 | self.fetch() |
| 433 | |
| 434 | commits_to_submit_and_boundary = self.parse_revs() |
| 435 | |
| 436 | commits_to_submit = [ |
| 437 | d for d in commits_to_submit_and_boundary if not d.boundary |
| 438 | ] |
| 439 | |
| 440 | # NB: A little bit of redundant parsing here, because we will re-parse |
| 441 | # commits that we had already parsed in commits_to_submit, and we will |
| 442 | # also parse prefix even if it's not being processed, but it's at most ~10 |
| 443 | # extra parses so whatever |
| 444 | commits_to_rebase_and_boundary = ghstack.git.split_header( |
| 445 | self.sh.git( |
| 446 | "rev-list", |
| 447 | "--boundary", |
| 448 | "--header", |
| 449 | "--topo-order", |
| 450 | # Get all commits reachable from HEAD... |
| 451 | "HEAD", |
| 452 | # ...as well as all the commits we are going to submit... |
| 453 | *[c.commit_id for c in commits_to_submit], |
| 454 | # ...but we don't need any commits that aren't draft |
| 455 | f"^{self.remote_name}/{self.base}", |
| 456 | ) |
| 457 | ) |
| 458 | |
| 459 | commits_to_rebase = [ |
| 460 | d for d in commits_to_rebase_and_boundary if not d.boundary |
| 461 | ] |
| 462 | |
| 463 | # NB: commits_to_rebase always contains all diffs to submit (because |
| 464 | # we always have to generate orig commits for submitted diffs.) |
| 465 | # However, commits_to_submit does not necessarily contain |
| 466 | # diffs_to_rebase. If you ask to submit only a prefix of your current |
| 467 | # stack, the suffix is not to be submitted, but it needs to be rebased |
| 468 | # (to, e.g., update the ghstack-source-id) |
| 469 | |
| 470 | commit_count = len(commits_to_submit) |
| 471 | |
| 472 | if commit_count == 0: |
| 473 | raise RuntimeError( |
| 474 | "There appears to be no commits to process, based on the revs you passed me." |
| 475 | ) |
| 476 | |
| 477 | # This is not really accurate if you're doing a fancy pattern; |
| 478 | # if this is a problem file us a bug. |
| 479 | run_pre_ghstack_hook( |
| 480 | self.sh, f"{self.remote_name}/{self.base}", commits_to_submit[0].commit_id |
| 481 | ) |
| 482 | |
| 483 | # NB: This is duplicative with prepare_submit to keep the |
| 484 | # check_invariants code small, as it counts as TCB |
| 485 | pre_branch_state_index: Dict[GitCommitHash, PreBranchState] = {} |
| 486 | if self.check_invariants: |
| 487 | for h in commits_to_submit: |
| 488 | d = ghstack.git.convert_header(h, self.github_url) |
no test coverage detected