@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Handle encoding if git tells us it's still not UTF-8

Summary:
Even though `--encoding` is passed to the command, git still fails
in some cases to correctly convert the output. Attempt the conversion
ourselves if it's non UTF-8.

Test Plan: Reparsed message in a repository with ISO-8859-1 encoded commit messages.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T452

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

authored by

David Reuss and committed by
epriestley
aa95ef24 2bb81505

+16 -3
+16 -3
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php
··· 25 25 26 26 // NOTE: %B was introduced somewhat recently in git's history, so pull 27 27 // commit message information with %s and %b instead. 28 + // Even though we pass --encoding here, git doesn't always succeed, so 29 + // we try a little harder, since git *does* tell us what the actual encoding 30 + // is correctly. 28 31 list($info) = $repository->execxLocalCommand( 29 32 "log -n 1 --encoding='UTF-8' " . 30 - "--pretty=format:%%cn%%x00%%an%%x00%%s%%n%%n%%b %s", 33 + "--pretty=format:%%e%%x00%%cn%%x00%%an%%x00%%s%%n%%n%%b %s", 31 34 $commit->getCommitIdentifier()); 32 35 33 - list($committer, $author, $message) = explode("\0", $info); 36 + list($encoding, $committer, $author, $message) = explode("\0", $info); 37 + 38 + // See note above - git doesn't always convert the encoding correctly. 39 + if (strtoupper($encoding) != "UTF-8") { 40 + if (function_exists('mb_convert_encoding')) { 41 + $message = mb_convert_encoding($message, "UTF-8", $encoding); 42 + $author = mb_convert_encoding($author, "UTF-8", $encoding); 43 + $committer = mb_convert_encoding($committer, "UTF-8", $encoding); 44 + } 45 + } 34 46 35 - // Make sure these are valid UTF-8. 47 + // Make sure these are valid UTF-8, even though we try 48 + // pretty hard just above. 36 49 $committer = phutil_utf8ize($committer); 37 50 $author = phutil_utf8ize($author); 38 51 $message = phutil_utf8ize($message);