Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F76431970
PhabricatorRepositoryMirrorEngine.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
Wed, Aug 7, 22:38
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Aug 9, 22:38 (2 d)
Engine
blob
Format
Raw Data
Handle
19713874
Attached To
rPH Phabricator
PhabricatorRepositoryMirrorEngine.php
View Options
<?php
/**
* Pushes a repository to its mirrors.
*/
final
class
PhabricatorRepositoryMirrorEngine
extends
PhabricatorRepositoryEngine
{
public
function
pushToMirrors
()
{
$viewer
=
$this
->
getViewer
();
$repository
=
$this
->
getRepository
();
if
(!
$repository
->
canMirror
())
{
return
;
}
if
(
PhabricatorEnv
::
getEnvConfig
(
'phabricator.silent'
))
{
$this
->
log
(
pht
(
'Phabricator is running in silent mode; declining to mirror.'
));
return
;
}
$uris
=
id
(
new
PhabricatorRepositoryURIQuery
())
->
setViewer
(
$viewer
)
->
withRepositories
(
array
(
$repository
))
->
execute
();
$io_mirror
=
PhabricatorRepositoryURI
::
IO_MIRROR
;
$exceptions
=
array
();
foreach
(
$uris
as
$mirror
)
{
if
(
$mirror
->
getIsDisabled
())
{
continue
;
}
$io_type
=
$mirror
->
getEffectiveIOType
();
if
(
$io_type
!=
$io_mirror
)
{
continue
;
}
try
{
$this
->
pushRepositoryToMirror
(
$repository
,
$mirror
);
}
catch
(
Exception
$ex
)
{
$exceptions
[]
=
$ex
;
}
}
if
(
$exceptions
)
{
throw
new
PhutilAggregateException
(
pht
(
'Exceptions occurred while mirroring the "%s" repository.'
,
$repository
->
getDisplayName
()),
$exceptions
);
}
}
private
function
pushRepositoryToMirror
(
PhabricatorRepository
$repository
,
PhabricatorRepositoryURI
$mirror_uri
)
{
$this
->
log
(
pht
(
'Pushing to remote "%s"...'
,
$mirror_uri
->
getEffectiveURI
()));
if
(
$repository
->
isGit
())
{
$this
->
pushToGitRepository
(
$repository
,
$mirror_uri
);
}
else
if
(
$repository
->
isHg
())
{
$this
->
pushToHgRepository
(
$repository
,
$mirror_uri
);
}
else
{
throw
new
Exception
(
pht
(
'Unsupported VCS!'
));
}
}
private
function
pushToGitRepository
(
PhabricatorRepository
$repository
,
PhabricatorRepositoryURI
$mirror_uri
)
{
$argv
=
array
(
'push --verbose --mirror -- %P'
,
$mirror_uri
->
getURIEnvelope
(),
);
$future
=
$mirror_uri
->
newCommandEngine
()
->
setArgv
(
$argv
)
->
newFuture
();
$future
->
setCWD
(
$repository
->
getLocalPath
())
->
resolvex
();
}
private
function
pushToHgRepository
(
PhabricatorRepository
$repository
,
PhabricatorRepositoryURI
$mirror_uri
)
{
$argv
=
array
(
'push --verbose --rev tip -- %P'
,
$mirror_uri
->
getURIEnvelope
(),
);
$future
=
$mirror_uri
->
newCommandEngine
()
->
setArgv
(
$argv
)
->
newFuture
();
try
{
$future
->
setCWD
(
$repository
->
getLocalPath
())
->
resolvex
();
}
catch
(
CommandException
$ex
)
{
if
(
preg_match
(
'/no changes found/'
,
$ex
->
getStdout
()))
{
// mercurial says nothing changed, but that's good
}
else
{
throw
$ex
;
}
}
}
}
Event Timeline
Log In to Comment