Skip to content

Commit 1bf68e0

Browse files
author
epriestley
committed
Improve Diffusion error messages and UI for partially imported repositories
Summary: - When you have an un-cloned repository, we currently throw random-looking Git/Hg exception. Instead, throw a useful error. - When you have a cloned but undiscovered repository, we show no commits. This is crazy confusing. Instead, show commits as "importing...". - Fix some warnings and errors for empty path table cases, etc. Test Plan: - Wiped database. - Added Mercurial repo without running daemons. Viewed in Diffusion, got a good exception. - Pulled Mercurial repo without discovering it. Got "Importing...". - Discovered Mercurial repo without parsing it. Got "Importing..." plus date information. - Parsed Mercurial repo, got everything working properly. - Added Git repo without running daemons, did all the stuff above, same results. - This doesn't improve SVN much but that's a trickier case since we don't actually make SVN calls and rely only on the parse state. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T776 Differential Revision: https://secure.phabricator.com/D2439
1 parent b98847d commit 1bf68e0

File tree

12 files changed

+131
-23
lines changed

12 files changed

+131
-23
lines changed

src/__phutil_library_map__.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@
373373
'DiffusionRepositoryPath' => 'applications/diffusion/data/repositorypath',
374374
'DiffusionRepositoryTag' => 'applications/diffusion/tag',
375375
'DiffusionRequest' => 'applications/diffusion/request/base',
376+
'DiffusionSetupException' => 'applications/diffusion/exception/setup',
376377
'DiffusionSvnBrowseQuery' => 'applications/diffusion/query/browse/svn',
377378
'DiffusionSvnCommitParentsQuery' => 'applications/diffusion/query/parents/svn',
378379
'DiffusionSvnCommitTagsQuery' => 'applications/diffusion/query/committags/svn',
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2012 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
final class DiffusionSetupException extends AphrontUsageException {
20+
21+
public function __construct($message) {
22+
parent::__construct('Diffusion Setup Exception', $message);
23+
}
24+
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'aphront/exception/usage');
10+
11+
12+
phutil_require_source('DiffusionSetupException.php');

src/applications/diffusion/query/base/DiffusionQuery.php

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,37 @@ final protected function loadCommitsByIdentifiers(array $identifiers) {
7575
$identifiers);
7676
$commits = mpull($commits, null, 'getCommitIdentifier');
7777

78-
// Reorder the commits in identifier order so we preserve nth-parent
79-
// relationships when the identifiers are the parents of a merge commit.
80-
$commits = array_select_keys($commits, $identifiers);
78+
// Build empty commit objects for every commit, so we can show unparsed
79+
// commits in history views as "unparsed" instead of not showing them. This
80+
// makes the process of importing and parsing commits much clearer to the
81+
// user.
8182

82-
if (!$commits) {
83-
return array();
83+
$commit_list = array();
84+
foreach ($identifiers as $identifier) {
85+
$commit_obj = idx($commits, $identifier);
86+
if (!$commit_obj) {
87+
$commit_obj = new PhabricatorRepositoryCommit();
88+
$commit_obj->setRepositoryID($repository->getID());
89+
$commit_obj->setCommitIdentifier($identifier);
90+
$commit_obj->setIsUnparsed(true);
91+
$commit_obj->makeEphemeral();
92+
}
93+
$commit_list[$identifier] = $commit_obj;
94+
}
95+
$commits = $commit_list;
96+
97+
$commit_ids = array_filter(mpull($commits, 'getID'));
98+
if ($commit_ids) {
99+
$commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
100+
'commitID in (%Ld)',
101+
$commit_ids);
102+
$commit_data = mpull($commit_data, null, 'getCommitID');
84103
}
85-
86-
$commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
87-
'commitID in (%Ld)',
88-
mpull($commits, 'getID'));
89-
$commit_data = mpull($commit_data, null, 'getCommitID');
90104

