@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.

Add vebose logging to PhutilRepositoryPullDaemon

Summary: Add verbose logging. This logging is activated by setting "phd.verbose" in the config, running "phd debug", or explicitly in scripts/repository/pull.php and scripst/repository/discover.php

Test Plan:
>>> orbital ~/devtools/phabricator $ ./scripts/repository/discover.php GTEST
Discovering 'GTEST'...
<VERB> PhabricatorRepositoryPullLocalDaemon Discovering commits in repository 'GTEST'...
<VERB> PhabricatorRepositoryPullLocalDaemon Examining branch '()_+abcd$100', at a37bc285a12efa7224fe19f3df54cd90fa2b897a.
<VERB> PhabricatorRepositoryPullLocalDaemon Skipping, HEAD is known.
<VERB> PhabricatorRepositoryPullLocalDaemon Examining branch '+abcd$100', at a37bc285a12efa7224fe19f3df54cd90fa2b897a.
<VERB> PhabricatorRepositoryPullLocalDaemon Skipping, HEAD is known.
<VERB> PhabricatorRepositoryPullLocalDaemon Examining branch '_+abcd$100', at a37bc285a12efa7224fe19f3df54cd90fa2b897a.
<VERB> PhabricatorRepositoryPullLocalDaemon Skipping, HEAD is known.
<VERB> PhabricatorRepositoryPullLocalDaemon Examining branch 'abcd$100', at a37bc285a12efa7224fe19f3df54cd90fa2b897a.
<VERB> PhabricatorRepositoryPullLocalDaemon Skipping, HEAD is known.
<VERB> PhabricatorRepositoryPullLocalDaemon Examining branch 'arcpatch', at 774c7737b2d560a291697126bf4513204ccf661a.
<VERB> PhabricatorRepositoryPullLocalDaemon Skipping, HEAD is known.
<VERB> PhabricatorRepositoryPullLocalDaemon Examining branch 'arcpatch-1', at dc97539bee07293f95990d71f4638335a2531d69.
<VERB> PhabricatorRepositoryPullLocalDaemon Skipping, HEAD is known.
<VERB> PhabricatorRepositoryPullLocalDaemon Examining branch 'arcpatch-2', at 1acfaec313c46dd3caa90448800181fb91b0270f.

Reviewers: jungejason

Reviewed By: jungejason

CC: aran

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

