2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Applies changes from Differential or a file to the working copy.
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
2011-01-10 00:22:25 +01:00
|
|
|
final class ArcanistPatchWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
|
2011-05-06 21:08:57 +02:00
|
|
|
const SOURCE_BUNDLE = 'bundle';
|
|
|
|
const SOURCE_PATCH = 'patch';
|
|
|
|
const SOURCE_REVISION = 'revision';
|
|
|
|
const SOURCE_DIFF = 'diff';
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
private $source;
|
|
|
|
private $sourceParam;
|
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'patch';
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-01-10 00:22:25 +01:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
2011-05-06 21:08:57 +02:00
|
|
|
**patch** __D12345__
|
|
|
|
**patch** __--revision__ __revision_id__
|
|
|
|
**patch** __--diff__ __diff_id__
|
|
|
|
**patch** __--patch__ __file__
|
|
|
|
**patch** __--arcbundle__ __bundlefile__
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2012-01-18 00:47:00 +01:00
|
|
|
Supports: git, svn, hg
|
2011-01-10 00:22:25 +01:00
|
|
|
Apply the changes in a Differential revision, patchfile, or arc
|
|
|
|
bundle to the working copy.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'revision' => array(
|
|
|
|
'param' => 'revision_id',
|
2011-01-15 05:00:11 +01:00
|
|
|
'paramtype' => 'complete',
|
2011-01-10 00:22:25 +01:00
|
|
|
'help' =>
|
|
|
|
"Apply changes from a Differential revision, using the most recent ".
|
2011-05-06 21:08:57 +02:00
|
|
|
"diff that has been attached to it. You can run 'arc patch D12345' ".
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
"as a shorthand.",
|
2011-01-10 00:22:25 +01:00
|
|
|
),
|
|
|
|
'diff' => array(
|
|
|
|
'param' => 'diff_id',
|
|
|
|
'help' =>
|
|
|
|
"Apply changes from a Differential diff. Normally you want to use ".
|
|
|
|
"--revision to get the most recent changes, but you can ".
|
|
|
|
"specifically apply an out-of-date diff or a diff which was never ".
|
|
|
|
"attached to a revision by using this flag.",
|
|
|
|
),
|
|
|
|
'arcbundle' => array(
|
|
|
|
'param' => 'bundlefile',
|
2011-01-15 05:00:11 +01:00
|
|
|
'paramtype' => 'file',
|
2011-01-10 00:22:25 +01:00
|
|
|
'help' =>
|
|
|
|
"Apply changes from an arc bundle generated with 'arc export'.",
|
|
|
|
),
|
|
|
|
'patch' => array(
|
|
|
|
'param' => 'patchfile',
|
2011-01-15 05:00:11 +01:00
|
|
|
'paramtype' => 'file',
|
2011-01-10 00:22:25 +01:00
|
|
|
'help' =>
|
|
|
|
"Apply changes from a git patchfile or unified patchfile.",
|
|
|
|
),
|
2012-03-14 15:08:06 +01:00
|
|
|
'encoding' => array(
|
|
|
|
'param' => 'encoding',
|
|
|
|
'help' =>
|
|
|
|
"Attempt to convert non UTF-8 patch into specified encoding.",
|
|
|
|
),
|
2012-01-19 21:16:01 +01:00
|
|
|
'update' => array(
|
|
|
|
'supports' => array(
|
|
|
|
'git', 'svn', 'hg'
|
|
|
|
),
|
|
|
|
'help' =>
|
|
|
|
"Update the local working copy before applying the patch.",
|
|
|
|
'conflicts' => array(
|
|
|
|
'nobranch' => true,
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
'bookmark' => true,
|
2012-01-19 21:16:01 +01:00
|
|
|
),
|
|
|
|
),
|
2012-01-18 00:47:00 +01:00
|
|
|
'nocommit' => array(
|
|
|
|
'supports' => array(
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
'git', 'hg'
|
2012-01-18 00:47:00 +01:00
|
|
|
),
|
|
|
|
'help' =>
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
"Normally under git/hg, if the patch is successful, the changes ".
|
|
|
|
"are committed to the working copy. This flag prevents the commit.",
|
2012-01-18 00:47:00 +01:00
|
|
|
),
|
2013-10-17 23:59:04 +02:00
|
|
|
'skip-dependencies' => array(
|
|
|
|
'supports' => array(
|
|
|
|
'git', 'hg'
|
|
|
|
),
|
|
|
|
'help' =>
|
|
|
|
'Normally, if a patch has dependencies that are not present in the '.
|
|
|
|
'working copy, arc tries to apply them as well. This flag prevents '.
|
|
|
|
'such work.',
|
|
|
|
),
|
2012-01-19 21:16:01 +01:00
|
|
|
'nobranch' => array(
|
|
|
|
'supports' => array(
|
2013-03-22 01:52:07 +01:00
|
|
|
'git', 'hg'
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
),
|
|
|
|
'help' =>
|
2013-03-22 01:52:07 +01:00
|
|
|
"Normally, a new branch (git) or bookmark (hg) is created and then ".
|
|
|
|
"the patch is applied and committed in the new branch/bookmark. ".
|
|
|
|
"This flag cherry-picks the resultant commit onto the original ".
|
|
|
|
"branch and deletes the temporary branch.",
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
'conflicts' => array(
|
|
|
|
'update' => true,
|
|
|
|
),
|
|
|
|
),
|
2011-11-30 07:27:40 +01:00
|
|
|
'force' => array(
|
|
|
|
'help' =>
|
|
|
|
"Do not run any sanity checks.",
|
|
|
|
),
|
2011-05-06 21:08:57 +02:00
|
|
|
'*' => 'name',
|
2011-01-10 00:22:25 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function didParseArguments() {
|
|
|
|
$source = null;
|
|
|
|
$requested = 0;
|
|
|
|
if ($this->getArgument('revision')) {
|
|
|
|
$source = self::SOURCE_REVISION;
|
|
|
|
$requested++;
|
|
|
|
}
|
|
|
|
if ($this->getArgument('diff')) {
|
|
|
|
$source = self::SOURCE_DIFF;
|
|
|
|
$requested++;
|
|
|
|
}
|
|
|
|
if ($this->getArgument('arcbundle')) {
|
|
|
|
$source = self::SOURCE_BUNDLE;
|
|
|
|
$requested++;
|
|
|
|
}
|
|
|
|
if ($this->getArgument('patch')) {
|
|
|
|
$source = self::SOURCE_PATCH;
|
|
|
|
$requested++;
|
|
|
|
}
|
|
|
|
|
2011-05-06 21:08:57 +02:00
|
|
|
$use_revision_id = null;
|
|
|
|
if ($this->getArgument('name')) {
|
|
|
|
$namev = $this->getArgument('name');
|
|
|
|
if (count($namev) > 1) {
|
|
|
|
throw new ArcanistUsageException("Specify at most one revision name.");
|
|
|
|
}
|
|
|
|
$source = self::SOURCE_REVISION;
|
|
|
|
$requested++;
|
|
|
|
|
|
|
|
$use_revision_id = $this->normalizeRevisionID(head($namev));
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($requested === 0) {
|
|
|
|
throw new ArcanistUsageException(
|
2011-05-06 21:08:57 +02:00
|
|
|
"Specify one of 'D12345', '--revision <revision_id>' (to select the ".
|
|
|
|
"current changes attached to a Differential revision), ".
|
|
|
|
"'--diff <diff_id>' (to select a specific, out-of-date diff or a ".
|
|
|
|
"diff which is not attached to a revision), '--arcbundle <file>' ".
|
|
|
|
"or '--patch <file>' to choose a patch source.");
|
2011-01-10 00:22:25 +01:00
|
|
|
} else if ($requested > 1) {
|
|
|
|
throw new ArcanistUsageException(
|
2011-05-06 21:08:57 +02:00
|
|
|
"Options 'D12345', '--revision', '--diff', '--arcbundle' and ".
|
|
|
|
"'--patch' are not compatible. Choose exactly one patch source.");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->source = $source;
|
2011-05-06 21:08:57 +02:00
|
|
|
$this->sourceParam = nonempty(
|
|
|
|
$use_revision_id,
|
|
|
|
$this->getArgument($source));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
2011-12-03 01:21:14 +01:00
|
|
|
return ($this->getSource() != self::SOURCE_PATCH);
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresWorkingCopy() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSource() {
|
|
|
|
return $this->source;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSourceParam() {
|
|
|
|
return $this->sourceParam;
|
|
|
|
}
|
|
|
|
|
2012-01-18 00:47:00 +01:00
|
|
|
private function shouldCommit() {
|
2013-10-17 23:59:04 +02:00
|
|
|
return !$this->getArgument('nocommit', false);
|
2012-01-18 00:47:00 +01:00
|
|
|
}
|
|
|
|
|
2012-10-17 01:46:21 +02:00
|
|
|
private function canBranch() {
|
2012-01-19 21:16:01 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
2013-03-22 01:52:07 +01:00
|
|
|
return ($repository_api instanceof ArcanistGitAPI) ||
|
|
|
|
($repository_api instanceof ArcanistMercurialAPI);
|
2012-10-17 01:46:21 +02:00
|
|
|
}
|
2012-01-19 21:16:01 +01:00
|
|
|
|
2012-10-17 01:46:21 +02:00
|
|
|
private function shouldBranch() {
|
2012-01-19 21:16:01 +01:00
|
|
|
$no_branch = $this->getArgument('nobranch', false);
|
|
|
|
if ($no_branch) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getBranchName(ArcanistBundle $bundle) {
|
|
|
|
$branch_name = null;
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
$revision_id = $bundle->getRevisionID();
|
2012-02-14 01:42:24 +01:00
|
|
|
$base_name = "arcpatch";
|
2012-01-19 21:16:01 +01:00
|
|
|
if ($revision_id) {
|
2012-02-14 01:42:24 +01:00
|
|
|
$base_name .= "-D{$revision_id}";
|
2012-01-19 21:16:01 +01:00
|
|
|
}
|
|
|
|
|
2013-08-07 23:56:03 +02:00
|
|
|
$suffixes = array(null, '_1', '_2', '_3');
|
2012-01-19 21:16:01 +01:00
|
|
|
foreach ($suffixes as $suffix) {
|
|
|
|
$proposed_name = $base_name.$suffix;
|
|
|
|
|
2012-03-25 18:32:20 +02:00
|
|
|
list($err) = $repository_api->execManualLocal(
|
|
|
|
'rev-parse --verify %s',
|
|
|
|
$proposed_name);
|
2012-01-19 21:16:01 +01:00
|
|
|
|
|
|
|
// no error means git rev-parse found a branch
|
|
|
|
if (!$err) {
|
|
|
|
echo phutil_console_format(
|
2013-02-19 23:09:20 +01:00
|
|
|
"Branch name {$proposed_name} already exists; trying a new name.\n");
|
2012-01-19 21:16:01 +01:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
$branch_name = $proposed_name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$branch_name) {
|
|
|
|
throw new Exception(
|
|
|
|
"Arc was unable to automagically make a name for this patch. ".
|
|
|
|
"Please clean up your working copy and try again."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $branch_name;
|
|
|
|
}
|
|
|
|
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
private function getBookmarkName(ArcanistBundle $bundle) {
|
|
|
|
$bookmark_name = null;
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
$revision_id = $bundle->getRevisionID();
|
|
|
|
$base_name = "arcpatch";
|
|
|
|
if ($revision_id) {
|
|
|
|
$base_name .= "-D{$revision_id}";
|
|
|
|
}
|
|
|
|
|
|
|
|
$suffixes = array(null, '-1', '-2', '-3');
|
|
|
|
foreach ($suffixes as $suffix) {
|
|
|
|
$proposed_name = $base_name.$suffix;
|
|
|
|
|
|
|
|
list($err) = $repository_api->execManualLocal(
|
|
|
|
'log -r %s',
|
2014-04-01 17:21:15 +02:00
|
|
|
hgsprintf('%s', $proposed_name));
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
|
|
|
|
// no error means hg log found a bookmark
|
|
|
|
if (!$err) {
|
|
|
|
echo phutil_console_format(
|
2013-02-19 23:09:20 +01:00
|
|
|
"Bookmark name %s already exists; trying a new name.\n",
|
|
|
|
$proposed_name);
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
$bookmark_name = $proposed_name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$bookmark_name) {
|
|
|
|
throw new Exception(
|
|
|
|
"Arc was unable to automagically make a name for this patch. ".
|
|
|
|
"Please clean up your working copy and try again."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $bookmark_name;
|
|
|
|
}
|
|
|
|
|
2012-10-17 01:46:21 +02:00
|
|
|
private function createBranch(ArcanistBundle $bundle, $has_base_revision) {
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
2013-03-22 01:52:07 +01:00
|
|
|
if ($repository_api instanceof ArcanistGitAPI) {
|
|
|
|
$branch_name = $this->getBranchName($bundle);
|
|
|
|
$base_revision = $bundle->getBaseRevision();
|
|
|
|
|
|
|
|
if ($base_revision && $has_base_revision) {
|
2014-04-08 19:46:12 +02:00
|
|
|
$base_revision = $repository_api->getCanonicalRevisionName(
|
|
|
|
$base_revision);
|
2013-03-22 01:52:07 +01:00
|
|
|
$repository_api->execxLocal(
|
|
|
|
'checkout -b %s %s',
|
|
|
|
$branch_name,
|
|
|
|
$base_revision);
|
|
|
|
} else {
|
|
|
|
$repository_api->execxLocal(
|
|
|
|
'checkout -b %s',
|
|
|
|
$branch_name);
|
|
|
|
}
|
2012-01-27 03:36:43 +01:00
|
|
|
|
2013-03-22 01:52:07 +01:00
|
|
|
echo phutil_console_format(
|
|
|
|
"Created and checked out branch %s.\n",
|
2012-01-19 21:16:01 +01:00
|
|
|
$branch_name);
|
2013-03-22 01:52:07 +01:00
|
|
|
} else if ($repository_api instanceof ArcanistMercurialAPI) {
|
|
|
|
$branch_name = $this->getBookmarkName($bundle);
|
|
|
|
$base_revision = $bundle->getBaseRevision();
|
2012-01-19 21:16:01 +01:00
|
|
|
|
2013-03-22 01:52:07 +01:00
|
|
|
if ($base_revision && $has_base_revision) {
|
|
|
|
$base_revision = $repository_api->getCanonicalRevisionName(
|
|
|
|
$base_revision);
|
2012-10-17 01:46:21 +02:00
|
|
|
|
2013-03-22 01:52:07 +01:00
|
|
|
echo "Updating to the revision's base commit\n";
|
|
|
|
$repository_api->execPassthru(
|
|
|
|
'update %s',
|
2014-04-01 17:21:15 +02:00
|
|
|
$base_revision);
|
2013-03-22 01:52:07 +01:00
|
|
|
}
|
2012-01-19 21:16:01 +01:00
|
|
|
|
2013-03-22 01:52:07 +01:00
|
|
|
$repository_api->execxLocal(
|
|
|
|
'bookmark %s',
|
2014-04-01 17:21:15 +02:00
|
|
|
$branch_name);
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
|
2013-03-22 01:52:07 +01:00
|
|
|
echo phutil_console_format(
|
|
|
|
"Created and checked out bookmark %s.\n",
|
|
|
|
$branch_name);
|
|
|
|
}
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
|
2013-03-22 01:52:07 +01:00
|
|
|
return $branch_name;
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
}
|
|
|
|
|
2013-10-17 23:59:04 +02:00
|
|
|
private function shouldApplyDependencies() {
|
|
|
|
return !$this->getArgument('skip-dependencies', false);
|
|
|
|
}
|
|
|
|
|
2012-01-19 21:16:01 +01:00
|
|
|
private function shouldUpdateWorkingCopy() {
|
|
|
|
return $this->getArgument('update', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function updateWorkingCopy() {
|
2012-03-16 21:40:33 +01:00
|
|
|
echo "Updating working copy...\n";
|
|
|
|
$this->getRepositoryAPI()->updateWorkingCopy();
|
|
|
|
echo "Done.\n";
|
2012-01-19 21:16:01 +01:00
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function run() {
|
|
|
|
|
|
|
|
$source = $this->getSource();
|
|
|
|
$param = $this->getSourceParam();
|
2011-11-01 20:34:27 +01:00
|
|
|
try {
|
|
|
|
switch ($source) {
|
|
|
|
case self::SOURCE_PATCH:
|
|
|
|
if ($param == '-') {
|
|
|
|
$patch = @file_get_contents('php://stdin');
|
|
|
|
if (!strlen($patch)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Failed to read patch from stdin!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$patch = Filesystem::readFile($param);
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
2011-11-01 20:34:27 +01:00
|
|
|
$bundle = ArcanistBundle::newFromDiff($patch);
|
|
|
|
break;
|
|
|
|
case self::SOURCE_BUNDLE:
|
|
|
|
$path = $this->getArgument('arcbundle');
|
|
|
|
$bundle = ArcanistBundle::newFromArcBundle($path);
|
|
|
|
break;
|
|
|
|
case self::SOURCE_REVISION:
|
|
|
|
$bundle = $this->loadRevisionBundleFromConduit(
|
|
|
|
$this->getConduit(),
|
|
|
|
$param);
|
|
|
|
break;
|
|
|
|
case self::SOURCE_DIFF:
|
|
|
|
$bundle = $this->loadDiffBundleFromConduit(
|
|
|
|
$this->getConduit(),
|
|
|
|
$param);
|
|
|
|
break;
|
|
|
|
}
|
2012-03-07 05:14:34 +01:00
|
|
|
} catch (ConduitClientException $ex) {
|
2011-11-01 20:34:27 +01:00
|
|
|
if ($ex->getErrorCode() == 'ERR-INVALID-SESSION') {
|
2011-11-30 07:27:40 +01:00
|
|
|
// Phabricator is not configured to allow anonymous access to
|
2011-11-01 20:34:27 +01:00
|
|
|
// Differential.
|
|
|
|
$this->authenticateConduit();
|
|
|
|
return $this->run();
|
|
|
|
} else {
|
|
|
|
throw $ex;
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
2012-03-14 15:08:06 +01:00
|
|
|
|
|
|
|
$try_encoding = nonempty($this->getArgument('encoding'), null);
|
|
|
|
if (!$try_encoding) {
|
2012-03-16 21:40:33 +01:00
|
|
|
if ($this->requiresConduit()) {
|
|
|
|
try {
|
|
|
|
$try_encoding = $this->getRepositoryEncoding();
|
|
|
|
} catch (ConduitClientException $e) {
|
|
|
|
$try_encoding = null;
|
|
|
|
}
|
2012-03-14 15:08:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($try_encoding) {
|
|
|
|
$bundle->setEncoding($try_encoding);
|
|
|
|
}
|
|
|
|
|
2013-10-17 23:59:04 +02:00
|
|
|
$sanity_check = !$this->getArgument('force', false);
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2013-10-17 23:59:04 +02:00
|
|
|
// we should update the working copy before we do ANYTHING else to
|
|
|
|
// the working copy
|
2012-01-19 21:16:01 +01:00
|
|
|
if ($this->shouldUpdateWorkingCopy()) {
|
|
|
|
$this->updateWorkingCopy();
|
|
|
|
}
|
|
|
|
|
2013-10-17 23:59:04 +02:00
|
|
|
if ($sanity_check) {
|
|
|
|
$this->requireCleanWorkingCopy();
|
|
|
|
}
|
2012-10-17 01:46:21 +02:00
|
|
|
|
2013-10-17 23:59:04 +02:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
$has_base_revision = $repository_api->hasLocalCommit(
|
|
|
|
$bundle->getBaseRevision());
|
|
|
|
if ($this->canBranch() &&
|
|
|
|
($this->shouldBranch() ||
|
|
|
|
($this->shouldCommit() && $has_base_revision))) {
|
Support --nobranch when not currently on a branch
Summary:
This is horrible and git specific, but fixes a case where people are using "arc
patch --nobranch ..." when they're not currently on a branch.
The old code assumed you were on a branch and used getBranchName() to record
this, in order to return to that branch later and cherry-pick the patch.
When not on a branch, and using arc patch --nobranch, this was trying to return
to the branch '(no branch)'.
Now, I detect that we're not on a branch and just record what HEAD is instead.
Test Plan:
Checkout the SHA of master (so I'm on master, but not on a branch) then try to
patch it with a feature diff:
€ git checkout e7a3ec68159d6847372cab5ad913f2f15aa7c249
Warning: you are leaving 1 commit behind, not connected to
any of your branches:
ac1ad39 Updating a-file
If you want to keep them by creating a new branch, this may be a good time
to do so with:
git branch new_branch_name ac1ad392350a51edd10343f12b9713f5e5b3707c
HEAD is now at e7a3ec6... Fix arcconfig
€ arc patch --nobranch D7
Created and checked out branch arcpatch-D7.
OKAY Successfully committed patch.
€ git branch
* (no branch)
feature
haddock
master
€ git log --oneline | head -2
38c0235 Updating a-file
e7a3ec6 Fix arcconfig
Reviewers: vrana, epriestley
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D3743
2012-10-19 21:12:57 +02:00
|
|
|
|
2013-03-22 01:52:07 +01:00
|
|
|
if ($repository_api instanceof ArcanistGitAPI) {
|
|
|
|
$original_branch = $repository_api->getBranchName();
|
|
|
|
} else if ($repository_api instanceof ArcanistMercurialAPI) {
|
|
|
|
$original_branch = $repository_api->getActiveBookmark();
|
|
|
|
}
|
|
|
|
|
Support --nobranch when not currently on a branch
Summary:
This is horrible and git specific, but fixes a case where people are using "arc
patch --nobranch ..." when they're not currently on a branch.
The old code assumed you were on a branch and used getBranchName() to record
this, in order to return to that branch later and cherry-pick the patch.
When not on a branch, and using arc patch --nobranch, this was trying to return
to the branch '(no branch)'.
Now, I detect that we're not on a branch and just record what HEAD is instead.
Test Plan:
Checkout the SHA of master (so I'm on master, but not on a branch) then try to
patch it with a feature diff:
€ git checkout e7a3ec68159d6847372cab5ad913f2f15aa7c249
Warning: you are leaving 1 commit behind, not connected to
any of your branches:
ac1ad39 Updating a-file
If you want to keep them by creating a new branch, this may be a good time
to do so with:
git branch new_branch_name ac1ad392350a51edd10343f12b9713f5e5b3707c
HEAD is now at e7a3ec6... Fix arcconfig
€ arc patch --nobranch D7
Created and checked out branch arcpatch-D7.
OKAY Successfully committed patch.
€ git branch
* (no branch)
feature
haddock
master
€ git log --oneline | head -2
38c0235 Updating a-file
e7a3ec6 Fix arcconfig
Reviewers: vrana, epriestley
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D3743
2012-10-19 21:12:57 +02:00
|
|
|
// If we weren't on a branch, then record the ref we'll return to
|
|
|
|
// instead.
|
|
|
|
if ($original_branch === null) {
|
2013-03-22 01:52:07 +01:00
|
|
|
if ($repository_api instanceof ArcanistGitAPI) {
|
|
|
|
$original_branch = $repository_api->getCanonicalRevisionName('HEAD');
|
|
|
|
} else if ($repository_api instanceof ArcanistMercurialAPI) {
|
|
|
|
$original_branch = $repository_api->getCanonicalRevisionName('.');
|
|
|
|
}
|
Support --nobranch when not currently on a branch
Summary:
This is horrible and git specific, but fixes a case where people are using "arc
patch --nobranch ..." when they're not currently on a branch.
The old code assumed you were on a branch and used getBranchName() to record
this, in order to return to that branch later and cherry-pick the patch.
When not on a branch, and using arc patch --nobranch, this was trying to return
to the branch '(no branch)'.
Now, I detect that we're not on a branch and just record what HEAD is instead.
Test Plan:
Checkout the SHA of master (so I'm on master, but not on a branch) then try to
patch it with a feature diff:
€ git checkout e7a3ec68159d6847372cab5ad913f2f15aa7c249
Warning: you are leaving 1 commit behind, not connected to
any of your branches:
ac1ad39 Updating a-file
If you want to keep them by creating a new branch, this may be a good time
to do so with:
git branch new_branch_name ac1ad392350a51edd10343f12b9713f5e5b3707c
HEAD is now at e7a3ec6... Fix arcconfig
€ arc patch --nobranch D7
Created and checked out branch arcpatch-D7.
OKAY Successfully committed patch.
€ git branch
* (no branch)
feature
haddock
master
€ git log --oneline | head -2
38c0235 Updating a-file
e7a3ec6 Fix arcconfig
Reviewers: vrana, epriestley
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D3743
2012-10-19 21:12:57 +02:00
|
|
|
}
|
2012-01-19 21:16:01 +01:00
|
|
|
|
2013-03-22 01:52:07 +01:00
|
|
|
$new_branch = $this->createBranch($bundle, $has_base_revision);
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
}
|
2013-10-17 23:59:04 +02:00
|
|
|
if (!$has_base_revision && $this->shouldApplyDependencies()) {
|
|
|
|
$this->applyDependencies($bundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sanity_check) {
|
|
|
|
$this->sanityCheck($bundle);
|
|
|
|
}
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($repository_api instanceof ArcanistSubversionAPI) {
|
2011-01-13 22:21:33 +01:00
|
|
|
$patch_err = 0;
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$copies = array();
|
|
|
|
$deletes = array();
|
|
|
|
$patches = array();
|
|
|
|
$propset = array();
|
|
|
|
$adds = array();
|
2011-03-08 06:33:36 +01:00
|
|
|
$symlinks = array();
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
$changes = $bundle->getChanges();
|
|
|
|
foreach ($changes as $change) {
|
|
|
|
$type = $change->getType();
|
|
|
|
$should_patch = true;
|
2011-03-08 06:33:36 +01:00
|
|
|
|
|
|
|
$filetype = $change->getFileType();
|
|
|
|
switch ($filetype) {
|
|
|
|
case ArcanistDiffChangeType::FILE_SYMLINK:
|
|
|
|
$should_patch = false;
|
|
|
|
$symlinks[] = $change;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
switch ($type) {
|
|
|
|
case ArcanistDiffChangeType::TYPE_MOVE_AWAY:
|
|
|
|
case ArcanistDiffChangeType::TYPE_MULTICOPY:
|
|
|
|
case ArcanistDiffChangeType::TYPE_DELETE:
|
|
|
|
$path = $change->getCurrentPath();
|
|
|
|
$fpath = $repository_api->getPath($path);
|
|
|
|
if (!@file_exists($fpath)) {
|
2011-03-19 20:15:28 +01:00
|
|
|
$ok = phutil_console_confirm(
|
2011-01-10 00:22:25 +01:00
|
|
|
"Patch deletes file '{$path}', but the file does not exist in ".
|
|
|
|
"the working copy. Continue anyway?");
|
2011-03-19 20:15:28 +01:00
|
|
|
if (!$ok) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
} else {
|
|
|
|
$deletes[] = $change->getCurrentPath();
|
|
|
|
}
|
|
|
|
$should_patch = false;
|
|
|
|
break;
|
|
|
|
case ArcanistDiffChangeType::TYPE_COPY_HERE:
|
|
|
|
case ArcanistDiffChangeType::TYPE_MOVE_HERE:
|
|
|
|
$path = $change->getOldPath();
|
|
|
|
$fpath = $repository_api->getPath($path);
|
|
|
|
if (!@file_exists($fpath)) {
|
|
|
|
$cpath = $change->getCurrentPath();
|
|
|
|
if ($type == ArcanistDiffChangeType::TYPE_COPY_HERE) {
|
|
|
|
$verbs = 'copies';
|
|
|
|
} else {
|
|
|
|
$verbs = 'moves';
|
|
|
|
}
|
2011-03-19 20:15:28 +01:00
|
|
|
$ok = phutil_console_confirm(
|
2011-01-10 00:22:25 +01:00
|
|
|
"Patch {$verbs} '{$path}' to '{$cpath}', but source path ".
|
|
|
|
"does not exist in the working copy. Continue anyway?");
|
2011-03-19 20:15:28 +01:00
|
|
|
if (!$ok) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
} else {
|
|
|
|
$copies[] = array(
|
|
|
|
$change->getOldPath(),
|
|
|
|
$change->getCurrentPath());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ArcanistDiffChangeType::TYPE_ADD:
|
|
|
|
$adds[] = $change->getCurrentPath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($should_patch) {
|
2012-09-20 00:59:39 +02:00
|
|
|
$cbundle = ArcanistBundle::newFromChanges(array($change));
|
|
|
|
$patches[$change->getCurrentPath()] = $cbundle->toUnifiedDiff();
|
2011-01-10 00:22:25 +01:00
|
|
|
$prop_old = $change->getOldProperties();
|
|
|
|
$prop_new = $change->getNewProperties();
|
|
|
|
$props = $prop_old + $prop_new;
|
|
|
|
foreach ($props as $key => $ignored) {
|
|
|
|
if (idx($prop_old, $key) !== idx($prop_new, $key)) {
|
2011-01-28 20:37:44 +01:00
|
|
|
$propset[$change->getCurrentPath()][$key] = idx($prop_new, $key);
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-08 05:21:16 +01:00
|
|
|
// Before we start doing anything, create all the directories we're going
|
|
|
|
// to add files to if they don't already exist.
|
|
|
|
foreach ($copies as $copy) {
|
|
|
|
list($src, $dst) = $copy;
|
|
|
|
$this->createParentDirectoryOf($dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($patches as $path => $patch) {
|
|
|
|
$this->createParentDirectoryOf($path);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($adds as $add) {
|
|
|
|
$this->createParentDirectoryOf($add);
|
|
|
|
}
|
|
|
|
|
2012-03-25 18:32:20 +02:00
|
|
|
// TODO: The SVN patch workflow likely does not work on windows because
|
|
|
|
// of the (cd ...) stuff.
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
foreach ($copies as $copy) {
|
|
|
|
list($src, $dst) = $copy;
|
|
|
|
passthru(
|
|
|
|
csprintf(
|
|
|
|
'(cd %s; svn cp %s %s)',
|
|
|
|
$repository_api->getPath(),
|
2013-02-15 23:53:25 +01:00
|
|
|
ArcanistSubversionAPI::escapeFileNameForSVN($src),
|
|
|
|
ArcanistSubversionAPI::escapeFileNameForSVN($dst)));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($deletes as $delete) {
|
|
|
|
passthru(
|
|
|
|
csprintf(
|
|
|
|
'(cd %s; svn rm %s)',
|
|
|
|
$repository_api->getPath(),
|
2013-02-15 23:53:25 +01:00
|
|
|
ArcanistSubversionAPI::escapeFileNameForSVN($delete)));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2011-03-08 06:33:36 +01:00
|
|
|
foreach ($symlinks as $symlink) {
|
|
|
|
$link_target = $symlink->getSymlinkTarget();
|
|
|
|
$link_path = $symlink->getCurrentPath();
|
|
|
|
switch ($symlink->getType()) {
|
|
|
|
case ArcanistDiffChangeType::TYPE_ADD:
|
2012-06-12 00:11:53 +02:00
|
|
|
case ArcanistDiffChangeType::TYPE_CHANGE:
|
2011-03-08 06:33:36 +01:00
|
|
|
case ArcanistDiffChangeType::TYPE_MOVE_HERE:
|
|
|
|
case ArcanistDiffChangeType::TYPE_COPY_HERE:
|
|
|
|
execx(
|
|
|
|
'(cd %s && ln -sf %s %s)',
|
|
|
|
$repository_api->getPath(),
|
|
|
|
$link_target,
|
|
|
|
$link_path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
foreach ($patches as $path => $patch) {
|
2011-01-13 22:21:33 +01:00
|
|
|
$err = null;
|
2012-09-20 00:59:39 +02:00
|
|
|
if ($patch) {
|
|
|
|
$tmp = new TempFile();
|
|
|
|
Filesystem::writeFile($tmp, $patch);
|
|
|
|
passthru(
|
|
|
|
csprintf(
|
|
|
|
'(cd %s; patch -p0 < %s)',
|
|
|
|
$repository_api->getPath(),
|
|
|
|
$tmp),
|
|
|
|
$err);
|
|
|
|
} else {
|
|
|
|
passthru(
|
|
|
|
csprintf(
|
|
|
|
'(cd %s; touch %s)',
|
|
|
|
$repository_api->getPath(),
|
|
|
|
$path),
|
|
|
|
$err);
|
|
|
|
}
|
2011-01-13 22:21:33 +01:00
|
|
|
if ($err) {
|
|
|
|
$patch_err = max($patch_err, $err);
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($adds as $add) {
|
|
|
|
passthru(
|
|
|
|
csprintf(
|
|
|
|
'(cd %s; svn add %s)',
|
|
|
|
$repository_api->getPath(),
|
2013-02-15 23:53:25 +01:00
|
|
|
ArcanistSubversionAPI::escapeFileNameForSVN($add)));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($propset as $path => $changes) {
|
2012-08-24 02:52:38 +02:00
|
|
|
foreach ($changes as $prop => $value) {
|
2012-09-26 19:24:10 +02:00
|
|
|
if ($prop == 'unix:filemode') {
|
|
|
|
// Setting this property also changes the file mode.
|
|
|
|
$prop = 'svn:executable';
|
|
|
|
$value = (octdec($value) & 0111 ? 'on' : null);
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($value === null) {
|
|
|
|
passthru(
|
|
|
|
csprintf(
|
|
|
|
'(cd %s; svn propdel %s %s)',
|
|
|
|
$repository_api->getPath(),
|
|
|
|
$prop,
|
2013-02-15 23:53:25 +01:00
|
|
|
ArcanistSubversionAPI::escapeFileNameForSVN($path)));
|
2011-01-10 00:22:25 +01:00
|
|
|
} else {
|
|
|
|
passthru(
|
|
|
|
csprintf(
|
|
|
|
'(cd %s; svn propset %s %s %s)',
|
|
|
|
$repository_api->getPath(),
|
|
|
|
$prop,
|
|
|
|
$value,
|
2013-02-15 23:53:25 +01:00
|
|
|
ArcanistSubversionAPI::escapeFileNameForSVN($path)));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 22:21:33 +01:00
|
|
|
if ($patch_err == 0) {
|
|
|
|
echo phutil_console_format(
|
2012-01-19 21:16:01 +01:00
|
|
|
"<bg:green>** OKAY **</bg> Successfully applied patch ".
|
|
|
|
"to the working copy.\n");
|
2011-01-13 22:21:33 +01:00
|
|
|
} else {
|
|
|
|
echo phutil_console_format(
|
|
|
|
"\n\n<bg:yellow>** WARNING **</bg> Some hunks could not be applied ".
|
|
|
|
"cleanly by the unix 'patch' utility. Your working copy may be ".
|
|
|
|
"different from the revision's base, or you may be in the wrong ".
|
|
|
|
"subdirectory. You can export the raw patch file using ".
|
|
|
|
"'arc export --unified', and then try to apply it by fiddling with ".
|
|
|
|
"options to 'patch' (particularly, -p), or manually. The output ".
|
|
|
|
"above, from 'patch', may be helpful in figuring out what went ".
|
|
|
|
"wrong.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $patch_err;
|
2012-01-17 02:12:34 +01:00
|
|
|
} else if ($repository_api instanceof ArcanistGitAPI) {
|
2012-03-26 18:43:37 +02:00
|
|
|
|
2013-05-31 06:03:21 +02:00
|
|
|
$patchfile = new TempFile();
|
|
|
|
Filesystem::writeFile($patchfile, $bundle->toGitPatch());
|
|
|
|
|
2013-09-28 15:53:15 +02:00
|
|
|
$passthru = new PhutilExecPassthru(
|
|
|
|
'git apply --index --reject -- %s',
|
2013-05-31 06:03:21 +02:00
|
|
|
$patchfile);
|
2013-09-28 15:53:15 +02:00
|
|
|
$passthru->setCWD($repository_api->getPath());
|
|
|
|
$err = $passthru->execute();
|
2013-05-31 06:03:21 +02:00
|
|
|
|
|
|
|
if ($err) {
|
2012-03-26 18:43:37 +02:00
|
|
|
echo phutil_console_format(
|
|
|
|
"\n<bg:red>** Patch Failed! **</bg>\n");
|
2013-05-31 06:03:21 +02:00
|
|
|
|
|
|
|
// NOTE: Git patches may fail if they change the case of a filename
|
|
|
|
// (for instance, from 'example.c' to 'Example.c'). As of now, Git
|
|
|
|
// can not apply these patches on case-insensitive filesystems and
|
|
|
|
// there is no way to build a patch which works.
|
|
|
|
|
|
|
|
throw new ArcanistUsageException("Unable to apply patch!");
|
2012-03-26 18:43:37 +02:00
|
|
|
}
|
2011-01-13 22:21:33 +01:00
|
|
|
|
Make arc patch slightly better about submodules
Summary:
Ref T3776, Ref T479. Say you have some DN, with a submodule X@Y. Later, X@Z in your working copy / repo. If you run arc patch DN, you'd end up with a dirty working copy claiming that X@Z was wrong and it should be X@Y.
To fix, basically run 'submodule init' and 'submodule update'. This makes it so after "arc patch" if you run "git status" it looks clean.
Gross part though now is if you then "git checkout master" you'll have a dirty checkout the other way. I think this is better though.
Test Plan: made a new repository where I added libphutil @ X, did some work (DX), then made libphutil @ y. When I arc patch'd DX, things looked good!
Reviewers: epriestley
Reviewed By: epriestley
CC: csilvers, Korvin, aran
Maniphest Tasks: T479, T3776
Differential Revision: https://secure.phabricator.com/D6837
2013-08-29 01:47:30 +02:00
|
|
|
// in case there were any submodule changes involved
|
|
|
|
$repository_api->execpassthru(
|
2013-09-05 21:45:59 +02:00
|
|
|
'submodule update --init --recursive');
|
Make arc patch slightly better about submodules
Summary:
Ref T3776, Ref T479. Say you have some DN, with a submodule X@Y. Later, X@Z in your working copy / repo. If you run arc patch DN, you'd end up with a dirty working copy claiming that X@Z was wrong and it should be X@Y.
To fix, basically run 'submodule init' and 'submodule update'. This makes it so after "arc patch" if you run "git status" it looks clean.
Gross part though now is if you then "git checkout master" you'll have a dirty checkout the other way. I think this is better though.
Test Plan: made a new repository where I added libphutil @ X, did some work (DX), then made libphutil @ y. When I arc patch'd DX, things looked good!
Reviewers: epriestley
Reviewed By: epriestley
CC: csilvers, Korvin, aran
Maniphest Tasks: T479, T3776
Differential Revision: https://secure.phabricator.com/D6837
2013-08-29 01:47:30 +02:00
|
|
|
|
2012-01-18 00:47:00 +01:00
|
|
|
if ($this->shouldCommit()) {
|
2013-02-06 05:11:39 +01:00
|
|
|
if ($bundle->getFullAuthor()) {
|
|
|
|
$author_cmd = csprintf('--author=%s', $bundle->getFullAuthor());
|
|
|
|
} else {
|
|
|
|
$author_cmd = '';
|
2012-11-09 22:36:15 +01:00
|
|
|
}
|
2013-02-06 05:11:39 +01:00
|
|
|
|
2012-01-18 00:47:00 +01:00
|
|
|
$commit_message = $this->getCommitMessage($bundle);
|
2012-03-25 18:32:20 +02:00
|
|
|
$future = $repository_api->execFutureLocal(
|
2013-02-06 05:11:39 +01:00
|
|
|
'commit -a %C -F -',
|
2012-11-09 22:36:15 +01:00
|
|
|
$author_cmd);
|
2012-01-18 00:47:00 +01:00
|
|
|
$future->write($commit_message);
|
|
|
|
$future->resolvex();
|
|
|
|
$verb = 'committed';
|
|
|
|
} else {
|
|
|
|
$verb = 'applied';
|
|
|
|
}
|
2012-10-17 01:46:21 +02:00
|
|
|
|
2013-10-17 23:59:04 +02:00
|
|
|
if ($this->canBranch() &&
|
|
|
|
!$this->shouldBranch() &&
|
|
|
|
$this->shouldCommit() && $has_base_revision) {
|
2012-10-17 01:46:21 +02:00
|
|
|
$repository_api->execxLocal('checkout %s', $original_branch);
|
|
|
|
$ex = null;
|
|
|
|
try {
|
|
|
|
$repository_api->execxLocal('cherry-pick %s', $new_branch);
|
2013-10-17 23:59:04 +02:00
|
|
|
} catch (Exception $ex) {
|
|
|
|
// do nothing
|
|
|
|
}
|
2012-10-17 01:46:21 +02:00
|
|
|
$repository_api->execxLocal('branch -D %s', $new_branch);
|
|
|
|
if ($ex) {
|
|
|
|
echo phutil_console_format(
|
|
|
|
"\n<bg:red>** Cherry Pick Failed!**</bg>\n");
|
|
|
|
throw $ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 22:21:33 +01:00
|
|
|
echo phutil_console_format(
|
2012-01-18 00:47:00 +01:00
|
|
|
"<bg:green>** OKAY **</bg> Successfully {$verb} patch.\n");
|
2012-01-17 02:12:34 +01:00
|
|
|
} else if ($repository_api instanceof ArcanistMercurialAPI) {
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
|
2012-03-25 18:32:20 +02:00
|
|
|
$future = $repository_api->execFutureLocal(
|
|
|
|
'import --no-commit -');
|
2012-01-17 02:12:34 +01:00
|
|
|
$future->write($bundle->toGitPatch());
|
|
|
|
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
try {
|
|
|
|
$future->resolvex();
|
|
|
|
} catch (CommandException $ex) {
|
|
|
|
echo phutil_console_format(
|
|
|
|
"\n<bg:red>** Patch Failed! **</bg>\n");
|
|
|
|
$stderr = $ex->getStdErr();
|
|
|
|
if (preg_match('/case-folding collision/', $stderr)) {
|
|
|
|
echo phutil_console_wrap(
|
|
|
|
phutil_console_format(
|
|
|
|
"\n<bg:yellow>** WARNING **</bg> This patch may have failed ".
|
|
|
|
"because it attempts to change the case of a filename (for ".
|
|
|
|
"instance, from 'example.c' to 'Example.c'). Mercurial cannot ".
|
|
|
|
"apply patches like this on case-insensitive filesystems. You ".
|
|
|
|
"must apply this patch manually.\n"));
|
|
|
|
}
|
|
|
|
throw $ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->shouldCommit()) {
|
2013-02-06 05:11:39 +01:00
|
|
|
$author = coalesce($bundle->getFullAuthor(), $bundle->getAuthorName());
|
|
|
|
if ($author !== null) {
|
|
|
|
$author_cmd = csprintf('-u %s', $author);
|
|
|
|
} else {
|
|
|
|
$author_cmd = '';
|
2012-11-09 22:36:15 +01:00
|
|
|
}
|
2013-02-06 05:11:39 +01:00
|
|
|
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
$commit_message = $this->getCommitMessage($bundle);
|
|
|
|
$future = $repository_api->execFutureLocal(
|
2013-03-20 22:40:28 +01:00
|
|
|
'commit %C -l -',
|
2012-11-09 22:36:15 +01:00
|
|
|
$author_cmd);
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
$future->write($commit_message);
|
|
|
|
$future->resolvex();
|
2013-03-22 01:52:07 +01:00
|
|
|
|
|
|
|
if (!$this->shouldBranch() && $has_base_revision) {
|
|
|
|
$original_rev = $repository_api->getCanonicalRevisionName(
|
|
|
|
$original_branch);
|
|
|
|
$current_parent = $repository_api->getCanonicalRevisionName(
|
|
|
|
hgsprintf('%s^', $new_branch));
|
|
|
|
|
|
|
|
$err = 0;
|
|
|
|
if ($original_rev != $current_parent) {
|
|
|
|
list($err) = $repository_api->execManualLocal(
|
|
|
|
'rebase --dest %s --rev %s',
|
|
|
|
hgsprintf('%s', $original_branch),
|
|
|
|
hgsprintf('%s', $new_branch));
|
|
|
|
}
|
|
|
|
|
|
|
|
$repository_api->execxLocal('bookmark --delete %s', $new_branch);
|
|
|
|
if ($err) {
|
|
|
|
$repository_api->execManualLocal('rebase --abort');
|
|
|
|
throw new ArcanistUsageException(phutil_console_format(
|
|
|
|
"\n<bg:red>** Rebase onto $original_branch failed!**</bg>\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
$verb = 'committed';
|
|
|
|
} else {
|
|
|
|
$verb = 'applied';
|
|
|
|
}
|
2013-03-22 01:52:07 +01:00
|
|
|
|
2012-01-17 02:12:34 +01:00
|
|
|
echo phutil_console_format(
|
[hg - arc patch] make mercurial bookmark with arc patch
Summary:
w00t!
Created new functions getBookmarkName, createBookmark that use mercurial
commands to create a new bookmark and apply the commit message when
running arc patch. Like with git, it checks if the bookmark already
exists. If it does, creates arcpatch-DXXX-1, -2 etc
Updated the mercurial section of run() to include applying the commit
message.
Pretty new to programming in general still, so I wasn't sure if I should
have just modified getBranchName and createBranch to work with Mercurial
(instead of creating new functions). This was easier for me to make sure
I didn't break the git functionality. Let me know I can merge the
functions.
Test Plan:
Tested in my www-hg repository. Probably need to test further (suggestions?)
Ran the following trials with arc patch D539987
1) the bookmark arcpatch-D539987 already existed
2) the bookmark did not exist
3) tried an invalid commit, arc patch R539987
4) --nobookmark flag (bookmark was not created, but the commit applied)
5) --nocommit flag (boomark was created, and the commit was not applied)
6) --nocommit and --nobokmark
Here's the summary of the results:
https://secure.phabricator.com/P493
Reviewers: dschleimer
Reviewed By: dschleimer
CC: aran, epriestley, phleet, bos, csilvers
Differential Revision: https://secure.phabricator.com/D3334
2012-08-18 20:23:56 +02:00
|
|
|
"<bg:green>** OKAY **</bg> Successfully {$verb} patch.\n");
|
|
|
|
|
2012-01-17 02:12:34 +01:00
|
|
|
} else {
|
|
|
|
throw new Exception('Unknown version control system.');
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-15 05:00:11 +01:00
|
|
|
|
2012-01-18 00:47:00 +01:00
|
|
|
private function getCommitMessage(ArcanistBundle $bundle) {
|
|
|
|
$revision_id = $bundle->getRevisionID();
|
|
|
|
$commit_message = null;
|
|
|
|
$prompt_message = null;
|
|
|
|
|
|
|
|
// if we have a revision id the commit message is in differential
|
2012-03-09 17:57:18 +01:00
|
|
|
|
|
|
|
// TODO: See T848 for the authenticated stuff.
|
|
|
|
if ($revision_id && $this->isConduitAuthenticated()) {
|
|
|
|
|
2012-01-18 00:47:00 +01:00
|
|
|
$conduit = $this->getConduit();
|
|
|
|
$commit_message = $conduit->callMethodSynchronous(
|
|
|
|
'differential.getcommitmessage',
|
|
|
|
array(
|
|
|
|
'revision_id' => $revision_id,
|
|
|
|
));
|
|
|
|
$prompt_message = " Note arcanist failed to load the commit message ".
|
|
|
|
"from differential for revision D{$revision_id}.";
|
|
|
|
}
|
|
|
|
|
|
|
|
// no revision id or failed to fetch commit message so get it from the
|
|
|
|
// user on the command line
|
|
|
|
if (!$commit_message) {
|
|
|
|
$template =
|
|
|
|
"\n\n".
|
|
|
|
"# Enter a commit message for this patch. If you just want to apply ".
|
|
|
|
"the patch to the working copy without committing, re-run arc patch ".
|
|
|
|
"with the --nocommit flag.".
|
|
|
|
$prompt_message.
|
|
|
|
"\n";
|
|
|
|
|
2012-07-12 01:55:11 +02:00
|
|
|
$commit_message = $this->newInteractiveEditor($template)
|
2012-01-18 00:47:00 +01:00
|
|
|
->setName('arcanist-patch-commit-message')
|
|
|
|
->editInteractively();
|
|
|
|
|
2012-04-18 15:08:41 +02:00
|
|
|
$commit_message = ArcanistCommentRemover::removeComments($commit_message);
|
|
|
|
if (!strlen(trim($commit_message))) {
|
2012-01-18 00:47:00 +01:00
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $commit_message;
|
|
|
|
}
|
|
|
|
|
2011-01-15 05:00:11 +01:00
|
|
|
public function getShellCompletions(array $argv) {
|
|
|
|
// TODO: Pull open diffs from 'arc list'?
|
|
|
|
return array('ARGUMENT');
|
|
|
|
}
|
2011-03-08 05:21:16 +01:00
|
|
|
|
2013-10-17 23:59:04 +02:00
|
|
|
private function applyDependencies(ArcanistBundle $bundle) {
|
|
|
|
// check for (and automagically apply on the user's be-hest) any revisions
|
|
|
|
// this patch depends on
|
|
|
|
$graph = $this->buildDependencyGraph($bundle);
|
|
|
|
if ($graph) {
|
|
|
|
$start_phid = $graph->getStartPHID();
|
|
|
|
$cycle_phids = $graph->detectCycles($start_phid);
|
|
|
|
if ($cycle_phids) {
|
|
|
|
$phids = array_keys($graph->getNodes());
|
|
|
|
$issue = 'The dependencies for this patch have a cycle. Applying them '.
|
|
|
|
'is not guaranteed to work. Continue anyway?';
|
|
|
|
$okay = phutil_console_confirm($issue, true);
|
|
|
|
} else {
|
|
|
|
$phids = $graph->getTopographicallySortedNodes();
|
|
|
|
$phids = array_reverse($phids);
|
|
|
|
$okay = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$okay) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$dep_on_revs = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'differential.query',
|
|
|
|
array(
|
|
|
|
'phids' => $phids,
|
|
|
|
'arcanistProjects' => array($bundle->getProjectID())
|
|
|
|
));
|
|
|
|
$revs = array();
|
|
|
|
foreach ($dep_on_revs as $dep_on_rev) {
|
|
|
|
$revs[$dep_on_rev['phid']] = 'D'.$dep_on_rev['id'];
|
|
|
|
}
|
|
|
|
// order them in case we got a topological sort earlier
|
|
|
|
$revs = array_select_keys($revs, $phids);
|
|
|
|
if (!empty($revs)) {
|
|
|
|
$base_args = array(
|
|
|
|
'--force',
|
|
|
|
'--skip-dependencies',
|
|
|
|
'--nobranch');
|
|
|
|
if (!$this->shouldCommit()) {
|
|
|
|
$base_args[] = '--nocommit';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($revs as $phid => $diff_id) {
|
|
|
|
// we'll apply this, the actual patch, later
|
|
|
|
// this should be the last in the list
|
|
|
|
if ($phid == $start_phid) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$args = $base_args;
|
|
|
|
$args[] = $diff_id;
|
|
|
|
$apply_workflow = $this->buildChildWorkflow(
|
|
|
|
'patch',
|
|
|
|
$args);
|
|
|
|
$apply_workflow->run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 07:27:40 +01:00
|
|
|
/**
|
|
|
|
* Do the best we can to prevent PEBKAC and id10t issues.
|
|
|
|
*/
|
2012-02-03 23:04:41 +01:00
|
|
|
private function sanityCheck(ArcanistBundle $bundle) {
|
2012-10-19 19:10:25 +02:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
2011-12-03 01:21:14 +01:00
|
|
|
// Check to see if the bundle's project id matches the working copy
|
2011-11-30 07:27:40 +01:00
|
|
|
// project id
|
|
|
|
$bundle_project_id = $bundle->getProjectID();
|
|
|
|
$working_copy_project_id = $this->getWorkingCopy()->getProjectID();
|
|
|
|
if (empty($bundle_project_id)) {
|
2011-12-03 01:21:14 +01:00
|
|
|
// this means $source is SOURCE_PATCH || SOURCE_BUNDLE w/ $version = 0
|
2011-11-30 07:27:40 +01:00
|
|
|
// they don't come with a project id so just do nothing
|
|
|
|
} else if ($bundle_project_id != $working_copy_project_id) {
|
2012-08-10 03:39:41 +02:00
|
|
|
if ($working_copy_project_id) {
|
|
|
|
$issue =
|
|
|
|
"This patch is for the '{$bundle_project_id}' project, but the ".
|
|
|
|
"working copy belongs to the '{$working_copy_project_id}' project.";
|
|
|
|
} else {
|
|
|
|
$issue =
|
|
|
|
"This patch is for the '{$bundle_project_id}' project, but the ".
|
|
|
|
"working copy does not have an '.arcconfig' file to identify which ".
|
|
|
|
"project it belongs to.";
|
|
|
|
}
|
2011-11-30 07:27:40 +01:00
|
|
|
$ok = phutil_console_confirm(
|
2012-08-10 03:39:41 +02:00
|
|
|
"{$issue} Still try to apply the patch?",
|
2013-02-19 23:09:20 +01:00
|
|
|
$default_no = false);
|
2011-11-30 07:27:40 +01:00
|
|
|
if (!$ok) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-03 01:21:14 +01:00
|
|
|
// Check to see if the bundle's base revision matches the working copy
|
|
|
|
// base revision
|
2012-12-17 21:54:08 +01:00
|
|
|
if ($repository_api->supportsLocalCommits()) {
|
2012-03-07 22:02:53 +01:00
|
|
|
$bundle_base_rev = $bundle->getBaseRevision();
|
|
|
|
if (empty($bundle_base_rev)) {
|
|
|
|
// this means $source is SOURCE_PATCH || SOURCE_BUNDLE w/ $version < 2
|
|
|
|
// they don't have a base rev so just do nothing
|
|
|
|
$commit_exists = true;
|
|
|
|
} else {
|
|
|
|
$commit_exists =
|
|
|
|
$repository_api->hasLocalCommit($bundle_base_rev);
|
|
|
|
}
|
|
|
|
if (!$commit_exists) {
|
2011-12-03 01:21:14 +01:00
|
|
|
// we have a problem...! lots of work because we need to ask
|
|
|
|
// differential for revision information for these base revisions
|
|
|
|
// to improve our error message.
|
|
|
|
$bundle_base_rev_str = null;
|
2012-03-07 22:02:53 +01:00
|
|
|
$source_base_rev = $repository_api->getWorkingCopyRevision();
|
2011-12-03 01:21:14 +01:00
|
|
|
$source_base_rev_str = null;
|
|
|
|
|
2012-03-07 22:02:53 +01:00
|
|
|
if ($repository_api instanceof ArcanistGitAPI) {
|
2011-12-03 01:21:14 +01:00
|
|
|
$hash_type = ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT;
|
|
|
|
} else if ($repository_api instanceof ArcanistMercurialAPI) {
|
|
|
|
$hash_type = ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT;
|
|
|
|
} else {
|
|
|
|
$hash_type = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($hash_type) {
|
|
|
|
// 2 round trips because even though we could send off one query
|
|
|
|
// we wouldn't be able to tell which revisions were for which hash
|
|
|
|
$hash = array($hash_type, $bundle_base_rev);
|
|
|
|
$bundle_revision = $this->loadRevisionFromHash($hash);
|
|
|
|
$hash = array($hash_type, $source_base_rev);
|
|
|
|
$source_revision = $this->loadRevisionFromHash($hash);
|
|
|
|
|
|
|
|
if ($bundle_revision) {
|
|
|
|
$bundle_base_rev_str = $bundle_base_rev .
|
|
|
|
' \ D' . $bundle_revision['id'];
|
|
|
|
}
|
|
|
|
if ($source_revision) {
|
|
|
|
$source_base_rev_str = $source_base_rev .
|
|
|
|
' \ D' . $source_revision['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bundle_base_rev_str = nonempty($bundle_base_rev_str,
|
|
|
|
$bundle_base_rev);
|
|
|
|
$source_base_rev_str = nonempty($source_base_rev_str,
|
|
|
|
$source_base_rev);
|
|
|
|
|
|
|
|
$ok = phutil_console_confirm(
|
|
|
|
"This diff is against commit {$bundle_base_rev_str}, but the ".
|
2012-03-07 22:02:53 +01:00
|
|
|
"commit is nowhere in the working copy. Try to apply it against ".
|
|
|
|
"the current working copy state? ({$source_base_rev_str})",
|
2013-02-19 23:09:20 +01:00
|
|
|
$default_no = false);
|
2011-12-03 01:21:14 +01:00
|
|
|
if (!$ok) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 07:27:40 +01:00
|
|
|
}
|
|
|
|
|
2011-03-08 05:21:16 +01:00
|
|
|
/**
|
|
|
|
* Create parent directories one at a time, since we need to "svn add" each
|
|
|
|
* one. (Technically we could "svn add" just the topmost new directory.)
|
|
|
|
*/
|
|
|
|
private function createParentDirectoryOf($path) {
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
$dir = dirname($path);
|
|
|
|
if (Filesystem::pathExists($dir)) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Make sure the parent directory exists before we make this one.
|
|
|
|
$this->createParentDirectoryOf($dir);
|
|
|
|
execx(
|
|
|
|
'(cd %s && mkdir %s)',
|
|
|
|
$repository_api->getPath(),
|
|
|
|
$dir);
|
|
|
|
passthru(
|
|
|
|
csprintf(
|
|
|
|
'(cd %s && svn add %s)',
|
|
|
|
$repository_api->getPath(),
|
|
|
|
$dir));
|
|
|
|
}
|
|
|
|
}
|
2011-12-03 01:21:14 +01:00
|
|
|
|
|
|
|
private function loadRevisionFromHash($hash) {
|
2012-02-20 00:24:03 +01:00
|
|
|
// TODO -- de-hack this as permissions become more clear with things
|
|
|
|
// like T848 (add scope to OAuth)
|
|
|
|
if (!$this->isConduitAuthenticated()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-12-03 01:21:14 +01:00
|
|
|
$conduit = $this->getConduit();
|
|
|
|
|
|
|
|
$revisions = $conduit->callMethodSynchronous(
|
|
|
|
'differential.query',
|
|
|
|
array(
|
|
|
|
'commitHashes' => array($hash),
|
2013-02-19 23:09:20 +01:00
|
|
|
));
|
2011-12-03 01:21:14 +01:00
|
|
|
|
|
|
|
|
2012-05-07 17:16:14 +02:00
|
|
|
// grab the latest closed revision only
|
2011-12-03 01:21:14 +01:00
|
|
|
$found_revision = null;
|
|
|
|
$revisions = isort($revisions, 'dateModified');
|
|
|
|
foreach ($revisions as $revision) {
|
2012-05-07 17:16:14 +02:00
|
|
|
if ($revision['status'] == ArcanistDifferentialRevisionStatus::CLOSED) {
|
2011-12-03 01:21:14 +01:00
|
|
|
$found_revision = $revision;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $found_revision;
|
|
|
|
}
|
2013-10-17 23:59:04 +02:00
|
|
|
|
|
|
|
private function buildDependencyGraph(ArcanistBundle $bundle) {
|
|
|
|
$graph = null;
|
|
|
|
if ($this->getRepositoryAPI() instanceof ArcanistSubversionAPI) {
|
|
|
|
return $graph;
|
|
|
|
}
|
|
|
|
$revision_id = $bundle->getRevisionID();
|
|
|
|
if ($revision_id) {
|
|
|
|
$revisions = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'differential.query',
|
|
|
|
array(
|
|
|
|
'ids' => array($revision_id),
|
|
|
|
));
|
|
|
|
if ($revisions) {
|
|
|
|
$revision = head($revisions);
|
|
|
|
$rev_auxiliary = idx($revision, 'auxiliary', array());
|
|
|
|
$phids = idx($rev_auxiliary, 'phabricator:depends-on', array());
|
|
|
|
if ($phids) {
|
|
|
|
$revision_phid = $revision['phid'];
|
|
|
|
$graph = id(new ArcanistDifferentialDependencyGraph())
|
|
|
|
->setConduit($this->getConduit())
|
|
|
|
->setRepositoryAPI($this->getRepositoryAPI())
|
|
|
|
->setStartPHID($revision_phid)
|
|
|
|
->addNodes(array($revision_phid => $phids))
|
|
|
|
->loadGraph();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $graph;
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|