Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97904091
ReleephCommitFinder.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jan 7, 09:50
Size
2 KB
Mime Type
text/x-php
Expires
Thu, Jan 9, 09:50 (2 d)
Engine
blob
Format
Raw Data
Handle
23436445
Attached To
rPH Phabricator
ReleephCommitFinder.php
View Options
<?php
final
class
ReleephCommitFinder
{
private
$releephProject
;
public
function
setReleephProject
(
ReleephProject
$rp
)
{
$this
->
releephProject
=
$rp
;
return
$this
;
}
public
function
fromPartial
(
$partial_string
)
{
// Look for diffs
$matches
=
array
();
if
(
preg_match
(
'/^D([1-9]
\d
*)$/'
,
$partial_string
,
$matches
))
{
$diff_id
=
$matches
[
1
];
$diff_rev
=
id
(
new
DifferentialRevision
())->
load
(
$diff_id
);
if
(!
$diff_rev
)
{
throw
new
ReleephCommitFinderException
(
"{$partial_string} does not refer to an existing diff."
);
}
$commit_phids
=
$diff_rev
->
loadCommitPHIDs
();
if
(!
$commit_phids
)
{
throw
new
ReleephCommitFinderException
(
"{$partial_string} has no commits associated with it yet."
);
}
$commits
=
id
(
new
PhabricatorRepositoryCommit
())->
loadAllWhere
(
'phid IN (%Ls) ORDER BY epoch ASC'
,
$commit_phids
);
return
head
(
$commits
);
}
// Look for a raw commit number, or r<callsign><commit-number>.
$repository
=
$this
->
releephProject
->
loadPhabricatorRepository
();
$dr_data
=
null
;
$matches
=
array
();
if
(
preg_match
(
'/^r(?P<callsign>[A-Z]+)(?P<commit>
\w
+)$/'
,
$partial_string
,
$matches
))
{
$callsign
=
$matches
[
'callsign'
];
if
(
$callsign
!=
$repository
->
getCallsign
())
{
throw
new
ReleephCommitFinderException
(
sprintf
(
"%s is in a different repository to this Releeph project (%s)."
,
$partial_string
,
$repository
->
getCallsign
()));
}
else
{
$dr_data
=
$matches
;
}
}
else
{
$dr_data
=
array
(
'callsign'
=>
$repository
->
getCallsign
(),
'commit'
=>
$partial_string
);
}
try
{
$dr
=
DiffusionRequest
::
newFromDictionary
(
$dr_data
);
}
catch
(
Exception
$ex
)
{
$message
=
"No commit matches {$partial_string}: "
.
$ex
->
getMessage
();
throw
new
ReleephCommitFinderException
(
$message
);
}
$phabricator_repository_commit
=
$dr
->
loadCommit
();
if
(!
$phabricator_repository_commit
)
{
throw
new
ReleephCommitFinderException
(
"The commit {$partial_string} doesn't exist in this repository."
);
}
return
$phabricator_repository_commit
;
}
}
Event Timeline
Log In to Comment