91105
foreach ($commits as $commit) {
106+
if (!$commit->getID()) {
107+
continue;
108+
}
92109
if (idx($commit_data, $commit->getID())) {
93110
$commit->attachCommitData($commit_data[$commit->getID()]);
94111
}
@@ -123,13 +140,18 @@ final protected function loadHistoryForCommitIdentifiers(array $identifiers) {
123140
$paths = ipull($paths, 'id', 'path');
124141
$path_id = idx($paths, $path_normal);
125142

126-
$path_changes = queryfx_all(
127-
$conn_r,
128-
'SELECT * FROM %T WHERE commitID IN (%Ld) AND pathID = %d',
129-
PhabricatorRepository::TABLE_PATHCHANGE,
130-
mpull($commits, 'getID'),
131-
$path_id);
132-
$path_changes = ipull($path_changes, null, 'commitID');
143+
$commit_ids = array_filter(mpull($commits, 'getID'));
144+
145+
$path_changes = array();
146+
if ($path_id && $commit_ids) {
147+
$path_changes = queryfx_all(
148+
$conn_r,
149+
'SELECT * FROM %T WHERE commitID IN (%Ld) AND pathID = %d',
150+
PhabricatorRepository::TABLE_PATHCHANGE,
151+
$commit_ids,
152+
$path_id);
153+
$path_changes = ipull($path_changes, null, 'commitID');
154+
}
133155

134156
$history = array();
135157
foreach ($identifiers as $identifier) {

src/applications/diffusion/request/base/DiffusionRequest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,16 @@ public static function parseRequestBlob($blob, $supports_branches) {
510510
return $result;
511511
}
512512

513+
protected function raiseCloneException() {
514+
$host = php_uname('n');
515+
$callsign = $this->getRepository()->getCallsign();
516+
throw new DiffusionSetupException(
517+
"The working copy for this repository ('{$callsign}') hasn't been ".
518+
"cloned yet on this machine ('{$host}'). Make sure you've started the ".
519+
"Phabricator daemons. If this problem persists for longer than a clone ".
520+
"should take, check the daemon logs (in the Daemon Console) to see if ".
521+
"there were errors cloning the repository. Consult the 'Diffusion User ".
522+
"Guide' in the documentation for help setting up repositories.");
523+
}
524+
513525
}

src/applications/diffusion/request/base/__init__.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88

9+
phutil_require_module('phabricator', 'applications/diffusion/exception/setup');
910
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
1011
phutil_require_module('phabricator', 'applications/repository/storage/commit');
1112
phutil_require_module('phabricator', 'applications/repository/storage/commitdata');

src/applications/diffusion/request/git/DiffusionGitRequest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ protected function getSupportsBranches() {
2626
}
2727

2828
protected function didInitialize() {
29+
$repository = $this->getRepository();
30+
31+
if (!Filesystem::pathExists($repository->getLocalPath())) {
32+
$this->raiseCloneException();
33+
}
34+
2935
if (!$this->commit) {
3036
return;
3137
}
3238

3339
// Expand short commit names and verify
3440

35-
$future = $this->getRepository()->getLocalCommandFuture(
41+
$future = $repository->getLocalCommandFuture(
3642
'cat-file --batch');
3743
$future->write($this->commit);
3844
list($stdout) = $future->resolvex();

src/applications/diffusion/request/git/__init__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
phutil_require_module('phabricator', 'applications/diffusion/data/branch');
1111
phutil_require_module('phabricator', 'applications/diffusion/request/base');
1212

13+
phutil_require_module('phutil', 'filesystem');
14+
1315

1416
phutil_require_source('DiffusionGitRequest.php');

src/applications/diffusion/request/mercurial/DiffusionMercurialRequest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,24 @@ protected function getSupportsBranches() {
2626
}
2727

2828
protected function didInitialize() {
29+
$repository = $this->getRepository();
30+
31+
if (!Filesystem::pathExists($repository->getLocalPath())) {
32+
$this->raiseCloneException();
33+
}
34+
2935
return;
3036
}
3137

3238
public function getBranch() {
3339
if ($this->branch) {
3440
return $this->branch;
3541
}
42+
3643
if ($this->repository) {
3744
return $this->repository->getDetail('default-branch', 'default');
3845
}
46+
3947
throw new Exception("Unable to determine branch!");
4048
}
4149

src/applications/diffusion/request/mercurial/__init__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
phutil_require_module('phabricator', 'applications/diffusion/request/base');
1010

11+
phutil_require_module('phutil', 'filesystem');
12+
1113

1214
phutil_require_source('DiffusionMercurialRequest.php');

0 commit comments

Comments
 (0)