@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<?php
2
3/**
4 * Guess which tracked repository a diff comes from.
5 */
6final class DifferentialRepositoryLookup extends Phobject {
7
8 private $viewer;
9 private $diff;
10
11 public function setDiff(DifferentialDiff $diff) {
12 $this->diff = $diff;
13 return $this;
14 }
15
16 public function setViewer(PhabricatorUser $viewer) {
17 $this->viewer = $viewer;
18 return $this;
19 }
20
21 public function lookupRepository() {
22 $viewer = $this->viewer;
23 $diff = $this->diff;
24
25 // Look for a repository UUID.
26 if ($diff->getRepositoryUUID()) {
27 $repositories = id(new PhabricatorRepositoryQuery())
28 ->setViewer($viewer)
29 ->withUUIDs(array($diff->getRepositoryUUID()))
30 ->execute();
31 if ($repositories) {
32 return head($repositories);
33 }
34 }
35
36 // Look for the base commit in Git and Mercurial.
37 $vcs = $diff->getSourceControlSystem();
38 $vcs_git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;
39 $vcs_hg = PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL;
40 if ($vcs == $vcs_git || $vcs == $vcs_hg) {
41 $base = $diff->getSourceControlBaseRevision();
42 if ($base) {
43 $commits = id(new DiffusionCommitQuery())
44 ->setViewer($viewer)
45 ->withIdentifiers(array($base))
46 ->execute();
47 $commits = mgroup($commits, 'getRepositoryID');
48 if (count($commits) == 1) {
49 $repository_id = key($commits);
50 $repositories = id(new PhabricatorRepositoryQuery())
51 ->setViewer($viewer)
52 ->withIDs(array($repository_id))
53 ->execute();
54 if ($repositories) {
55 return head($repositories);
56 }
57 }
58 }
59 }
60
61 // TODO: Compare SVN remote URIs? Compare Git/Hg remote URIs? Add
62 // an explicit option to `.arcconfig`?
63
64 return null;
65 }
66
67}