forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorRepositoryManagementMarkReachableWorkflow.php
103 lines (84 loc) · 2.54 KB
/
PhabricatorRepositoryManagementMarkReachableWorkflow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
final class PhabricatorRepositoryManagementMarkReachableWorkflow
extends PhabricatorRepositoryManagementWorkflow {
private $untouchedCount = 0;
protected function didConstruct() {
$this
->setName('mark-reachable')
->setExamples('**mark-reachable** [__options__] __repository__ ...')
->setSynopsis(
pht(
'Rebuild "unreachable" flags for commits in __repository__.'))
->setArguments(
array(
array(
'name' => 'repos',
'wildcard' => true,
),
));
}
public function execute(PhutilArgumentParser $args) {
$repos = $this->loadRepositories($args, 'repos');
if (!$repos) {
throw new PhutilArgumentUsageException(
pht(
'Specify one or more repositories to correct reachability status '.
'for.'));
}
foreach ($repos as $repo) {
$this->markReachable($repo);
}
echo tsprintf(
"%s\n",
pht(
'Examined %s commits already in the correct state.',
new PhutilNumber($this->untouchedCount)));
echo tsprintf(
"%s\n",
pht('Done.'));
return 0;
}
private function markReachable(PhabricatorRepository $repository) {
if (!$repository->isGit()) {
throw new PhutilArgumentUsageException(
pht(
'Only Git repositories are supported, this repository ("%s") is '.
'not a Git repository.',
$repository->getDisplayName()));
}
$viewer = $this->getViewer();
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepository($repository)
->execute();
$flag = PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE;
$graph = new PhabricatorGitGraphStream($repository);
foreach ($commits as $commit) {
$identifier = $commit->getCommitIdentifier();
try {
$graph->getCommitDate($identifier);
$unreachable = false;
} catch (Exception $ex) {
$unreachable = true;
}
// The commit has proper reachability, so do nothing.
if ($commit->isUnreachable() === $unreachable) {
$this->untouchedCount++;
continue;
}
if ($unreachable) {
echo tsprintf(
"%s: %s\n",
$commit->getMonogram(),
pht('Marking commit unreachable.'));
$commit->writeImportStatusFlag($flag);
} else {
echo tsprintf(
"%s: %s\n",
$commit->getMonogram(),
pht('Marking commit reachable.'));
$commit->clearImportStatusFlag($flag);
}
}
}
}