<?php

final class DiffusionMercurialLastModifiedQuery
  extends DiffusionLastModifiedQuery {

  protected function executeQuery() {
    $drequest = $this->getRequest();
    $repository = $drequest->getRepository();

    $path = $drequest->getPath();

    // TODO: Share some of this with History query.
    list($hash) = $repository->execxLocalCommand(
      'log --template %s --limit 1 -b %s --rev %s:0 -- %s',
      '{node}',
      $drequest->getBranch(),
      $drequest->getCommit(),
      nonempty(ltrim($path, '/'), '.'));

    $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
      'repositoryID = %d AND commitIdentifier = %s',
      $repository->getID(),
      $hash);

    if ($commit) {
      $commit_data = $commit->loadCommitData();
    } else {
      $commit_data = null;
    }

    return array($commit, $commit_data);
  }

}

<?php

final class DiffusionMercurialLastModifiedQuery
  extends DiffusionLastModifiedQuery {

  protected function executeQuery() {
    $drequest = $this->getRequest();
    $repository = $drequest->getRepository();

    $path = $drequest->getPath();

    list($hash) = $repository->execxLocalCommand(
      'log --template %s --limit 1 --rev %s:0 -- %s',
      '{node}',
      $drequest->getCommit(),
      nonempty(ltrim($path, '/'), '.'));

    $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
      'repositoryID = %d AND commitIdentifier = %s',
      $repository->getID(),
      $hash);

    if ($commit) {
      $commit_data = $commit->loadCommitData();
    } else {
      $commit_data = null;
    }

    return array($commit, $commit_data);
  }

}

Fix Mercurial "Last Modified" query
Fix Mercurial "Last Modified" query

Summary:
To determine when a file was last modified, we currently run `hg log ... -b branch ... file`. However, this is incorrect, because Mercurial does not interpret "-b x" as "all ancestors of the commit named x" like Git does, and we don't care about where the modification happened anyway (we always have a resolved commit as a starting point). I think this got copy-pasta'd from the History query.

Instead, drop the branch-specific qualifier and find the last modification, period.

Test Plan: Mercurial commit views of commits not on the repository's default branch are no longer broken.

Reviewers: DurhamGoode, vrana, chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D5146
