1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

Include email in Git author/committer lookup

Summary: We currently omit email from Git author/committer lookups, which gives us some bad results when identify commit authors. Include email. Also simplify this block a little bit.

Test Plan: Ran "reparse.php --message" on several commits, verified that the author/committer seemed reasonable with var_dump()s.

Reviewers: btrahan, vrana, nh

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1337

Differential Revision: https://secure.phabricator.com/D3039
This commit is contained in:
epriestley 2012-07-23 13:59:58 -07:00
parent 9a3998806d
commit 8cbd860e31

View file

@ -29,26 +29,46 @@ final class PhabricatorRepositoryGitCommitMessageParserWorker
// we try a little harder, since git *does* tell us what the actual encoding
// is correctly (unless it doesn't; encoding is sometimes empty).
list($info) = $repository->execxLocalCommand(
"log -n 1 --encoding='UTF-8' " .
"--pretty=format:%%e%%x00%%cn%%x00%%an%%x00%%s%%n%%n%%b %s",
'log -n 1 --encoding=%s --format=%s %s --',
'UTF-8',
implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%s%n%n%b')),
$commit->getCommitIdentifier());
list($encoding, $committer, $author, $message) = explode("\0", $info);
$parts = explode("\0", $info);
$encoding = array_shift($parts);
// See note above - git doesn't always convert the encoding correctly.
if (strlen($encoding) && strtoupper($encoding) != "UTF-8") {
$do_convert = false;
if (strlen($encoding) && strtoupper($encoding) != 'UTF-8') {
if (function_exists('mb_convert_encoding')) {
$message = mb_convert_encoding($message, "UTF-8", $encoding);
$author = mb_convert_encoding($author, "UTF-8", $encoding);
$committer = mb_convert_encoding($committer, "UTF-8", $encoding);
$do_convert = true;
}
}
// Make completely sure these are valid UTF-8.
$committer = phutil_utf8ize($committer);
$author = phutil_utf8ize($author);
$message = phutil_utf8ize($message);
$message = trim($message);
foreach ($parts as $key => $part) {
if ($do_convert) {
$parts[$key] = mb_convert_encoding($part, 'UTF-8', $encoding);
}
$parts[$key] = phutil_utf8ize($part);
}
$committer_name = $parts[0];
$committer_email = $parts[1];
$author_name = $parts[2];
$author_email = $parts[3];
$message = $parts[4];
if (strlen($author_email)) {
$author = "{$author_name} <{$author_email}>";
} else {
$author = "{$author_name}";
}
if (strlen($committer_email)) {
$committer = "{$committer_name} <{$committer_email}>";
} else {
$committer = "{$committer_name}";
}
if ($committer == $author) {
$committer = null;