diff --git a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php index 854487b6e2..8d394ab679 100644 --- a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php @@ -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;