]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow 'arc diff .^' for hg repos
authordurham <durham@fb.com>
Wed, 10 Apr 2013 00:00:34 +0000 (17:00 -0700)
committerdurham <durham@fb.com>
Wed, 10 Apr 2013 00:00:34 +0000 (17:00 -0700)
Summary:
Previously arc diff for hg only allowed bookmark names, rev numbers,
and commit hashes as the input base commit. This was because it escaped all
inputs and treated them as raw identifiers.

This change makes it treat the input as a revset if the escaped version fails.
This allows users to do things like "arc diff .^" when they only want to diff
the top commit.

Test Plan:
Created a stack of commits, master->A->B.
hg up B
arc diff .^
Verified the diff message only showed B as part of the diff.

arc diff .^~
Verified an error occurred ("Commit '.^~' is not a valid Mercurial commit id.")

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Maniphest Tasks: T2888

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

src/repository/api/ArcanistMercurialAPI.php

index cec7b38f3f4724c076a3f1a5a9e0b0314cf1fbb2..001eeebabef9536f129fb8be954c05272178754e 100644 (file)
@@ -96,9 +96,15 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
         $commit = $this->getCanonicalRevisionName(
           hgsprintf('ancestor(%s,.)', $symbolic_commit));
       } catch (Exception $ex) {
-        throw new ArcanistUsageException(
-          "Commit '{$symbolic_commit}' is not a valid Mercurial commit ".
-          "identifier.");
+        // Try it as a revset instead of a commit id
+        try {
+          $commit = $this->getCanonicalRevisionName(
+            hgsprintf('ancestor(%R,.)', $symbolic_commit));
+        } catch (Exception $ex) {
+          throw new ArcanistUsageException(
+            "Commit '{$symbolic_commit}' is not a valid Mercurial commit ".
+            "identifier.");
+        }
       }
 
       $this->setBaseCommitExplanation("it is the greatest common ancestor of ".
@@ -752,14 +758,21 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
             return trim($merge_base);
           }
         } else {
-          list($err) = $this->execManualLocal(
-            'id -r %s',
-            $name);
+          list($err, $commit) = $this->execManualLocal(
+            'log --template {node} --rev %s',
+            hgsprintf('%s', $name));
+
+          if ($err) {
+            list($err, $commit) = $this->execManualLocal(
+              'log --template {node} --rev %s',
+              $name);
+          }
+
           if (!$err) {
             $this->setBaseCommitExplanation(
               "it is specified by '{$rule}' in your {$source} 'base' ".
               "configuration.");
-            return $name;
+            return trim($commit);
           }
         }
         break;