Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15392899
D7534.id16994.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D7534.id16994.diff
View Options
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -388,6 +388,7 @@
'DifferentialLandingActionMenuEventListener' => 'applications/differential/landing/DifferentialLandingActionMenuEventListener.php',
'DifferentialLandingStrategy' => 'applications/differential/landing/DifferentialLandingStrategy.php',
'DifferentialLandingToHostedGit' => 'applications/differential/landing/DifferentialLandingToHostedGit.php',
+ 'DifferentialLandingToHostedMercurial' => 'applications/differential/landing/DifferentialLandingToHostedMercurial.php',
'DifferentialLinesFieldSpecification' => 'applications/differential/field/specification/DifferentialLinesFieldSpecification.php',
'DifferentialLintFieldSpecification' => 'applications/differential/field/specification/DifferentialLintFieldSpecification.php',
'DifferentialLintStatus' => 'applications/differential/constants/DifferentialLintStatus.php',
@@ -2647,6 +2648,7 @@
'DifferentialJIRAIssuesFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialLandingActionMenuEventListener' => 'PhabricatorEventListener',
'DifferentialLandingToHostedGit' => 'DifferentialLandingStrategy',
+ 'DifferentialLandingToHostedMercurial' => 'DifferentialLandingStrategy',
'DifferentialLinesFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialLintFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialLocalCommitsView' => 'AphrontView',
Index: src/applications/differential/DifferentialGetWorkingCopy.php
===================================================================
--- src/applications/differential/DifferentialGetWorkingCopy.php
+++ src/applications/differential/DifferentialGetWorkingCopy.php
@@ -36,4 +36,32 @@
return $workspace;
}
+ /**
+ * Creates and/or cleans a workspace for the requested repo.
+ *
+ * return ArcanistMercurialAPI
+ */
+ public static function getCleanMercurialWorkspace(
+ PhabricatorRepository $repo) {
+
+ $origin_path = $repo->getLocalPath();
+
+ $path = rtrim($origin_path, '/');
+ $path = $path . '__workspace';
+
+ if (!Filesystem::pathExists($path)) {
+ $repo->execxLocalCommand(
+ 'clone -- file:%s %s',
+ $origin_path,
+ $path);
+ }
+
+ $workspace = new ArcanistMercurialAPI($path);
+ $workspace->execxLocal('pull');
+ $workspace->execxLocal('update --clean default');
+ $workspace->reloadWorkingCopy();
+
+ return $workspace;
+ }
+
}
Index: src/applications/differential/controller/DifferentialRevisionLandController.php
===================================================================
--- src/applications/differential/controller/DifferentialRevisionLandController.php
+++ src/applications/differential/controller/DifferentialRevisionLandController.php
@@ -68,7 +68,7 @@
$prompt = hsprintf('%s<br><br>%s',
pht(
'This will squash and rebase revision %s, and push it to '.
- 'origin/master.',
+ 'the default / master branch.',
$revision_id),
pht('It is an experimental feature and may not work.'));
Index: src/applications/differential/landing/DifferentialLandingStrategy.php
===================================================================
--- src/applications/differential/landing/DifferentialLandingStrategy.php
+++ src/applications/differential/landing/DifferentialLandingStrategy.php
@@ -35,7 +35,21 @@
try {
return DifferentialGetWorkingCopy::getCleanGitWorkspace($repository);
} catch (Exception $e) {
- throw new PhutilProxyException (
+ throw new PhutilProxyException(
+ 'Failed to allocate a workspace',
+ $e);
+ }
+ }
+
+ /**
+ * might break if repository is not Mercurial.
+ */
+ protected function getMercurialWorkspace(PhabricatorRepository $repository) {
+ try {
+ return DifferentialGetWorkingCopy::getCleanMercurialWorkspace(
+ $repository);
+ } catch (Exception $e) {
+ throw new PhutilProxyException(
'Failed to allocate a workspace',
$e);
}
Index: src/applications/differential/landing/DifferentialLandingToHostedMercurial.php
===================================================================
--- /dev/null
+++ src/applications/differential/landing/DifferentialLandingToHostedMercurial.php
@@ -0,0 +1,120 @@
+<?php
+
+final class DifferentialLandingToHostedMercurial
+ extends DifferentialLandingStrategy {
+
+ public function processLandRequest(
+ AphrontRequest $request,
+ DifferentialRevision $revision,
+ PhabricatorRepository $repository) {
+
+ $viewer = $request->getUser();
+
+ $workspace = $this->getMercurialWorkspace($repository);
+
+ try {
+ $this->commitRevisionToWorkspace(
+ $revision,
+ $workspace,
+ $viewer);
+ } catch (Exception $e) {
+ throw new PhutilProxyException(
+ 'Failed to commit patch',
+ $e);
+ }
+
+ try {
+ $this->pushWorkspaceRepository(
+ $repository,
+ $workspace,
+ $viewer);
+ } catch (Exception $e) {
+ throw new PhutilProxyException(
+ 'Failed to push changes upstream',
+ $e);
+ }
+ }
+
+ public function commitRevisionToWorkspace(
+ DifferentialRevision $revision,
+ ArcanistRepositoryAPI $workspace,
+ PhabricatorUser $user) {
+
+ $diff_id = $revision->loadActiveDiff()->getID();
+
+ $call = new ConduitCall(
+ 'differential.getrawdiff',
+ array(
+ 'diffID' => $diff_id,
+ ));
+
+ $call->setUser($user);
+ $raw_diff = $call->execute();
+
+ $future = $workspace->execFutureLocal('patch --no-commit -');
+ $future->write($raw_diff);
+ $future->resolvex();
+
+ $workspace->reloadWorkingCopy();
+
+ $call = new ConduitCall(
+ 'differential.getcommitmessage',
+ array(
+ 'revision_id' => $revision->getID(),
+ ));
+
+ $call->setUser($user);
+ $message = $call->execute();
+
+ $author = id(new PhabricatorUser())->loadOneWhere(
+ 'phid = %s',
+ $revision->getAuthorPHID());
+
+ $author_string = sprintf(
+ '%s <%s>',
+ $author->getRealName(),
+ $author->loadPrimaryEmailAddress());
+ $author_date = $revision->getDateCreated();
+
+ $workspace->execxLocal(
+ 'commit --date=%s --user=%s '.
+ '--message=%s',
+ $author_date.' 0',
+ $author_string,
+ $message);
+ }
+
+
+ public function pushWorkspaceRepository(
+ PhabricatorRepository $repository,
+ ArcanistRepositoryAPI $workspace,
+ PhabricatorUser $user) {
+
+ $workspace->execxLocal("push -b default");
+ }
+
+ public function createMenuItems(
+ PhabricatorUser $viewer,
+ DifferentialRevision $revision,
+ PhabricatorRepository $repository) {
+
+ $vcs = $repository->getVersionControlSystem();
+ if ($vcs !== PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL) {
+ return;
+ }
+
+ if (!$repository->isHosted()) {
+ return;
+ }
+
+ $can_push = PhabricatorPolicyFilter::hasCapability(
+ $viewer,
+ $repository,
+ DiffusionCapabilityPush::CAPABILITY);
+
+ return $this->createActionView(
+ $revision,
+ pht('Land to Hosted Repository'),
+ !$can_push);
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 16, 6:19 PM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7707480
Default Alt Text
D7534.id16994.diff (7 KB)
Attached To
Mode
D7534: Add support for landing to hosted Mercurial repos.
Attached
Detach File
Event Timeline
Log In to Comment