+97 -68
+4 -1
scripts/repository/discover.php
··· 46 46 foreach ($repos as $repo) { 47 47 $callsign = $repo->getCallsign(); 48 48 echo "Discovering '{$callsign}'...\n"; 49 - PhabricatorRepositoryPullLocalDaemon::discoverRepository($repo); 49 + 50 + $daemon = new PhabricatorRepositoryPullLocalDaemon(array()); 51 + $daemon->setVerbose(true); 52 + $daemon->discoverRepository($repo); 50 53 } 51 54 echo "Done.\n";
+4 -1
scripts/repository/pull.php
··· 46 46 foreach ($repos as $repo) { 47 47 $callsign = $repo->getCallsign(); 48 48 echo "Pulling '{$callsign}'...\n"; 49 - PhabricatorRepositoryPullLocalDaemon::pullRepository($repo); 49 + 50 + $daemon = new PhabricatorRepositoryPullLocalDaemon(array()); 51 + $daemon->setVerbose(true); 52 + $daemon->pullRepository($repo); 50 53 } 51 54 echo "Done.\n";
+89 -66
src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
··· 45 45 final class PhabricatorRepositoryPullLocalDaemon 46 46 extends PhabricatorDaemon { 47 47 48 - private static $commitCache = array(); 48 + private $commitCache = array(); 49 49 50 50 51 51 /* -( Pulling Repositories )----------------------------------------------- */ ··· 127 127 } 128 128 129 129 try { 130 - self::pullRepository($repository); 130 + $this->pullRepository($repository); 131 131 132 132 if (!$no_discovery) { 133 133 // TODO: It would be nice to discover only if we pulled something, 134 134 // but this isn't totally trivial. 135 - self::discoverRepository($repository); 135 + $this->discoverRepository($repository); 136 136 } 137 137 138 138 $sleep_for = $repository->getDetail('pull-frequency', $min_sleep); ··· 171 171 /** 172 172 * @task pull 173 173 */ 174 - public static function pullRepository(PhabricatorRepository $repository) { 174 + public function pullRepository(PhabricatorRepository $repository) { 175 175 $vcs = $repository->getVersionControlSystem(); 176 176 177 177 $is_svn = ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_SVN); ··· 202 202 } 203 203 204 204 if ($is_git) { 205 - return self::executeGitCreate($repository, $local_path); 205 + return $this->executeGitCreate($repository, $local_path); 206 206 } else if ($is_hg) { 207 - return self::executeHgCreate($repository, $local_path); 207 + return $this->executeHgCreate($repository, $local_path); 208 208 } 209 209 } else { 210 210 if ($is_git) { 211 - return self::executeGitUpdate($repository, $local_path); 211 + return $this->executeGitUpdate($repository, $local_path); 212 212 } else if ($is_hg) { 213 - return self::executeHgUpdate($repository, $local_path); 213 + return $this->executeHgUpdate($repository, $local_path); 214 214 } 215 215 } 216 216 } 217 217 218 - public static function discoverRepository(PhabricatorRepository $repository) { 218 + public function discoverRepository(PhabricatorRepository $repository) { 219 219 $vcs = $repository->getVersionControlSystem(); 220 220 switch ($vcs) { 221 221 case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 222 - return self::executeGitDiscover($repository); 222 + return $this->executeGitDiscover($repository); 223 223 case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 224 - return self::executeSvnDiscover($repository); 224 + return $this->executeSvnDiscover($repository); 225 225 case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 226 - return self::executeHgDiscover($repository); 226 + return $this->executeHgDiscover($repository); 227 227 default: 228 228 throw new Exception("Unknown VCS '{$vcs}'!"); 229 229 } 230 230 } 231 231 232 232 233 - private static function isKnownCommit( 233 + private function isKnownCommit( 234 234 PhabricatorRepository $repository, 235 235 $target) { 236 236 237 - if (self::getCache($repository, $target)) { 237 + if ($this->getCache($repository, $target)) { 238 238 return true; 239 239 } 240 240 ··· 247 247 return false; 248 248 } 249 249 250 - self::setCache($repository, $target); 251 - while (count(self::$commitCache) > 2048) { 252 - array_shift(self::$commitCache); 250 + $this->setCache($repository, $target); 251 + while (count($this->commitCache) > 2048) { 252 + array_shift($this->commitCache); 253 253 } 254 254 255 255 return true; 256 256 } 257 257 258 - private static function isKnownCommitOnAnyAutocloseBranch( 258 + private function isKnownCommitOnAnyAutocloseBranch( 259 259 PhabricatorRepository $repository, 260 260 $target) { 261 261 ··· 280 280 return false; 281 281 } 282 282 283 - private static function recordCommit( 283 + private function recordCommit( 284 284 PhabricatorRepository $repository, 285 285 $commit_identifier, 286 286 $epoch) { ··· 300 300 )); 301 301 $event->recordEvent(); 302 302 303 - self::insertTask($repository, $commit); 303 + $this->insertTask($repository, $commit); 304 304 305 305 queryfx( 306 306 $repository->establishConnection('w'), ··· 316 316 $commit->getID(), 317 317 $epoch); 318 318 319 - self::setCache($repository, $commit_identifier); 319 + $this->setCache($repository, $commit_identifier); 320 320 } catch (AphrontQueryDuplicateKeyException $ex) { 321 321 // Ignore. This can happen because we discover the same new commit 322 322 // more than once when looking at history, or because of races or 323 323 // data inconsistency or cosmic radiation; in any case, we're still 324 324 // in a good state if we ignore the failure. 325 - self::setCache($repository, $commit_identifier); 325 + $this->setCache($repository, $commit_identifier); 326 326 } 327 327 } 328 328 329 - private static function updateCommit( 329 + private function updateCommit( 330 330 PhabricatorRepository $repository, 331 331 $commit_identifier, 332 332 $branch) { ··· 355 355 $data->setCommitDetail('seenOnBranches', $branches); 356 356 $data->save(); 357 357 358 - self::insertTask( 358 + $this->insertTask( 359 359 $repository, 360 360 $commit, 361 361 array( ··· 363 363 )); 364 364 } 365 365 366 - private static function insertTask( 366 + private function insertTask( 367 367 PhabricatorRepository $repository, 368 368 PhabricatorRepositoryCommit $commit, 369 369 $data = array()) { ··· 392 392 } 393 393 394 394 395 - private static function setCache( 395 + private function setCache( 396 396 PhabricatorRepository $repository, 397 397 $commit_identifier) { 398 398 399 - $key = self::getCacheKey($repository, $commit_identifier); 400 - self::$commitCache[$key] = true; 399 + $key = $this->getCacheKey($repository, $commit_identifier); 400 + $this->commitCache[$key] = true; 401 401 } 402 402 403 - private static function getCache( 403 + private function getCache( 404 404 PhabricatorRepository $repository, 405 405 $commit_identifier) { 406 406 407 - $key = self::getCacheKey($repository, $commit_identifier); 408 - return idx(self::$commitCache, $key, false); 407 + $key = $this->getCacheKey($repository, $commit_identifier); 408 + return idx($this->commitCache, $key, false); 409 409 } 410 410 411 - private static function getCacheKey( 411 + private function getCacheKey( 412 412 PhabricatorRepository $repository, 413 413 $commit_identifier) { 414 414 ··· 423 423 /** 424 424 * @task git 425 425 */ 426 - private static function executeGitCreate( 426 + private function executeGitCreate( 427 427 PhabricatorRepository $repository, 428 428 $path) { 429 429 ··· 437 437 /** 438 438 * @task git 439 439 */ 440 - private static function executeGitUpdate( 440 + private function executeGitUpdate( 441 441 PhabricatorRepository $repository, 442 442 $path) { 443 443 ··· 502 502 /** 503 503 * @task git 504 504 */ 505 - private static function executeGitDiscover( 505 + private function executeGitDiscover( 506 506 PhabricatorRepository $repository) { 507 507 508 508 list($remotes) = $repository->execxLocalCommand( ··· 514 514 "Expected 'Fetch URL' in 'git remote show -n origin'."); 515 515 } 516 516 517 - self::executeGitverifySameOrigin( 517 + self::executeGitVerifySameOrigin( 518 518 $matches[1], 519 519 $repository->getRemoteURI(), 520 520 $repository->getLocalPath()); ··· 525 525 $branches = DiffusionGitBranchQuery::parseGitRemoteBranchOutput( 526 526 $stdout, 527 527 $only_this_remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE); 528 + 529 + $callsign = $repository->getCallsign(); 528 530 529 531 $tracked_something = false; 532 + 533 + $this->log("Discovering commits in repository '{$callsign}'..."); 530 534 foreach ($branches as $name => $commit) { 535 + $this->log("Examining branch '{$name}', at {$commit}."); 531 536 if (!$repository->shouldTrackBranch($name)) { 537 + $this->log("Skipping, branch is untracked."); 532 538 continue; 533 539 } 534 540 535 541 $tracked_something = true; 536 542 537 - if (self::isKnownCommit($repository, $commit)) { 543 + if ($this->isKnownCommit($repository, $commit)) { 544 + $this->log("Skipping, HEAD is known."); 538 545 continue; 539 - } else { 540 - self::executeGitDiscoverCommit($repository, $commit); 541 546 } 547 + 548 + $this->log("Looking for new commits."); 549 + $this->executeGitDiscoverCommit($repository, $commit); 542 550 } 543 551 544 552 if (!$tracked_something) { ··· 549 557 "Verify that your branch filtering settings are correct."); 550 558 } 551 559 560 + 561 + $this->log("Discovering commits on autoclose branches..."); 552 562 foreach ($branches as $name => $commit) { 563 + $this->log("Examining branch '{$name}', at {$commit}'."); 553 564 if (!$repository->shouldTrackBranch($name)) { 565 + $this->log("Skipping, branch is untracked."); 554 566 continue; 555 567 } 556 568 557 569 if (!$repository->shouldAutocloseBranch($name)) { 570 + $this->log("Skipping, branch is not autoclose."); 558 571 continue; 559 572 } 560 573 561 - if (self::isKnownCommitOnAnyAutocloseBranch($repository, $commit)) { 574 + if ($this->isKnownCommitOnAnyAutocloseBranch($repository, $commit)) { 575 + $this->log("Skipping, commit is known on an autoclose branch."); 562 576 continue; 563 577 } 564 578 565 - self::executeGitDiscoverCommit($repository, $commit, $name); 579 + $this->log("Looking for new autoclose commits."); 580 + $this->executeGitDiscoverCommit($repository, $commit, $name); 566 581 } 567 582 } 568 583 ··· 570 585 /** 571 586 * @task git 572 587 */ 573 - private static function executeGitDiscoverCommit( 588 + private function executeGitDiscoverCommit( 574 589 PhabricatorRepository $repository, 575 590 $commit, 576 591 $branch = null) { ··· 596 611 } 597 612 $seen_parent[$parent] = true; 598 613 if ($branch !== null) { 599 - $known = self::isKnownCommitOnAnyAutocloseBranch( 614 + $known = $this->isKnownCommitOnAnyAutocloseBranch( 600 615 $repository, 601 616 $parent); 602 617 } else { 603 - $known = self::isKnownCommit($repository, $parent); 618 + $known = $this->isKnownCommit($repository, $parent); 604 619 } 605 620 if (!$known) { 621 + $this->log("Discovered commit '{$parent}'."); 606 622 $discover[] = $parent; 607 623 $insert[] = $parent; 608 624 } ··· 612 628 } 613 629 } 614 630 631 + $n = count($insert); 632 + if ($branch !== null) { 633 + $this->log("Found {$n} new autoclose commits on branch '{$branch}'."); 634 + } else { 635 + $this->log("Found {$n} new commits."); 636 + } 637 + 615 638 while (true) { 616 639 $target = array_pop($insert); 617 640 list($epoch) = $repository->execxLocalCommand( ··· 620 643 $epoch = trim($epoch); 621 644 622 645 if ($branch !== null) { 623 - self::updateCommit($repository, $target, $branch); 646 + $this->updateCommit($repository, $target, $branch); 624 647 } else { 625 - self::recordCommit($repository, $target, $epoch); 648 + $this->recordCommit($repository, $target, $epoch); 626 649 } 627 650 628 651 if (empty($insert)) { ··· 674 697 /** 675 698 * @task hg 676 699 */ 677 - private static function executeHgCreate( 700 + private function executeHgCreate( 678 701 PhabricatorRepository $repository, 679 702 $path) { 680 703 ··· 688 711 /** 689 712 * @task hg 690 713 */ 691 - private static function executeHgUpdate( 714 + private function executeHgUpdate( 692 715 PhabricatorRepository $repository, 693 716 $path) { 694 717 ··· 725 748 } 726 749 } 727 750 728 - private static function executeHgDiscover(PhabricatorRepository $repository) { 751 + private function executeHgDiscover(PhabricatorRepository $repository) { 729 752 // NOTE: "--debug" gives us 40-character hashes. 730 753 list($stdout) = $repository->execxLocalCommand('--debug branches'); 731 754 ··· 733 756 $got_something = false; 734 757 foreach ($branches as $name => $branch) { 735 758 $commit = $branch['rev']; 736 - if (self::isKnownCommit($repository, $commit)) { 759 + if ($this->isKnownCommit($repository, $commit)) { 737 760 continue; 738 761 } else { 739 - self::executeHgDiscoverCommit($repository, $commit); 762 + $this->executeHgDiscoverCommit($repository, $commit); 740 763 $got_something = true; 741 764 } 742 765 } ··· 744 767 return $got_something; 745 768 } 746 769 747 - private static function executeHgDiscoverCommit( 770 + private function executeHgDiscoverCommit( 748 771 PhabricatorRepository $repository, 749 772 $commit) { 750 773 ··· 767 790 continue; 768 791 } 769 792 $seen_parent[$parent] = true; 770 - if (!self::isKnownCommit($repository, $parent)) { 793 + if (!$this->isKnownCommit($repository, $parent)) { 771 794 $discover[] = $parent; 772 795 $insert[] = $parent; 773 796 } ··· 776 799 777 800 foreach ($insert as $target) { 778 801 $epoch = $stream->getCommitDate($target); 779 - self::recordCommit($repository, $target, $epoch); 802 + $this->recordCommit($repository, $target, $epoch); 780 803 } 781 804 } 782 805 ··· 784 807 /* -( Subversion Implementation )------------------------------------------ */ 785 808 786 809 787 - private static function executeSvnDiscover( 810 + private function executeSvnDiscover( 788 811 PhabricatorRepository $repository) { 789 812 790 - $uri = self::executeSvnGetBaseSVNLogURI($repository); 813 + $uri = $this->executeSvnGetBaseSVNLogURI($repository); 791 814 792 815 list($xml) = $repository->execxRemoteCommand( 793 816 'log --xml --quiet --limit 1 %s@HEAD', 794 817 $uri); 795 818 796 - $results = self::executeSvnParseLogXML($xml); 819 + $results = $this->executeSvnParseLogXML($xml); 797 820 $commit = head_key($results); 798 821 $epoch = head($results); 799 822 800 - if (self::isKnownCommit($repository, $commit)) { 823 + if ($this->isKnownCommit($repository, $commit)) { 801 824 return false; 802 825 } 803 826 804 - self::executeSvnDiscoverCommit($repository, $commit, $epoch); 827 + $this->executeSvnDiscoverCommit($repository, $commit, $epoch); 805 828 return true; 806 829 } 807 830 808 - private static function executeSvnDiscoverCommit( 831 + private function executeSvnDiscoverCommit( 809 832 PhabricatorRepository $repository, 810 833 $commit, 811 834 $epoch) { 812 835 813 - $uri = self::executeSvnGetBaseSVNLogURI($repository); 836 + $uri = $this->executeSvnGetBaseSVNLogURI($repository); 814 837 815 838 $discover = array( 816 839 $commit => $epoch, ··· 819 842 820 843 $limit = 1; 821 844 while ($upper_bound > 1 && 822 - !self::isKnownCommit($repository, $upper_bound)) { 845 + !$this->isKnownCommit($repository, $upper_bound)) { 823 846 // Find all the unknown commits on this path. Note that we permit 824 847 // importing an SVN subdirectory rather than the entire repository, so 825 848 // commits may be nonsequential. ··· 837 860 throw new Exception("svn log error #{$err}: {$stderr}"); 838 861 } 839 862 } 840 - $discover += self::executeSvnParseLogXML($xml); 863 + $discover += $this->executeSvnParseLogXML($xml); 841 864 842 865 $upper_bound = min(array_keys($discover)); 843 866 ··· 856 879 857 880 ksort($discover); 858 881 foreach ($discover as $commit => $epoch) { 859 - self::recordCommit($repository, $commit, $epoch); 882 + $this->recordCommit($repository, $commit, $epoch); 860 883 } 861 884 } 862 885 863 - private static function executeSvnParseLogXML($xml) { 886 + private function executeSvnParseLogXML($xml) { 864 887 $xml = phutil_utf8ize($xml); 865 888 866 889 $result = array(); ··· 876 899 } 877 900 878 901 879 - private static function executeSvnGetBaseSVNLogURI( 902 + private function executeSvnGetBaseSVNLogURI( 880 903 PhabricatorRepository $repository) { 881 904 882 905 $uri = $repository->getDetail('remote-uri');