diff --git a/src/applications/diffusion/query/history/DiffusionMercurialHistoryQuery.php b/src/applications/diffusion/query/history/DiffusionMercurialHistoryQuery.php index c1aafb5e2e..7b6add1adb 100644 --- a/src/applications/diffusion/query/history/DiffusionMercurialHistoryQuery.php +++ b/src/applications/diffusion/query/history/DiffusionMercurialHistoryQuery.php @@ -26,20 +26,36 @@ final class DiffusionMercurialHistoryQuery extends DiffusionHistoryQuery { $commit_hash = $drequest->getStableCommitName(); $path = DiffusionPathIDQuery::normalizePath($path); + $path = ltrim($path, '/'); - // NOTE: Using '' as a default path produces the correct behavior if HEAD - // is a merge commit; using '.' does not (the merge commit is not included - // in the log). - $default_path = ''; + // NOTE: Older versions of Mercurial give different results for these + // commands (see T1268): + // + // $ hg log -- '' + // $ hg log + // + // All versions of Mercurial give different results for these commands + // (merge commits are excluded with the "." version): + // + // $ hg log -- . + // $ hg log + // + // If we don't have a path component in the query, omit it from the command + // entirely to avoid these inconsistencies. + + $path_arg = ''; + if (strlen($path)) { + $path_arg = csprintf('-- %s', $path); + } // NOTE: --branch used to be called --only-branch; use -b for compatibility. list($stdout) = $repository->execxLocalCommand( - 'log --debug --template %s --limit %d -b %s --rev %s:0 -- %s', + 'log --debug --template %s --limit %d -b %s --rev %s:0 %C', '{node};{parents}\\n', ($this->getOffset() + $this->getLimit()), // No '--skip' in Mercurial. $drequest->getBranch(), $commit_hash, - nonempty(ltrim($path, '/'), $default_path)); + $path_arg); $lines = explode("\n", trim($stdout)); $lines = array_slice($lines, $this->getOffset()); diff --git a/src/applications/diffusion/request/DiffusionMercurialRequest.php b/src/applications/diffusion/request/DiffusionMercurialRequest.php index 99d6baf720..b2ef171813 100644 --- a/src/applications/diffusion/request/DiffusionMercurialRequest.php +++ b/src/applications/diffusion/request/DiffusionMercurialRequest.php @@ -59,8 +59,22 @@ final class DiffusionMercurialRequest extends DiffusionRequest { if ($this->commit) { $this->stableCommitName = $this->commit; } else { + + // NOTE: For branches with spaces in their name like "a b", this + // does not work properly: + // + // $ hg log --rev 'a b' + // + // We can use revsets instead: + // + // $ hg log --rev branch('a b') + // + // ...but they require a somewhat newer version of Mercurial. Instead, + // use "-b" flag with limit 1 for greatest compatibility across + // versions. + list($this->stableCommitName) = $this->repository->execxLocalCommand( - 'log --template=%s --rev %s', + 'log --template=%s -b %s --limit 1', '{node}', $this->getBranch()); }