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

Drive blame generation through `diffusion.blame`

Summary:
Ref T2450. Ref T9319. This is still a bit messy, but not quite so bad as it was: instead of using a single call to get both blame information and file content, use `diffusion.blame` for blame information.

This will make optimizations to both blame and file content easier.

Test Plan: Viewed a bunch of blame (color on/off, blame on/off).

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T2450, T9319

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

+182 -332
-2
src/__phutil_library_map__.php
··· 607 607 'DiffusionGitBranch' => 'applications/diffusion/data/DiffusionGitBranch.php', 608 608 'DiffusionGitBranchTestCase' => 'applications/diffusion/data/__tests__/DiffusionGitBranchTestCase.php', 609 609 'DiffusionGitFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php', 610 - 'DiffusionGitFileContentQueryTestCase' => 'applications/diffusion/query/__tests__/DiffusionGitFileContentQueryTestCase.php', 611 610 'DiffusionGitRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionGitRawDiffQuery.php', 612 611 'DiffusionGitReceivePackSSHWorkflow' => 'applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php', 613 612 'DiffusionGitRequest' => 'applications/diffusion/request/DiffusionGitRequest.php', ··· 4577 4576 'DiffusionGitBranch' => 'Phobject', 4578 4577 'DiffusionGitBranchTestCase' => 'PhabricatorTestCase', 4579 4578 'DiffusionGitFileContentQuery' => 'DiffusionFileContentQuery', 4580 - 'DiffusionGitFileContentQueryTestCase' => 'PhabricatorTestCase', 4581 4579 'DiffusionGitRawDiffQuery' => 'DiffusionRawDiffQuery', 4582 4580 'DiffusionGitReceivePackSSHWorkflow' => 'DiffusionGitSSHWorkflow', 4583 4581 'DiffusionGitRequest' => 'DiffusionRequest',
+4 -2
src/applications/diffusion/DiffusionLintSaveRunner.php
··· 257 257 'path' => $path, 258 258 'commit' => $this->lintCommit, 259 259 )); 260 - $query = DiffusionFileContentQuery::newFromDiffusionRequest($drequest) 261 - ->setNeedsBlame(true); 260 + 261 + // TODO: Restore blame information / generally fix this workflow. 262 + 263 + $query = DiffusionFileContentQuery::newFromDiffusionRequest($drequest); 262 264 $queries[$path] = $query; 263 265 $futures[$path] = $query->getFileContentFuture(); 264 266 }
+4 -12
src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
··· 19 19 return array( 20 20 'path' => 'required string', 21 21 'commit' => 'required string', 22 - 'needsBlame' => 'optional bool', 23 22 'timeout' => 'optional int', 24 23 'byteLimit' => 'optional int', 25 24 ); ··· 27 26 28 27 protected function getResult(ConduitAPIRequest $request) { 29 28 $drequest = $this->getDiffusionRequest(); 30 - $needs_blame = $request->getValue('needsBlame'); 31 - $file_query = DiffusionFileContentQuery::newFromDiffusionRequest( 32 - $drequest); 33 - $file_query 34 - ->setViewer($request->getUser()) 35 - ->setNeedsBlame($needs_blame); 29 + 30 + $file_query = DiffusionFileContentQuery::newFromDiffusionRequest($drequest) 31 + ->setViewer($request->getUser()); 36 32 37 33 $timeout = $request->getValue('timeout'); 38 34 if ($timeout) { ··· 46 42 47 43 $file_content = $file_query->loadFileContent(); 48 44 49 - if ($needs_blame) { 50 - list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); 51 - } else { 52 - $text_list = $rev_list = $blame_dict = array(); 53 - } 45 + $text_list = $rev_list = $blame_dict = array(); 54 46 55 47 $file_content 56 48 ->setBlameDict($blame_dict)
+130 -74
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 130 130 $params = array( 131 131 'commit' => $drequest->getCommit(), 132 132 'path' => $drequest->getPath(), 133 - 'needsBlame' => $needs_blame, 134 133 ); 135 134 136 135 $byte_limit = null; ··· 572 571 $path, 573 572 $data) { 574 573 574 + $viewer = $this->getViewer(); 575 + 576 + $blame_handles = array(); 577 + if ($needs_blame) { 578 + $blame = $this->loadBlame($path, $drequest->getCommit()); 579 + if ($blame) { 580 + $author_phids = mpull($blame, 'getAuthorPHID'); 581 + $blame_handles = $viewer->loadHandles($author_phids); 582 + } 583 + } else { 584 + $blame = array(); 585 + } 586 + 587 + $file_corpus = $file_content->getCorpus(); 588 + 575 589 if (!$show_color) { 590 + $lines = phutil_split_lines($file_corpus); 591 + 576 592 $style = 577 593 'border: none; width: 100%; height: 80em; font-family: monospace'; 578 594 if (!$show_blame) { ··· 581 597 array( 582 598 'style' => $style, 583 599 ), 584 - $file_content->getCorpus()); 600 + $file_corpus); 585 601 } else { 586 - $text_list = $file_content->getTextList(); 587 - $rev_list = $file_content->getRevList(); 588 - $blame_dict = $file_content->getBlameDict(); 589 - 590 602 $rows = array(); 591 - foreach ($text_list as $k => $line) { 592 - $rev = $rev_list[$k]; 593 - $author = $blame_dict[$rev]['author']; 594 - $rows[] = 595 - sprintf('%-10s %-20s %s', substr($rev, 0, 7), $author, $line); 603 + foreach ($lines as $line_number => $line) { 604 + $commit = idx($blame, $line_number); 605 + if ($commit) { 606 + $author = $commit->renderAuthorShortName($blame_handles); 607 + $commit_name = $commit->getShortName(); 608 + } else { 609 + $author = null; 610 + $commit_name = null; 611 + } 612 + 613 + $rows[] = sprintf( 614 + '%-10s %-20s %s', 615 + $commit_name, 616 + $author, 617 + $line); 596 618 } 597 619 598 620 $corpus = phutil_tag( ··· 600 622 array( 601 623 'style' => $style, 602 624 ), 603 - implode("\n", $rows)); 625 + implode('', $rows)); 604 626 } 605 627 } else { 606 628 require_celerity_resource('syntax-highlighting-css'); 607 - $text_list = $file_content->getTextList(); 608 - $rev_list = $file_content->getRevList(); 609 - $blame_dict = $file_content->getBlameDict(); 610 629 611 - $text_list = implode("\n", $text_list); 612 - $text_list = PhabricatorSyntaxHighlighter::highlightWithFilename( 630 + $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename( 613 631 $path, 614 - $text_list); 615 - $text_list = explode("\n", $text_list); 632 + $file_corpus); 633 + $lines = phutil_split_lines($highlighted); 616 634 617 - $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, 618 - $needs_blame, $drequest, $show_blame, $show_color); 635 + $rows = $this->buildDisplayRows( 636 + $lines, 637 + $blame, 638 + $show_blame, 639 + $show_color); 619 640 620 641 $corpus_table = javelin_tag( 621 642 'table', ··· 824 845 825 846 826 847 private function buildDisplayRows( 827 - array $text_list, 828 - array $rev_list, 829 - array $blame_dict, 830 - $needs_blame, 831 - DiffusionRequest $drequest, 832 - $show_blame, 833 - $show_color) { 848 + array $lines, 849 + array $blame, 850 + $show_color, 851 + $show_blame) { 852 + 853 + $drequest = $this->getDiffusionRequest(); 834 854 835 855 $handles = array(); 836 - if ($blame_dict) { 837 - $epoch_list = ipull(ifilter($blame_dict, 'epoch'), 'epoch'); 856 + if ($blame) { 857 + $epoch_list = mpull($blame, 'getEpoch', 'getID'); 858 + $epoch_list = array_filter($epoch_list); 859 + $epoch_list = array_unique($epoch_list); 860 + $epoch_list = array_values($epoch_list); 861 + 838 862 $epoch_min = min($epoch_list); 839 863 $epoch_max = max($epoch_list); 840 864 $epoch_range = ($epoch_max - $epoch_min) + 1; 865 + } 841 866 842 - $author_phids = ipull(ifilter($blame_dict, 'authorPHID'), 'authorPHID'); 843 - $handles = $this->loadViewerHandles($author_phids); 844 - } 845 867 846 868 $line_arr = array(); 847 869 $line_str = $drequest->getLine(); ··· 864 886 $display = array(); 865 887 866 888 $line_number = 1; 867 - $last_rev = null; 889 + $last_commit = null; 868 890 $color = null; 869 - foreach ($text_list as $k => $line) { 891 + foreach ($lines as $line_index => $line) { 870 892 $display_line = array( 871 893 'epoch' => null, 872 894 'commit' => null, ··· 882 904 // with same color; otherwise generate blame info. The newer a change 883 905 // is, the more saturated the color. 884 906 885 - $rev = idx($rev_list, $k, $last_rev); 907 + $commit = idx($blame, $line_index, $last_commit); 886 908 887 - if ($last_rev == $rev) { 909 + if ($commit && $last_commit && 910 + ($last_commit->getID() == $commit->getID())) { 888 911 $display_line['color'] = $color; 889 912 } else { 890 - $blame = $blame_dict[$rev]; 913 + if ($commit) { 914 + $epoch = $commit->getEpoch(); 915 + } else { 916 + $epoch = null; 917 + } 891 918 892 - if (!isset($blame['epoch'])) { 893 - $color = '#ffd'; // Render as warning. 919 + if (!$epoch) { 920 + if (!$blame) { 921 + $color = '#f6f6f6'; 922 + } else { 923 + $color = '#ffd'; // Render as warning. 924 + } 894 925 } else { 895 - $color_ratio = ($blame['epoch'] - $epoch_min) / $epoch_range; 926 + $color_ratio = ($epoch - $epoch_min) / $epoch_range; 896 927 $color_value = 0xE6 * (1.0 - $color_ratio); 897 928 $color = sprintf( 898 929 '#%02x%02x%02x', ··· 901 932 $color_value); 902 933 } 903 934 904 - $display_line['epoch'] = idx($blame, 'epoch'); 935 + $display_line['epoch'] = $epoch; 905 936 $display_line['color'] = $color; 906 - $display_line['commit'] = $rev; 907 937 908 - $author_phid = idx($blame, 'authorPHID'); 909 - if ($author_phid && $handles[$author_phid]) { 910 - $author_link = $handles[$author_phid]->renderLink(); 938 + if ($commit) { 939 + $display_line['commit'] = $commit; 911 940 } else { 912 - $author_link = $blame['author']; 941 + $display_line['commit'] = null; 913 942 } 914 - $display_line['author'] = $author_link; 915 943 916 - $last_rev = $rev; 944 + $last_commit = $commit; 917 945 } 918 946 } 919 947 ··· 936 964 $request = $this->getRequest(); 937 965 $viewer = $request->getUser(); 938 966 939 - $commits = array_filter(ipull($display, 'commit')); 940 - if ($commits) { 941 - $commits = id(new DiffusionCommitQuery()) 942 - ->setViewer($viewer) 943 - ->withRepository($drequest->getRepository()) 944 - ->withIdentifiers($commits) 945 - ->execute(); 946 - $commits = mpull($commits, null, 'getCommitIdentifier'); 947 - } 967 + $commits = mpull($blame, null, 'getCommitIdentifier'); 948 968 949 969 $revision_ids = id(new DifferentialRevision()) 950 970 ->loadIDsByCommitPHIDs(mpull($commits, 'getPHID')); ··· 957 977 } 958 978 959 979 $phids = array(); 960 - foreach ($commits as $commit) { 961 - if ($commit->getAuthorPHID()) { 962 - $phids[] = $commit->getAuthorPHID(); 980 + foreach ($commits as $blame_commit) { 981 + if ($blame_commit->getAuthorPHID()) { 982 + $phids[] = $blame_commit->getAuthorPHID(); 963 983 } 964 984 } 965 985 foreach ($revisions as $revision) { ··· 1002 1022 $engine); 1003 1023 1004 1024 foreach ($display as $line) { 1005 - 1006 1025 $line_href = $drequest->generateURI( 1007 1026 array( 1008 1027 'action' => 'browse', ··· 1023 1042 if (idx($line, 'commit')) { 1024 1043 $commit = $line['commit']; 1025 1044 1026 - if (idx($commits, $commit)) { 1045 + if ($commit) { 1027 1046 $tooltip = $this->renderCommitTooltip( 1028 - $commits[$commit], 1047 + $commit, 1029 1048 $handles, 1030 - $line['author']); 1049 + $commit->renderAuthorLink($handles)); 1031 1050 } else { 1032 1051 $tooltip = null; 1033 1052 } ··· 1041 1060 'href' => $drequest->generateURI( 1042 1061 array( 1043 1062 'action' => 'commit', 1044 - 'commit' => $line['commit'], 1063 + 'commit' => $commit->getCommitIdentifier(), 1045 1064 )), 1046 1065 'sigil' => 'has-tooltip', 1047 1066 'meta' => array( ··· 1050 1069 'size' => 600, 1051 1070 ), 1052 1071 ), 1053 - id(new PhutilUTF8StringTruncator()) 1054 - ->setMaximumGlyphs(9) 1055 - ->setTerminator('') 1056 - ->truncateString($line['commit'])); 1072 + $commit->getShortName()); 1057 1073 1058 1074 $revision_id = null; 1059 - if (idx($commits, $commit)) { 1060 - $revision_id = idx($revision_ids, $commits[$commit]->getPHID()); 1075 + if ($commit) { 1076 + $revision_id = idx($revision_ids, $commit->getPHID()); 1061 1077 } 1062 1078 1063 1079 if ($revision_id) { ··· 1207 1223 1208 1224 private function renderInlines( 1209 1225 array $inlines, 1210 - $needs_blame, 1226 + $show_blame, 1211 1227 $has_coverage, 1212 1228 $engine) { 1213 1229 ··· 1222 1238 ->setInlineComment($inline) 1223 1239 ->render(); 1224 1240 1225 - $row = array_fill(0, ($needs_blame ? 3 : 1), phutil_tag('th')); 1241 + $row = array_fill(0, ($show_blame ? 3 : 1), phutil_tag('th')); 1226 1242 1227 1243 $row[] = phutil_tag('td', array(), $inline_view); 1228 1244 ··· 1720 1736 $view->setHandles($handles); 1721 1737 1722 1738 return $view; 1739 + } 1740 + 1741 + private function loadBlame($path, $commit) { 1742 + $blame = $this->callConduitWithDiffusionRequest( 1743 + 'diffusion.blame', 1744 + array( 1745 + 'commit' => $commit, 1746 + 'paths' => array($path), 1747 + )); 1748 + 1749 + $identifiers = idx($blame, $path, array()); 1750 + 1751 + if ($identifiers) { 1752 + $viewer = $this->getViewer(); 1753 + $drequest = $this->getDiffusionRequest(); 1754 + $repository = $drequest->getRepository(); 1755 + 1756 + $commits = id(new DiffusionCommitQuery()) 1757 + ->setViewer($viewer) 1758 + ->withRepository($repository) 1759 + ->withIdentifiers($identifiers) 1760 + // TODO: We only fetch this to improve author display behavior, but 1761 + // shouldn't really need to? 1762 + ->needCommitData(true) 1763 + ->execute(); 1764 + $commits = mpull($commits, null, 'getCommitIdentifier'); 1765 + } else { 1766 + $commits = array(); 1767 + } 1768 + 1769 + foreach ($identifiers as $key => $identifier) { 1770 + $commit = idx($commits, $identifier); 1771 + if ($commit) { 1772 + $identifiers[$key] = $commit; 1773 + } else { 1774 + $identifiers[$key] = null; 1775 + } 1776 + } 1777 + 1778 + return $identifiers; 1723 1779 } 1724 1780 1725 1781 }
-32
src/applications/diffusion/query/__tests__/DiffusionGitFileContentQueryTestCase.php
··· 1 - <?php 2 - 3 - final class DiffusionGitFileContentQueryTestCase extends PhabricatorTestCase { 4 - 5 - public function testAuthorName() { 6 - // A normal case - no parenthesis in user name 7 - $result = DiffusionGitFileContentQuery::match( 8 - '8220d5d54f6d5d5552a636576cbe9c35f15b65b2 '. 9 - '(Andrew Gallagher 2010-12-03 324) $somevar = $this->call()'); 10 - $this->assertEqual($result[0], '8220d5d54f6d5d5552a636576cbe9c35f15b65b2'); 11 - $this->assertEqual($result[1], 'Andrew Gallagher'); 12 - $this->assertEqual($result[2], ' $somevar = $this->call()'); 13 - 14 - // User name like 'Jimmy (He) Zhang' 15 - $result = DiffusionGitFileContentQuery::match( 16 - '8220d5d54f6d5d5552a636576cbe9c35f15b65b2 '. 17 - '( Jimmy (He) Zhang 2013-10-11 5) '. 18 - 'code(); "(string literal 9999-99-99 2)"; more_code();'); 19 - $this->assertEqual($result[1], 'Jimmy (He) Zhang'); 20 - $this->assertEqual($result[2], 21 - ' code(); "(string literal 9999-99-99 2)"; more_code();'); 22 - 23 - // User name like 'Scott Shapiro (Ads Product Marketing)' 24 - $result = DiffusionGitFileContentQuery::match( 25 - '8220d5d54f6d5d5552a636576cbe9c35f15b65b2 '. 26 - '( Scott Shapiro (Ads Product Marketing) 2013-10-11 5) '. 27 - 'code(); "(string literal 9999-99-99 2)"; more_code();'); 28 - $this->assertEqual($result[1], 'Scott Shapiro (Ads Product Marketing)'); 29 - $this->assertEqual($result[2], 30 - ' code(); "(string literal 9999-99-99 2)"; more_code();'); 31 - } 32 - }
+9 -107
src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
··· 8 8 */ 9 9 abstract class DiffusionFileContentQuery extends DiffusionQuery { 10 10 11 - private $needsBlame; 12 11 private $fileContent; 13 12 private $viewer; 14 13 private $timeout; ··· 30 29 31 30 public function getByteLimit() { 32 31 return $this->byteLimit; 32 + } 33 + 34 + public function setViewer(PhabricatorUser $user) { 35 + $this->viewer = $user; 36 + return $this; 37 + } 38 + 39 + public function getViewer() { 40 + return $this->viewer; 33 41 } 34 42 35 43 final public static function newFromDiffusionRequest( ··· 90 98 return $this->fileContent->getCorpus(); 91 99 } 92 100 93 - /** 94 - * Pretty hairy function. If getNeedsBlame is false, this returns 95 - * 96 - * ($text_list, array(), array()) 97 - * 98 - * Where $text_list is the raw file content with trailing new lines stripped. 99 - * 100 - * If getNeedsBlame is true, this returns 101 - * 102 - * ($text_list, $line_rev_dict, $blame_dict) 103 - * 104 - * Where $text_list is just the lines of code -- the raw file content will 105 - * contain lots of blame data, $line_rev_dict is a dictionary of line number 106 - * => revision id, and $blame_dict is another complicated data structure. 107 - * In detail, $blame_dict contains [revision id][author] keys, as well 108 - * as [commit id][authorPhid] and [commit id][epoch] keys. 109 - * 110 - * @return ($text_list, $line_rev_dict, $blame_dict) 111 - */ 112 - final public function getBlameData() { 113 - $raw_data = preg_replace('/\n$/', '', $this->getRawData()); 114 - 115 - $text_list = array(); 116 - $line_rev_dict = array(); 117 - $blame_dict = array(); 118 - 119 - if (!$this->getNeedsBlame()) { 120 - $text_list = explode("\n", $raw_data); 121 - } else if ($raw_data != '') { 122 - $lines = array(); 123 - foreach (explode("\n", $raw_data) as $k => $line) { 124 - $lines[$k] = $this->tokenizeLine($line); 125 - 126 - list($rev_id, $author, $text) = $lines[$k]; 127 - $text_list[$k] = $text; 128 - $line_rev_dict[$k] = $rev_id; 129 - } 130 - 131 - $line_rev_dict = $this->processRevList($line_rev_dict); 132 - 133 - foreach ($lines as $k => $line) { 134 - list($rev_id, $author, $text) = $line; 135 - $rev_id = $line_rev_dict[$k]; 136 - 137 - if (!isset($blame_dict[$rev_id])) { 138 - $blame_dict[$rev_id]['author'] = $author; 139 - } 140 - } 141 - 142 - $repository = $this->getRequest()->getRepository(); 143 - 144 - $commits = id(new DiffusionCommitQuery()) 145 - ->setViewer($this->getViewer()) 146 - ->withDefaultRepository($repository) 147 - ->withIdentifiers(array_unique($line_rev_dict)) 148 - ->execute(); 149 - 150 - foreach ($commits as $commit) { 151 - $blame_dict[$commit->getCommitIdentifier()]['epoch'] = 152 - $commit->getEpoch(); 153 - } 154 - 155 - if ($commits) { 156 - $commits_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere( 157 - 'commitID IN (%Ls)', 158 - mpull($commits, 'getID')); 159 - 160 - foreach ($commits_data as $data) { 161 - $author_phid = $data->getCommitDetail('authorPHID'); 162 - if (!$author_phid) { 163 - continue; 164 - } 165 - $commit = $commits[$data->getCommitID()]; 166 - $commit_identifier = $commit->getCommitIdentifier(); 167 - $blame_dict[$commit_identifier]['authorPHID'] = $author_phid; 168 - } 169 - } 170 - 171 - } 172 - 173 - return array($text_list, $line_rev_dict, $blame_dict); 174 - } 175 - 176 - abstract protected function tokenizeLine($line); 177 - 178 - public function setNeedsBlame($needs_blame) { 179 - $this->needsBlame = $needs_blame; 180 - return $this; 181 - } 182 - 183 - public function getNeedsBlame() { 184 - return $this->needsBlame; 185 - } 186 - 187 - public function setViewer(PhabricatorUser $user) { 188 - $this->viewer = $user; 189 - return $this; 190 - } 191 - 192 - public function getViewer() { 193 - return $this->viewer; 194 - } 195 - 196 - protected function processRevList(array $rev_list) { 197 - return $rev_list; 198 - } 199 101 }
+4 -35
src/applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php
··· 9 9 $path = $drequest->getPath(); 10 10 $commit = $drequest->getCommit(); 11 11 12 - if ($this->getNeedsBlame()) { 13 - return $repository->getLocalCommandFuture( 14 - '--no-pager blame -c -l --date=short %s -- %s', 15 - $commit, 16 - $path); 17 - } else { 18 - return $repository->getLocalCommandFuture( 19 - 'cat-file blob %s:%s', 20 - $commit, 21 - $path); 22 - } 12 + return $repository->getLocalCommandFuture( 13 + 'cat-file blob %s:%s', 14 + $commit, 15 + $path); 23 16 } 24 17 25 18 protected function executeQueryFromFuture(Future $future) { ··· 29 22 $file_content->setCorpus($corpus); 30 23 31 24 return $file_content; 32 - } 33 - 34 - protected function tokenizeLine($line) { 35 - return self::match($line); 36 - } 37 - 38 - public static function match($line) { 39 - $m = array(); 40 - // sample lines: 41 - // 42 - // d1b4fcdd2a7c8c0f8cbdd01ca839d992135424dc 43 - // ( hzhao 2009-05-01 202)function print(); 44 - // 45 - // 8220d5d54f6d5d5552a636576cbe9c35f15b65b2 46 - // (Andrew Gallagher 2010-12-03 324) 47 - // // Add the lines for trailing context 48 - preg_match( 49 - '/^\s*?(\S+?)\s*\(\s*(.*?)\s+\d{4}-\d{2}-\d{2}\s+\d+\)(.*)?$/', 50 - $line, 51 - $m); 52 - $rev_id = $m[1]; 53 - $author = $m[2]; 54 - $text = idx($m, 3); 55 - return array($rev_id, $author, $text); 56 25 } 57 26 58 27 }
+4 -54
src/applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php
··· 10 10 $path = $drequest->getPath(); 11 11 $commit = $drequest->getCommit(); 12 12 13 - if ($this->getNeedsBlame()) { 14 - // NOTE: We're using "--number" instead of "--changeset" because there is 15 - // no way to get "--changeset" to show us the full commit hashes. 16 - return $repository->getLocalCommandFuture( 17 - 'annotate --user --number --rev %s -- %s', 18 - $commit, 19 - $path); 20 - } else { 21 - return $repository->getLocalCommandFuture( 22 - 'cat --rev %s -- %s', 23 - $commit, 24 - $path); 25 - } 13 + return $repository->getLocalCommandFuture( 14 + 'cat --rev %s -- %s', 15 + $commit, 16 + $path); 26 17 } 27 18 28 19 protected function executeQueryFromFuture(Future $future) { ··· 32 23 $file_content->setCorpus($corpus); 33 24 34 25 return $file_content; 35 - } 36 - 37 - protected function tokenizeLine($line) { 38 - $matches = null; 39 - 40 - preg_match( 41 - '/^(.*?)\s+([0-9]+): (.*)$/', 42 - $line, 43 - $matches); 44 - 45 - return array($matches[2], $matches[1], $matches[3]); 46 - } 47 - 48 - /** 49 - * Convert local revision IDs into full commit identifier hashes. 50 - */ 51 - protected function processRevList(array $rev_list) { 52 - $drequest = $this->getRequest(); 53 - $repository = $drequest->getRepository(); 54 - 55 - $revs = array_unique($rev_list); 56 - foreach ($revs as $key => $rev) { 57 - $revs[$key] = '--rev '.(int)$rev; 58 - } 59 - 60 - list($stdout) = $repository->execxLocalCommand( 61 - 'log --template=%s %C', 62 - '{rev} {node}\\n', 63 - implode(' ', $revs)); 64 - 65 - $map = array(); 66 - foreach (explode("\n", trim($stdout)) as $line) { 67 - list($rev, $node) = explode(' ', $line); 68 - $map[$rev] = $node; 69 - } 70 - 71 - foreach ($rev_list as $k => $rev) { 72 - $rev_list[$k] = $map[$rev]; 73 - } 74 - 75 - return $rev_list; 76 26 } 77 27 78 28 }
+1 -14
src/applications/diffusion/query/filecontent/DiffusionSvnFileContentQuery.php
··· 10 10 $commit = $drequest->getCommit(); 11 11 12 12 return $repository->getRemoteCommandFuture( 13 - '%C %s', 14 - $this->getNeedsBlame() ? 'blame --force' : 'cat', 13 + 'cat %s', 15 14 $repository->getSubversionPathURI($path, $commit)); 16 15 } 17 16 ··· 39 38 $file_content->setCorpus($corpus); 40 39 41 40 return $file_content; 42 - } 43 - 44 - protected function tokenizeLine($line) { 45 - // sample line: 46 - // 347498 yliu function print(); 47 - $m = array(); 48 - preg_match('/^\s*(\d+)\s+(\S+)(?: (.*))?$/', $line, $m); 49 - $rev_id = $m[1]; 50 - $author = $m[2]; 51 - $text = idx($m, 3); 52 - 53 - return array($rev_id, $author, $text); 54 41 } 55 42 56 43 }
+26
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 266 266 return $repository->formatCommitName($identifier); 267 267 } 268 268 269 + public function getShortName() { 270 + $identifier = $this->getCommitIdentifier(); 271 + return substr($identifier, 0, 9); 272 + } 273 + 274 + public function renderAuthorLink($handles) { 275 + $author_phid = $this->getAuthorPHID(); 276 + if ($author_phid && isset($handles[$author_phid])) { 277 + return $handles[$author_phid]->renderLink(); 278 + } 279 + 280 + return $this->renderAuthorShortName($handles); 281 + } 282 + 283 + public function renderAuthorShortName($handles) { 284 + $author_phid = $this->getAuthorPHID(); 285 + if ($author_phid && isset($handles[$author_phid])) { 286 + return $handles[$author_phid]->getName(); 287 + } 288 + 289 + $data = $this->getCommitData(); 290 + $name = $data->getAuthorName(); 291 + 292 + $parsed = new PhutilEmailAddress($name); 293 + return nonempty($parsed->getDisplayName(), $parsed->getAddress()); 294 + } 269 295 270 296 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 271 297