]> khamidou — GitHub mirrors - arcanist.git/commitdiff
add short option for fetching git revision hash
authorslawekbiel <slawekbiel@fb.com>
Wed, 27 Apr 2011 21:10:19 +0000 (14:10 -0700)
committerslawekbiel <slawekbiel@fb.com>
Wed, 27 Apr 2011 22:26:20 +0000 (15:26 -0700)
Summary:
Sometimes we need to show abbreviated hashes, passing --short is more
reliable than substring of fixed number of characters.

Test Plan:
- called with and without the parameter, got correct results
           -

Reviewed By: jungejason
Reviewers: jungejason
CC: jungejason
Revert Plan:
sure

Other Notes:

Differential Revision: 170

src/repository/api/git/ArcanistGitAPI.php

index d74f4dbe1473c5821896c5d66ff082ac04ed2653..5b4e2c30d426a19a18936c777f1ac2a249abb2e3 100644 (file)
@@ -147,10 +147,20 @@ class ArcanistGitAPI extends ArcanistRepositoryAPI {
     return rtrim($stdout, "\n");
   }
 
-  public function getGitHeadRevision() {
+  /**
+   * Returns the sha1 of the HEAD revision
+   * @param boolean $short whether return the abbreviated or full hash.
+   */
+  public function getGitHeadRevision($short=false) {
+    if ($short) {
+      $flags = '--short';
+    } else {
+      $flags = '';
+    }
     list($stdout) = execx(
-      '(cd %s; git rev-parse HEAD)',
-      $this->getPath());
+      '(cd %s; git rev-parse %s HEAD)',
+      $this->getPath(),
+      $flags);
     return rtrim($stdout, "\n");
   }