Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F87949
D7685.diff
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D7685.diff
View Options
diff --git a/scripts/repository/commit_hook.php b/scripts/repository/commit_hook.php
--- a/scripts/repository/commit_hook.php
+++ b/scripts/repository/commit_hook.php
@@ -29,11 +29,16 @@
// Figure out which user is writing the commit.
-if ($repository->isGit()) {
+if ($repository->isGit() || $repository->isHg()) {
$username = getenv('PHABRICATOR_USER');
if (!strlen($username)) {
throw new Exception(pht('usage: PHABRICATOR_USER should be defined!'));
}
+
+ // TODO: If this is a Mercurial repository, the hook we're responding to
+ // is available in $argv[2]. It's unclear if we actually need this, or if
+ // we can block all actions we care about with just pretxnchangegroup.
+
} else if ($repository->isSVN()) {
// NOTE: In Subversion, the entire environment gets wiped so we can't read
// PHABRICATOR_USER. Instead, we've set "--tunnel-user" to specify the
@@ -50,7 +55,7 @@
$engine->setSubversionTransactionInfo($svn_txn, $svn_repo);
} else {
- throw new Exceptiont(pht('Unknown repository type.'));
+ throw new Exception(pht('Unknown repository type.'));
}
$user = id(new PhabricatorPeopleQuery())
@@ -67,9 +72,16 @@
// Read stdin for the hook engine.
-$stdin = @file_get_contents('php://stdin');
-if ($stdin === false) {
- throw new Exception(pht('Failed to read stdin!'));
+if ($repository->isHg()) {
+ // Mercurial leaves stdin open, so we can't just read it until EOF.
+ $stdin = '';
+} else {
+ // Git and Subversion write data into stdin and then close it. Read the
+ // data.
+ $stdin = @file_get_contents('php://stdin');
+ if ($stdin === false) {
+ throw new Exception(pht('Failed to read stdin!'));
+ }
}
$engine->setStdin($stdin);
diff --git a/src/applications/diffusion/controller/DiffusionServeController.php b/src/applications/diffusion/controller/DiffusionServeController.php
--- a/src/applications/diffusion/controller/DiffusionServeController.php
+++ b/src/applications/diffusion/controller/DiffusionServeController.php
@@ -406,15 +406,19 @@
return $user;
}
- private function serveMercurialRequest(PhabricatorRepository $repository) {
+ private function serveMercurialRequest(
+ PhabricatorRepository $repository,
+ PhabricatorUser $viewer) {
$request = $this->getRequest();
$bin = Filesystem::resolveBinary('hg');
if (!$bin) {
throw new Exception("Unable to find `hg` in PATH!");
}
- $env = array();
+ $env = array(
+ 'PHABRICATOR_USER' => $viewer->getUsername(),
+ );
$input = PhabricatorStartup::getRawInput();
$cmd = $request->getStr('cmd');
diff --git a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
--- a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
+++ b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
@@ -51,6 +51,9 @@
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$err = $this->executeSubversionHook();
break;
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
+ $err = $this->executeMercurialHook();
+ break;
default:
throw new Exception(pht('Unsupported repository type "%s"!', $type));
}
@@ -73,6 +76,13 @@
return 0;
}
+ private function executeMercurialHook() {
+
+ // TODO: Here, too, useful things should be done.
+
+ return 0;
+ }
+
private function parseGitUpdates($stdin) {
$updates = array();
diff --git a/src/applications/diffusion/ssh/DiffusionSSHMercurialServeWorkflow.php b/src/applications/diffusion/ssh/DiffusionSSHMercurialServeWorkflow.php
--- a/src/applications/diffusion/ssh/DiffusionSSHMercurialServeWorkflow.php
+++ b/src/applications/diffusion/ssh/DiffusionSSHMercurialServeWorkflow.php
@@ -42,7 +42,8 @@
$command = csprintf('hg -R %s serve --stdio', $repository->getLocalPath());
$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command);
- $future = new ExecFuture('%C', $command);
+ $future = id(new ExecFuture('%C', $command))
+ ->setEnv($this->getEnvironment());
$io_channel = $this->getIOChannel();
$protocol_channel = new DiffusionSSHMercurialWireClientProtocolChannel(
diff --git a/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php b/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
--- a/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
+++ b/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
@@ -87,6 +87,8 @@
$this->installGitHook();
} else if ($is_svn) {
$this->installSubversionHook();
+ } else if ($is_hg) {
+ $this->installMercurialHook();
} else {
$this->logPull(
pht(
@@ -335,7 +337,7 @@
$path);
} else {
$repository->execxRemoteCommand(
- 'clone -- %s %s',
+ 'clone --noupdate -- %s %s',
$repository->getRemoteURI(),
$path);
}
@@ -383,6 +385,33 @@
}
+ /**
+ * @task hg
+ */
+ private function installMercurialHook() {
+ $repository = $this->getRepository();
+ $path = $repository->getLocalPath().'.hg/hgrc';
+
+ $root = dirname(phutil_get_library_root('phabricator'));
+ $bin = $root.'/bin/commit-hook';
+
+ $data = array();
+ $data[] = '[hooks]';
+ $data[] = csprintf(
+ 'pretxnchangegroup.phabricator = %s %s %s',
+ $bin,
+ $repository->getCallsign(),
+ 'pretxnchangegroup');
+ $data[] = null;
+
+ $data = implode("\n", $data);
+
+ $this->log('%s', pht('Installing commit hook config to "%s"...', $path));
+
+ Filesystem::writeFile($path, $data);
+ }
+
+
/* -( Pulling Subversion Working Copies )---------------------------------- */
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/im/zd/qiof2bmgywpaporr
Default Alt Text
D7685.diff (5 KB)
Attached To
Mode
D7685: Support Mercurial pretxnchangegroup hooks
Attached
Detach File
Event Timeline
Log In to Comment