@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove all the multi-pass autoclose-branch separate-cache / seenOnBranches junk

Summary:
Ref T4327. Simplify the git discovery process so I can move it to the DiscoveryEngine, so I can make change parsing testable.

In particular:

- As an optimization, we process closeable branches ("master") first, then process uncloseable branches ("epriestley-devel"). This means that in the common case we can insert a commit as closeable immediately when it is discovered, the first pass through the pipeline will get it right, and the "ref update" step will never need to do any meaningful work.
- Commits which do not initially appear on a closeable branch, but later move to one (via merges or ref moves) will now be caught in the ref update step, have the closeable flag set, and have a message step re-queued.
- We no longer need to do a separate discovery step on closable branches.
- We no longer need to keep track of `seenOnBranches`.

Test Plan: Ran discovery on repositories after pushing commits, got reasonable results.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4327

Differential Revision: https://secure.phabricator.com/D7985

+38 -121
+2 -4
src/applications/diffusion/controller/DiffusionCommitController.php
··· 348 348 $change_list->setRenderURI('/diffusion/'.$callsign.'/diff/'); 349 349 $change_list->setRepository($repository); 350 350 $change_list->setUser($user); 351 - // pick the first branch for "Browse in Diffusion" View Option 352 - $branches = $commit_data->getCommitDetail('seenOnBranches', array()); 353 - $first_branch = reset($branches); 354 - $change_list->setBranch($first_branch); 351 + 352 + // TODO: Try to setBranch() to something reasonable here? 355 353 356 354 $change_list->setStandaloneURI( 357 355 '/diffusion/'.$callsign.'/diff/');
+33 -117
src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
··· 246 246 $repository, 247 247 $ref->getIdentifier(), 248 248 $ref->getEpoch(), 249 - $ref->getBranch()); 249 + $close_immediately = true); 250 250 } 251 251 } 252 252 ··· 319 319 return true; 320 320 } 321 321 322 - private function isKnownCommitOnAnyAutocloseBranch( 323 - PhabricatorRepository $repository, 324 - $target) { 325 - 326 - $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 327 - 'repositoryID = %d AND commitIdentifier = %s', 328 - $repository->getID(), 329 - $target); 330 - 331 - if (!$commit) { 332 - $callsign = $repository->getCallsign(); 333 - 334 - $console = PhutilConsole::getConsole(); 335 - $console->writeErr( 336 - "WARNING: Repository '%s' is missing commits ('%s' is missing from ". 337 - "history). Run '%s' to repair the repository.\n", 338 - $callsign, 339 - $target, 340 - "bin/repository discover --repair {$callsign}"); 341 - 342 - return false; 343 - } 344 - 345 - $data = $commit->loadCommitData(); 346 - if (!$data) { 347 - return false; 348 - } 349 - 350 - if ($repository->shouldAutocloseCommit($commit, $data)) { 351 - return true; 352 - } 353 - 354 - return false; 355 - } 356 - 357 322 private function recordCommit( 358 323 PhabricatorRepository $repository, 359 324 $commit_identifier, 360 325 $epoch, 361 - $branch = null) { 326 + $close_immediately) { 362 327 363 328 $commit = new PhabricatorRepositoryCommit(); 364 329 $commit->setRepositoryID($repository->getID()); 365 330 $commit->setCommitIdentifier($commit_identifier); 366 331 $commit->setEpoch($epoch); 332 + if ($close_immediately) { 333 + $commit->setImportStatus(PhabricatorRepositoryCommit::IMPORTED_CLOSEABLE); 334 + } 367 335 368 336 $data = new PhabricatorRepositoryCommitData(); 369 - if ($branch) { 370 - $data->setCommitDetail('seenOnBranches', array($branch)); 371 - } 372 337 373 338 try { 374 339 $commit->openTransaction(); ··· 419 384 } 420 385 } 421 386 422 - private function updateCommit( 423 - PhabricatorRepository $repository, 424 - $commit_identifier, 425 - $branch) { 426 - 427 - $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 428 - 'repositoryID = %d AND commitIdentifier = %s', 429 - $repository->getID(), 430 - $commit_identifier); 431 - 432 - if (!$commit) { 433 - // This can happen if the phabricator DB doesn't have the commit info, 434 - // or the commit is so big that phabricator couldn't parse it. In this 435 - // case we just ignore it. 436 - return; 437 - } 438 - 439 - $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( 440 - 'commitID = %d', 441 - $commit->getID()); 442 - if (!$data) { 443 - $data = new PhabricatorRepositoryCommitData(); 444 - $data->setCommitID($commit->getID()); 445 - } 446 - $branches = $data->getCommitDetail('seenOnBranches', array()); 447 - $branches[] = $branch; 448 - $data->setCommitDetail('seenOnBranches', $branches); 449 - $data->save(); 450 - 451 - $this->insertTask( 452 - $repository, 453 - $commit, 454 - array( 455 - 'only' => true 456 - )); 457 - } 458 - 459 387 private function insertTask( 460 388 PhabricatorRepository $repository, 461 389 PhabricatorRepositoryCommit $commit, ··· 566 494 return; 567 495 } 568 496 497 + $branches = $this->sortBranches($repository, $branches); 498 + 569 499 $callsign = $repository->getCallsign(); 570 500 571 501 $tracked_something = false; ··· 586 516 } 587 517 588 518 $this->log("Looking for new commits."); 589 - $this->executeGitDiscoverCommit($repository, $commit, $name, false); 519 + $this->executeGitDiscoverCommit( 520 + $repository, 521 + $commit, 522 + $repository->shouldAutocloseBranch($name)); 590 523 } 591 524 592 525 if (!$tracked_something) { ··· 596 529 "Repository r{$repo_callsign} '{$repo_name}' has no tracked branches! ". 597 530 "Verify that your branch filtering settings are correct."); 598 531 } 532 + } 599 533 534 + /** 535 + * Sort branches so we process closeable branches first. This makes the 536 + * whole import process a little cheaper, since we can close these commits 537 + * the first time through rather than catching them in the refs step. 538 + */ 539 + private function sortBranches( 540 + PhabricatorRepository $repository, 541 + array $branches) { 600 542 601 - $this->log("Discovering commits on autoclose branches..."); 543 + $head_branches = array(); 544 + $tail_branches = array(); 602 545 foreach ($branches as $name => $commit) { 603 - $this->log("Examining branch '{$name}', at {$commit}'."); 604 - if (!$repository->shouldTrackBranch($name)) { 605 - $this->log("Skipping, branch is untracked."); 606 - continue; 546 + if ($repository->shouldAutocloseBranch($name)) { 547 + $head_branches[$name] = $commit; 548 + } else { 549 + $tail_branches[$name] = $commit; 607 550 } 551 + } 608 552 609 - if (!$repository->shouldAutocloseBranch($name)) { 610 - $this->log("Skipping, branch is not autoclose."); 611 - continue; 612 - } 613 - 614 - if ($this->isKnownCommitOnAnyAutocloseBranch($repository, $commit)) { 615 - $this->log("Skipping, commit is known on an autoclose branch."); 616 - continue; 617 - } 618 - 619 - $this->log("Looking for new autoclose commits."); 620 - $this->executeGitDiscoverCommit($repository, $commit, $name, true); 621 - } 553 + return $head_branches + $tail_branches; 622 554 } 623 - 624 555 625 556 626 557 /** ··· 629 560 private function executeGitDiscoverCommit( 630 561 PhabricatorRepository $repository, 631 562 $commit, 632 - $branch, 633 - $autoclose) { 563 + $close_immediately) { 634 564 635 565 $discover = array($commit); 636 566 $insert = array($commit); ··· 651 581 continue; 652 582 } 653 583 $seen_parent[$parent] = true; 654 - if ($autoclose) { 655 - $known = $this->isKnownCommitOnAnyAutocloseBranch( 656 - $repository, 657 - $parent); 658 - } else { 659 - $known = $this->isKnownCommit($repository, $parent); 660 - } 584 + $known = $this->isKnownCommit($repository, $parent); 661 585 if (!$known) { 662 - $this->log("Discovered commit '{$parent}'."); 586 + $this->log(pht('Discovered commit "%s".', $parent)); 663 587 $discover[] = $parent; 664 588 $insert[] = $parent; 665 589 } ··· 670 594 } 671 595 672 596 $n = count($insert); 673 - if ($autoclose) { 674 - $this->log("Found {$n} new autoclose commits on branch '{$branch}'."); 675 - } else { 676 - $this->log("Found {$n} new commits on branch '{$branch}'."); 677 - } 597 + $this->log(pht('Found %d new commits.', new PhutilNumber($n))); 678 598 679 599 while (true) { 680 600 $target = array_pop($insert); 681 601 $epoch = $stream->getCommitDate($target); 682 602 $epoch = trim($epoch); 683 603 684 - if ($autoclose) { 685 - $this->updateCommit($repository, $target, $branch); 686 - } else { 687 - $this->recordCommit($repository, $target, $epoch, $branch); 688 - } 604 + $this->recordCommit($repository, $target, $epoch, $close_immediately); 689 605 690 606 if (empty($insert)) { 691 607 break;
+3
src/applications/repository/storage/PhabricatorRepository.php
··· 557 557 return true; 558 558 } 559 559 560 + // TODO: Remove this eventually, it's no longer written to by the import 561 + // pipeline (however, old tasks may still be queued which don't reflect 562 + // the new data format). 560 563 $branches = $data->getCommitDetail('seenOnBranches', array()); 561 564 foreach ($branches as $branch) { 562 565 if ($this->shouldAutocloseBranch($branch)) {