akester/storehouse

Fork Project

You aren't logged in. You won't be able to create discussions or comment on existing ones until you login. If you don't have an account, sign up for a free account.

737e28bb5a3b54267f89ae4464f034f663959322

Authored By: Andrew Kester Date: July 7, 2017 4:03 pm

Add method to filter out very large diffs.

Diffs with a lot of lines take a long time to process and we probably shouldn't try to parse and display them.

src/StorehouseBundle/Entity/VCS/LargeDiff.php
0
+<?php
1
+namespace StorehouseBundle\Entity\VCS;
2
+
3
+/*
4
+ * The Storehouse - Project Storage for Big Ideas
5
+ *
6
+ * This file is part of The Storehouse. Copyright 2017 Andrew Kester.
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as published
10
+ * by the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+class LargeDiff
22
+{
23
+}
src/StorehouseBundle/Resources/assets/scss/pages/project.scss
94 94
 	}
95 95
 }
96 96
 
97
-.unknown-type {
97
+.unknown-type, .large-diff {
98 98
 	border: 1px solid map-get($foundation-palette, light);
99 99
 	display: block;
100 100
 	padding: 2rem 3rem;
src/StorehouseBundle/Resources/views/Project/_Partials/Diffs/Large.html.twig
0
+{#
1
+ # The Storehouse - Project Storage for Big Ideas
2
+ #
3
+ # This file is part of The Storehouse. Copyright 2017 Andrew Kester.
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #}
18
+
19
+<div class="large-diff">
20
+	<p>
21
+		There are too many changes to show what changed in a browser.  Clone the project and use your local version control
22
+		program to view the changes.
23
+	</p>
24
+</div>
src/StorehouseBundle/Utils/Browser/Diff/DiffFormatter.php
5 5
 use StorehouseBundle\Utils\Browser\Diff\Types;
6 6
 use StorehouseBundle\Utils\Browser\Diff\Types\DiffTypeInterface;
7 7
 use StorehouseBundle\Entity\VCS\Diff;
8
+use StorehouseBundle\Entity\VCS\LargeDiff;
9 8
 
10 9
 /*
11 10
  * The Storehouse - Project Storage for Big Ideas
52 53
      *            Second file to compare
53 54
      * @return DiffTypeInterface
54 55
      */
