From 3edf60627d5b8854a4f9b51cc35e160acc891856 Mon Sep 17 00:00:00 2001 From: Dave Ingram Date: Thu, 19 Jan 2012 17:39:54 +0000 Subject: [PATCH] Add support for marking files as "generated" by regexp against path Summary: Not all auto-generated files can include the magical "generated" annotation for one reason or another, but they may follow path rules. This patch allows files to be marked as automatically generated by matching the path with a regular expression. Test Plan: Alter 'differential.generated-paths' setting in config. Create a new diff that affects a file matching one of those regular expressions. Verify that Differential marks it as automatically generated and therefore probably not worth reviewing (in the same way as the magical "generated" annotation. Reviewers: epriestley CC: aran Differential Revision: https://secure.phabricator.com/D1455 --- conf/default.conf.php | 7 +++++++ .../parser/changeset/DifferentialChangesetParser.php | 11 +++++++++++ .../differential/parser/changeset/__init__.php | 1 + 3 files changed, 19 insertions(+) diff --git a/conf/default.conf.php b/conf/default.conf.php index 6ee2c8ea36..19dd22e12b 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -605,6 +605,13 @@ return array( // interact with the revisions. 'differential.anonymous-access' => false, + // List of file regexps that should be treated as if they are generated by + // an automatic process, and thus get hidden by default in differential + 'differential.generated-paths' => array( + // '/config\.h$/', + // '#/autobuilt/#', + ), + // -- Maniphest ------------------------------------------------------------- // diff --git a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php index b1716e25b3..6ec3193481 100644 --- a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php @@ -508,6 +508,17 @@ class DifferentialChangesetParser { $generated_guess = (strpos($new_corpus_block, '@'.'generated') !== false); + if (!$generated_guess) { + $config_key = 'differential.generated-paths'; + $generated_path_regexps = PhabricatorEnv::getEnvConfig($config_key); + foreach ($generated_path_regexps as $regexp) { + if (preg_match($regexp, $this->changeset->getFilename())) { + $generated_guess = true; + break; + } + } + } + $event = new PhabricatorEvent( PhabricatorEventType::TYPE_DIFFERENTIAL_WILLMARKGENERATED, array( diff --git a/src/applications/differential/parser/changeset/__init__.php b/src/applications/differential/parser/changeset/__init__.php index 15d1a09dc3..75f3d0475a 100644 --- a/src/applications/differential/parser/changeset/__init__.php +++ b/src/applications/differential/parser/changeset/__init__.php @@ -15,6 +15,7 @@ phutil_require_module('phabricator', 'applications/differential/view/inlinecomme phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/markup/syntax'); phutil_require_module('phabricator', 'infrastructure/diff/engine'); +phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'infrastructure/events/constant/type'); phutil_require_module('phabricator', 'infrastructure/events/event'); phutil_require_module('phabricator', 'infrastructure/javelin/markup');