]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add an "--update <revision>" flag to Arcanist
authorepriestley <git@epriestley.com>
Mon, 9 Jan 2012 17:33:55 +0000 (09:33 -0800)
committerepriestley <git@epriestley.com>
Mon, 9 Jan 2012 19:42:14 +0000 (11:42 -0800)
Summary:
See T614. This flag explicitly tells Arcanist to use the message for an existing
revision, and attach the change to it directly.

Next step is to have "arc diff" automatically choose "--create" or "--update" in
the absence of "--create", "--update", "--only", "--preview" or a template
commit message.

Test Plan:
Ran "arc diff --update <n>" for various revisions. Got updates or
errors as expected.

Reviewers: btrahan, jungejason

Reviewed By: btrahan

CC: aran, btrahan, jungejason
Maniphest Tasks: T614

Differential Revision: https://secure.phabricator.com/D1346

src/differential/commitmessage/ArcanistDifferentialCommitMessage.php
src/workflow/diff/ArcanistDiffWorkflow.php

index 8924f65cdc96ecbb9037320ef3b7538a51fe4e21..f807221c4e29dc8ae1c10ccece7cab7c5d9e36c6 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -79,12 +79,11 @@ class ArcanistDifferentialCommitMessage {
   }
 
   public function pullDataFromConduit(ConduitClient $conduit) {
-    $result = $conduit->callMethod(
+    $result = $conduit->callMethodSynchronous(
       'differential.parsecommitmessage',
       array(
         'corpus' => $this->rawCorpus,
       ));
-    $result = $result->resolve();
     if (!empty($result['errors'])) {
       throw new ArcanistDifferentialCommitMessageParserException(
         $result['errors']);
index 6a187457ed8b1e8b52f7b165bfe93cf7d73b6697..449ba7061e64b9f0212596757c44c2cb39079473 100644 (file)
@@ -139,13 +139,19 @@ EOTEXT
         ),
       ),
       'create' => array(
-        'help' => "(EXPERIMENTAL) Create a new revision.",
+        'help' => "Always create a new revision.",
         'conflicts' => array(
           'edit'    => '--create can not be used with --edit.',
           'only'    => '--create can not be used with --only.',
           'preview' => '--create can not be used with --preview.',
+
+          'update'  => '--create can not be used with --update.',
         ),
       ),
+      'update' => array(
+        'param' => 'revision_id',
+        'help'  => "Always update a specific revision.",
+      ),
       'nounit' => array(
         'help' =>
           "Do not run unit tests.",
@@ -459,6 +465,10 @@ EOTEXT
       return false;
     }
 
+    if ($this->getArgument('update')) {
+      return false;
+    }
+
     if ($this->isRawDiffSource()) {
       return true;
     }
@@ -1061,6 +1071,7 @@ EOTEXT
    */
   private function buildCommitMessage() {
     $is_create = $this->getArgument('create');
+    $is_update = $this->getArgument('update');
     $is_raw = $this->isRawDiffSource();
 
     $message = null;
@@ -1073,6 +1084,10 @@ EOTEXT
       }
     }
 
+    if ($is_update) {
+      return $this->getCommitMessageFromRevision($is_update);
+    }
+
     if ($is_raw) {
       return null;
     }
@@ -1144,6 +1159,45 @@ EOTEXT
   }
 
 
+  /**
+   * @task message
+   */
+  private function getCommitMessageFromRevision($revision_id) {
+    $id = $this->normalizeRevisionID($revision_id);
+
+    $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,
+      ));
+
+    $obj = ArcanistDifferentialCommitMessage::newFromRawCorpus($message);
+    $obj->pullDataFromConduit($this->getConduit());
+
+    return $obj;
+  }
+
+
   /**
    * @task message
    */