From 5d27aeb2403ac4af7eeda8493108950683fc9e7c Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 9 Dec 2013 09:20:40 -0800 Subject: [PATCH] Fix the exception when watching the first commit of a mercurial repo Summary: Most checks were actually in place, but `ExecFuture` throws a `CommandException` which wasn't taken into account. Test Plan: look at the first command and no longer saw an exception. Also, other commits worked as well. Reviewers: richardvanvelzen Reviewed By: richardvanvelzen CC: krisbuist, Korvin, epriestley, aran Differential Revision: https://secure.phabricator.com/D7730 --- .../DiffusionMercurialRawDiffQuery.php | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/applications/diffusion/query/rawdiff/DiffusionMercurialRawDiffQuery.php b/src/applications/diffusion/query/rawdiff/DiffusionMercurialRawDiffQuery.php index 4a016703ac..50285684a4 100644 --- a/src/applications/diffusion/query/rawdiff/DiffusionMercurialRawDiffQuery.php +++ b/src/applications/diffusion/query/rawdiff/DiffusionMercurialRawDiffQuery.php @@ -3,23 +3,7 @@ final class DiffusionMercurialRawDiffQuery extends DiffusionRawDiffQuery { protected function executeQuery() { - $raw_diff = $this->executeRawDiffCommand(); - - // the only legitimate case here is if we are looking at the first commit - // in the repository. no parents means first commit. - if (!$raw_diff) { - $drequest = $this->getRequest(); - $parent_query = - DiffusionCommitParentsQuery::newFromDiffusionRequest($drequest); - $parents = $parent_query->loadParents(); - if ($parents === array()) { - // mercurial likes the string null here - $this->setAgainstCommit('null'); - $raw_diff = $this->executeRawDiffCommand(); - } - } - - return $raw_diff; + return $this->executeRawDiffCommand(); } @@ -34,11 +18,14 @@ final class DiffusionMercurialRawDiffQuery extends DiffusionRawDiffQuery { $against = $this->getAgainstCommit(); if ($against === null) { - $against = $commit.'^'; + // If `$commit` has no parents (usually because it's the first commit + // in the repository), we want to diff against `null`. This revset will + // do that for us automatically. + $against = '('.$commit.'^ or null)'; } $future = $repository->getLocalCommandFuture( - 'diff -U %d --git --rev %s:%s -- %s', + 'diff -U %d --git --rev %s --rev %s -- %s', $this->getLinesOfContext(), $against, $commit,