2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-05 20:26:17 +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
|
|
|
/**
|
|
|
|
* Sends changes from your working copy to Differential for code review.
|
|
|
|
*
|
2012-01-05 20:26:17 +01:00
|
|
|
* @task lintunit Lint and Unit Tests
|
|
|
|
* @task message Commit and Update Messages
|
|
|
|
* @task diffspec Diff Specification
|
|
|
|
* @task diffprop Diff Properties
|
|
|
|
*
|
2011-02-19 20:36:08 +01:00
|
|
|
* @group workflow
|
|
|
|
*/
|
2012-01-31 21:07:05 +01:00
|
|
|
final class ArcanistDiffWorkflow extends ArcanistBaseWorkflow {
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-08-06 22:40:20 +02:00
|
|
|
private $console;
|
2011-01-10 00:22:25 +01:00
|
|
|
private $hasWarnedExternals = false;
|
2011-01-12 05:21:17 +01:00
|
|
|
private $unresolvedLint;
|
2012-02-23 00:57:55 +01:00
|
|
|
private $lintExcuse;
|
|
|
|
private $unitExcuse;
|
2012-01-31 21:07:19 +01:00
|
|
|
private $testResults;
|
2011-01-22 01:17:30 +01:00
|
|
|
private $diffID;
|
2012-02-23 18:18:49 +01:00
|
|
|
private $revisionID;
|
2012-07-03 00:53:22 +02:00
|
|
|
private $postponedLinters;
|
Fix some arc/mercurial issues
Summary:
- In "arc which", we recommend "--rev x --rev ." to show changes. This is not accurate if there are uncommitted changes in the working copy. Just "--rev x" shows the correct changes (implicitly, the other end of the range is the working copy state).
- When you diff only working copy changes, we currently incorrectly identify all your open revisions as belonging to the working copy. Instead, correctly identify none of them as belonging to the working copy (in theory, we could go farther than this and do path-based identification like SVN, but with --amend in hg 2.2+ this workflow should be going away in the long run).
- If you have uncommitted working copy changes, never try to amend.
Test Plan: Ran "arc which .", "arc diff ." in a working copy with dirty changes, got better results than before.
Reviewers: dschleimer, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1507
Differential Revision: https://secure.phabricator.com/D2980
2012-07-18 01:16:11 +02:00
|
|
|
private $haveUncommittedChanges = false;
|
2012-10-13 00:01:19 +02:00
|
|
|
private $diffPropertyFutures = array();
|
2012-10-16 20:51:15 +02:00
|
|
|
private $commitMessageFromRevision;
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-01-10 00:22:25 +01:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**diff** [__paths__] (svn)
|
2011-12-03 00:50:36 +01:00
|
|
|
**diff** [__commit__] (git, hg)
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2011-12-03 00:50:36 +01:00
|
|
|
Supports: git, svn, hg
|
2011-01-10 00:22:25 +01:00
|
|
|
Generate a Differential diff or revision from local changes.
|
|
|
|
|
|
|
|
Under git, you can specify a commit (like __HEAD^^^__ or __master__)
|
|
|
|
and Differential will generate a diff against the merge base of that
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
commit and HEAD.
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
Under svn, you can choose to include only some of the modified files
|
|
|
|
in the working copy in the diff by specifying their paths. If you
|
|
|
|
omit paths, all changes are included in the diff.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
2012-06-27 20:21:19 +02:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function requiresWorkingCopy() {
|
2012-01-05 22:36:24 +01:00
|
|
|
return !$this->isRawDiffSource();
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
2012-03-05 19:08:50 +01:00
|
|
|
if (!$this->isRawDiffSource()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->getArgument('use-commit-message')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
2011-01-30 02:18:32 +01:00
|
|
|
|
2011-01-22 01:17:30 +01:00
|
|
|
public function getDiffID() {
|
|
|
|
return $this->diffID;
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
public function getArguments() {
|
2012-09-18 23:14:12 +02:00
|
|
|
$arguments = array(
|
2011-01-10 00:22:25 +01:00
|
|
|
'message' => array(
|
|
|
|
'short' => 'm',
|
|
|
|
'param' => 'message',
|
|
|
|
'help' =>
|
2012-03-20 03:15:58 +01:00
|
|
|
"When updating a revision, use the specified message instead of ".
|
|
|
|
"prompting.",
|
2011-01-10 00:22:25 +01:00
|
|
|
),
|
2011-12-03 00:50:36 +01:00
|
|
|
'message-file' => array(
|
|
|
|
'short' => 'F',
|
|
|
|
'param' => 'file',
|
|
|
|
'paramtype' => 'file',
|
|
|
|
'help' => 'When creating a revision, read revision information '.
|
|
|
|
'from this file.',
|
|
|
|
),
|
2012-01-13 04:03:11 +01:00
|
|
|
'use-commit-message' => array(
|
|
|
|
'supports' => array(
|
|
|
|
'git',
|
|
|
|
// TODO: Support mercurial.
|
|
|
|
),
|
|
|
|
'short' => 'C',
|
|
|
|
'param' => 'commit',
|
|
|
|
'help' => 'Read revision information from a specific commit.',
|
|
|
|
'conflicts' => array(
|
|
|
|
'only' => null,
|
|
|
|
'preview' => null,
|
|
|
|
'update' => null,
|
|
|
|
),
|
|
|
|
),
|
2011-01-10 00:22:25 +01:00
|
|
|
'edit' => array(
|
|
|
|
'supports' => array(
|
|
|
|
'git',
|
|
|
|
),
|
|
|
|
'nosupport' => array(
|
|
|
|
'svn' => 'Edit revisions via the web interface when using SVN.',
|
|
|
|
),
|
|
|
|
'help' =>
|
|
|
|
"When updating a revision under git, edit revision information ".
|
|
|
|
"before updating.",
|
|
|
|
),
|
2012-01-05 22:36:24 +01:00
|
|
|
'raw' => array(
|
|
|
|
'help' =>
|
|
|
|
"Read diff from stdin, not from the working copy. This disables ".
|
|
|
|
"many Arcanist/Phabricator features which depend on having access ".
|
|
|
|
"to the working copy.",
|
|
|
|
'conflicts' => array(
|
|
|
|
'less-context' => null,
|
|
|
|
'apply-patches' => '--raw disables lint.',
|
|
|
|
'never-apply-patches' => '--raw disables lint.',
|
|
|
|
'lintall' => '--raw disables lint.',
|
|
|
|
|
|
|
|
'create' => '--raw and --create both need stdin. '.
|
|
|
|
'Use --raw-command.',
|
|
|
|
'edit' => '--raw and --edit both need stdin. '.
|
|
|
|
'Use --raw-command.',
|
|
|
|
'raw-command' => null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'raw-command' => array(
|
|
|
|
'param' => 'command',
|
|
|
|
'help' =>
|
|
|
|
"Generate diff by executing a specified command, not from the ".
|
|
|
|
"working copy. This disables many Arcanist/Phabricator features ".
|
|
|
|
"which depend on having access to the working copy.",
|
|
|
|
'conflicts' => array(
|
|
|
|
'less-context' => null,
|
|
|
|
'apply-patches' => '--raw-command disables lint.',
|
|
|
|
'never-apply-patches' => '--raw-command disables lint.',
|
|
|
|
'lintall' => '--raw-command disables lint.',
|
|
|
|
),
|
|
|
|
),
|
2011-12-03 00:50:36 +01:00
|
|
|
'create' => array(
|
2012-01-09 18:33:55 +01:00
|
|
|
'help' => "Always create a new revision.",
|
2011-12-03 00:50:36 +01:00
|
|
|
'conflicts' => array(
|
|
|
|
'edit' => '--create can not be used with --edit.',
|
2012-01-05 20:26:17 +01:00
|
|
|
'only' => '--create can not be used with --only.',
|
|
|
|
'preview' => '--create can not be used with --preview.',
|
2012-01-09 18:33:55 +01:00
|
|
|
'update' => '--create can not be used with --update.',
|
2011-12-03 00:50:36 +01:00
|
|
|
),
|
|
|
|
),
|
2012-01-09 18:33:55 +01:00
|
|
|
'update' => array(
|
|
|
|
'param' => 'revision_id',
|
|
|
|
'help' => "Always update a specific revision.",
|
|
|
|
),
|
2011-01-10 00:22:25 +01:00
|
|
|
'nounit' => array(
|
|
|
|
'help' =>
|
|
|
|
"Do not run unit tests.",
|
|
|
|
),
|
|
|
|
'nolint' => array(
|
|
|
|
'help' =>
|
|
|
|
"Do not run lint.",
|
|
|
|
'conflicts' => array(
|
|
|
|
'lintall' => '--nolint suppresses lint.',
|
2011-01-10 23:03:12 +01:00
|
|
|
'apply-patches' => '--nolint suppresses lint.',
|
|
|
|
'never-apply-patches' => '--nolint suppresses lint.',
|
2011-01-10 00:22:25 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'only' => array(
|
|
|
|
'help' =>
|
|
|
|
"Only generate a diff, without running lint, unit tests, or other ".
|
2012-01-05 22:36:24 +01:00
|
|
|
"auxiliary steps. See also --preview.",
|
2011-01-10 00:22:25 +01:00
|
|
|
'conflicts' => array(
|
|
|
|
'preview' => null,
|
|
|
|
'message' => '--only does not affect revisions.',
|
|
|
|
'edit' => '--only does not affect revisions.',
|
|
|
|
'lintall' => '--only suppresses lint.',
|
2011-01-10 23:03:12 +01:00
|
|
|
'apply-patches' => '--only suppresses lint.',
|
|
|
|
'never-apply-patches' => '--only suppresses lint.',
|
2011-01-10 00:22:25 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'preview' => array(
|
|
|
|
'help' =>
|
|
|
|
"Instead of creating or updating a revision, only create a diff, ".
|
|
|
|
"which you may later attach to a revision. This still runs lint ".
|
|
|
|
"unit tests. See also --only.",
|
|
|
|
'conflicts' => array(
|
|
|
|
'only' => null,
|
|
|
|
'edit' => '--preview does affect revisions.',
|
|
|
|
'message' => '--preview does not update any revision.',
|
|
|
|
),
|
|
|
|
),
|
2011-12-01 17:56:03 +01:00
|
|
|
'encoding' => array(
|
|
|
|
'param' => 'encoding',
|
|
|
|
'help' =>
|
|
|
|
"Attempt to convert non UTF-8 hunks into specified encoding.",
|
|
|
|
),
|
2011-01-10 00:22:25 +01:00
|
|
|
'allow-untracked' => array(
|
|
|
|
'help' =>
|
|
|
|
"Skip checks for untracked files in the working copy.",
|
|
|
|
),
|
2012-03-01 01:30:17 +01:00
|
|
|
'excuse' => array(
|
|
|
|
'param' => 'excuse',
|
|
|
|
'help' => 'Provide a prepared in advance excuse for any lints/tests'.
|
|
|
|
' shall they fail.',
|
|
|
|
),
|
2011-01-10 00:22:25 +01:00
|
|
|
'less-context' => array(
|
|
|
|
'help' =>
|
|
|
|
"Normally, files are diffed with full context: the entire file is ".
|
|
|
|
"sent to Differential so reviewers can 'show more' and see it. If ".
|
|
|
|
"you are making changes to very large files with tens of thousands ".
|
|
|
|
"of lines, this may not work well. With this flag, a diff will ".
|
|
|
|
"be created that has only a few lines of context.",
|
|
|
|
),
|
|
|
|
'lintall' => array(
|
|
|
|
'help' =>
|
|
|
|
"Raise all lint warnings, not just those on lines you changed.",
|
2011-02-02 05:32:10 +01:00
|
|
|
'passthru' => array(
|
|
|
|
'lint' => true,
|
|
|
|
),
|
2011-01-10 00:22:25 +01:00
|
|
|
),
|
2011-01-10 23:03:12 +01:00
|
|
|
'apply-patches' => array(
|
|
|
|
'help' =>
|
|
|
|
'Apply patches suggested by lint to the working copy without '.
|
|
|
|
'prompting.',
|
|
|
|
'conflicts' => array(
|
|
|
|
'never-apply-patches' => true,
|
|
|
|
),
|
2011-02-02 05:32:10 +01:00
|
|
|
'passthru' => array(
|
|
|
|
'lint' => true,
|
|
|
|
),
|
2011-01-10 23:03:12 +01:00
|
|
|
),
|
|
|
|
'never-apply-patches' => array(
|
|
|
|
'help' => 'Never apply patches suggested by lint.',
|
|
|
|
'conflicts' => array(
|
|
|
|
'apply-patches' => true,
|
|
|
|
),
|
2011-02-02 05:32:10 +01:00
|
|
|
'passthru' => array(
|
|
|
|
'lint' => true,
|
|
|
|
),
|
2011-01-10 23:03:12 +01:00
|
|
|
),
|
2012-04-06 21:23:19 +02:00
|
|
|
'amend-all' => array(
|
|
|
|
'help' =>
|
|
|
|
'When linting git repositories, amend HEAD with all patches '.
|
|
|
|
'suggested by lint without prompting.',
|
|
|
|
'passthru' => array(
|
|
|
|
'lint' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'amend-autofixes' => array(
|
|
|
|
'help' =>
|
|
|
|
'When linting git repositories, amend HEAD with autofix '.
|
|
|
|
'patches suggested by lint without prompting.',
|
|
|
|
'passthru' => array(
|
|
|
|
'lint' => true,
|
|
|
|
),
|
|
|
|
),
|
2011-06-23 23:37:43 +02:00
|
|
|
'json' => array(
|
|
|
|
'help' =>
|
|
|
|
'Emit machine-readable JSON. EXPERIMENTAL! Probably does not work!',
|
|
|
|
),
|
2012-02-01 23:33:01 +01:00
|
|
|
'no-amend' => array(
|
|
|
|
'help' => 'Never amend commits in the working copy.',
|
|
|
|
),
|
2012-03-20 03:17:10 +01:00
|
|
|
'uncommitted' => array(
|
Fix some arc/mercurial issues
Summary:
- In "arc which", we recommend "--rev x --rev ." to show changes. This is not accurate if there are uncommitted changes in the working copy. Just "--rev x" shows the correct changes (implicitly, the other end of the range is the working copy state).
- When you diff only working copy changes, we currently incorrectly identify all your open revisions as belonging to the working copy. Instead, correctly identify none of them as belonging to the working copy (in theory, we could go farther than this and do path-based identification like SVN, but with --amend in hg 2.2+ this workflow should be going away in the long run).
- If you have uncommitted working copy changes, never try to amend.
Test Plan: Ran "arc which .", "arc diff ." in a working copy with dirty changes, got better results than before.
Reviewers: dschleimer, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1507
Differential Revision: https://secure.phabricator.com/D2980
2012-07-18 01:16:11 +02:00
|
|
|
'help' => 'Suppress warning about uncommitted changes.',
|
2012-03-20 03:17:10 +01:00
|
|
|
'supports' => array(
|
|
|
|
'hg',
|
|
|
|
),
|
|
|
|
),
|
2012-04-10 21:06:41 +02:00
|
|
|
'verbatim' => array(
|
With `--verbatim`, update some fields automatically when updating revisions
Summary:
Essentially D2391, but with, uh, more comments?
- I forgot that we already implemented shouldOverwriteWhenCommitMessageIsEdited(). This patch already behaves nearly correctly.
- Requires changes in D2412.
- Use `'edit' => 'edit'`, which does the same thing as `'edit' => true`, but is more correct after the "edit" / "create" split.
- Under "--verbatim", always get the message "from the user", which means "from the working copy" because verbtatim disables the editor part.
Test Plan:
- Created and updated revisions with `arc diff`.
- Created and updated revisions with `arc diff --verbatim`.
- Updated revisions with `arc diff --edit`.
Reviewers: jungejason, btrahan
Reviewed By: jungejason
CC: vrana, aran
Differential Revision: https://secure.phabricator.com/D2411
2012-05-07 17:16:29 +02:00
|
|
|
'help' => 'When creating a revision, try to use the working copy '.
|
|
|
|
'commit message verbatim, without prompting to edit it. '.
|
|
|
|
'When updating a revision, update some fields from the '.
|
|
|
|
'local commit message.',
|
2012-04-10 21:06:41 +02:00
|
|
|
'supports' => array(
|
|
|
|
'hg',
|
|
|
|
'git',
|
|
|
|
),
|
|
|
|
'conflicts' => array(
|
|
|
|
'use-commit-message' => true,
|
|
|
|
'update' => true,
|
|
|
|
'only' => true,
|
|
|
|
'preview' => true,
|
|
|
|
'raw' => true,
|
|
|
|
'raw-command' => true,
|
|
|
|
'message-file' => true,
|
|
|
|
),
|
|
|
|
),
|
2012-05-22 23:38:53 +02:00
|
|
|
'reviewers' => array(
|
|
|
|
'param' => 'usernames',
|
|
|
|
'help' => 'When creating a revision, add reviewers.',
|
|
|
|
'conflicts' => array(
|
|
|
|
'only' => true,
|
|
|
|
'preview' => true,
|
|
|
|
'update' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'cc' => array(
|
|
|
|
'param' => 'usernames',
|
|
|
|
'help' => 'When creating a revision, add CCs.',
|
|
|
|
'conflicts' => array(
|
|
|
|
'only' => true,
|
|
|
|
'preview' => true,
|
|
|
|
'update' => true,
|
|
|
|
),
|
|
|
|
),
|
2012-05-30 23:11:07 +02:00
|
|
|
'skip-binaries' => array(
|
|
|
|
'help' => 'Do not upload binaries (like images).',
|
|
|
|
),
|
2012-07-17 00:54:11 +02:00
|
|
|
'ignore-unsound-tests' => array(
|
|
|
|
'help' => 'Ignore unsound test failures without prompting.',
|
|
|
|
),
|
Add a DSL for selecting base commits
Summary:
New optional mode. If you set 'base' in local, project or global config or pass '--base' to 'arc diff' or 'arc which', it switches to DSL mode.
In DSL mode, lists of rules from args, local, project and global config are resolved, in that order. Rules can manipulate the rule machine or resolve into actual commits. Provides support for some 'arc' rules (mostly machine manipulation) and 'git' rules (symbolic ref and merge-base).
Test Plan:
Ran unit tests. Also:
```$ arc which --show-base --base 'arc:prompt'
Against which commit? HEAD
HEAD
$ arc which --show-base --base 'git:HEAD'
HEAD
$ arc which --show-base --base 'git:fake'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'git:origin/master'
origin/master
$ arc which --show-base --base 'git:upstream'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'literal:derp'
derp
$ arc which --show-base --base 'arc:halt'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc set-config --local base git:origin/master
Set key 'base' = 'git:origin/master' in local config.
$ arc which --show-base
origin/master
$ arc which --show-base --base 'git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:yield, git:HEAD^'
origin/master
$ arc which --show-base --base 'arc:global, git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:global, git:merge-base(origin/master)'
3f4f8992fba8d1f142974da36a82bae900e247c0```
Reviewers: dschleimer, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1233
Differential Revision: https://secure.phabricator.com/D2748
2012-06-15 23:01:28 +02:00
|
|
|
'base' => array(
|
|
|
|
'param' => 'rules',
|
|
|
|
'help' => 'Additional rules for determining base revision.',
|
|
|
|
'nosupport' => array(
|
|
|
|
'svn' => 'Subversion does not use base commits.',
|
|
|
|
),
|
|
|
|
'supports' => array('git', 'hg'),
|
|
|
|
),
|
2012-08-06 22:40:20 +02:00
|
|
|
'no-diff' => array(
|
|
|
|
'help' => 'Only run lint and unit tests. Intended for internal use.',
|
|
|
|
),
|
|
|
|
'background' => array(
|
|
|
|
'param' => 'bool',
|
|
|
|
'help' =>
|
|
|
|
'Run lint and unit tests on background. '.
|
2012-09-18 23:14:12 +02:00
|
|
|
'"0" to disable, "1" to enable (default).',
|
2012-08-06 22:40:20 +02:00
|
|
|
),
|
2011-01-10 00:22:25 +01:00
|
|
|
'*' => 'paths',
|
|
|
|
);
|
2012-09-18 23:14:12 +02:00
|
|
|
|
|
|
|
if (phutil_is_windows()) {
|
|
|
|
unset($arguments['background']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $arguments;
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2012-01-05 22:36:24 +01:00
|
|
|
public function isRawDiffSource() {
|
|
|
|
return $this->getArgument('raw') || $this->getArgument('raw-command');
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function run() {
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console = PhutilConsole::getConsole();
|
|
|
|
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
$this->runRepositoryAPISetup();
|
|
|
|
|
2012-08-06 22:40:20 +02:00
|
|
|
if ($this->getArgument('no-diff')) {
|
|
|
|
$this->removeScratchFile('diff-result.json');
|
|
|
|
$data = $this->runLintUnit();
|
2012-08-08 21:08:41 +02:00
|
|
|
$this->writeScratchJSONFile('diff-result.json', $data);
|
2012-08-06 22:40:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-20 21:51:01 +01:00
|
|
|
$this->runDiffSetupBasics();
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-09-26 02:57:01 +02:00
|
|
|
$background = $this->getArgument('background', true);
|
|
|
|
if ($this->isRawDiffSource() || phutil_is_windows()) {
|
|
|
|
$background = false;
|
|
|
|
}
|
2012-09-18 23:14:12 +02:00
|
|
|
|
|
|
|
if ($background) {
|
2012-09-24 20:32:38 +02:00
|
|
|
$argv = $this->getPassedArguments();
|
2012-08-06 22:40:20 +02:00
|
|
|
if (!PhutilConsoleFormatter::getDisableANSI()) {
|
2012-09-24 20:32:38 +02:00
|
|
|
array_unshift($argv, '--ansi');
|
2012-08-06 22:40:20 +02:00
|
|
|
}
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
|
2012-09-24 20:32:38 +02:00
|
|
|
$lint_unit = new ExecFuture(
|
|
|
|
'php %s --recon diff --no-diff %Ls',
|
|
|
|
phutil_get_library_root('arcanist').'/../scripts/arcanist.php',
|
|
|
|
$argv);
|
2012-08-06 22:40:20 +02:00
|
|
|
$lint_unit->write('', true);
|
|
|
|
$lint_unit->start();
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
$commit_message = $this->buildCommitMessage();
|
2011-03-13 02:57:35 +01:00
|
|
|
|
2012-09-04 21:08:04 +02:00
|
|
|
$this->dispatchEvent(
|
|
|
|
ArcanistEventType::TYPE_DIFF_DIDBUILDMESSAGE,
|
|
|
|
array());
|
2012-08-28 03:21:49 +02:00
|
|
|
|
2012-08-08 21:08:41 +02:00
|
|
|
if (!$this->shouldOnlyCreateDiff()) {
|
|
|
|
$revision = $this->buildRevisionFromCommitMessage($commit_message);
|
|
|
|
}
|
|
|
|
|
2012-09-18 23:14:12 +02:00
|
|
|
if ($background) {
|
2012-08-06 22:40:20 +02:00
|
|
|
$server = new PhutilConsoleServer();
|
|
|
|
$server->addExecFutureClient($lint_unit);
|
|
|
|
$server->run();
|
|
|
|
|
|
|
|
list($err) = $lint_unit->resolve();
|
2012-08-08 21:08:41 +02:00
|
|
|
$data = $this->readScratchJSONFile('diff-result.json');
|
2012-08-06 22:40:20 +02:00
|
|
|
if ($err || !$data) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$data = $this->runLintUnit();
|
|
|
|
}
|
|
|
|
$lint_result = $data['lintResult'];
|
|
|
|
$this->lintExcuse = $data['lintExcuse'];
|
|
|
|
$this->unresolvedLint = $data['unresolvedLint'];
|
|
|
|
$this->postponedLinters = $data['postponedLinters'];
|
|
|
|
$unit_result = $data['unitResult'];
|
|
|
|
$this->unitExcuse = $data['unitExcuse'];
|
|
|
|
$this->testResults = $data['testResults'];
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
$changes = $this->generateChanges();
|
|
|
|
if (!$changes) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"There are no changes to generate a diff from!");
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
$diff_spec = array(
|
2012-01-05 22:36:24 +01:00
|
|
|
'changes' => mpull($changes, 'toDictionary'),
|
2012-01-05 20:26:17 +01:00
|
|
|
'lintStatus' => $this->getLintStatus($lint_result),
|
|
|
|
'unitStatus' => $this->getUnitStatus($unit_result),
|
|
|
|
) + $this->buildDiffSpecification();
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-02-20 21:51:01 +01:00
|
|
|
$conduit = $this->getConduit();
|
2011-01-10 00:22:25 +01:00
|
|
|
$diff_info = $conduit->callMethodSynchronous(
|
|
|
|
'differential.creatediff',
|
2012-01-05 20:26:17 +01:00
|
|
|
$diff_spec);
|
|
|
|
|
|
|
|
$this->diffID = $diff_info['diffid'];
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-09-04 21:08:04 +02:00
|
|
|
$event = $this->dispatchEvent(
|
2012-08-13 21:20:34 +02:00
|
|
|
ArcanistEventType::TYPE_DIFF_WASCREATED,
|
|
|
|
array(
|
|
|
|
'diffID' => $diff_info['diffid'],
|
|
|
|
'lintResult' => $lint_result,
|
|
|
|
'unitResult' => $unit_result,
|
|
|
|
));
|
2012-07-03 00:53:22 +02:00
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
$this->updateLintDiffProperty();
|
|
|
|
$this->updateUnitDiffProperty();
|
|
|
|
$this->updateLocalDiffProperty();
|
2012-10-13 00:01:19 +02:00
|
|
|
$this->resolveDiffPropertyUpdates();
|
2011-01-12 07:13:31 +01:00
|
|
|
|
2012-02-20 21:51:01 +01:00
|
|
|
$output_json = $this->getArgument('json');
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($this->shouldOnlyCreateDiff()) {
|
2011-06-23 23:37:43 +02:00
|
|
|
if (!$output_json) {
|
|
|
|
echo phutil_console_format(
|
|
|
|
"Created a new Differential diff:\n".
|
|
|
|
" **Diff URI:** __%s__\n\n",
|
|
|
|
$diff_info['uri']);
|
|
|
|
} else {
|
|
|
|
$human = ob_get_clean();
|
|
|
|
echo json_encode(array(
|
|
|
|
'diffURI' => $diff_info['uri'],
|
2012-01-05 20:26:17 +01:00
|
|
|
'diffID' => $this->getDiffID(),
|
2011-06-23 23:37:43 +02:00
|
|
|
'human' => $human,
|
|
|
|
))."\n";
|
|
|
|
ob_start();
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
} else {
|
2012-01-05 20:26:17 +01:00
|
|
|
|
2012-08-08 21:08:41 +02:00
|
|
|
$revision['diffid'] = $this->getDiffID();
|
2012-02-23 18:18:49 +01:00
|
|
|
|
2012-08-08 21:08:41 +02:00
|
|
|
if ($commit_message->getRevisionID()) {
|
2011-01-10 00:22:25 +01:00
|
|
|
$future = $conduit->callMethod(
|
|
|
|
'differential.updaterevision',
|
|
|
|
$revision);
|
|
|
|
$result = $future->resolve();
|
2012-08-08 21:08:41 +02:00
|
|
|
|
|
|
|
foreach (array('edit-messages.json', 'update-messages.json') as $file) {
|
|
|
|
$messages = $this->readScratchJSONFile($file);
|
|
|
|
unset($messages[$revision['id']]);
|
|
|
|
$this->writeScratchJSONFile($file, $messages);
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
echo "Updated an existing Differential revision:\n";
|
|
|
|
} else {
|
2011-07-15 21:44:03 +02:00
|
|
|
$revision['user'] = $this->getUserPHID();
|
2012-08-30 21:28:35 +02:00
|
|
|
|
|
|
|
$revision = $this->dispatchWillCreateRevisionEvent($revision);
|
|
|
|
|
2012-10-13 00:01:19 +02:00
|
|
|
$result = $conduit->callMethodSynchronous(
|
2011-01-10 00:22:25 +01:00
|
|
|
'differential.createrevision',
|
|
|
|
$revision);
|
2011-12-21 00:05:46 +01:00
|
|
|
|
|
|
|
$revised_message = $conduit->callMethodSynchronous(
|
|
|
|
'differential.getcommitmessage',
|
|
|
|
array(
|
|
|
|
'revision_id' => $result['revisionid'],
|
|
|
|
));
|
|
|
|
|
Fix some arc/mercurial issues
Summary:
- In "arc which", we recommend "--rev x --rev ." to show changes. This is not accurate if there are uncommitted changes in the working copy. Just "--rev x" shows the correct changes (implicitly, the other end of the range is the working copy state).
- When you diff only working copy changes, we currently incorrectly identify all your open revisions as belonging to the working copy. Instead, correctly identify none of them as belonging to the working copy (in theory, we could go farther than this and do path-based identification like SVN, but with --amend in hg 2.2+ this workflow should be going away in the long run).
- If you have uncommitted working copy changes, never try to amend.
Test Plan: Ran "arc which .", "arc diff ." in a working copy with dirty changes, got better results than before.
Reviewers: dschleimer, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1507
Differential Revision: https://secure.phabricator.com/D2980
2012-07-18 01:16:11 +02:00
|
|
|
if ($this->shouldAmend()) {
|
2012-01-05 22:36:24 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
2012-06-04 21:30:50 +02:00
|
|
|
if ($repository_api->supportsAmend()) {
|
2012-01-05 22:36:24 +01:00
|
|
|
echo "Updating commit message...\n";
|
2012-06-04 21:30:50 +02:00
|
|
|
$repository_api->amendCommit($revised_message);
|
|
|
|
} else {
|
|
|
|
echo "Commit message was not amended. Amending commit message is ".
|
|
|
|
"only supported in git and hg (version 2.2 or newer)";
|
2012-01-05 22:36:24 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-21 00:05:46 +01:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
echo "Created a new Differential revision:\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$uri = $result['uri'];
|
|
|
|
echo phutil_console_format(
|
|
|
|
" **Revision URI:** __%s__\n\n",
|
|
|
|
$uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Included changes:\n";
|
|
|
|
foreach ($changes as $change) {
|
|
|
|
echo ' '.$change->renderTextSummary()."\n";
|
|
|
|
}
|
2011-01-30 02:18:32 +01:00
|
|
|
|
2011-06-23 23:37:43 +02:00
|
|
|
if ($output_json) {
|
|
|
|
ob_get_clean();
|
|
|
|
}
|
|
|
|
|
2012-02-21 21:35:39 +01:00
|
|
|
$this->removeScratchFile('create-message');
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
private function runRepositoryAPISetup() {
|
|
|
|
if (!$this->requiresRepositoryAPI()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-23 01:22:52 +01:00
|
|
|
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
if ($this->getArgument('less-context')) {
|
|
|
|
$repository_api->setDiffLinesOfContext(3);
|
|
|
|
}
|
Add a DSL for selecting base commits
Summary:
New optional mode. If you set 'base' in local, project or global config or pass '--base' to 'arc diff' or 'arc which', it switches to DSL mode.
In DSL mode, lists of rules from args, local, project and global config are resolved, in that order. Rules can manipulate the rule machine or resolve into actual commits. Provides support for some 'arc' rules (mostly machine manipulation) and 'git' rules (symbolic ref and merge-base).
Test Plan:
Ran unit tests. Also:
```$ arc which --show-base --base 'arc:prompt'
Against which commit? HEAD
HEAD
$ arc which --show-base --base 'git:HEAD'
HEAD
$ arc which --show-base --base 'git:fake'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'git:origin/master'
origin/master
$ arc which --show-base --base 'git:upstream'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'literal:derp'
derp
$ arc which --show-base --base 'arc:halt'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc set-config --local base git:origin/master
Set key 'base' = 'git:origin/master' in local config.
$ arc which --show-base
origin/master
$ arc which --show-base --base 'git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:yield, git:HEAD^'
origin/master
$ arc which --show-base --base 'arc:global, git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:global, git:merge-base(origin/master)'
3f4f8992fba8d1f142974da36a82bae900e247c0```
Reviewers: dschleimer, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1233
Differential Revision: https://secure.phabricator.com/D2748
2012-06-15 23:01:28 +02:00
|
|
|
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
$repository_api->setBaseCommitArgumentRules(
|
|
|
|
$this->getArgument('base', ''));
|
2012-03-23 01:22:52 +01:00
|
|
|
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
if ($repository_api->supportsRelativeLocalCommits()) {
|
2012-03-23 01:22:52 +01:00
|
|
|
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
// Parse the relative commit as soon as we can, to avoid generating
|
|
|
|
// caches we need to drop later and expensive discovery operations
|
|
|
|
// (particularly in Mercurial).
|
|
|
|
|
|
|
|
$relative = $this->getArgument('paths');
|
|
|
|
if ($relative) {
|
|
|
|
$repository_api->parseRelativeLocalCommit($relative);
|
2012-03-23 01:22:52 +01:00
|
|
|
}
|
2012-02-20 21:51:01 +01:00
|
|
|
}
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
}
|
2012-02-20 21:51:01 +01:00
|
|
|
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
private function runDiffSetupBasics() {
|
2012-02-20 21:51:01 +01:00
|
|
|
$output_json = $this->getArgument('json');
|
|
|
|
if ($output_json) {
|
|
|
|
// TODO: We should move this to a higher-level and put an indirection
|
|
|
|
// layer between echoing stuff and stdout.
|
|
|
|
ob_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->requiresWorkingCopy()) {
|
2012-03-20 03:17:10 +01:00
|
|
|
try {
|
|
|
|
$this->requireCleanWorkingCopy();
|
|
|
|
} catch (ArcanistUncommittedChangesException $ex) {
|
|
|
|
if ($repository_api instanceof ArcanistMercurialAPI) {
|
|
|
|
|
|
|
|
// Some Mercurial users prefer to use it like SVN, where they don't
|
|
|
|
// commit changes before sending them for review. This would be a
|
|
|
|
// pretty bad workflow in Git, but Mercurial users are significantly
|
|
|
|
// more expert at change management.
|
|
|
|
|
|
|
|
$use_dirty_changes = false;
|
|
|
|
if ($this->getArgument('uncommitted')) {
|
|
|
|
// OK.
|
|
|
|
} else {
|
|
|
|
$ok = phutil_console_confirm(
|
|
|
|
"You have uncommitted changes in your working copy. You can ".
|
|
|
|
"include them in the diff, or abort and deal with them. (Use ".
|
|
|
|
"'--uncommitted' to include them and skip this prompt.) ".
|
|
|
|
"Do you want to include uncommitted changes in the diff?");
|
|
|
|
if (!$ok) {
|
|
|
|
throw $ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$repository_api->setIncludeDirectoryStateInDiffs(true);
|
Fix some arc/mercurial issues
Summary:
- In "arc which", we recommend "--rev x --rev ." to show changes. This is not accurate if there are uncommitted changes in the working copy. Just "--rev x" shows the correct changes (implicitly, the other end of the range is the working copy state).
- When you diff only working copy changes, we currently incorrectly identify all your open revisions as belonging to the working copy. Instead, correctly identify none of them as belonging to the working copy (in theory, we could go farther than this and do path-based identification like SVN, but with --amend in hg 2.2+ this workflow should be going away in the long run).
- If you have uncommitted working copy changes, never try to amend.
Test Plan: Ran "arc which .", "arc diff ." in a working copy with dirty changes, got better results than before.
Reviewers: dschleimer, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1507
Differential Revision: https://secure.phabricator.com/D2980
2012-07-18 01:16:11 +02:00
|
|
|
$this->haveUncommittedChanges = true;
|
2012-08-06 20:56:01 +02:00
|
|
|
} else {
|
|
|
|
throw $ex;
|
2012-03-20 03:17:10 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-20 21:51:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 20:51:15 +02:00
|
|
|
private function buildRevisionFromCommitMessage(
|
|
|
|
ArcanistDifferentialCommitMessage $message) {
|
|
|
|
|
2012-08-08 21:08:41 +02:00
|
|
|
$conduit = $this->getConduit();
|
|
|
|
|
|
|
|
$revision_id = $message->getRevisionID();
|
|
|
|
$revision = array(
|
|
|
|
'fields' => $message->getFields(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($revision_id) {
|
|
|
|
|
|
|
|
// With '--verbatim', pass the (possibly modified) local fields. This
|
|
|
|
// allows the user to edit some fields (like "title" and "summary")
|
|
|
|
// locally without '--edit' and have changes automatically synchronized.
|
|
|
|
// Without '--verbatim', we do not update the revision to reflect local
|
|
|
|
// commit message changes.
|
|
|
|
if ($this->getArgument('verbatim')) {
|
|
|
|
$use_fields = $message->getFields();
|
|
|
|
} else {
|
|
|
|
$use_fields = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$should_edit = $this->getArgument('edit');
|
|
|
|
$edit_messages = $this->readScratchJSONFile('edit-messages.json');
|
|
|
|
$remote_corpus = idx($edit_messages, $revision_id);
|
|
|
|
|
|
|
|
if (!$should_edit || !$remote_corpus || $use_fields) {
|
2012-10-16 20:51:15 +02:00
|
|
|
if ($this->commitMessageFromRevision) {
|
|
|
|
$remote_corpus = $this->commitMessageFromRevision;
|
|
|
|
} else {
|
|
|
|
$remote_corpus = $conduit->callMethodSynchronous(
|
|
|
|
'differential.getcommitmessage',
|
|
|
|
array(
|
|
|
|
'revision_id' => $revision_id,
|
|
|
|
'edit' => 'edit',
|
|
|
|
'fields' => $use_fields,
|
|
|
|
));
|
|
|
|
}
|
2012-08-08 21:08:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($should_edit) {
|
2012-10-16 20:51:15 +02:00
|
|
|
$edited = $this->newInteractiveEditor($remote_corpus)
|
2012-08-08 21:08:41 +02:00
|
|
|
->setName('differential-edit-revision-info')
|
|
|
|
->editInteractively();
|
2012-10-16 20:51:15 +02:00
|
|
|
if ($edited != $remote_corpus) {
|
|
|
|
$remote_corpus = $edited;
|
|
|
|
$edit_messages[$revision_id] = $remote_corpus;
|
|
|
|
$this->writeScratchJSONFile('edit-messages.json', $edit_messages);
|
|
|
|
}
|
2012-08-08 21:08:41 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 20:51:15 +02:00
|
|
|
if ($this->commitMessageFromRevision == $remote_corpus) {
|
|
|
|
$new_message = $message;
|
|
|
|
} else {
|
|
|
|
$new_message = ArcanistDifferentialCommitMessage::newFromRawCorpus(
|
|
|
|
$remote_corpus);
|
|
|
|
$new_message->pullDataFromConduit($conduit);
|
|
|
|
}
|
2012-08-08 21:08:41 +02:00
|
|
|
|
|
|
|
$revision['fields'] = $new_message->getFields();
|
|
|
|
|
|
|
|
$revision['id'] = $revision_id;
|
|
|
|
$this->revisionID = $revision_id;
|
|
|
|
|
|
|
|
$revision['message'] = $this->getArgument('message');
|
|
|
|
if (!strlen($revision['message'])) {
|
|
|
|
$update_messages = $this->readScratchJSONFile('update-messages.json');
|
|
|
|
|
|
|
|
$update_messages[$revision_id] = $this->getUpdateMessage(
|
|
|
|
$revision['fields'],
|
|
|
|
idx($update_messages, $revision_id));
|
|
|
|
|
|
|
|
$revision['message'] = ArcanistCommentRemover::removeComments(
|
|
|
|
$update_messages[$revision_id]);
|
|
|
|
if (!strlen(trim($revision['message']))) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->writeScratchJSONFile('update-messages.json', $update_messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $revision;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
protected function shouldOnlyCreateDiff() {
|
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
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
if ($this->getArgument('create')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-09 18:33:55 +01:00
|
|
|
if ($this->getArgument('update')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-13 04:03:11 +01:00
|
|
|
if ($this->getArgument('use-commit-message')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-05 22:36:24 +01:00
|
|
|
if ($this->isRawDiffSource()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
return $this->getArgument('preview') ||
|
|
|
|
$this->getArgument('only');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function generateAffectedPaths() {
|
2012-01-05 22:36:24 +01:00
|
|
|
if ($this->isRawDiffSource()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
if ($repository_api instanceof ArcanistSubversionAPI) {
|
|
|
|
$file_list = new FileList($this->getArgument('paths', array()));
|
|
|
|
$paths = $repository_api->getSVNStatus($externals = true);
|
|
|
|
foreach ($paths as $path => $mask) {
|
|
|
|
if (!$file_list->contains($repository_api->getPath($path), true)) {
|
|
|
|
unset($paths[$path]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$warn_externals = array();
|
|
|
|
foreach ($paths as $path => $mask) {
|
|
|
|
$any_mod = ($mask & ArcanistRepositoryAPI::FLAG_ADDED) ||
|
|
|
|
($mask & ArcanistRepositoryAPI::FLAG_MODIFIED) ||
|
|
|
|
($mask & ArcanistRepositoryAPI::FLAG_DELETED);
|
|
|
|
if ($mask & ArcanistRepositoryAPI::FLAG_EXTERNALS) {
|
|
|
|
unset($paths[$path]);
|
|
|
|
if ($any_mod) {
|
|
|
|
$warn_externals[] = $path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($warn_externals && !$this->hasWarnedExternals) {
|
|
|
|
echo phutil_console_format(
|
|
|
|
"The working copy includes changes to 'svn:externals' paths. These ".
|
|
|
|
"changes will not be included in the diff because SVN can not ".
|
|
|
|
"commit 'svn:externals' changes alongside normal changes.".
|
|
|
|
"\n\n".
|
|
|
|
"Modified 'svn:externals' files:".
|
|
|
|
"\n\n".
|
2012-03-29 06:38:31 +02:00
|
|
|
phutil_console_wrap(implode("\n", $warn_externals), 8));
|
2011-01-10 00:22:25 +01:00
|
|
|
$prompt = "Generate a diff (with just local changes) anyway?";
|
|
|
|
if (!phutil_console_confirm($prompt)) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
} else {
|
|
|
|
$this->hasWarnedExternals = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-15 03:44:54 +02:00
|
|
|
} else if ($repository_api->supportsRelativeLocalCommits()) {
|
2011-01-10 00:22:25 +01:00
|
|
|
$paths = $repository_api->getWorkingCopyStatus();
|
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
|
|
|
} else {
|
|
|
|
throw new Exception("Unknown VCS!");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
2011-02-19 01:52:27 +01:00
|
|
|
|
|
|
|
foreach ($paths as $path => $mask) {
|
|
|
|
if ($mask & ArcanistRepositoryAPI::FLAG_UNTRACKED) {
|
|
|
|
unset($paths[$path]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
return $paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function generateChanges() {
|
2012-07-18 01:16:18 +02:00
|
|
|
$parser = $this->newDiffParser();
|
2012-01-05 22:36:24 +01:00
|
|
|
|
|
|
|
$is_raw = $this->isRawDiffSource();
|
|
|
|
if ($is_raw) {
|
|
|
|
|
|
|
|
if ($this->getArgument('raw')) {
|
2012-10-09 01:23:49 +02:00
|
|
|
fwrite(STDERR, "Reading diff from stdin...\n");
|
2012-01-05 22:36:24 +01:00
|
|
|
$raw_diff = file_get_contents('php://stdin');
|
|
|
|
} else if ($this->getArgument('raw-command')) {
|
|
|
|
list($raw_diff) = execx($this->getArgument('raw-command'));
|
|
|
|
} else {
|
|
|
|
throw new Exception("Unknown raw diff source.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$changes = $parser->parseDiff($raw_diff);
|
|
|
|
foreach ($changes as $key => $change) {
|
|
|
|
// Remove "message" changes, e.g. from "git show".
|
|
|
|
if ($change->getType() == ArcanistDiffChangeType::TYPE_MESSAGE) {
|
|
|
|
unset($changes[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $changes;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
|
|
|
if ($repository_api instanceof ArcanistSubversionAPI) {
|
|
|
|
$paths = $this->generateAffectedPaths();
|
|
|
|
$this->primeSubversionWorkingCopyData($paths);
|
|
|
|
|
|
|
|
// Check to make sure the user is diffing from a consistent base revision.
|
|
|
|
// This is mostly just an abuse sanity check because it's silly to do this
|
|
|
|
// and makes the code more difficult to effectively review, but it also
|
|
|
|
// affects patches and makes them nonportable.
|
|
|
|
$bases = $repository_api->getSVNBaseRevisions();
|
|
|
|
|
|
|
|
// Remove all files with baserev "0"; these files are new.
|
|
|
|
foreach ($bases as $path => $baserev) {
|
2012-03-13 00:18:44 +01:00
|
|
|
if ($bases[$path] <= 0) {
|
2011-01-10 00:22:25 +01:00
|
|
|
unset($bases[$path]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bases) {
|
2011-02-23 21:06:22 +01:00
|
|
|
$rev = reset($bases);
|
2011-06-23 23:37:43 +02:00
|
|
|
|
|
|
|
$revlist = array();
|
|
|
|
foreach ($bases as $path => $baserev) {
|
|
|
|
$revlist[] = " Revision {$baserev}, {$path}";
|
|
|
|
}
|
|
|
|
$revlist = implode("\n", $revlist);
|
|
|
|
|
2011-02-23 21:06:22 +01:00
|
|
|
foreach ($bases as $path => $baserev) {
|
|
|
|
if ($baserev !== $rev) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Base revisions of changed paths are mismatched. Update all ".
|
|
|
|
"paths to the same base revision before creating a diff: ".
|
|
|
|
"\n\n".
|
|
|
|
$revlist);
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-25 01:34:27 +01:00
|
|
|
|
2011-02-23 21:06:22 +01:00
|
|
|
// If you have a change which affects several files, all of which are
|
|
|
|
// at a consistent base revision, treat that revision as the effective
|
|
|
|
// base revision. The use case here is that you made a change to some
|
|
|
|
// file, which updates it to HEAD, but want to be able to change it
|
|
|
|
// again without updating the entire working copy. This is a little
|
|
|
|
// sketchy but it arises in Facebook Ops workflows with config files and
|
|
|
|
// doesn't have any real material tradeoffs (e.g., these patches are
|
|
|
|
// perfectly applyable).
|
|
|
|
$repository_api->overrideSVNBaseRevisionNumber($rev);
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$changes = $parser->parseSubversionDiff(
|
|
|
|
$repository_api,
|
|
|
|
$paths);
|
|
|
|
} else if ($repository_api instanceof ArcanistGitAPI) {
|
|
|
|
$diff = $repository_api->getFullGitDiff();
|
|
|
|
if (!strlen($diff)) {
|
Improve git behavior in the zero- and one- commit case
Summary:
Git works completely differently for commits zero and one than for 2..N so add
more special casing to handle them. See:
- {T206}
- {T596}
The getCommitRange() block is also fatal land, although I wasn't able to reach
it. I'll follow up with @s on T596.
Test Plan:
- Created a new, empty repository ("mkdir x; cd x; git init").
- Ran "arc lint", "arc unit", "arc diff" against it with no commits (the first
two work, the third fails helpfully).
- Made an initial commit.
- Ran "arc lint", "arc unit", "arc diff" against it (all work correctly).
Reviewers: btrahan, jungejason, aran
Reviewed By: aran
CC: s, aran
Differential Revision: 1142
2011-11-30 18:15:37 +01:00
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"No changes found. (Did you specify the wrong commit range?)");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
$changes = $parser->parseDiff($diff);
|
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
|
|
|
} else if ($repository_api instanceof ArcanistMercurialAPI) {
|
|
|
|
$diff = $repository_api->getFullMercurialDiff();
|
2012-03-20 03:17:10 +01:00
|
|
|
if (!strlen($diff)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"No changes found. (Did you specify the wrong commit range?)");
|
|
|
|
}
|
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
|
|
|
$changes = $parser->parseDiff($diff);
|
2011-01-10 00:22:25 +01:00
|
|
|
} else {
|
|
|
|
throw new Exception("Repository API is not supported.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($changes) > 250) {
|
|
|
|
$count = number_format(count($changes));
|
2012-08-16 23:27:35 +02:00
|
|
|
$link =
|
|
|
|
"http://www.phabricator.com/docs/phabricator/article/".
|
|
|
|
"Differential_User_Guide_Large_Changes.html";
|
2011-01-10 00:22:25 +01:00
|
|
|
$message =
|
|
|
|
"This diff has a very large number of changes ({$count}). ".
|
|
|
|
"Differential works best for changes which will receive detailed ".
|
|
|
|
"human review, and not as well for large automated changes or ".
|
2012-08-16 23:27:35 +02:00
|
|
|
"bulk checkins. See {$link} for information about reviewing big ".
|
|
|
|
"checkins. Continue anyway?";
|
2011-01-10 00:22:25 +01:00
|
|
|
if (!phutil_console_confirm($message)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Aborted generation of gigantic diff.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$limit = 1024 * 1024 * 4;
|
|
|
|
foreach ($changes as $change) {
|
|
|
|
$size = 0;
|
|
|
|
foreach ($change->getHunks() as $hunk) {
|
|
|
|
$size += strlen($hunk->getCorpus());
|
|
|
|
}
|
|
|
|
if ($size > $limit) {
|
|
|
|
$file_name = $change->getCurrentPath();
|
|
|
|
$change_size = number_format($size);
|
|
|
|
$byte_warning =
|
|
|
|
"Diff for '{$file_name}' with context is {$change_size} bytes in ".
|
2012-04-14 01:21:23 +02:00
|
|
|
"length. Generally, source changes should not be this large.";
|
|
|
|
if (!$this->getArgument('less-context')) {
|
|
|
|
$byte_warning .=
|
|
|
|
" If this file is a huge text file, try using the ".
|
|
|
|
"'--less-context' flag.";
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($repository_api instanceof ArcanistSubversionAPI) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"{$byte_warning} If the file is not a text file, mark it as ".
|
|
|
|
"binary with:".
|
|
|
|
"\n\n".
|
|
|
|
" $ svn propset svn:mime-type application/octet-stream <filename>".
|
|
|
|
"\n");
|
|
|
|
} else {
|
|
|
|
$confirm =
|
|
|
|
"{$byte_warning} If the file is not a text file, you can ".
|
|
|
|
"mark it 'binary'. Mark this file as 'binary' and continue?";
|
|
|
|
if (phutil_console_confirm($confirm)) {
|
|
|
|
$change->convertToBinaryChange();
|
|
|
|
} else {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Aborted generation of gigantic diff.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 15:08:06 +01:00
|
|
|
$try_encoding = nonempty($this->getArgument('encoding'), null);
|
Add very hacky encoding transformation support for arc
Summary:
Adds a secret, undoucmented "encoding" key to ".arcconfig" which makes a very
half-hearted effort to convert encodings. This is probably good enough that
Differential can be used for code review, but there will be issues with 'arc
patch', 'arc export', paste, maybe conduit stuff, Diffusion, and whatever else I
haven't thought of.
This also doesn't store the original encoding so anything converted like this
won't reasonably be able to be made to work with all that stuff in the future.
See T452 for a broader discussion of the issues involved.
Test Plan:
Short circuited the UTF-8 detection to always fail, had my files "converted"
from ISO-8859-1 to UTF-8.
@davidreuss: you can test this by applying this patch to arcanist/, adding
'"encoding" : "ISO-8859-1"' to your .arcconfig, touching some non-ASCII file,
and then running "arc diff".
Reviewers: davidreuss, jungejason, tuomaspelkonen, aran
Reviewed By: davidreuss
CC: aran, davidreuss, epriestley, nshamg123
Differential Revision: 812
2011-08-15 18:10:22 +02:00
|
|
|
|
2011-05-21 16:16:12 +02:00
|
|
|
$utf8_problems = array();
|
|
|
|
foreach ($changes as $change) {
|
|
|
|
foreach ($change->getHunks() as $hunk) {
|
Add very hacky encoding transformation support for arc
Summary:
Adds a secret, undoucmented "encoding" key to ".arcconfig" which makes a very
half-hearted effort to convert encodings. This is probably good enough that
Differential can be used for code review, but there will be issues with 'arc
patch', 'arc export', paste, maybe conduit stuff, Diffusion, and whatever else I
haven't thought of.
This also doesn't store the original encoding so anything converted like this
won't reasonably be able to be made to work with all that stuff in the future.
See T452 for a broader discussion of the issues involved.
Test Plan:
Short circuited the UTF-8 detection to always fail, had my files "converted"
from ISO-8859-1 to UTF-8.
@davidreuss: you can test this by applying this patch to arcanist/, adding
'"encoding" : "ISO-8859-1"' to your .arcconfig, touching some non-ASCII file,
and then running "arc diff".
Reviewers: davidreuss, jungejason, tuomaspelkonen, aran
Reviewed By: davidreuss
CC: aran, davidreuss, epriestley, nshamg123
Differential Revision: 812
2011-08-15 18:10:22 +02:00
|
|
|
$corpus = $hunk->getCorpus();
|
|
|
|
if (!phutil_is_utf8($corpus)) {
|
|
|
|
|
|
|
|
// If this corpus is heuristically binary, don't try to convert it.
|
|
|
|
// mb_check_encoding() and mb_convert_encoding() are both very very
|
|
|
|
// liberal about what they're willing to process.
|
|
|
|
$is_binary = ArcanistDiffUtils::isHeuristicBinaryFile($corpus);
|
|
|
|
if (!$is_binary) {
|
2012-03-14 15:08:06 +01:00
|
|
|
|
|
|
|
if (!$try_encoding) {
|
2011-12-01 17:56:03 +01:00
|
|
|
try {
|
2012-03-14 15:08:06 +01:00
|
|
|
$try_encoding = $this->getRepositoryEncoding();
|
2011-12-01 17:56:03 +01:00
|
|
|
} catch (ConduitClientException $e) {
|
2012-03-14 15:08:06 +01:00
|
|
|
if ($e->getErrorCode() == 'ERR-BAD-ARCANIST-PROJECT') {
|
|
|
|
echo phutil_console_wrap(
|
|
|
|
"Lookup of encoding in arcanist project failed\n".
|
|
|
|
$e->getMessage());
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
2011-12-01 17:56:03 +01:00
|
|
|
}
|
Add very hacky encoding transformation support for arc
Summary:
Adds a secret, undoucmented "encoding" key to ".arcconfig" which makes a very
half-hearted effort to convert encodings. This is probably good enough that
Differential can be used for code review, but there will be issues with 'arc
patch', 'arc export', paste, maybe conduit stuff, Diffusion, and whatever else I
haven't thought of.
This also doesn't store the original encoding so anything converted like this
won't reasonably be able to be made to work with all that stuff in the future.
See T452 for a broader discussion of the issues involved.
Test Plan:
Short circuited the UTF-8 detection to always fail, had my files "converted"
from ISO-8859-1 to UTF-8.
@davidreuss: you can test this by applying this patch to arcanist/, adding
'"encoding" : "ISO-8859-1"' to your .arcconfig, touching some non-ASCII file,
and then running "arc diff".
Reviewers: davidreuss, jungejason, tuomaspelkonen, aran
Reviewed By: davidreuss
CC: aran, davidreuss, epriestley, nshamg123
Differential Revision: 812
2011-08-15 18:10:22 +02:00
|
|
|
}
|
2012-03-14 15:08:06 +01:00
|
|
|
|
2012-08-12 17:50:01 +02:00
|
|
|
if ($try_encoding) {
|
|
|
|
$corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding);
|
Add very hacky encoding transformation support for arc
Summary:
Adds a secret, undoucmented "encoding" key to ".arcconfig" which makes a very
half-hearted effort to convert encodings. This is probably good enough that
Differential can be used for code review, but there will be issues with 'arc
patch', 'arc export', paste, maybe conduit stuff, Diffusion, and whatever else I
haven't thought of.
This also doesn't store the original encoding so anything converted like this
won't reasonably be able to be made to work with all that stuff in the future.
See T452 for a broader discussion of the issues involved.
Test Plan:
Short circuited the UTF-8 detection to always fail, had my files "converted"
from ISO-8859-1 to UTF-8.
@davidreuss: you can test this by applying this patch to arcanist/, adding
'"encoding" : "ISO-8859-1"' to your .arcconfig, touching some non-ASCII file,
and then running "arc diff".
Reviewers: davidreuss, jungejason, tuomaspelkonen, aran
Reviewed By: davidreuss
CC: aran, davidreuss, epriestley, nshamg123
Differential Revision: 812
2011-08-15 18:10:22 +02:00
|
|
|
$name = $change->getCurrentPath();
|
|
|
|
if (phutil_is_utf8($corpus)) {
|
|
|
|
$this->writeStatusMessage(
|
2012-07-03 04:34:59 +02:00
|
|
|
"Converted a '{$name}' hunk from '{$try_encoding}' ".
|
|
|
|
"to UTF-8.\n");
|
Add very hacky encoding transformation support for arc
Summary:
Adds a secret, undoucmented "encoding" key to ".arcconfig" which makes a very
half-hearted effort to convert encodings. This is probably good enough that
Differential can be used for code review, but there will be issues with 'arc
patch', 'arc export', paste, maybe conduit stuff, Diffusion, and whatever else I
haven't thought of.
This also doesn't store the original encoding so anything converted like this
won't reasonably be able to be made to work with all that stuff in the future.
See T452 for a broader discussion of the issues involved.
Test Plan:
Short circuited the UTF-8 detection to always fail, had my files "converted"
from ISO-8859-1 to UTF-8.
@davidreuss: you can test this by applying this patch to arcanist/, adding
'"encoding" : "ISO-8859-1"' to your .arcconfig, touching some non-ASCII file,
and then running "arc diff".
Reviewers: davidreuss, jungejason, tuomaspelkonen, aran
Reviewed By: davidreuss
CC: aran, davidreuss, epriestley, nshamg123
Differential Revision: 812
2011-08-15 18:10:22 +02:00
|
|
|
$hunk->setCorpus($corpus);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-21 16:16:12 +02:00
|
|
|
$utf8_problems[] = $change;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are non-binary files which aren't valid UTF-8, warn the user
|
|
|
|
// and treat them as binary changes. See D327 for discussion of why Arcanist
|
|
|
|
// has this behavior.
|
|
|
|
if ($utf8_problems) {
|
2012-06-12 03:33:19 +02:00
|
|
|
$utf8_warning =
|
|
|
|
pht(
|
|
|
|
"This diff includes file(s) which are not valid UTF-8 (they contain ".
|
|
|
|
"invalid byte sequences). You can either stop this workflow and ".
|
|
|
|
"fix these files, or continue. If you continue, these files will ".
|
|
|
|
"be marked as binary.",
|
|
|
|
count($utf8_problems))."\n\n".
|
Add very hacky encoding transformation support for arc
Summary:
Adds a secret, undoucmented "encoding" key to ".arcconfig" which makes a very
half-hearted effort to convert encodings. This is probably good enough that
Differential can be used for code review, but there will be issues with 'arc
patch', 'arc export', paste, maybe conduit stuff, Diffusion, and whatever else I
haven't thought of.
This also doesn't store the original encoding so anything converted like this
won't reasonably be able to be made to work with all that stuff in the future.
See T452 for a broader discussion of the issues involved.
Test Plan:
Short circuited the UTF-8 detection to always fail, had my files "converted"
from ISO-8859-1 to UTF-8.
@davidreuss: you can test this by applying this patch to arcanist/, adding
'"encoding" : "ISO-8859-1"' to your .arcconfig, touching some non-ASCII file,
and then running "arc diff".
Reviewers: davidreuss, jungejason, tuomaspelkonen, aran
Reviewed By: davidreuss
CC: aran, davidreuss, epriestley, nshamg123
Differential Revision: 812
2011-08-15 18:10:22 +02:00
|
|
|
"You can learn more about how Phabricator handles character encodings ".
|
|
|
|
"(and how to configure encoding settings and detect and correct ".
|
|
|
|
"encoding problems) by reading 'User Guide: UTF-8 and Character ".
|
|
|
|
"Encoding' in the Phabricator documentation.\n\n";
|
2012-06-12 03:33:19 +02:00
|
|
|
" ".pht('AFFECTED FILE(S)', count($utf8_problems))."\n";
|
|
|
|
$confirm = pht(
|
|
|
|
'Do you want to mark these files as binary and continue?',
|
|
|
|
count($utf8_problems));
|
2011-05-21 16:16:12 +02:00
|
|
|
|
|
|
|
echo phutil_console_format("**Invalid Content Encoding (Non-UTF8)**\n");
|
|
|
|
echo phutil_console_wrap($utf8_warning);
|
|
|
|
|
|
|
|
$file_list = mpull($utf8_problems, 'getCurrentPath');
|
|
|
|
$file_list = ' '.implode("\n ", $file_list);
|
|
|
|
echo $file_list;
|
|
|
|
|
|
|
|
if (!phutil_console_confirm($confirm, $default_no = false)) {
|
|
|
|
throw new ArcanistUsageException("Aborted workflow to fix UTF-8.");
|
|
|
|
} else {
|
|
|
|
foreach ($utf8_problems as $change) {
|
|
|
|
$change->convertToBinaryChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-11 22:02:38 +01:00
|
|
|
|
|
|
|
foreach ($changes as $change) {
|
2012-05-01 01:47:12 +02:00
|
|
|
$path = $change->getCurrentPath();
|
|
|
|
|
|
|
|
// Certain types of changes (moves and copies) don't contain change data
|
|
|
|
// when expressed in raw "git diff" form. Augment any such diffs with
|
|
|
|
// textual data.
|
|
|
|
if ($change->getNeedsSyntheticGitHunks()) {
|
|
|
|
$diff = $repository_api->getRawDiffText($path, $moves = false);
|
2012-07-18 01:16:18 +02:00
|
|
|
$parser = $this->newDiffParser();
|
|
|
|
|
2012-05-01 01:47:12 +02:00
|
|
|
$raw_changes = $parser->parseDiff($diff);
|
|
|
|
foreach ($raw_changes as $raw_change) {
|
|
|
|
if ($raw_change->getCurrentPath() == $path) {
|
|
|
|
$change->setFileType($raw_change->getFileType());
|
|
|
|
foreach ($raw_change->getHunks() as $hunk) {
|
2012-09-19 23:36:38 +02:00
|
|
|
// Git thinks that this file has been added. But we know that it
|
|
|
|
// has been moved or copied without a change.
|
|
|
|
$hunk->setCorpus(
|
|
|
|
preg_replace('/^\+/m', ' ', $hunk->getCorpus()));
|
2012-05-01 01:47:12 +02:00
|
|
|
$change->addHunk($hunk);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$change->setNeedsSyntheticGitHunks(false);
|
|
|
|
}
|
|
|
|
|
2011-01-11 22:02:38 +01:00
|
|
|
if ($change->getFileType() != ArcanistDiffChangeType::FILE_BINARY) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-11-10 04:44:53 +01:00
|
|
|
$name = basename($path);
|
2011-01-11 22:02:38 +01:00
|
|
|
|
2011-11-10 04:44:53 +01:00
|
|
|
$old_file = $repository_api->getOriginalFileData($path);
|
|
|
|
$old_dict = $this->uploadFile($old_file, $name, 'old binary');
|
2011-01-11 22:02:38 +01:00
|
|
|
if ($old_dict['guid']) {
|
2011-06-15 06:25:31 +02:00
|
|
|
$change->setMetadata('old:binary-phid', $old_dict['guid']);
|
2011-01-11 22:02:38 +01:00
|
|
|
}
|
2011-11-10 04:44:53 +01:00
|
|
|
$change->setMetadata('old:file:size', $old_dict['size']);
|
|
|
|
$change->setMetadata('old:file:mime-type', $old_dict['mime']);
|
|
|
|
|
|
|
|
$new_file = $repository_api->getCurrentFileData($path);
|
|
|
|
$new_dict = $this->uploadFile($new_file, $name, 'new binary');
|
2011-01-11 22:02:38 +01:00
|
|
|
if ($new_dict['guid']) {
|
2011-06-15 06:25:31 +02:00
|
|
|
$change->setMetadata('new:binary-phid', $new_dict['guid']);
|
2011-01-11 22:02:38 +01:00
|
|
|
}
|
2011-11-10 04:44:53 +01:00
|
|
|
$change->setMetadata('new:file:size', $new_dict['size']);
|
2011-01-11 22:02:38 +01:00
|
|
|
$change->setMetadata('new:file:mime-type', $new_dict['mime']);
|
|
|
|
|
2012-09-19 00:07:01 +02:00
|
|
|
$mime_type = coalesce($new_dict['mime'], $old_dict['mime']);
|
|
|
|
if (preg_match('@^image/@', $mime_type)) {
|
2011-01-11 22:02:38 +01:00
|
|
|
$change->setFileType(ArcanistDiffChangeType::FILE_IMAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
return $changes;
|
|
|
|
}
|
|
|
|
|
2011-01-11 22:02:38 +01:00
|
|
|
private function uploadFile($data, $name, $desc) {
|
|
|
|
$result = array(
|
|
|
|
'guid' => null,
|
|
|
|
'mime' => null,
|
2011-11-10 04:44:53 +01:00
|
|
|
'size' => null
|
2011-01-11 22:02:38 +01:00
|
|
|
);
|
|
|
|
|
2012-05-30 23:11:07 +02:00
|
|
|
if ($this->getArgument('skip-binaries')) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2011-11-10 04:44:53 +01:00
|
|
|
$result['size'] = $size = strlen($data);
|
|
|
|
if (!$size) {
|
2011-01-11 22:02:38 +01:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2012-04-27 21:48:47 +02:00
|
|
|
$tmp = new TempFile();
|
|
|
|
Filesystem::writeFile($tmp, $data);
|
|
|
|
$mime_type = Filesystem::getMimeType($tmp);
|
2011-01-11 22:02:38 +01:00
|
|
|
$result['mime'] = $mime_type;
|
|
|
|
|
2011-11-10 04:44:53 +01:00
|
|
|
echo "Uploading {$desc} '{$name}' ({$mime_type}, {$size} bytes)...\n";
|
2011-01-11 22:02:38 +01:00
|
|
|
|
2011-11-10 04:44:53 +01:00
|
|
|
try {
|
|
|
|
$guid = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'file.upload',
|
|
|
|
array(
|
|
|
|
'data_base64' => base64_encode($data),
|
|
|
|
'name' => $name,
|
2011-01-11 22:02:38 +01:00
|
|
|
));
|
|
|
|
|
2011-11-10 04:44:53 +01:00
|
|
|
$result['guid'] = $guid;
|
2012-05-30 23:11:07 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
echo "Failed to upload {$desc} '{$name}'.\n";
|
|
|
|
|
|
|
|
if (!phutil_console_confirm('Continue?', $default_no = false)) {
|
2011-11-10 04:44:53 +01:00
|
|
|
throw new ArcanistUsageException(
|
2012-05-30 23:11:07 +02:00
|
|
|
'Aborted due to file upload failure. You can use --skip-binaries '.
|
|
|
|
'to skip binary uploads.');
|
2011-11-10 04:44:53 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-11 22:02:38 +01:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
private function getGitParentLogInfo() {
|
|
|
|
$info = array(
|
|
|
|
'parent' => null,
|
|
|
|
'base_revision' => null,
|
|
|
|
'base_path' => null,
|
2011-04-06 05:12:37 +02:00
|
|
|
'uuid' => null,
|
2011-01-10 00:22:25 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$conduit = $this->getConduit();
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
2012-07-18 01:16:18 +02:00
|
|
|
$parser = $this->newDiffParser();
|
2011-01-10 00:22:25 +01:00
|
|
|
$history_messages = $repository_api->getGitHistoryLog();
|
|
|
|
if (!$history_messages) {
|
|
|
|
// This can occur on the initial commit.
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
$history_messages = $parser->parseDiff($history_messages);
|
|
|
|
|
|
|
|
foreach ($history_messages as $key => $change) {
|
|
|
|
try {
|
|
|
|
$message = ArcanistDifferentialCommitMessage::newFromRawCorpus(
|
|
|
|
$change->getMetadata('message'));
|
|
|
|
if ($message->getRevisionID() && $info['parent'] === null) {
|
|
|
|
$info['parent'] = $message->getRevisionID();
|
|
|
|
}
|
|
|
|
if ($message->getGitSVNBaseRevision() &&
|
|
|
|
$info['base_revision'] === null) {
|
|
|
|
$info['base_revision'] = $message->getGitSVNBaseRevision();
|
|
|
|
$info['base_path'] = $message->getGitSVNBasePath();
|
|
|
|
}
|
2011-04-06 05:12:37 +02:00
|
|
|
if ($message->getGitSVNUUID()) {
|
|
|
|
$info['uuid'] = $message->getGitSVNUUID();
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($info['parent'] && $info['base_revision']) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (ArcanistDifferentialCommitMessageParserException $ex) {
|
|
|
|
// Ignore.
|
2012-05-09 01:31:26 +02:00
|
|
|
} catch (ArcanistUsageException $ex) {
|
|
|
|
// Ignore an invalid Differential Revision field in the parent commit
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function primeSubversionWorkingCopyData($paths) {
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
|
|
|
$futures = array();
|
|
|
|
$targets = array();
|
|
|
|
foreach ($paths as $path => $mask) {
|
|
|
|
$futures[] = $repository_api->buildDiffFuture($path);
|
|
|
|
$targets[] = array('command' => 'diff', 'path' => $path);
|
|
|
|
$futures[] = $repository_api->buildInfoFuture($path);
|
|
|
|
$targets[] = array('command' => 'info', 'path' => $path);
|
|
|
|
}
|
|
|
|
|
2012-06-01 09:15:52 +02:00
|
|
|
foreach (Futures($futures)->limit(8) as $key => $future) {
|
2011-01-10 00:22:25 +01:00
|
|
|
$target = $targets[$key];
|
|
|
|
if ($target['command'] == 'diff') {
|
|
|
|
$repository_api->primeSVNDiffResult(
|
|
|
|
$target['path'],
|
|
|
|
$future->resolve());
|
|
|
|
} else {
|
|
|
|
$repository_api->primeSVNInfoResult(
|
|
|
|
$target['path'],
|
|
|
|
$future->resolve());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 23:33:01 +01:00
|
|
|
private function shouldAmend() {
|
Fix some arc/mercurial issues
Summary:
- In "arc which", we recommend "--rev x --rev ." to show changes. This is not accurate if there are uncommitted changes in the working copy. Just "--rev x" shows the correct changes (implicitly, the other end of the range is the working copy state).
- When you diff only working copy changes, we currently incorrectly identify all your open revisions as belonging to the working copy. Instead, correctly identify none of them as belonging to the working copy (in theory, we could go farther than this and do path-based identification like SVN, but with --amend in hg 2.2+ this workflow should be going away in the long run).
- If you have uncommitted working copy changes, never try to amend.
Test Plan: Ran "arc which .", "arc diff ." in a working copy with dirty changes, got better results than before.
Reviewers: dschleimer, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1507
Differential Revision: https://secure.phabricator.com/D2980
2012-07-18 01:16:11 +02:00
|
|
|
if ($this->haveUncommittedChanges) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isHistoryImmutable()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->getArgument('no-amend')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isRawDiffSource()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-02-01 23:33:01 +01:00
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
/* -( Lint and Unit Tests )------------------------------------------------ */
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
/**
|
|
|
|
* @task lintunit
|
|
|
|
*/
|
2012-08-06 22:40:20 +02:00
|
|
|
private function runLintUnit() {
|
|
|
|
$lint_result = $this->runLint();
|
|
|
|
$unit_result = $this->runUnit();
|
|
|
|
return array(
|
|
|
|
'lintResult' => $lint_result,
|
|
|
|
'lintExcuse' => $this->lintExcuse,
|
|
|
|
'unresolvedLint' => $this->unresolvedLint,
|
|
|
|
'postponedLinters' => $this->postponedLinters,
|
|
|
|
'unitResult' => $unit_result,
|
|
|
|
'unitExcuse' => $this->unitExcuse,
|
|
|
|
'testResults' => $this->testResults,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task lintunit
|
|
|
|
*/
|
|
|
|
private function runLint() {
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($this->getArgument('nolint') ||
|
2012-01-05 22:36:24 +01:00
|
|
|
$this->getArgument('only') ||
|
|
|
|
$this->isRawDiffSource()) {
|
2011-01-10 00:22:25 +01:00
|
|
|
return ArcanistLintWorkflow::RESULT_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut("Linting...\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
try {
|
2011-02-02 05:32:10 +01:00
|
|
|
$argv = $this->getPassthruArgumentsAsArgv('lint');
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 21:40:50 +01:00
|
|
|
if ($repository_api->supportsRelativeLocalCommits()) {
|
|
|
|
$argv[] = '--rev';
|
2011-01-10 00:22:25 +01:00
|
|
|
$argv[] = $repository_api->getRelativeCommit();
|
|
|
|
}
|
Improve handling of `--background` with `--base`
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.
Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.
Test Plan:
- Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
- Created a commit on master.
- Ran `arc diff HEAD^`.
- Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
- After this change, the command succeeds.
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D3574
2012-10-02 20:01:49 +02:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$lint_workflow = $this->buildChildWorkflow('lint', $argv);
|
2011-01-30 02:18:32 +01:00
|
|
|
|
2012-02-04 00:26:13 +01:00
|
|
|
if ($this->shouldAmend()) {
|
2011-08-26 02:53:59 +02:00
|
|
|
// TODO: We should offer to create a checkpoint commit.
|
|
|
|
$lint_workflow->setShouldAmendChanges(true);
|
|
|
|
}
|
2011-01-30 02:18:32 +01:00
|
|
|
|
|
|
|
$lint_result = $lint_workflow->run();
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
switch ($lint_result) {
|
|
|
|
case ArcanistLintWorkflow::RESULT_OKAY:
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut(
|
2011-01-10 00:22:25 +01:00
|
|
|
"<bg:green>** LINT OKAY **</bg> No lint problems.\n");
|
|
|
|
break;
|
|
|
|
case ArcanistLintWorkflow::RESULT_WARNINGS:
|
2012-06-01 07:57:29 +02:00
|
|
|
$this->lintExcuse = $this->getErrorExcuse(
|
|
|
|
"Lint issued unresolved warnings.",
|
2012-06-20 03:14:26 +02:00
|
|
|
'lint-excuses');
|
2011-01-10 00:22:25 +01:00
|
|
|
break;
|
|
|
|
case ArcanistLintWorkflow::RESULT_ERRORS:
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut(
|
2011-01-10 00:22:25 +01:00
|
|
|
"<bg:red>** LINT ERRORS **</bg> Lint raised errors!\n");
|
2012-06-01 07:57:29 +02:00
|
|
|
$this->lintExcuse = $this->getErrorExcuse(
|
|
|
|
"Lint issued unresolved errors!",
|
2012-06-20 03:14:26 +02:00
|
|
|
'lint-excuses');
|
2011-01-10 00:22:25 +01:00
|
|
|
break;
|
2012-07-03 00:53:22 +02:00
|
|
|
case ArcanistLintWorkflow::RESULT_POSTPONED:
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut(
|
2012-07-03 00:53:22 +02:00
|
|
|
"<bg:yellow>** LINT POSTPONED **</bg> ".
|
|
|
|
"Lint results are postponed.\n");
|
|
|
|
break;
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->unresolvedLint = array();
|
|
|
|
foreach ($lint_workflow->getUnresolvedMessages() as $message) {
|
|
|
|
$this->unresolvedLint[] = array(
|
|
|
|
'path' => $message->getPath(),
|
|
|
|
'line' => $message->getLine(),
|
|
|
|
'char' => $message->getChar(),
|
|
|
|
'code' => $message->getCode(),
|
|
|
|
'severity' => $message->getSeverity(),
|
|
|
|
'name' => $message->getName(),
|
|
|
|
'description' => $message->getDescription(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-07-03 00:53:22 +02:00
|
|
|
$this->postponedLinters = $lint_workflow->getPostponedLinters();
|
2011-01-12 07:13:31 +01:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
return $lint_result;
|
|
|
|
} catch (ArcanistNoEngineException $ex) {
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut("No lint engine configured for this project.\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
} catch (ArcanistNoEffectException $ex) {
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut("No paths to lint.\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @task lintunit
|
|
|
|
*/
|
2012-08-06 22:40:20 +02:00
|
|
|
private function runUnit() {
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($this->getArgument('nounit') ||
|
2012-01-05 22:36:24 +01:00
|
|
|
$this->getArgument('only') ||
|
|
|
|
$this->isRawDiffSource()) {
|
2011-01-10 00:22:25 +01:00
|
|
|
return ArcanistUnitWorkflow::RESULT_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut("Running unit tests...\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
try {
|
2011-02-02 05:32:10 +01:00
|
|
|
$argv = $this->getPassthruArgumentsAsArgv('unit');
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 21:40:50 +01:00
|
|
|
if ($repository_api->supportsRelativeLocalCommits()) {
|
|
|
|
$argv[] = '--rev';
|
|
|
|
$argv[] = $repository_api->getRelativeCommit();
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
2012-08-07 01:56:11 +02:00
|
|
|
$unit_workflow = $this->buildChildWorkflow('unit', $argv);
|
|
|
|
$unit_result = $unit_workflow->run();
|
2012-06-01 07:57:29 +02:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
switch ($unit_result) {
|
|
|
|
case ArcanistUnitWorkflow::RESULT_OKAY:
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut(
|
2011-01-10 00:22:25 +01:00
|
|
|
"<bg:green>** UNIT OKAY **</bg> No unit test failures.\n");
|
|
|
|
break;
|
|
|
|
case ArcanistUnitWorkflow::RESULT_UNSOUND:
|
2012-07-17 00:54:11 +02:00
|
|
|
if ($this->getArgument('ignore-unsound-tests')) {
|
|
|
|
echo phutil_console_format(
|
|
|
|
"<bg:yellow>** UNIT UNSOUND **</bg> Unit testing raised errors, ".
|
|
|
|
"but all failing tests are unsound.\n");
|
|
|
|
} else {
|
2012-08-16 00:54:34 +02:00
|
|
|
$continue = $this->console->confirm(
|
2012-07-17 00:54:11 +02:00
|
|
|
"Unit test results included failures, but all failing tests ".
|
|
|
|
"are known to be unsound. Ignore unsound test failures?");
|
|
|
|
if (!$continue) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ArcanistUnitWorkflow::RESULT_FAIL:
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut(
|
2011-01-10 00:22:25 +01:00
|
|
|
"<bg:red>** UNIT ERRORS **</bg> Unit testing raised errors!\n");
|
2012-06-01 07:57:29 +02:00
|
|
|
$this->unitExcuse = $this->getErrorExcuse(
|
|
|
|
"Unit test results include failures!",
|
2012-06-20 03:14:26 +02:00
|
|
|
'unit-excuses');
|
2011-01-10 00:22:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->testResults = array();
|
|
|
|
foreach ($unit_workflow->getTestResults() as $test) {
|
|
|
|
$this->testResults[] = array(
|
|
|
|
'name' => $test->getName(),
|
2012-09-07 03:44:15 +02:00
|
|
|
'link' => $test->getLink(),
|
2012-08-06 22:40:20 +02:00
|
|
|
'result' => $test->getResult(),
|
|
|
|
'userdata' => $test->getUserData(),
|
|
|
|
'coverage' => $test->getCoverage(),
|
2012-08-15 19:34:29 +02:00
|
|
|
'extra' => $test->getExtraData(),
|
2012-08-06 22:40:20 +02:00
|
|
|
);
|
|
|
|
}
|
2011-01-12 07:13:31 +01:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
return $unit_result;
|
|
|
|
} catch (ArcanistNoEngineException $ex) {
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut(
|
|
|
|
"No unit test engine is configured for this project.\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
} catch (ArcanistNoEffectException $ex) {
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut("No tests to run.\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-10-13 00:21:00 +02:00
|
|
|
public function getTestResults() {
|
|
|
|
return $this->testResults;
|
|
|
|
}
|
|
|
|
|
2012-06-20 03:14:26 +02:00
|
|
|
private function getErrorExcuse($prompt, $history) {
|
2012-06-01 07:57:29 +02:00
|
|
|
if ($this->getArgument('excuse')) {
|
|
|
|
$prompt .= " Ignore them?";
|
2012-08-06 22:40:20 +02:00
|
|
|
if (!$this->console->confirm($prompt)) {
|
2012-06-01 07:57:29 +02:00
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
|
|
|
return $this->getArgument('excuse');
|
|
|
|
}
|
2012-02-23 00:57:55 +01:00
|
|
|
|
2012-06-20 03:14:26 +02:00
|
|
|
$history = $this->getRepositoryAPI()->getScratchFilePath($history);
|
|
|
|
|
2012-06-01 07:57:29 +02:00
|
|
|
$prompt .= " Provide explanation to continue or press Enter to abort.";
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->console->writeOut("\n\n%s", phutil_console_wrap($prompt));
|
|
|
|
$return = $this->console->prompt("Explanation:", $history);
|
2012-05-25 19:52:26 +02:00
|
|
|
if ($return == '') {
|
2012-06-01 07:57:29 +02:00
|
|
|
throw new ArcanistUserAbortException();
|
2012-02-23 00:57:55 +01:00
|
|
|
}
|
2012-05-25 19:52:26 +02:00
|
|
|
return $return;
|
2012-02-23 00:57:55 +01:00
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
|
|
|
|
/* -( Commit and Update Messages )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task message
|
|
|
|
*/
|
|
|
|
private function buildCommitMessage() {
|
2012-04-12 19:32:54 +02:00
|
|
|
if ($this->getArgument('preview') || $this->getArgument('only')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
$is_create = $this->getArgument('create');
|
2012-01-09 18:33:55 +01:00
|
|
|
$is_update = $this->getArgument('update');
|
2012-01-05 22:36:24 +01:00
|
|
|
$is_raw = $this->isRawDiffSource();
|
2012-01-13 04:03:11 +01:00
|
|
|
$is_message = $this->getArgument('use-commit-message');
|
With `--verbatim`, update some fields automatically when updating revisions
Summary:
Essentially D2391, but with, uh, more comments?
- I forgot that we already implemented shouldOverwriteWhenCommitMessageIsEdited(). This patch already behaves nearly correctly.
- Requires changes in D2412.
- Use `'edit' => 'edit'`, which does the same thing as `'edit' => true`, but is more correct after the "edit" / "create" split.
- Under "--verbatim", always get the message "from the user", which means "from the working copy" because verbtatim disables the editor part.
Test Plan:
- Created and updated revisions with `arc diff`.
- Created and updated revisions with `arc diff --verbatim`.
- Updated revisions with `arc diff --edit`.
Reviewers: jungejason, btrahan
Reviewed By: jungejason
CC: vrana, aran
Differential Revision: https://secure.phabricator.com/D2411
2012-05-07 17:16:29 +02:00
|
|
|
$is_verbatim = $this->getArgument('verbatim');
|
2012-01-13 04:03:11 +01:00
|
|
|
|
|
|
|
if ($is_message) {
|
|
|
|
return $this->getCommitMessageFromCommit($is_message);
|
|
|
|
}
|
2012-01-05 20:26:17 +01:00
|
|
|
|
With `--verbatim`, update some fields automatically when updating revisions
Summary:
Essentially D2391, but with, uh, more comments?
- I forgot that we already implemented shouldOverwriteWhenCommitMessageIsEdited(). This patch already behaves nearly correctly.
- Requires changes in D2412.
- Use `'edit' => 'edit'`, which does the same thing as `'edit' => true`, but is more correct after the "edit" / "create" split.
- Under "--verbatim", always get the message "from the user", which means "from the working copy" because verbtatim disables the editor part.
Test Plan:
- Created and updated revisions with `arc diff`.
- Created and updated revisions with `arc diff --verbatim`.
- Updated revisions with `arc diff --edit`.
Reviewers: jungejason, btrahan
Reviewed By: jungejason
CC: vrana, aran
Differential Revision: https://secure.phabricator.com/D2411
2012-05-07 17:16:29 +02:00
|
|
|
if ($is_verbatim) {
|
|
|
|
return $this->getCommitMessageFromUser();
|
|
|
|
}
|
|
|
|
|
Make "--auto" the default for "arc diff"
Summary:
NOTE: This is a disruptive change to how 'arc diff' behaves by default.
Many years ago, Differential (then DiffCamp) supported SVN. Someone added a "-i" mode to the "diffcamp" script so you could "git show | diffcamp -i", and thus we were
forever bound to storing metadata in commit messages.
But this isn't a common use case outside of Facebook + git-svn, and isn't very flexible. We now have a great deal of flexibility to identify revisions based on
hashes, branch names, etc, and to sync metdata from web to CLI and back. I want to jettison the commit-message-bound artifacts of the tool's history, and move to a
more flexible, modern workflow.
I added "--auto" a while ago, which figures out if you want to create or update a diff automatically, and then prompts you for whatever data it needs, reading
information if it can from commit messages in the range. This is a vastly better workflow in general, especially for SVN and Mercurial users (who currently need to
jump to the web UI to create revisions). It's better for git users too, since they don't need to use template commits and don't have to muck with or configure
templates. However, it's a nontrivial change to git users' core workflow that is clearly different in more ways than it is clearly better.
- This might be contentious, but probably not toooo much, I hope?
- I also deleted the (fairly ridiculous) workflow where we sync commit message changes from the working copy. I think two or three people will be REALLY upset about
this but I have no sympathy. "--edit" covers this and has been around for like two years now, and making the commit message and web dual-authoritative was always a bad
idea that we only ever half-accommodated anyway (see giant swaths of removed TOOD nonsense).
Test Plan:
- I've been using "--auto" exclusively for like a month, it seems to work well.
- Created/updated SVN, Git and HG diffs with "arc diff" under this workflow.
Reviewers: btrahan, jungejason, nh
Reviewed By: btrahan
CC: Makinde, vrana, zeeg, mbautin, aran, yairlivne, 20after4
Maniphest Tasks: T614
Differential Revision: https://secure.phabricator.com/D2080
2012-04-07 19:39:27 +02:00
|
|
|
if (!$is_raw && !$is_create && !$is_update) {
|
2012-02-20 21:51:01 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
$revisions = $repository_api->loadWorkingCopyDifferentialRevisions(
|
|
|
|
$this->getConduit(),
|
|
|
|
array(
|
|
|
|
'authors' => array($this->getUserPHID()),
|
2012-02-22 19:07:43 +01:00
|
|
|
'status' => 'status-open',
|
2012-02-20 21:51:01 +01:00
|
|
|
));
|
|
|
|
if (!$revisions) {
|
|
|
|
$is_create = true;
|
|
|
|
} else if (count($revisions) == 1) {
|
|
|
|
$revision = head($revisions);
|
|
|
|
$is_update = $revision['id'];
|
|
|
|
} else {
|
|
|
|
throw new ArcanistUsageException(
|
2012-04-10 21:06:41 +02:00
|
|
|
"There are several revisions which match the working copy:\n\n".
|
2012-02-20 21:51:01 +01:00
|
|
|
$this->renderRevisionList($revisions)."\n".
|
|
|
|
"Use '--update' to choose one, or '--create' to create a new ".
|
|
|
|
"revision.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
$message = null;
|
|
|
|
if ($is_create) {
|
|
|
|
$message_file = $this->getArgument('message-file');
|
|
|
|
if ($message_file) {
|
|
|
|
return $this->getCommitMessageFromFile($message_file);
|
|
|
|
} else {
|
|
|
|
return $this->getCommitMessageFromUser();
|
|
|
|
}
|
Make "--auto" the default for "arc diff"
Summary:
NOTE: This is a disruptive change to how 'arc diff' behaves by default.
Many years ago, Differential (then DiffCamp) supported SVN. Someone added a "-i" mode to the "diffcamp" script so you could "git show | diffcamp -i", and thus we were
forever bound to storing metadata in commit messages.
But this isn't a common use case outside of Facebook + git-svn, and isn't very flexible. We now have a great deal of flexibility to identify revisions based on
hashes, branch names, etc, and to sync metdata from web to CLI and back. I want to jettison the commit-message-bound artifacts of the tool's history, and move to a
more flexible, modern workflow.
I added "--auto" a while ago, which figures out if you want to create or update a diff automatically, and then prompts you for whatever data it needs, reading
information if it can from commit messages in the range. This is a vastly better workflow in general, especially for SVN and Mercurial users (who currently need to
jump to the web UI to create revisions). It's better for git users too, since they don't need to use template commits and don't have to muck with or configure
templates. However, it's a nontrivial change to git users' core workflow that is clearly different in more ways than it is clearly better.
- This might be contentious, but probably not toooo much, I hope?
- I also deleted the (fairly ridiculous) workflow where we sync commit message changes from the working copy. I think two or three people will be REALLY upset about
this but I have no sympathy. "--edit" covers this and has been around for like two years now, and making the commit message and web dual-authoritative was always a bad
idea that we only ever half-accommodated anyway (see giant swaths of removed TOOD nonsense).
Test Plan:
- I've been using "--auto" exclusively for like a month, it seems to work well.
- Created/updated SVN, Git and HG diffs with "arc diff" under this workflow.
Reviewers: btrahan, jungejason, nh
Reviewed By: btrahan
CC: Makinde, vrana, zeeg, mbautin, aran, yairlivne, 20after4
Maniphest Tasks: T614
Differential Revision: https://secure.phabricator.com/D2080
2012-04-07 19:39:27 +02:00
|
|
|
} else if ($is_update) {
|
2012-05-12 03:40:02 +02:00
|
|
|
$revision_id = $this->normalizeRevisionID($is_update);
|
|
|
|
if (!is_numeric($revision_id)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
'Parameter to --update must be a Differential Revision number');
|
|
|
|
}
|
|
|
|
return $this->getCommitMessageFromRevision($revision_id);
|
Make "--auto" the default for "arc diff"
Summary:
NOTE: This is a disruptive change to how 'arc diff' behaves by default.
Many years ago, Differential (then DiffCamp) supported SVN. Someone added a "-i" mode to the "diffcamp" script so you could "git show | diffcamp -i", and thus we were
forever bound to storing metadata in commit messages.
But this isn't a common use case outside of Facebook + git-svn, and isn't very flexible. We now have a great deal of flexibility to identify revisions based on
hashes, branch names, etc, and to sync metdata from web to CLI and back. I want to jettison the commit-message-bound artifacts of the tool's history, and move to a
more flexible, modern workflow.
I added "--auto" a while ago, which figures out if you want to create or update a diff automatically, and then prompts you for whatever data it needs, reading
information if it can from commit messages in the range. This is a vastly better workflow in general, especially for SVN and Mercurial users (who currently need to
jump to the web UI to create revisions). It's better for git users too, since they don't need to use template commits and don't have to muck with or configure
templates. However, it's a nontrivial change to git users' core workflow that is clearly different in more ways than it is clearly better.
- This might be contentious, but probably not toooo much, I hope?
- I also deleted the (fairly ridiculous) workflow where we sync commit message changes from the working copy. I think two or three people will be REALLY upset about
this but I have no sympathy. "--edit" covers this and has been around for like two years now, and making the commit message and web dual-authoritative was always a bad
idea that we only ever half-accommodated anyway (see giant swaths of removed TOOD nonsense).
Test Plan:
- I've been using "--auto" exclusively for like a month, it seems to work well.
- Created/updated SVN, Git and HG diffs with "arc diff" under this workflow.
Reviewers: btrahan, jungejason, nh
Reviewed By: btrahan
CC: Makinde, vrana, zeeg, mbautin, aran, yairlivne, 20after4
Maniphest Tasks: T614
Differential Revision: https://secure.phabricator.com/D2080
2012-04-07 19:39:27 +02:00
|
|
|
} else {
|
|
|
|
// This is --raw without enough info to create a revision, so force just
|
|
|
|
// a diff.
|
2012-01-05 22:36:24 +01:00
|
|
|
return null;
|
|
|
|
}
|
2012-01-05 20:26:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-13 04:03:11 +01:00
|
|
|
/**
|
|
|
|
* @task message
|
|
|
|
*/
|
2012-07-01 20:06:05 +02:00
|
|
|
private function getCommitMessageFromCommit($commit) {
|
|
|
|
$text = $this->getRepositoryAPI()->getCommitMessage($commit);
|
|
|
|
$message = ArcanistDifferentialCommitMessage::newFromRawCorpus($text);
|
2012-01-13 04:03:11 +01:00
|
|
|
$message->pullDataFromConduit($this->getConduit());
|
|
|
|
$this->validateCommitMessage($message);
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
/**
|
|
|
|
* @task message
|
|
|
|
*/
|
2011-12-03 00:50:36 +01:00
|
|
|
private function getCommitMessageFromUser() {
|
|
|
|
$conduit = $this->getConduit();
|
|
|
|
|
2012-02-21 21:35:39 +01:00
|
|
|
$template = null;
|
2011-12-03 00:50:36 +01:00
|
|
|
|
2012-05-04 09:08:42 +02:00
|
|
|
if (!$this->getArgument('verbatim')) {
|
|
|
|
$saved = $this->readScratchFile('create-message');
|
|
|
|
if ($saved) {
|
|
|
|
$where = $this->getReadableScratchFilePath('create-message');
|
|
|
|
|
|
|
|
$preview = explode("\n", $saved);
|
|
|
|
$preview = array_shift($preview);
|
|
|
|
$preview = trim($preview);
|
|
|
|
$preview = phutil_utf8_shorten($preview, 64);
|
|
|
|
|
|
|
|
if ($preview) {
|
|
|
|
$preview = "Message begins:\n\n {$preview}\n\n";
|
|
|
|
} else {
|
|
|
|
$preview = null;
|
|
|
|
}
|
2012-02-21 21:35:39 +01:00
|
|
|
|
2012-05-04 09:08:42 +02:00
|
|
|
echo
|
|
|
|
"You have a saved revision message in '{$where}'.\n".
|
|
|
|
"{$preview}".
|
|
|
|
"You can use this message, or discard it.";
|
2012-02-21 21:35:39 +01:00
|
|
|
|
2012-05-04 09:08:42 +02:00
|
|
|
$use = phutil_console_confirm(
|
|
|
|
"Do you want to use this message?",
|
|
|
|
$default_no = false);
|
|
|
|
if ($use) {
|
|
|
|
$template = $saved;
|
|
|
|
} else {
|
|
|
|
$this->removeScratchFile('create-message');
|
|
|
|
}
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$template_is_default = false;
|
2012-02-29 02:00:35 +01:00
|
|
|
$notes = array();
|
2012-05-07 22:18:16 +02:00
|
|
|
$included = array();
|
2012-02-21 21:35:39 +01:00
|
|
|
|
2012-09-28 20:49:04 +02:00
|
|
|
list($fields, $notes, $included_commits) = $this->getDefaultCreateFields();
|
2012-05-07 22:18:16 +02:00
|
|
|
if ($template) {
|
|
|
|
$fields = array();
|
|
|
|
$notes = array();
|
|
|
|
} else {
|
2012-02-29 02:00:35 +01:00
|
|
|
if (!$fields) {
|
|
|
|
$template_is_default = true;
|
|
|
|
}
|
|
|
|
|
2012-06-12 22:29:05 +02:00
|
|
|
if ($notes) {
|
|
|
|
$commit = head($this->getRepositoryAPI()->getLocalCommitInformation());
|
|
|
|
$template = $commit['message'];
|
|
|
|
} else {
|
|
|
|
$template = $conduit->callMethodSynchronous(
|
|
|
|
'differential.getcommitmessage',
|
|
|
|
array(
|
|
|
|
'revision_id' => null,
|
|
|
|
'edit' => 'create',
|
|
|
|
'fields' => $fields,
|
|
|
|
));
|
|
|
|
}
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-28 20:49:04 +02:00
|
|
|
$included = array();
|
|
|
|
if ($included_commits) {
|
|
|
|
foreach ($included_commits as $commit) {
|
|
|
|
$included[] = ' '.$commit;
|
2012-05-07 22:18:16 +02:00
|
|
|
}
|
2012-05-25 02:48:56 +02:00
|
|
|
$in_branch = '';
|
|
|
|
if (!$this->isRawDiffSource()) {
|
|
|
|
$in_branch = ' in branch '.$this->getRepositoryAPI()->getBranchName();
|
|
|
|
}
|
2012-05-07 22:18:16 +02:00
|
|
|
$included = array_merge(
|
|
|
|
array(
|
|
|
|
"",
|
2012-05-25 02:48:56 +02:00
|
|
|
"Included commits{$in_branch}:",
|
2012-05-07 22:18:16 +02:00
|
|
|
"",
|
|
|
|
),
|
2012-09-28 20:49:04 +02:00
|
|
|
$included);
|
2012-05-07 22:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$issues = array_merge(
|
|
|
|
array(
|
|
|
|
'NEW DIFFERENTIAL REVISION',
|
|
|
|
'Describe the changes in this new revision.',
|
|
|
|
),
|
|
|
|
$included,
|
|
|
|
array(
|
2012-09-28 20:49:04 +02:00
|
|
|
'',
|
2012-05-07 22:18:16 +02:00
|
|
|
'arc could not identify any existing revision in your working copy.',
|
|
|
|
'If you intended to update an existing revision, use:',
|
|
|
|
'',
|
|
|
|
' $ arc diff --update <revision>',
|
|
|
|
));
|
2012-02-29 02:00:35 +01:00
|
|
|
if ($notes) {
|
|
|
|
$issues = array_merge($issues, array(''), $notes);
|
|
|
|
}
|
2012-02-21 21:35:39 +01:00
|
|
|
|
|
|
|
$done = false;
|
2012-04-10 21:06:41 +02:00
|
|
|
$first = true;
|
2012-02-21 21:35:39 +01:00
|
|
|
while (!$done) {
|
2012-05-24 20:48:59 +02:00
|
|
|
$template = rtrim($template, "\r\n")."\n\n";
|
2012-02-21 21:35:39 +01:00
|
|
|
foreach ($issues as $issue) {
|
|
|
|
$template .= '# '.$issue."\n";
|
|
|
|
}
|
|
|
|
$template .= "\n";
|
|
|
|
|
2012-04-10 21:06:41 +02:00
|
|
|
if ($first && $this->getArgument('verbatim') && !$template_is_default) {
|
|
|
|
$new_template = $template;
|
|
|
|
} else {
|
2012-07-12 01:55:11 +02:00
|
|
|
$new_template = $this->newInteractiveEditor($template)
|
2012-04-10 21:06:41 +02:00
|
|
|
->setName('new-commit')
|
|
|
|
->editInteractively();
|
|
|
|
}
|
|
|
|
$first = false;
|
2012-02-21 21:35:39 +01:00
|
|
|
|
|
|
|
if ($template_is_default && ($new_template == $template)) {
|
2012-04-10 21:06:41 +02:00
|
|
|
throw new ArcanistUsageException("Template not edited.");
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
|
2012-04-18 15:08:41 +02:00
|
|
|
$template = ArcanistCommentRemover::removeComments($new_template);
|
2012-09-28 20:49:04 +02:00
|
|
|
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
$should_amend = (count($included_commits) == 1 && $this->shouldAmend());
|
|
|
|
if ($should_amend && $repository_api->supportsAmend()) {
|
|
|
|
$repository_api->amendCommit($template);
|
|
|
|
$wrote = true;
|
|
|
|
$where = 'commit message';
|
|
|
|
} else {
|
|
|
|
$wrote = $this->writeScratchFile('create-message', $template);
|
|
|
|
$where = "'".$this->getReadableScratchFilePath('create-message')."'";
|
|
|
|
}
|
2012-02-21 21:35:39 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
$message = ArcanistDifferentialCommitMessage::newFromRawCorpus(
|
|
|
|
$template);
|
|
|
|
$message->pullDataFromConduit($conduit);
|
|
|
|
$this->validateCommitMessage($message);
|
|
|
|
$done = true;
|
|
|
|
} catch (ArcanistDifferentialCommitMessageParserException $ex) {
|
|
|
|
echo "Commit message has errors:\n\n";
|
|
|
|
$issues = array('Resolve these errors:');
|
|
|
|
foreach ($ex->getParserErrors() as $error) {
|
2012-06-12 21:10:51 +02:00
|
|
|
echo phutil_console_wrap("- ".$error."\n", 6);
|
2012-02-21 21:35:39 +01:00
|
|
|
$issues[] = ' - '.$error;
|
|
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
echo "You must resolve these errors to continue.";
|
|
|
|
$again = phutil_console_confirm(
|
|
|
|
"Do you want to edit the message?",
|
|
|
|
$default_no = false);
|
|
|
|
if ($again) {
|
|
|
|
// Keep going.
|
|
|
|
} else {
|
|
|
|
$saved = null;
|
|
|
|
if ($wrote) {
|
2012-09-28 20:49:04 +02:00
|
|
|
$saved = "A copy was saved to {$where}.";
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
throw new ArcanistUsageException(
|
2012-02-29 02:00:35 +01:00
|
|
|
"Message has unresolved errrors. {$saved}");
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
if ($wrote) {
|
2012-09-28 20:49:04 +02:00
|
|
|
echo phutil_console_wrap("(Message saved to {$where}.)\n");
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
throw $ex;
|
|
|
|
}
|
2011-12-03 00:50:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @task message
|
|
|
|
*/
|
2011-12-03 00:50:36 +01:00
|
|
|
private function getCommitMessageFromFile($file) {
|
|
|
|
$conduit = $this->getConduit();
|
|
|
|
|
|
|
|
$data = Filesystem::readFile($file);
|
|
|
|
$message = ArcanistDifferentialCommitMessage::newFromRawCorpus($data);
|
|
|
|
$message->pullDataFromConduit($conduit);
|
2012-01-05 20:26:17 +01:00
|
|
|
|
|
|
|
$this->validateCommitMessage($message);
|
|
|
|
|
2011-12-03 00:50:36 +01:00
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
|
2012-01-09 18:33:55 +01:00
|
|
|
/**
|
|
|
|
* @task message
|
|
|
|
*/
|
|
|
|
private function getCommitMessageFromRevision($revision_id) {
|
2012-05-12 03:40:02 +02:00
|
|
|
$id = $revision_id;
|
2012-01-09 18:33:55 +01:00
|
|
|
|
|
|
|
$revision = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'differential.query',
|
|
|
|
array(
|
|
|
|
'ids' => array($id),
|
|
|
|
));
|
|
|
|
$revision = head($revision);
|
|
|
|
|
|
|
|
if (!$revision) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Revision '{$revision_id}' does not exist!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($revision['authorPHID'] != $this->getUserPHID()) {
|
|
|
|
$rev_title = $revision['title'];
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"You don't own revision D{$id} '{$rev_title}'. You can only update ".
|
|
|
|
"revisions you own.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'differential.getcommitmessage',
|
|
|
|
array(
|
|
|
|
'revision_id' => $id,
|
|
|
|
'edit' => false,
|
|
|
|
));
|
2012-10-16 20:51:15 +02:00
|
|
|
$this->commitMessageFromRevision = $message;
|
2012-01-09 18:33:55 +01:00
|
|
|
|
|
|
|
$obj = ArcanistDifferentialCommitMessage::newFromRawCorpus($message);
|
|
|
|
$obj->pullDataFromConduit($this->getConduit());
|
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
/**
|
|
|
|
* @task message
|
|
|
|
*/
|
|
|
|
private function validateCommitMessage(
|
|
|
|
ArcanistDifferentialCommitMessage $message) {
|
|
|
|
$reviewers = $message->getFieldValue('reviewerPHIDs');
|
|
|
|
if (!$reviewers) {
|
|
|
|
$confirm = "You have not specified any reviewers. Continue anyway?";
|
|
|
|
if (!phutil_console_confirm($confirm)) {
|
|
|
|
throw new ArcanistUsageException('Specify reviewers and retry.');
|
|
|
|
}
|
2012-05-18 04:27:24 +02:00
|
|
|
} else {
|
2012-05-18 19:27:44 +02:00
|
|
|
$users = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'user.query',
|
2012-05-18 04:27:24 +02:00
|
|
|
array(
|
2012-05-18 19:27:44 +02:00
|
|
|
'phids' => $reviewers,
|
2012-05-18 04:27:24 +02:00
|
|
|
));
|
2012-05-18 19:27:44 +02:00
|
|
|
$untils = array();
|
|
|
|
foreach ($users as $user) {
|
|
|
|
if (idx($user, 'currentStatus') == 'away') {
|
|
|
|
$untils[] = $user['currentStatusUntil'];
|
2012-05-18 04:27:24 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-18 19:27:44 +02:00
|
|
|
if (count($untils) == count($reviewers)) {
|
|
|
|
$until = date('l, M j Y', min($untils));
|
|
|
|
$confirm = "All reviewers are away until {$until}. Continue anyway?";
|
2012-05-18 04:27:24 +02:00
|
|
|
if (!phutil_console_confirm($confirm)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
'Specify available reviewers and retry.');
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 20:26:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task message
|
|
|
|
*/
|
2012-08-08 21:08:41 +02:00
|
|
|
private function getUpdateMessage(array $fields, $template = '') {
|
2012-03-20 03:15:58 +01:00
|
|
|
if ($this->getArgument('raw')) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"When using '--raw' to update a revision, specify an update message ".
|
|
|
|
"with '--message'. (Normally, we'd launch an editor to ask you for a ".
|
2012-03-20 03:16:50 +01:00
|
|
|
"message, but can not do that because stdin is the diff source.)");
|
2012-03-20 03:15:58 +01:00
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
// When updating a revision using git without specifying '--message', try
|
|
|
|
// to prefill with the message in HEAD if it isn't a template message. The
|
|
|
|
// idea is that if you do:
|
|
|
|
//
|
|
|
|
// $ git commit -a -m 'fix some junk'
|
|
|
|
// $ arc diff
|
|
|
|
//
|
2012-02-23 18:18:49 +01:00
|
|
|
// ...you shouldn't have to retype the update message. Similar things apply
|
|
|
|
// to Mercurial.
|
|
|
|
|
2012-08-08 21:08:41 +02:00
|
|
|
if ($template == '') {
|
|
|
|
$comments = $this->getDefaultUpdateMessage();
|
|
|
|
|
|
|
|
$template =
|
|
|
|
rtrim($comments).
|
|
|
|
"\n\n".
|
|
|
|
"# Updating D{$fields['revisionID']}: {$fields['title']}\n".
|
|
|
|
"#\n".
|
|
|
|
"# Enter a brief description of the changes included in this update.\n".
|
|
|
|
"# The first line is used as subject, next lines as comment.\n".
|
|
|
|
"#\n".
|
|
|
|
"# If you intended to create a new revision, use:\n".
|
|
|
|
"# $ arc diff --create\n".
|
|
|
|
"\n";
|
|
|
|
}
|
2012-01-05 20:26:17 +01:00
|
|
|
|
2012-07-12 01:55:11 +02:00
|
|
|
$comments = $this->newInteractiveEditor($template)
|
2012-01-05 20:26:17 +01:00
|
|
|
->setName('differential-update-comments')
|
|
|
|
->editInteractively();
|
|
|
|
|
|
|
|
return $comments;
|
|
|
|
}
|
|
|
|
|
2012-02-29 02:00:35 +01:00
|
|
|
private function getDefaultCreateFields() {
|
2012-05-21 01:39:38 +02:00
|
|
|
$result = array(array(), array(), array());
|
2012-02-29 02:00:35 +01:00
|
|
|
|
2012-03-05 19:08:50 +01:00
|
|
|
if ($this->isRawDiffSource()) {
|
2012-05-21 01:39:38 +02:00
|
|
|
return $result;
|
2012-02-29 02:00:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
$local = $repository_api->getLocalCommitInformation();
|
|
|
|
if ($local) {
|
|
|
|
$result = $this->parseCommitMessagesIntoFields($local);
|
2012-02-29 02:00:35 +01:00
|
|
|
}
|
|
|
|
|
2012-05-21 01:39:38 +02:00
|
|
|
$result[0] = $this->dispatchWillBuildEvent($result[0]);
|
|
|
|
|
|
|
|
return $result;
|
2012-02-29 02:00:35 +01:00
|
|
|
}
|
|
|
|
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
/**
|
|
|
|
* Convert a list of commits from `getLocalCommitInformation()` into
|
|
|
|
* a format usable by arc to create a new diff. Specifically, we emit:
|
|
|
|
*
|
|
|
|
* - A dictionary of commit message fields.
|
|
|
|
* - A list of errors encountered while parsing the messages.
|
|
|
|
* - A human-readable list of the commits themselves.
|
|
|
|
*
|
|
|
|
* For example, if the user runs "arc diff HEAD^^^" and selects a diff range
|
|
|
|
* which includes several diffs, we attempt to merge them somewhat
|
|
|
|
* intelligently into a single message, because we can only send one
|
|
|
|
* "Summary:", "Reviewers:", etc., field to Differential. We also return
|
|
|
|
* errors (e.g., if the user typed a reviewer name incorrectly) and a
|
|
|
|
* summary of the commits themselves.
|
|
|
|
*
|
|
|
|
* @param dict Local commit information.
|
|
|
|
* @return list Complex output, see summary.
|
|
|
|
* @task message
|
|
|
|
*/
|
|
|
|
private function parseCommitMessagesIntoFields(array $local) {
|
2012-02-29 02:00:35 +01:00
|
|
|
$conduit = $this->getConduit();
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
$local = ipull($local, null, 'commit');
|
2012-02-29 02:00:35 +01:00
|
|
|
|
2012-05-22 23:38:53 +02:00
|
|
|
// If the user provided "--reviewers" or "--ccs", add a faux message to
|
|
|
|
// the list with the implied fields.
|
|
|
|
|
|
|
|
$faux_message = array();
|
|
|
|
if ($this->getArgument('reviewers')) {
|
|
|
|
$faux_message[] = 'Reviewers: '.$this->getArgument('reviewers');
|
|
|
|
}
|
|
|
|
if ($this->getArgument('cc')) {
|
|
|
|
$faux_message[] = 'CC: '.$this->getArgument('cc');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($faux_message) {
|
|
|
|
$faux_message = implode("\n\n", $faux_message);
|
|
|
|
$local = array(
|
|
|
|
'(Flags) ' => array(
|
|
|
|
'message' => $faux_message,
|
|
|
|
'summary' => 'Command-Line Flags',
|
|
|
|
),
|
|
|
|
) + $local;
|
|
|
|
}
|
|
|
|
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
// Build a human-readable list of the commits, so we can show the user which
|
|
|
|
// commits are included in the diff.
|
|
|
|
$included = array();
|
|
|
|
foreach ($local as $hash => $info) {
|
|
|
|
$included[] = substr($hash, 0, 12).' '.$info['summary'];
|
2012-02-29 02:00:35 +01:00
|
|
|
}
|
|
|
|
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
// Parse all of the messages into fields.
|
2012-02-29 02:00:35 +01:00
|
|
|
$messages = array();
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
foreach ($local as $hash => $info) {
|
|
|
|
$text = $info['message'];
|
|
|
|
$obj = ArcanistDifferentialCommitMessage::newFromRawCorpus($text);
|
|
|
|
$messages[$hash] = $obj;
|
2012-02-29 02:00:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$notes = array();
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
$fields = array();
|
2012-02-29 02:00:35 +01:00
|
|
|
foreach ($messages as $hash => $message) {
|
|
|
|
try {
|
|
|
|
$message->pullDataFromConduit($conduit, $partial = true);
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
$fields[$hash] = $message->getFields();
|
2012-02-29 02:00:35 +01:00
|
|
|
} catch (ArcanistDifferentialCommitMessageParserException $ex) {
|
2012-05-04 21:22:47 +02:00
|
|
|
if ($this->getArgument('verbatim')) {
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
// In verbatim mode, just bail when we hit an error. The user can
|
|
|
|
// rerun without --verbatim if they want to fix it manually. Most
|
|
|
|
// users will probably `git commit --amend` instead.
|
2012-05-04 21:22:47 +02:00
|
|
|
throw $ex;
|
|
|
|
}
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
$fields[$hash] = $message->getFields();
|
2012-05-04 21:22:47 +02:00
|
|
|
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
$frev = substr($hash, 0, 12);
|
2012-02-29 02:00:35 +01:00
|
|
|
$notes[] = "NOTE: commit {$frev} could not be completely parsed:";
|
|
|
|
foreach ($ex->getParserErrors() as $error) {
|
|
|
|
$notes[] = " - {$error}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Improve default fill of Differential messages from commits
Summary:
- When you run "arc diff" in Mercurial, we currently give you an empty template. Instead, prefill a likely template by parsing messages, as we do for Git.
- Unify Git and Mercurial logic for acquiring messages, since `getLocalCommitInformation()` now provides this information. This should improve Git performance, and allows us to delete some code.
- Merge messages more intelligently. Currently, we just overwrite fields. Instead, merge arrays (like ccs, reviewers, tasks) and concatenate strings (like summary and test plan). We need to special case "title", see inline.
- @csilvers: this is a precursor to implementing "--reviewers", etc.
Test Plan: See next post, test plan includes giant output.
Reviewers: btrahan, csilvers, Makinde, jungejason, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2536
2012-05-22 20:08:57 +02:00
|
|
|
// Merge commit message fields. We do this somewhat-intelligently so that
|
|
|
|
// multiple "Reviewers" or "CC" fields will merge into the concatenation
|
|
|
|
// of all values.
|
|
|
|
|
|
|
|
// We have special parsing rules for 'title' because we can't merge
|
|
|
|
// multiple titles, and one-line commit messages like "fix stuff" will
|
|
|
|
// parse as titles. Instead, pick the first title we encounter. When we
|
|
|
|
// encounter subsequent titles, treat them as part of the summary. Then
|
|
|
|
// we merge all the summaries together below.
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
// Process fields in oldest-first order, so earlier commits get to set the
|
|
|
|
// title of record and reviewers/ccs are listed in chronological order.
|
|
|
|
$fields = array_reverse($fields);
|
|
|
|
|
|
|
|
foreach ($fields as $hash => $dict) {
|
|
|
|
$title = idx($dict, 'title');
|
|
|
|
if (!strlen($title)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($result['title'])) {
|
|
|
|
// We don't have a title yet, so use this one.
|
|
|
|
$result['title'] = $title;
|
|
|
|
} else {
|
|
|
|
// We already have a title, so merge this new title into the summary.
|
|
|
|
$summary = idx($dict, 'summary');
|
|
|
|
if ($summary) {
|
|
|
|
$summary = $title."\n\n".$summary;
|
|
|
|
} else {
|
|
|
|
$summary = $title;
|
|
|
|
}
|
|
|
|
$fields[$hash]['summary'] = $summary;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, merge all the other fields in a general sort of way.
|
|
|
|
|
|
|
|
foreach ($fields as $hash => $dict) {
|
|
|
|
foreach ($dict as $key => $value) {
|
|
|
|
if ($key == 'title') {
|
|
|
|
// This has been handled above, and either assigned directly or
|
|
|
|
// merged into the summary.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($value)) {
|
|
|
|
// For array values, merge the arrays, appending the new values.
|
|
|
|
// Examples are "Reviewers" and "Cc", where this produces a list of
|
|
|
|
// all users specified as reviewers.
|
|
|
|
$cur = idx($result, $key, array());
|
|
|
|
$new = array_merge($cur, $value);
|
|
|
|
$result[$key] = $new;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (!strlen(trim($value))) {
|
|
|
|
// Ignore empty fields.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For string values, append the new field to the old field with
|
|
|
|
// a blank line separating them. Examples are "Test Plan" and
|
|
|
|
// "Summary".
|
|
|
|
$cur = idx($result, $key, '');
|
|
|
|
if (strlen($cur)) {
|
|
|
|
$new = $cur."\n\n".$value;
|
|
|
|
} else {
|
|
|
|
$new = $value;
|
|
|
|
}
|
|
|
|
$result[$key] = $new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array($result, $notes, $included);
|
2012-02-29 02:00:35 +01:00
|
|
|
}
|
|
|
|
|
2012-02-23 18:18:49 +01:00
|
|
|
private function getDefaultUpdateMessage() {
|
2012-03-05 19:08:50 +01:00
|
|
|
if ($this->isRawDiffSource()) {
|
2012-02-23 18:18:49 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
if ($repository_api instanceof ArcanistGitAPI) {
|
|
|
|
return $this->getGitUpdateMessage();
|
|
|
|
}
|
|
|
|
|
2012-02-29 01:59:40 +01:00
|
|
|
if ($repository_api instanceof ArcanistMercurialAPI) {
|
|
|
|
return $this->getMercurialUpdateMessage();
|
|
|
|
}
|
|
|
|
|
2012-02-23 18:18:49 +01:00
|
|
|
return null;
|
|
|
|
}
|
2012-01-05 20:26:17 +01:00
|
|
|
|
|
|
|
/**
|
2012-02-29 01:59:40 +01:00
|
|
|
* Retrieve the git messages between HEAD and the last update.
|
2012-01-05 20:26:17 +01:00
|
|
|
*
|
|
|
|
* @task message
|
|
|
|
*/
|
|
|
|
private function getGitUpdateMessage() {
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
2012-07-18 01:16:18 +02:00
|
|
|
$parser = $this->newDiffParser();
|
2012-01-05 20:26:17 +01:00
|
|
|
$commit_messages = $repository_api->getGitCommitLog();
|
|
|
|
$commit_messages = $parser->parseDiff($commit_messages);
|
|
|
|
|
2012-02-23 18:18:49 +01:00
|
|
|
if (count($commit_messages) == 1) {
|
|
|
|
// If there's only one message, assume this is an amend-based workflow and
|
|
|
|
// that using it to prefill doesn't make sense.
|
2012-01-05 20:26:17 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-02-23 18:18:49 +01:00
|
|
|
// We have more than one message, so figure out which ones are new. We
|
|
|
|
// do this by pulling the current diff and comparing commit hashes in the
|
|
|
|
// working copy with attached commit hashes. It's not super important that
|
|
|
|
// we always get this 100% right, we're just trying to do something
|
|
|
|
// reasonable.
|
|
|
|
|
2012-02-29 01:59:40 +01:00
|
|
|
$local = $this->loadActiveLocalCommitInfo();
|
2012-02-23 18:18:49 +01:00
|
|
|
$hashes = ipull($local, null, 'commit');
|
|
|
|
|
|
|
|
$usable = array();
|
|
|
|
foreach ($commit_messages as $message) {
|
|
|
|
$text = $message->getMetadata('message');
|
|
|
|
|
|
|
|
$parsed = ArcanistDifferentialCommitMessage::newFromRawCorpus($text);
|
|
|
|
if ($parsed->getRevisionID()) {
|
|
|
|
// If this is an amended commit message with a revision ID, it's
|
|
|
|
// certainly not new. Stop marking commits as usable and break out.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($hashes[$message->getCommitHash()])) {
|
|
|
|
// If this commit is currently part of the diff, stop using commit
|
|
|
|
// messages, since anything older than this isn't new.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, this looks new, so it's a usable commit message.
|
2012-04-07 19:36:16 +02:00
|
|
|
$usable[] = $text;
|
2012-02-23 18:18:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$usable) {
|
|
|
|
// No new commit messages, so we don't have anywhere to start from.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-02-29 01:59:40 +01:00
|
|
|
return $this->formatUsableLogs($usable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the hg messages between tip and the last update.
|
|
|
|
*
|
|
|
|
* @task message
|
|
|
|
*/
|
|
|
|
private function getMercurialUpdateMessage() {
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
|
|
|
$messages = $repository_api->getCommitMessageLog();
|
|
|
|
|
|
|
|
$local = $this->loadActiveLocalCommitInfo();
|
2012-05-10 20:43:21 +02:00
|
|
|
$hashes = ipull($local, null, 'commit');
|
2012-02-29 01:59:40 +01:00
|
|
|
|
|
|
|
$usable = array();
|
|
|
|
foreach ($messages as $rev => $message) {
|
|
|
|
if (isset($hashes[$rev])) {
|
|
|
|
// If this commit is currently part of the active diff on the revision,
|
|
|
|
// stop using commit messages, since anything older than this isn't new.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, this looks new, so it's a usable commit message.
|
|
|
|
$usable[] = $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$usable) {
|
|
|
|
// No new commit messages, so we don't have anywhere to start from.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->formatUsableLogs($usable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format log messages to prefill a diff update.
|
|
|
|
*
|
|
|
|
* @task message
|
|
|
|
*/
|
|
|
|
private function formatUsableLogs(array $usable) {
|
2012-02-23 18:18:49 +01:00
|
|
|
// Flip messages so they'll read chronologically (oldest-first) in the
|
|
|
|
// template, e.g.:
|
|
|
|
//
|
|
|
|
// - Added foobar.
|
|
|
|
// - Fixed foobar bug.
|
|
|
|
// - Documented foobar.
|
|
|
|
|
|
|
|
$usable = array_reverse($usable);
|
|
|
|
$default = array();
|
|
|
|
foreach ($usable as $message) {
|
|
|
|
// Pick the first line out of each message.
|
2012-02-29 01:59:40 +01:00
|
|
|
$text = trim($message);
|
2012-02-23 18:18:49 +01:00
|
|
|
$text = head(explode("\n", $text));
|
|
|
|
$default[] = ' - '.$text."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode('', $default);
|
2012-01-05 20:26:17 +01:00
|
|
|
}
|
|
|
|
|
2012-02-29 01:59:40 +01:00
|
|
|
private function loadActiveLocalCommitInfo() {
|
|
|
|
$current_diff = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'differential.getdiff',
|
|
|
|
array(
|
|
|
|
'revision_id' => $this->revisionID,
|
|
|
|
));
|
|
|
|
|
|
|
|
$properties = idx($current_diff, 'properties', array());
|
|
|
|
return idx($properties, 'local:commits', array());
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
|
|
|
|
/* -( Diff Specification )------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task diffspec
|
|
|
|
*/
|
|
|
|
private function getLintStatus($lint_result) {
|
|
|
|
$map = array(
|
|
|
|
ArcanistLintWorkflow::RESULT_OKAY => 'okay',
|
|
|
|
ArcanistLintWorkflow::RESULT_ERRORS => 'fail',
|
|
|
|
ArcanistLintWorkflow::RESULT_WARNINGS => 'warn',
|
|
|
|
ArcanistLintWorkflow::RESULT_SKIP => 'skip',
|
2012-07-03 00:53:22 +02:00
|
|
|
ArcanistLintWorkflow::RESULT_POSTPONED => 'postponed',
|
2012-01-05 20:26:17 +01:00
|
|
|
);
|
|
|
|
return idx($map, $lint_result, 'none');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task diffspec
|
|
|
|
*/
|
|
|
|
private function getUnitStatus($unit_result) {
|
|
|
|
$map = array(
|
|
|
|
ArcanistUnitWorkflow::RESULT_OKAY => 'okay',
|
|
|
|
ArcanistUnitWorkflow::RESULT_FAIL => 'fail',
|
|
|
|
ArcanistUnitWorkflow::RESULT_UNSOUND => 'warn',
|
|
|
|
ArcanistUnitWorkflow::RESULT_SKIP => 'skip',
|
|
|
|
ArcanistUnitWorkflow::RESULT_POSTPONED => 'postponed',
|
|
|
|
);
|
|
|
|
return idx($map, $unit_result, 'none');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task diffspec
|
|
|
|
*/
|
|
|
|
private function buildDiffSpecification() {
|
|
|
|
|
2012-01-05 22:36:24 +01:00
|
|
|
$base_revision = null;
|
|
|
|
$base_path = null;
|
|
|
|
$vcs = null;
|
2012-01-05 20:26:17 +01:00
|
|
|
$repo_uuid = null;
|
|
|
|
$parent = null;
|
2012-01-05 22:36:24 +01:00
|
|
|
$source_path = null;
|
|
|
|
$branch = null;
|
2012-07-01 01:00:48 +02:00
|
|
|
$bookmark = null;
|
2012-01-05 22:36:24 +01:00
|
|
|
|
2012-03-05 19:08:50 +01:00
|
|
|
if (!$this->isRawDiffSource()) {
|
2012-01-05 22:36:24 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
|
|
|
$base_revision = $repository_api->getSourceControlBaseRevision();
|
|
|
|
$base_path = $repository_api->getSourceControlPath();
|
|
|
|
$vcs = $repository_api->getSourceControlSystemName();
|
|
|
|
$source_path = $repository_api->getPath();
|
|
|
|
$branch = $repository_api->getBranchName();
|
|
|
|
|
|
|
|
if ($repository_api instanceof ArcanistGitAPI) {
|
|
|
|
$info = $this->getGitParentLogInfo();
|
|
|
|
if ($info['parent']) {
|
|
|
|
$parent = $info['parent'];
|
|
|
|
}
|
|
|
|
if ($info['base_revision']) {
|
|
|
|
$base_revision = $info['base_revision'];
|
|
|
|
}
|
|
|
|
if ($info['base_path']) {
|
|
|
|
$base_path = $info['base_path'];
|
|
|
|
}
|
|
|
|
if ($info['uuid']) {
|
|
|
|
$repo_uuid = $info['uuid'];
|
|
|
|
}
|
|
|
|
} else if ($repository_api instanceof ArcanistSubversionAPI) {
|
|
|
|
$repo_uuid = $repository_api->getRepositorySVNUUID();
|
|
|
|
} else if ($repository_api instanceof ArcanistMercurialAPI) {
|
2012-07-01 01:00:48 +02:00
|
|
|
|
|
|
|
$bookmark = $repository_api->getActiveBookmark();
|
|
|
|
$svn_info = $repository_api->getSubversionInfo();
|
|
|
|
$repo_uuid = idx($svn_info, 'uuid');
|
|
|
|
$base_path = idx($svn_info, 'base_path', $base_path);
|
|
|
|
$base_revision = idx($svn_info, 'base_revision', $base_revision);
|
|
|
|
|
|
|
|
// TODO: provide parent info
|
|
|
|
|
2012-01-05 22:36:24 +01:00
|
|
|
} else {
|
|
|
|
throw new Exception("Unsupported repository API!");
|
2012-01-05 20:26:17 +01:00
|
|
|
}
|
2012-01-05 22:36:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$project_id = null;
|
|
|
|
if ($this->requiresWorkingCopy()) {
|
|
|
|
$project_id = $this->getWorkingCopy()->getProjectID();
|
2012-01-05 20:26:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'sourceMachine' => php_uname('n'),
|
2012-01-05 22:36:24 +01:00
|
|
|
'sourcePath' => $source_path,
|
|
|
|
'branch' => $branch,
|
2012-07-01 01:00:48 +02:00
|
|
|
'bookmark' => $bookmark,
|
2012-01-05 20:26:17 +01:00
|
|
|
'sourceControlSystem' => $vcs,
|
|
|
|
'sourceControlPath' => $base_path,
|
|
|
|
'sourceControlBaseRevision' => $base_revision,
|
|
|
|
'parentRevisionID' => $parent,
|
|
|
|
'repositoryUUID' => $repo_uuid,
|
|
|
|
'creationMethod' => 'arc',
|
2012-01-05 22:36:24 +01:00
|
|
|
'arcanistProject' => $project_id,
|
2012-01-05 20:26:17 +01:00
|
|
|
'authorPHID' => $this->getUserPHID(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -( Diff Properties )---------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update lint information for the diff.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @task diffprop
|
|
|
|
*/
|
|
|
|
private function updateLintDiffProperty() {
|
|
|
|
|
2012-07-03 00:53:22 +02:00
|
|
|
if ($this->unresolvedLint) {
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->updateDiffProperty('arc:lint', json_encode($this->unresolvedLint));
|
2012-07-03 00:53:22 +02:00
|
|
|
if (strlen($this->lintExcuse)) {
|
|
|
|
$this->updateDiffProperty('arc:lint-excuse',
|
|
|
|
json_encode($this->lintExcuse));
|
|
|
|
}
|
2012-01-05 20:26:17 +01:00
|
|
|
}
|
|
|
|
|
2012-07-03 00:53:22 +02:00
|
|
|
$postponed = $this->postponedLinters;
|
|
|
|
if ($postponed) {
|
|
|
|
$this->updateDiffProperty('arc:lint-postponed', json_encode($postponed));
|
2012-02-23 00:57:55 +01:00
|
|
|
}
|
2012-07-03 00:53:22 +02:00
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update unit test information for the diff.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @task diffprop
|
|
|
|
*/
|
|
|
|
private function updateUnitDiffProperty() {
|
2012-01-31 21:07:19 +01:00
|
|
|
if (!$this->testResults) {
|
2012-01-05 20:26:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-06 22:40:20 +02:00
|
|
|
$this->updateDiffProperty('arc:unit', json_encode($this->testResults));
|
2012-02-23 00:57:55 +01:00
|
|
|
if (strlen($this->unitExcuse)) {
|
|
|
|
$this->updateDiffProperty('arc:unit-excuse',
|
|
|
|
json_encode($this->unitExcuse));
|
|
|
|
}
|
2012-01-05 20:26:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update local commit information for the diff.
|
|
|
|
*
|
|
|
|
* @task diffprop
|
|
|
|
*/
|
|
|
|
private function updateLocalDiffProperty() {
|
2012-01-05 22:36:24 +01:00
|
|
|
if ($this->isRawDiffSource()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:26:17 +01:00
|
|
|
$local_info = $this->getRepositoryAPI()->getLocalCommitInformation();
|
|
|
|
if (!$local_info) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->updateDiffProperty('local:commits', json_encode($local_info));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update an arbitrary diff property.
|
|
|
|
*
|
|
|
|
* @param string Diff property name.
|
|
|
|
* @param string Diff property value.
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @task diffprop
|
|
|
|
*/
|
|
|
|
private function updateDiffProperty($name, $data) {
|
2012-10-13 00:01:19 +02:00
|
|
|
$this->diffPropertyFutures[] = $this->getConduit()->callMethod(
|
2012-01-05 20:26:17 +01:00
|
|
|
'differential.setdiffproperty',
|
|
|
|
array(
|
|
|
|
'diff_id' => $this->getDiffID(),
|
|
|
|
'name' => $name,
|
|
|
|
'data' => $data,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-10-13 00:01:19 +02:00
|
|
|
/**
|
|
|
|
* Wait for finishing all diff property updates.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @task diffprop
|
|
|
|
*/
|
|
|
|
private function resolveDiffPropertyUpdates() {
|
|
|
|
Futures($this->diffPropertyFutures)->resolveAll();
|
|
|
|
$this->diffPropertyFutures = array();
|
|
|
|
}
|
|
|
|
|
2012-08-30 21:28:35 +02:00
|
|
|
private function dispatchWillCreateRevisionEvent(array $fields) {
|
2012-09-04 21:08:04 +02:00
|
|
|
$event = $this->dispatchEvent(
|
2012-08-30 21:28:35 +02:00
|
|
|
ArcanistEventType::TYPE_REVISION_WILLCREATEREVISION,
|
|
|
|
array(
|
|
|
|
'specification' => $fields,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $event->getValue('specification');
|
|
|
|
}
|
|
|
|
|
2012-05-21 01:39:38 +02:00
|
|
|
private function dispatchWillBuildEvent(array $fields) {
|
2012-09-04 21:08:04 +02:00
|
|
|
$event = $this->dispatchEvent(
|
2012-05-21 01:39:38 +02:00
|
|
|
ArcanistEventType::TYPE_DIFF_WILLBUILDMESSAGE,
|
|
|
|
array(
|
2012-08-30 21:28:35 +02:00
|
|
|
'fields' => $fields,
|
2012-05-21 01:39:38 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
return $event->getValue('fields');
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|