<?php

final class DiffusionGitBlameQuery extends DiffusionBlameQuery {

  protected function newBlameFuture(DiffusionRequest $request, $path) {
    $repository = $request->getRepository();

    $commit = $request->getCommit();

    return $repository->getLocalCommandFuture(
      '--no-pager blame -s -l %s -- %s',
      $commit,
      $path);
  }

  protected function resolveBlameFuture(ExecFuture $future) {
    list($err, $stdout) = $future->resolve();

    if ($err) {
      return null;
    }

    $result = array();

    $lines = phutil_split_lines($stdout);
    foreach ($lines as $line) {
      list($commit) = explode(' ', $line, 2);
      $result[] = $commit;
    }

    return $result;
  }

}

<?php

final class DiffusionGitBlameQuery extends DiffusionBlameQuery {

  protected function newBlameFuture(DiffusionRequest $request, $path) {
    $repository = $request->getRepository();

    $commit = $request->getCommit();

    // NOTE: The "--root" flag suppresses the addition of the "^" boundary
    // commit marker. Without it, root commits render with a "^" before them,
    // and one fewer character of the commit hash.

    return $repository->getLocalCommandFuture(
      '--no-pager blame --root -s -l %s -- %s',
      $commit,
      $path);
  }

  protected function resolveBlameFuture(ExecFuture $future) {
    list($err, $stdout) = $future->resolve();

    if ($err) {
      return null;
    }

    $result = array();

    $lines = phutil_split_lines($stdout);
    foreach ($lines as $line) {
      list($commit) = explode(' ', $line, 2);
      $result[] = $commit;
    }

    return $result;
  }

}

Stop "git blame" from printing "^" markers on root repository commits
Stop "git blame" from printing "^" markers on root repository commits

Summary: Depends on D19391. Ref T13126. See that task for some details on what's going on here.

Test Plan:
  - Viewed a file which includes lines that were added during the first commit to the repository.
  - Before D19391: fatal.
  - After D19391: blank.
  - After this patch: accurate blame information.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13126

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