1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Fix some mercurial edge cases

Summary:
  - Old versions of Mercurial give different output for `hg log -- ''` and `hg log`. Just use `hg log`.
  - Branch names with spaces can't be specified in `--rev`. I talked with hstuart in #mercurial and apparently am not crazy.

Test Plan:
  - Viewed history of a repository.
  - Viewed history of a file.
  - Viewed branch `m m m m m 2:ffffffffffff (inactive)`
  - Learned that you checkout this branch with `hg checkout ':m m m m m 2:ffffffffffff (inactive)'`

Reviewers: dschleimer, btrahan

Reviewed By: dschleimer

CC: aran

Maniphest Tasks: T1268

Differential Revision: https://secure.phabricator.com/D2950
This commit is contained in:
epriestley 2012-07-10 10:36:33 -07:00
parent e2e9aed4fa
commit 176b4a68a8
2 changed files with 37 additions and 7 deletions

View file

@ -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());

View file

@ -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());
}