56
-    public function getDiffType(Diff $diff)
55
+    public function getDiffType($diff)
56 57
     {
57
+        /* Check if the diff is too large.  This is the outlier case so it goes here rather than in the normal loop below. */
58
+        if ($diff instanceof LargeDiff) {
59
+            return new Types\LargeDiffType();
60
+        }
61
+
62
+        /* Check known types */
63 58
         foreach (self::$types as $typeClass) {
64 59
             $diffType = new $typeClass();
65 60
             if ($diffType->isOfType($diff->file1, $diff->file2)) {
src/StorehouseBundle/Utils/Browser/Diff/Types/LargeDiffType.php
0
+<?php
1
+namespace StorehouseBundle\Utils\Browser\Diff\Types;
2
+
3
+use StorehouseBundle\Entity\VCS\File;
4
+
5
+/*
6
+ * The Storehouse - Project Storage for Big Ideas
7
+ *
8
+ * This file is part of The Storehouse. Copyright 2017 Andrew Kester.
9
+ *
10
+ * This program is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU Affero General Public License as published
12
+ * by the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * This program is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU Affero General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Affero General Public License
21
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
+ */
23
+/**
24
+ * Diff that is too large to be displayed in a browser.
25
+ *
26
+ * @author Andrew Kester <andrew@sthse.co>
27
+ * @copyright 2017 Andrew Kester
28
+ * @license GNU AGPL - See README for details
29
+ */
30
+class LargeDiffType implements DiffTypeInterface
31
+{
32
+
33
+    /**
34
+     *
35
+     * {@inheritdoc}
36
+     *
37
+     * @see \StorehouseBundle\Utils\Diff\Types\AbstractTextDiff::isOfType()
38
+     */
39
+    public function isOfType(File $file1, File $file2)
40
+    {
41
+        return true;
42
+    }
43
+
44
+    /**
45
+     *
46
+     * {@inheritdoc}
47
+     *
48
+     * @see \StorehouseBundle\Utils\Browser\Diff\Types\DiffTypeInterface::getDisplayData()
49
+     */
50
+    public function getDisplayData()
51
+    {
52
+        return array();
53
+    }
54
+
55
+    /**
56
+     *
57
+     * {@inheritdoc}
58
+     *
59
+     * @see \StorehouseBundle\Utils\Browser\Diff\Types\DiffTypeInterface::getTemplate()
60
+     */
61
+    public function getTemplate()
62
+    {
63
+        return 'StorehouseBundle::Project/_Partials/Diffs/Large.html.twig';
64
+    }
65
+}
src/StorehouseBundle/Utils/Browser/Diff/Types/TextDiffType.php
23 23
  * You should have received a copy of the GNU Affero General Public License
24 24
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
  */
26
+/**
27
+ * Normal text diff type.
28
+ *
29
+ * @author Andrew Kester <andrew@sthse.co>
30
+ * @copyright 2017 Andrew Kester
31
+ * @license GNU AGPL - See README for details
32
+ */
33 26
 class TextDiffType implements DiffTypeInterface
34 27
 {
35 28
 
src/StorehouseBundle/Utils/Browser/Diff/Types/UnknownDiffType.php
21 21
  * You should have received a copy of the GNU Affero General Public License
22 22
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 23
  */
24
+/**
25
+ * Diff type for files that we're not sure how to display in the browser.
26
+ *
27
+ * @author Andrew Kester <andrew@sthse.co>
28
+ * @copyright 2017 Andrew Kester
29
+ * @license GNU AGPL - See README for details
30
+ */
31 24
 class UnknownDiffType implements DiffTypeInterface
32 25
 {
33 26
 
src/StorehouseBundle/Utils/VCS/AbstractWrapper.php
14 14
 use StorehouseBundle\Entity\User\UnknownUser;
15 15
 use StorehouseBundle\Entity\Json\JsonUser;
16 16
 use StorehouseBundle\Entity\VCS\Diff;
17
+use StorehouseBundle\Entity\VCS\LargeDiff;
18 17
 
19 18
 /*
20 19
  * The Storehouse - Project Storage for Big Ideas
416 417
 
417 418
         /* Resolve the diff's files */
418 419
         foreach ($resolvedCommit->diff as $diff) {
419
+            if ($diff instanceof LargeDiff) {
420
+                continue;
421
+            }
422
+
423 420
             $diff->file1->project = $this->project;
424 421
             $diff->file1->type = TypeGuesser::guessFileType($diff->file1);
425 422
 
src/StorehouseBundle/Utils/VCS/Commands/Helpers/ExtractDiff.php
5 5
 use StorehouseBundle\Entity\VCS\File;
6 6
 use StorehouseBundle\Entity\VCS\DiffGroup;
7 7
 use StorehouseBundle\Entity\VCS\DiffLine;
8
+use StorehouseBundle\Entity\VCS\LargeDiff;
9 8
 
10 9
 /*
11 10
  * The Storehouse - Project Storage for Big Ideas
34 35
 class ExtractDiff
35 36
 {
36 37
 
37
+    /**
38
+     * The max number of lines we'll try to parse in a diff.
39
+     *
40
+     * @var integer
41
+     */
42
+    const DIFF_LINE_LIMIT = 10000;
43
+
44 38
     /**
45 39
      * Get files that are being diffed from a git style diff.
46 40
      *
219 227
      */
220 228
     public static function extractGitDiff($output)
221 229
     {
222
+        /* Check for too large diffs */
223
+        if (count($output) > self::DIFF_LINE_LIMIT) {
224
+            return array(
225
+                new LargeDiff()
226
+            );
227
+        }
228
+
229 230
         return self::extractDiff($output, 'diff --git', 'git');
230 231
     }
231 232
 
231 246
      */
232 247
     public static function extractSvnDiff($output, $paths)
233 248
     {
234
+        /* Check for too large diffs */
235
+        if (count($output) > self::DIFF_LINE_LIMIT) {
236
+            return array(
237
+                new LargeDiff()
238
+            );
239
+        }
240
+
241 249
         $diffs = self::extractDiff($output, 'Index', 'svn');
242 250
 
243 251
         /* Process summary output to get added and removed files */
261 283
      */
262 284
     public static function extractHgDiff($output)
263 285
     {
264
+        /* Check for too large diffs */
265
+        if (count($output) > self::DIFF_LINE_LIMIT) {
266
+            return array(
267
+                new LargeDiff()
268
+            );
269
+        }
270
+
271 286
         return self::extractDiff($output, 'diff ', 'hg');
272 287
     }
273 288
 }
274 289
\ No newline at end of file
275 290