From 8332d86ad23049a8a5dd0c3369aafdcb3176a514 Mon Sep 17 00:00:00 2001 From: slawekbiel Date: Wed, 27 Apr 2011 14:10:19 -0700 Subject: [PATCH] add short option for fetching git revision hash 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 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/repository/api/git/ArcanistGitAPI.php b/src/repository/api/git/ArcanistGitAPI.php index d74f4dbe..5b4e2c30 100644 --- a/src/repository/api/git/ArcanistGitAPI.php +++ b/src/repository/api/git/ArcanistGitAPI.php @@ -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"); } -- 2.43.0