1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-04 04:32:42 +01:00
phorge-arcanist/src/workflow/ArcanistGitHookPreReceiveWorkflow.php
vrana 66d204be81 Delete license headers from files
Summary:
This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory).

We are removing the headers for these reasons:

- It wastes space in editors, less code is visible in editor upon opening a file.
- It brings noise to diff of the first change of any file every year.
- It confuses Git file copy detection when creating small files.
- We don't have an explicit license header in other files (JS, CSS, images, documentation).
- Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new.

This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook).

Test Plan: Verified that the license survived only in unit tests and LICENSE file.

Reviewers: epriestley, btrahan, edward

Reviewed By: epriestley

CC: aran, Korvin, davidrecordon

Maniphest Tasks: T2035

Differential Revision: https://secure.phabricator.com/D3881
2012-11-05 11:16:24 -08:00

122 lines
3 KiB
PHP

<?php
/**
* Installable as a git pre-receive hook.
*
* @group workflow
*/
final class ArcanistGitHookPreReceiveWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'git-hook-pre-receive';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**git-hook-pre-receive**
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git
You can install this as a git pre-receive hook.
EOTEXT
);
}
public function getArguments() {
return array(
);
}
public function requiresConduit() {
return true;
}
public function requiresWorkingCopy() {
return true;
}
public function shouldShellComplete() {
return false;
}
public function run() {
$working_copy = $this->getWorkingCopy();
if (!$working_copy->getProjectID()) {
throw new ArcanistUsageException(
"You have installed a git pre-receive hook in a remote without an ".
".arcconfig.");
}
// Git repositories have special rules in pre-receive hooks. We need to
// construct the API against the .git directory instead of the project
// root or commands don't work properly.
$repository_api = ArcanistGitAPI::newHookAPI($_SERVER['PWD']);
$root = $working_copy->getProjectRoot();
$parser = new ArcanistDiffParser();
$mark_revisions = array();
$stdin = file_get_contents('php://stdin');
$commits = array_filter(explode("\n", $stdin));
foreach ($commits as $commit) {
list($old_ref, $new_ref, $refname) = explode(' ', $commit);
list($log) = execx(
'(cd %s && git log -n1 %s)',
$repository_api->getPath(),
$new_ref);
$message_log = reset($parser->parseDiff($log));
$message = ArcanistDifferentialCommitMessage::newFromRawCorpus(
$message_log->getMetadata('message'));
$revision_id = $message->getRevisionID();
if ($revision_id) {
$mark_revisions[] = $revision_id;
}
// TODO: Do commit message junk.
$info = $repository_api->getPreReceiveHookStatus($old_ref, $new_ref);
$paths = ipull($info, 'mask');
$frefs = ipull($info, 'ref');
$data = array();
foreach ($paths as $path => $mask) {
list($stdout) = execx(
'(cd %s && git cat-file blob %s)',
$repository_api->getPath(),
$frefs[$path]);
$data[$path] = $stdout;
}
// TODO: Do commit content junk.
$commit_name = $new_ref;
if ($revision_id) {
$commit_name = 'D'.$revision_id.' ('.$commit_name.')';
}
echo "[arc pre-receive] {$commit_name} OK...\n";
}
$conduit = $this->getConduit();
$futures = array();
foreach ($mark_revisions as $revision_id) {
$futures[] = $conduit->callMethod(
'differential.close',
array(
'revisionID' => $revision_id,
));
}
Futures($futures)->resolveAll();
return 0;
}
}