@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 66 lines 2.1 kB view raw
1<?php 2 3final class DiffusionMercurialBlameQuery extends DiffusionBlameQuery { 4 5 protected function newBlameFuture(DiffusionRequest $request, $path) { 6 $repository = $request->getRepository(); 7 $commit = $request->getCommit(); 8 9 // NOTE: Using "--template" or "--debug" to get the full commit hashes. 10 $hg_analyzer = PhutilBinaryAnalyzer::getForBinary('hg'); 11 if ($hg_analyzer->isMercurialAnnotateTemplatesAvailable()) { 12 // See `hg help annotate --verbose` for more info on the template format. 13 // Use array of arguments so the template line does not need wrapped in 14 // quotes. 15 $template = array( 16 '--template', 17 "{lines % '{node}: {line}'}", 18 ); 19 } else { 20 $template = array( 21 '--debug', 22 '--changeset', 23 ); 24 } 25 26 return $repository->getLocalCommandFuture( 27 'annotate %Ls --rev %s -- %s', 28 $template, 29 $commit, 30 $path); 31 } 32 33 protected function resolveBlameFuture(ExecFuture $future) { 34 list($err, $stdout) = $future->resolve(); 35 36 if ($err) { 37 return null; 38 } 39 40 $result = array(); 41 42 $lines = phutil_split_lines($stdout); 43 foreach ($lines as $line) { 44 // If the `--debug` flag was used above instead of `--template` then 45 // there's a good change additional output was included which is not 46 // relevant to the information we want. It should be safe to call this 47 // regardless of whether we used `--debug` or `--template` so there isn't 48 // a need to track which argument was used. 49 $line = DiffusionMercurialCommandEngine::filterMercurialDebugOutput( 50 $line); 51 52 // Just in case new versions of Mercurial add arbitrary output when using 53 // the `--debug`, do a quick sanity check that this line is formatted in 54 // a way we're expecting. 55 if (strpos($line, ':') === false) { 56 phlog(pht('Unexpected output from hg annotate: %s', $line)); 57 continue; 58 } 59 list($commit) = explode(':', $line, 2); 60 $result[] = $commit; 61 } 62 63 return $result; 64 } 65 66}