From 0ecfb75101ee43964de283a2c8f70e0d509ce2a5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 3 Jan 2013 06:01:53 -0800 Subject: [PATCH] Expand abbreviated Mercurial hashes to full hashes Summary: If you go to `/rXnnnn` in Git, we expand the hash. If you go to `/rXnnnn` in Mercurial, we give you a confusing error message. Reconcile Mercurial behavior with Git. Fixes T2265. Test Plan: Viewed partial hash, full hash commit in Diffusion. Viewed very short hash, got reasonable behaviors. Reviewers: btrahan, tido Reviewed By: tido CC: aran Maniphest Tasks: T2265 Differential Revision: https://secure.phabricator.com/D4330 --- .../request/DiffusionMercurialRequest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/applications/diffusion/request/DiffusionMercurialRequest.php b/src/applications/diffusion/request/DiffusionMercurialRequest.php index 18c7d66b10..891b534a8b 100644 --- a/src/applications/diffusion/request/DiffusionMercurialRequest.php +++ b/src/applications/diffusion/request/DiffusionMercurialRequest.php @@ -16,6 +16,29 @@ final class DiffusionMercurialRequest extends DiffusionRequest { $this->raiseCloneException(); } + // Expand abbreviated hashes to full hashes so "/rXnnnn" (i.e., fewer than + // 40 characters) works correctly. + if (!$this->commit) { + return; + } + + if (strlen($this->commit) == 40) { + return; + } + + list($full_hash) = $this->repository->execxLocalCommand( + 'log --template=%s --rev %s', + '{node}', + $this->commit); + + $full_hash = explode("\n", trim($full_hash)); + + // TODO: Show "multiple matching commits" if count is larger than 1. For + // now, pick the first one. + + $this->commit = head($full_hash); + + return; }