Skip to content

Commit 07f4772

Browse files
author
epriestley
committed
Make all parsers use credentials
Summary: We need to issue all commands as $repository->junk() so we can pick up credentials. Some of this stuff predates that change landing. (I removed the "https" vs "svn+ssh" fallback code since it's specific to Facebook, affected a tiny number of commits, is basically an SVN bug with UTF-8 handling and HTTP support, and doesn't make sense in the general case. The user has the tools they need to force it via "reparse.php" if it's really an issue.) Test Plan: Created new authenticated-remote mercurial and git repositories and pulled/discovered them with credentials. Reviewers: Makinde, jungejason, nh, tuomaspelkonen, aran Reviewed By: Makinde CC: aran, Makinde Differential Revision: 970
1 parent b1e1b1f commit 07f4772

13 files changed

+51
-66
lines changed

src/applications/repository/daemon/commitdiscovery/git/PhabricatorRepositoryGitCommitDiscoveryDaemon.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ protected function discoverCommits() {
3232

3333
$repository_phid = $repository->getPHID();
3434

35-
$repo_base = $repository->getDetail('local-path');
36-
list($stdout) = execx(
37-
'(cd %s && git branch -r --verbose --no-abbrev)',
38-
$repo_base);
35+
list($stdout) = $repository->execxLocalCommand(
36+
'branch -r --verbose --no-abbrev');
3937

4038
$branches = DiffusionGitBranchQuery::parseGitRemoteBranchOutput($stdout);
4139

@@ -57,7 +55,6 @@ private function discoverCommit($commit) {
5755
$insert = array();
5856

5957
$repository = $this->getRepository();
60-
$repo_base = $repository->getDetail('local-path');
6158

6259
$discover[] = $commit;
6360
$insert[] = $commit;
@@ -66,9 +63,8 @@ private function discoverCommit($commit) {
6663

6764
while (true) {
6865
$target = array_pop($discover);
69-
list($parents) = execx(
70-
'(cd %s && git log -n1 --pretty="%%P" %s)',
71-
$repo_base,
66+
list($parents) = $repository->execxLocalCommand(
67+
'log -n1 --pretty="%%P" %s',
7268
$target);
7369
$parents = array_filter(explode(' ', trim($parents)));
7470
foreach ($parents as $parent) {
@@ -93,9 +89,8 @@ private function discoverCommit($commit) {
9389

9490
while (true) {
9591
$target = array_pop($insert);
96-
list($epoch) = execx(
97-
'(cd %s && git log -n1 --pretty="%%at" %s)',
98-
$repo_base,
92+
list($epoch) = $repository->execxLocalCommand(
93+
'log -n1 --pretty="%%at" %s',
9994
$target);
10095
$epoch = trim($epoch);
10196

src/applications/repository/daemon/commitdiscovery/git/__init__.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@
1010
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
1111
phutil_require_module('phabricator', 'applications/repository/daemon/commitdiscovery/base');
1212

13-
phutil_require_module('phutil', 'future/exec');
14-
1513

1614
phutil_require_source('PhabricatorRepositoryGitCommitDiscoveryDaemon.php');

src/applications/repository/daemon/commitdiscovery/mercurial/PhabricatorRepositoryMercurialCommitDiscoveryDaemon.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ protected function discoverCommits() {
2929

3030
$repository_phid = $repository->getPHID();
3131

32-
$repo_base = $repository->getDetail('local-path');
3332
list($stdout) = $repository->execxLocalCommand('branches');
3433

3534
$branches = ArcanistMercurialParser::parseMercurialBranches($stdout);

src/applications/repository/daemon/commitdiscovery/svn/PhabricatorRepositorySvnCommitDiscoveryDaemon.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ protected function discoverCommits() {
2929

3030
$uri = $this->getBaseSVNLogURI();
3131
list($xml) = $repository->execxRemoteCommand(
32-
' log --xml --quiet --limit 1 %s@HEAD',
33-
$uri);
32+
'log --xml --quiet --limit 1 %s@HEAD',
33+
$uri);
3434

3535
$results = $this->parseSVNLogXML($xml);
3636
$commit = key($results);

src/applications/repository/daemon/gitfetch/PhabricatorRepositoryGitFetchDaemon.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@ protected function getSupportedRepositoryType() {
2323
return PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;
2424
}
2525

26-
protected function executeCreate($remote_uri, $local_path) {
27-
execx('git clone %s %s', $remote_uri, rtrim($local_path, '/'));
26+
protected function executeCreate(
27+
PhabricatorRepository $repository,
28+
$local_path) {
29+
30+
$repository->execxRemoteCommand(
31+
'clone %s %s',
32+
$repository->getRemoteURI(),
33+
rtrim($local_path, '/'));
2834
}
2935

30-
protected function executeUpdate($remote_uri, $local_path) {
31-
execx('(cd %s && git fetch --all)', $local_path);
36+
protected function executeUpdate(
37+
PhabricatorRepository $repository,
38+
$local_path) {
39+
40+
$repository->execxLocalCommand(
41+
'fetch --all');
3242
}
3343

3444
}

src/applications/repository/daemon/gitfetch/__init__.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@
99
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
1010
phutil_require_module('phabricator', 'applications/repository/daemon/pulllocal');
1111

12-
phutil_require_module('phutil', 'future/exec');
13-
1412

1513
phutil_require_source('PhabricatorRepositoryGitFetchDaemon.php');

src/applications/repository/daemon/mercurialpull/PhabricatorRepositoryMercurialPullDaemon.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ protected function getSupportedRepositoryType() {
2323
return PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL;
2424
}
2525

26-
protected function executeCreate($remote_uri, $local_path) {
27-
execx('hg clone %s %s', $remote_uri, rtrim($local_path, '/'));
26+
protected function executeCreate(
27+
PhabricatorRepository $repository,
28+
$local_path) {
29+
$repository->execxRemoteCommand(
30+
'clone %s %s',
31+
$repository->getRemoteURI(),
32+
rtrim($local_path, '/'));
2833
}
2934

30-
protected function executeUpdate($remote_uri, $local_path) {
31-
execx('(cd %s && hg pull -u)', $local_path);
35+
protected function executeUpdate(
36+
PhabricatorRepository $repository,
37+
$local_path) {
38+
$repository->execxLocalCommand(
39+
'pull -u');
3240
}
3341

3442
}

src/applications/repository/daemon/mercurialpull/__init__.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@
99
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
1010
phutil_require_module('phabricator', 'applications/repository/daemon/pulllocal');
1111

12-
phutil_require_module('phutil', 'future/exec');
13-
1412

1513
phutil_require_source('PhabricatorRepositoryMercurialPullDaemon.php');

src/applications/repository/daemon/pulllocal/PhabricatorRepositoryPullLocalDaemon.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ abstract class PhabricatorRepositoryPullLocalDaemon
2020
extends PhabricatorRepositoryDaemon {
2121

2222
abstract protected function getSupportedRepositoryType();
23-
abstract protected function executeCreate($remote_uri, $local_path);
24-
abstract protected function executeUpdate($remote_uri, $local_path);
23+
abstract protected function executeCreate(
24+
PhabricatorRepository $repository,
25+
$local_path);
26+
abstract protected function executeUpdate(
27+
PhabricatorRepository $repository,
28+
$local_path);
2529

2630
final public function run() {
2731
$repository = $this->loadRepository();
@@ -45,21 +49,17 @@ final public function run() {
4549
}
4650

4751
$local_path = $repository->getDetail('local-path');
48-
$remote_uri = $repository->getDetail('remote-uri');
4952

5053
if (!$local_path) {
5154
throw new Exception("No local path is available for this repository.");
5255
}
5356

5457
while (true) {
5558
if (!Filesystem::pathExists($local_path)) {
56-
if (!$remote_uri) {
57-
throw new Exception("No remote URI is available.");
58-
}
5959
execx('mkdir -p %s', dirname($local_path));
60-
$this->executeCreate($remote_uri, $local_path);
60+
$this->executeCreate($repository, $local_path);
6161
} else {
62-
$this->executeUpdate($remote_uri, $local_path);
62+
$this->executeUpdate($repository, $local_path);
6363
}
6464
$this->sleep($repository->getDetail('pull-frequency', 15));
6565
}

src/applications/repository/worker/base/PhabricatorRepositoryCommitParserWorker.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,10 @@ protected function getSVNLogXMLObject($uri, $revision, $verbose = false) {
6767
$verbose = '--verbose';
6868
}
6969

70-
try {
71-
list($xml) = $this->repository->execxRemoteCommand(
72-
"log --xml {$verbose} --limit 1 %s@%d",
73-
$uri,
74-
$revision);
75-
} catch (CommandException $ex) {
76-
// HTTPS is generally faster and more reliable than svn+ssh, but some
77-
// commit messages with non-UTF8 text can't be retrieved over HTTPS, see
78-
// Facebook rE197184 for one example. Make an attempt to fall back to
79-
// svn+ssh if we've failed outright to retrieve the message.
80-
$fallback_uri = new PhutilURI($uri);
81-
if ($fallback_uri->getProtocol() != 'https') {
82-
throw $ex;
83-
}
84-
$fallback_uri->setProtocol('svn+ssh');
85-
list($xml) = execx(
86-
"svn log --xml {$verbose} --limit 1 --non-interactive %s@%d",
87-
$fallback_uri,
88-
$revision);
89-
}
70+
list($xml) = $this->repository->execxRemoteCommand(
71+
"log --xml {$verbose} --limit 1 %s@%d",
72+
$uri,
73+
$revision);
9074

9175
// Subversion may send us back commit messages which won't parse because
9276
// they have non UTF-8 garbage in them. Slam them into valid UTF-8.

0 commit comments

Comments
 (0)