2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-12-03 01:21:14 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-10 00:22:25 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Interfaces with the VCS in the working copy.
|
|
|
|
*
|
|
|
|
* @group workingcopy
|
|
|
|
*/
|
2011-01-10 00:22:25 +01:00
|
|
|
abstract class ArcanistRepositoryAPI {
|
|
|
|
|
|
|
|
const FLAG_MODIFIED = 1;
|
|
|
|
const FLAG_ADDED = 2;
|
|
|
|
const FLAG_DELETED = 4;
|
|
|
|
const FLAG_UNTRACKED = 8;
|
|
|
|
const FLAG_CONFLICT = 16;
|
|
|
|
const FLAG_MISSING = 32;
|
|
|
|
const FLAG_UNSTAGED = 64;
|
|
|
|
const FLAG_UNCOMMITTED = 128;
|
|
|
|
const FLAG_EXTERNALS = 256;
|
|
|
|
|
2011-03-13 02:57:35 +01:00
|
|
|
// Occurs in SVN when you replace a file with a directory without telling
|
|
|
|
// SVN about it.
|
2011-01-10 00:22:25 +01:00
|
|
|
const FLAG_OBSTRUCTED = 512;
|
|
|
|
|
2011-03-13 02:57:35 +01:00
|
|
|
// Occurs in SVN when an update was interrupted or failed, e.g. you ^C'd it.
|
|
|
|
const FLAG_INCOMPLETE = 1024;
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
protected $path;
|
|
|
|
protected $diffLinesOfContext = 0x7FFF;
|
|
|
|
|
|
|
|
abstract public function getSourceControlSystemName();
|
|
|
|
|
|
|
|
public function getDiffLinesOfContext() {
|
|
|
|
return $this->diffLinesOfContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDiffLinesOfContext($lines) {
|
|
|
|
$this->diffLinesOfContext = $lines;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function newAPIFromWorkingCopyIdentity(
|
|
|
|
ArcanistWorkingCopyIdentity $working_copy) {
|
|
|
|
|
|
|
|
$root = $working_copy->getProjectRoot();
|
|
|
|
|
|
|
|
if (!$root) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"There is no readable '.arcconfig' file in the working directory or ".
|
|
|
|
"any parent directory. Create an '.arcconfig' file to configure arc.");
|
|
|
|
}
|
|
|
|
|
Basic Mercurial support for Arcanist
Summary:
There's a lot of ground left to cover but this makes "arc diff" work (on one
trivial diff) in my sandbox, at least, and supports parsing of Mercurial native
diffs (which are unified + a custom header). Piles of missing features, still.
Some of this is blocked by me not understanding the mercurial model well yet.
This is also a really good opportunity for cleanup (especially, reducing the
level of "instanceof" in the diff workflow), I'll try to do a bunch of that in
followup diffs.
Test Plan: Ran "arc diff" in a mercurial repository, got a diff out of it.
Reviewed By: aran
Reviewers: Makinde, jungejason, tuomaspelkonen, aran, codeblock
CC: aran, epriestley, codeblock, fratrik
Differential Revision: 792
2011-08-09 18:00:29 +02:00
|
|
|
if (Filesystem::pathExists($root.'/.svn')) {
|
|
|
|
return newv('ArcanistSubversionAPI', array($root));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
Basic Mercurial support for Arcanist
Summary:
There's a lot of ground left to cover but this makes "arc diff" work (on one
trivial diff) in my sandbox, at least, and supports parsing of Mercurial native
diffs (which are unified + a custom header). Piles of missing features, still.
Some of this is blocked by me not understanding the mercurial model well yet.
This is also a really good opportunity for cleanup (especially, reducing the
level of "instanceof" in the diff workflow), I'll try to do a bunch of that in
followup diffs.
Test Plan: Ran "arc diff" in a mercurial repository, got a diff out of it.
Reviewed By: aran
Reviewers: Makinde, jungejason, tuomaspelkonen, aran, codeblock
CC: aran, epriestley, codeblock, fratrik
Differential Revision: 792
2011-08-09 18:00:29 +02:00
|
|
|
if (Filesystem::pathExists($root.'/.hg')) {
|
|
|
|
return newv('ArcanistMercurialAPI', array($root));
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$git_root = self::discoverGitBaseDirectory($root);
|
|
|
|
if ($git_root) {
|
|
|
|
if (!Filesystem::pathsAreEquivalent($root, $git_root)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"'.arcconfig' file is located at '{$root}', but working copy root ".
|
|
|
|
"is '{$git_root}'. Move '.arcconfig' file to the working copy root.");
|
|
|
|
}
|
Basic Mercurial support for Arcanist
Summary:
There's a lot of ground left to cover but this makes "arc diff" work (on one
trivial diff) in my sandbox, at least, and supports parsing of Mercurial native
diffs (which are unified + a custom header). Piles of missing features, still.
Some of this is blocked by me not understanding the mercurial model well yet.
This is also a really good opportunity for cleanup (especially, reducing the
level of "instanceof" in the diff workflow), I'll try to do a bunch of that in
followup diffs.
Test Plan: Ran "arc diff" in a mercurial repository, got a diff out of it.
Reviewed By: aran
Reviewers: Makinde, jungejason, tuomaspelkonen, aran, codeblock
CC: aran, epriestley, codeblock, fratrik
Differential Revision: 792
2011-08-09 18:00:29 +02:00
|
|
|
|
|
|
|
return newv('ArcanistGitAPI', array($root));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"The current working directory is not part of a working copy for a ".
|
Basic Mercurial support for Arcanist
Summary:
There's a lot of ground left to cover but this makes "arc diff" work (on one
trivial diff) in my sandbox, at least, and supports parsing of Mercurial native
diffs (which are unified + a custom header). Piles of missing features, still.
Some of this is blocked by me not understanding the mercurial model well yet.
This is also a really good opportunity for cleanup (especially, reducing the
level of "instanceof" in the diff workflow), I'll try to do a bunch of that in
followup diffs.
Test Plan: Ran "arc diff" in a mercurial repository, got a diff out of it.
Reviewed By: aran
Reviewers: Makinde, jungejason, tuomaspelkonen, aran, codeblock
CC: aran, epriestley, codeblock, fratrik
Differential Revision: 792
2011-08-09 18:00:29 +02:00
|
|
|
"supported version control system (svn, git or mercurial).");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
Basic Mercurial support for Arcanist
Summary:
There's a lot of ground left to cover but this makes "arc diff" work (on one
trivial diff) in my sandbox, at least, and supports parsing of Mercurial native
diffs (which are unified + a custom header). Piles of missing features, still.
Some of this is blocked by me not understanding the mercurial model well yet.
This is also a really good opportunity for cleanup (especially, reducing the
level of "instanceof" in the diff workflow), I'll try to do a bunch of that in
followup diffs.
Test Plan: Ran "arc diff" in a mercurial repository, got a diff out of it.
Reviewed By: aran
Reviewers: Makinde, jungejason, tuomaspelkonen, aran, codeblock
CC: aran, epriestley, codeblock, fratrik
Differential Revision: 792
2011-08-09 18:00:29 +02:00
|
|
|
public function __construct($path) {
|
2011-01-10 00:22:25 +01:00
|
|
|
$this->path = $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPath($to_file = null) {
|
|
|
|
if ($to_file !== null) {
|
|
|
|
return $this->path.'/'.ltrim($to_file, '/');
|
|
|
|
} else {
|
|
|
|
return $this->path.'/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUntrackedChanges() {
|
|
|
|
return $this->getWorkingCopyFilesWithMask(self::FLAG_UNTRACKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUnstagedChanges() {
|
|
|
|
return $this->getWorkingCopyFilesWithMask(self::FLAG_UNSTAGED);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUncommittedChanges() {
|
|
|
|
return $this->getWorkingCopyFilesWithMask(self::FLAG_UNCOMMITTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMergeConflicts() {
|
|
|
|
return $this->getWorkingCopyFilesWithMask(self::FLAG_CONFLICT);
|
|
|
|
}
|
|
|
|
|
2011-03-13 02:57:35 +01:00
|
|
|
public function getIncompleteChanges() {
|
|
|
|
return $this->getWorkingCopyFilesWithMask(self::FLAG_INCOMPLETE);
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
private function getWorkingCopyFilesWithMask($mask) {
|
|
|
|
$match = array();
|
|
|
|
foreach ($this->getWorkingCopyStatus() as $file => $flags) {
|
|
|
|
if ($flags & $mask) {
|
|
|
|
$match[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $match;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function discoverGitBaseDirectory($root) {
|
|
|
|
try {
|
2012-03-05 22:22:04 +01:00
|
|
|
|
|
|
|
// NOTE: This awkward construction is to make sure things work on Windows.
|
|
|
|
$future = new ExecFuture('git rev-parse --show-cdup');
|
|
|
|
$future->setCWD($root);
|
|
|
|
list($stdout) = $future->resolvex();
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
return Filesystem::resolvePath(rtrim($stdout, "\n"), $root);
|
|
|
|
} catch (CommandException $ex) {
|
|
|
|
if (preg_match('/^fatal: Not a git repository/', $ex->getStdErr())) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
throw $ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract public function getBlame($path);
|
|
|
|
abstract public function getWorkingCopyStatus();
|
|
|
|
abstract public function getRawDiffText($path);
|
2011-01-11 22:02:38 +01:00
|
|
|
abstract public function getOriginalFileData($path);
|
|
|
|
abstract public function getCurrentFileData($path);
|
2011-08-24 03:48:55 +02:00
|
|
|
abstract public function getLocalCommitInformation();
|
2011-12-03 01:21:14 +01:00
|
|
|
abstract public function getSourceControlBaseRevision();
|
2011-09-15 03:44:54 +02:00
|
|
|
abstract public function supportsRelativeLocalCommits();
|
2011-12-03 01:21:14 +01:00
|
|
|
abstract public function getWorkingCopyRevision();
|
2012-01-24 17:07:38 +01:00
|
|
|
abstract public function loadWorkingCopyDifferentialRevisions(
|
|
|
|
ConduitClient $conduit,
|
|
|
|
array $query);
|
2011-09-15 03:44:54 +02:00
|
|
|
|
2012-01-13 04:03:11 +01:00
|
|
|
public function getCommitMessageForRevision($revision) {
|
|
|
|
throw new ArcanistCapabilityNotSupportedException($this);
|
|
|
|
}
|
|
|
|
|
2011-09-15 03:44:54 +02:00
|
|
|
public function parseRelativeLocalCommit(array $argv) {
|
Add an "arc merge" workflow
Summary:
This should support conservative rewrite policies in git fairly well, under an
assumed workflow of:
- Develop in local branches, never rewrite history.
- Commit with "-m" or by typing a brief, non-template commit message
describing the checkpoint.
- Provide rich information in the web console (reviewers, etc.)
- Finalize with "git checkout master && arc merge branch && git push" or some
flavor thereof.
This supports Mercurial somewhat. The major problem is that "hg merge" fails if
the local is a fastforward of the remote, at which point there's nowhere we can
throw the commit message. Oh well. Just push it and we'll do our best to link
them up based on local commit info.
I am increasingly forming an opinion that Mercurial is "saftey-scissors git".
But also maybe I have no clue what I'm doing. I just don't understand why anyone
would think it's a good idea to have a trunk consisting of ~50% known-broken
revisions, random checkpoint parts, whitespace changes, typo fixes, etc. If you
use git with branching you can avoid this by making a trunk out of merges or
with rebase/amend, but there seems to be no way to have "one commit = one idea"
in any real sense in Mercurial.
Test Plan: Execute "arc merge" in git and mercurial.
Reviewers: fratrik, Makinde, aran, jungejason, tuomaspelkonen
Reviewed By: Makinde
CC: aran, epriestley, Makinde
Differential Revision: 860
2011-08-26 01:02:03 +02:00
|
|
|
throw new ArcanistCapabilityNotSupportedException($this);
|
2011-09-15 03:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllLocalChanges() {
|
Add an "arc merge" workflow
Summary:
This should support conservative rewrite policies in git fairly well, under an
assumed workflow of:
- Develop in local branches, never rewrite history.
- Commit with "-m" or by typing a brief, non-template commit message
describing the checkpoint.
- Provide rich information in the web console (reviewers, etc.)
- Finalize with "git checkout master && arc merge branch && git push" or some
flavor thereof.
This supports Mercurial somewhat. The major problem is that "hg merge" fails if
the local is a fastforward of the remote, at which point there's nowhere we can
throw the commit message. Oh well. Just push it and we'll do our best to link
them up based on local commit info.
I am increasingly forming an opinion that Mercurial is "saftey-scissors git".
But also maybe I have no clue what I'm doing. I just don't understand why anyone
would think it's a good idea to have a trunk consisting of ~50% known-broken
revisions, random checkpoint parts, whitespace changes, typo fixes, etc. If you
use git with branching you can avoid this by making a trunk out of merges or
with rebase/amend, but there seems to be no way to have "one commit = one idea"
in any real sense in Mercurial.
Test Plan: Execute "arc merge" in git and mercurial.
Reviewers: fratrik, Makinde, aran, jungejason, tuomaspelkonen
Reviewed By: Makinde
CC: aran, epriestley, Makinde
Differential Revision: 860
2011-08-26 01:02:03 +02:00
|
|
|
throw new ArcanistCapabilityNotSupportedException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract public function supportsLocalBranchMerge();
|
|
|
|
|
|
|
|
public function performLocalBranchMerge($branch, $message) {
|
|
|
|
throw new ArcanistCapabilityNotSupportedException($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFinalizedRevisionMessage() {
|
|
|
|
throw new ArcanistCapabilityNotSupportedException($this);
|
2011-09-15 03:44:54 +02:00
|
|
|
}
|
|
|
|
|
2012-03-03 01:47:34 +01:00
|
|
|
public function execxLocal($pattern /*, ... */) {
|
|
|
|
$args = func_get_args();
|
|
|
|
return $this->buildLocalFuture($args)->resolvex();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execManualLocal($pattern /*, ... */) {
|
|
|
|
$args = func_get_args();
|
|
|
|
return $this->buildLocalFuture($args)->resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected function buildLocalFuture(array $argv);
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|