Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistDiffWorkflow.php
Show First 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | $arguments = array( | ||||
'help' => pht( | 'help' => pht( | ||||
'Instead of creating or updating a revision, only create a diff, '. | 'Instead of creating or updating a revision, only create a diff, '. | ||||
'which you may later attach to a revision.'), | 'which you may later attach to a revision.'), | ||||
'conflicts' => array( | 'conflicts' => array( | ||||
'edit' => pht('%s does affect revisions.', '--only'), | 'edit' => pht('%s does affect revisions.', '--only'), | ||||
'message' => pht('%s does not update any revision.', '--only'), | 'message' => pht('%s does not update any revision.', '--only'), | ||||
), | ), | ||||
), | ), | ||||
'encoding' => array( | |||||
'param' => 'encoding', | |||||
'help' => pht( | |||||
'Attempt to convert non UTF-8 hunks into specified encoding.'), | |||||
), | |||||
'allow-untracked' => array( | 'allow-untracked' => array( | ||||
'help' => pht('Skip checks for untracked files in the working copy.'), | 'help' => pht('Skip checks for untracked files in the working copy.'), | ||||
), | ), | ||||
'less-context' => array( | 'less-context' => array( | ||||
'help' => pht( | 'help' => pht( | ||||
"Normally, files are diffed with full context: the entire file is ". | "Normally, files are diffed with full context: the entire file is ". | ||||
"sent to Differential so reviewers can 'show more' and see it. If ". | "sent to Differential so reviewers can 'show more' and see it. If ". | ||||
"you are making changes to very large files with tens of thousands ". | "you are making changes to very large files with tens of thousands ". | ||||
▲ Show 20 Lines • Show All 736 Lines • ▼ Show 20 Lines | foreach ($changes as $change) { | ||||
} else { | } else { | ||||
throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
pht('Aborted generation of gigantic diff.')); | pht('Aborted generation of gigantic diff.')); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$try_encoding = nonempty($this->getArgument('encoding'), null); | |||||
$utf8_problems = array(); | $utf8_problems = array(); | ||||
foreach ($changes as $change) { | foreach ($changes as $change) { | ||||
foreach ($change->getHunks() as $hunk) { | foreach ($change->getHunks() as $hunk) { | ||||
$corpus = $hunk->getCorpus(); | $corpus = $hunk->getCorpus(); | ||||
if (!phutil_is_utf8($corpus)) { | if (!phutil_is_utf8($corpus)) { | ||||
// If this corpus is heuristically binary, don't try to convert it. | // If this corpus is heuristically binary, don't try to convert it. | ||||
// mb_check_encoding() and mb_convert_encoding() are both very very | // mb_check_encoding() and mb_convert_encoding() are both very very | ||||
// liberal about what they're willing to process. | // liberal about what they're willing to process. | ||||
$is_binary = ArcanistDiffUtils::isHeuristicBinaryFile($corpus); | $is_binary = ArcanistDiffUtils::isHeuristicBinaryFile($corpus); | ||||
if (!$is_binary) { | if (!$is_binary) { | ||||
if (!$try_encoding) { | |||||
try { | try { | ||||
$try_encoding = $this->getRepositoryEncoding(); | $try_encoding = $this->getRepositoryEncoding(); | ||||
} catch (ConduitClientException $e) { | } catch (ConduitClientException $e) { | ||||
if ($e->getErrorCode() == 'ERR-BAD-ARCANIST-PROJECT') { | if ($e->getErrorCode() == 'ERR-BAD-ARCANIST-PROJECT') { | ||||
echo phutil_console_wrap( | echo phutil_console_wrap( | ||||
pht('Lookup of encoding in arcanist project failed: %s', | pht('Lookup of encoding in arcanist project failed: %s', | ||||
$e->getMessage())."\n"); | $e->getMessage())."\n"); | ||||
} else { | } else { | ||||
throw $e; | throw $e; | ||||
} | } | ||||
} | } | ||||
} | |||||
if ($try_encoding) { | if ($try_encoding) { | ||||
$corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding); | $corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding); | ||||
$name = $change->getCurrentPath(); | $name = $change->getCurrentPath(); | ||||
if (phutil_is_utf8($corpus)) { | if (phutil_is_utf8($corpus)) { | ||||
$this->writeStatusMessage( | $this->writeStatusMessage( | ||||
pht( | pht( | ||||
"Converted a '%s' hunk from '%s' to UTF-8.\n", | "Converted a '%s' hunk from '%s' to UTF-8.\n", | ||||
▲ Show 20 Lines • Show All 1,918 Lines • Show Last 20 Lines |