From 4e900c096fabfa05ae23850cd5c3e69c7ffd1237 Mon Sep 17 00:00:00 2001 From: David Reuss Date: Fri, 28 Oct 2011 08:04:57 -0700 Subject: [PATCH] Convert "falsey" binary hunks if we have a repository encoding Summary: This adds an encoding detail to the repository, so we can attempt to convert hunks previously detected as binary. We also add the encoding information to the arcanist projectinfo API so we can pull the information if we have it when uploading changes via arc. Test Plan: Changed encoding through the edit UI, and saw "This is binary file", and changed it back and saw the correct output from the diff. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Differential Revision: 1009 --- ...ConduitAPI_arcanist_projectinfo_Method.php | 1 + .../query/diff/git/DiffusionGitDiffQuery.php | 6 ++++++ .../mercurial/DiffusionMercurialDiffQuery.php | 6 ++++++ .../query/diff/svn/DiffusionSvnDiffQuery.php | 7 +++++++ .../PhabricatorRepositoryEditController.php | 19 +++++++++++++++++++ 5 files changed, 39 insertions(+) diff --git a/src/applications/conduit/method/arcanist/projectinfo/ConduitAPI_arcanist_projectinfo_Method.php b/src/applications/conduit/method/arcanist/projectinfo/ConduitAPI_arcanist_projectinfo_Method.php index 60ed56f01c..2673aefef0 100644 --- a/src/applications/conduit/method/arcanist/projectinfo/ConduitAPI_arcanist_projectinfo_Method.php +++ b/src/applications/conduit/method/arcanist/projectinfo/ConduitAPI_arcanist_projectinfo_Method.php @@ -67,6 +67,7 @@ class ConduitAPI_arcanist_projectinfo_Method 'phid' => $project->getPHID(), 'repositoryPHID' => $repository_phid, 'tracked' => $tracked, + 'encoding' => $repository->getDetail('encoding') ); } diff --git a/src/applications/diffusion/query/diff/git/DiffusionGitDiffQuery.php b/src/applications/diffusion/query/diff/git/DiffusionGitDiffQuery.php index 02ec97d327..194a16e86a 100644 --- a/src/applications/diffusion/query/diff/git/DiffusionGitDiffQuery.php +++ b/src/applications/diffusion/query/diff/git/DiffusionGitDiffQuery.php @@ -76,6 +76,12 @@ final class DiffusionGitDiffQuery extends DiffusionDiffQuery { } $parser = new ArcanistDiffParser(); + + $try_encoding = $repository->getDetail('encoding'); + if ($try_encoding) { + $parser->setTryEncoding($try_encoding); + } + $parser->setDetectBinaryFiles(true); $changes = $parser->parseDiff($raw_diff); diff --git a/src/applications/diffusion/query/diff/mercurial/DiffusionMercurialDiffQuery.php b/src/applications/diffusion/query/diff/mercurial/DiffusionMercurialDiffQuery.php index 4032b94848..1df0c97a00 100644 --- a/src/applications/diffusion/query/diff/mercurial/DiffusionMercurialDiffQuery.php +++ b/src/applications/diffusion/query/diff/mercurial/DiffusionMercurialDiffQuery.php @@ -38,6 +38,12 @@ final class DiffusionMercurialDiffQuery extends DiffusionDiffQuery { $path); $parser = new ArcanistDiffParser(); + + $try_encoding = $repository->getDetail('encoding'); + if ($try_encoding) { + $parser->setTryEncoding($try_encoding); + } + $parser->setDetectBinaryFiles(true); $changes = $parser->parseDiff($raw_diff); diff --git a/src/applications/diffusion/query/diff/svn/DiffusionSvnDiffQuery.php b/src/applications/diffusion/query/diff/svn/DiffusionSvnDiffQuery.php index cf8543002b..1b386e34d2 100644 --- a/src/applications/diffusion/query/diff/svn/DiffusionSvnDiffQuery.php +++ b/src/applications/diffusion/query/diff/svn/DiffusionSvnDiffQuery.php @@ -20,6 +20,7 @@ final class DiffusionSvnDiffQuery extends DiffusionDiffQuery { protected function executeQuery() { $drequest = $this->getRequest(); + $repository = $drequest->getRepository(); if (!$drequest->getRawCommit()) { $effective_commit = $this->getEffectiveCommit(); @@ -111,6 +112,12 @@ final class DiffusionSvnDiffQuery extends DiffusionDiffQuery { $raw_diff = $engine->generateRawDiffFromFileContent($old_data, $new_data); $parser = new ArcanistDiffParser(); + + $try_encoding = $repository->getDetail('encoding'); + if ($try_encoding) { + $parser->setTryEncoding($try_encoding); + } + $parser->setDetectBinaryFiles(true); $arcanist_changes = DiffusionPathChange::convertToArcanistChanges( diff --git a/src/applications/repository/controller/edit/PhabricatorRepositoryEditController.php b/src/applications/repository/controller/edit/PhabricatorRepositoryEditController.php index e02426fd3a..7f4adfb023 100644 --- a/src/applications/repository/controller/edit/PhabricatorRepositoryEditController.php +++ b/src/applications/repository/controller/edit/PhabricatorRepositoryEditController.php @@ -113,6 +113,7 @@ class PhabricatorRepositoryEditController } $repository->setDetail('description', $request->getStr('description')); + $repository->setDetail('encoding', $request->getStr('encoding')); if (!$errors) { $repository->save(); @@ -134,6 +135,9 @@ class PhabricatorRepositoryEditController 'Repository changes were saved.'); } + $encoding_doc_link = PhabricatorEnv::getDoclink( + 'article/User_Guide:_UTF-8_and_Character_Encoding.html'); + $form = new AphrontFormView(); $form ->setUser($user) @@ -156,6 +160,21 @@ class PhabricatorRepositoryEditController ->setLabel('Callsign') ->setName('callsign') ->setValue($repository->getCallsign())) + ->appendChild(' +

'. + 'If source code in this repository uses a character '. + 'encoding other than UTF-8 (for example, ISO-8859-1), '. + 'specify it here. You can usually leave this field blank. '. + 'See User Guide: '. + ''. + 'UTF-8 and Character Encoding'. + ' for more information.'. + '

') + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel('Encoding') + ->setName('encoding') + ->setValue($repository->getDetail('encoding'))) ->appendChild( id(new AphrontFormStaticControl()) ->setLabel('Type')