1. Matthew J Little
  2. RhodeCode

Commits

Marcin Kuzminski  committed 7a0004e

Added extra check for very large diffs in changesets, sometimes for very large diffs the diff parser could kill CPU.

  • Participants
  • Parent commits 64cb961
  • Branches beta

Comments (0)

Files changed (1)

File rhodecode/controllers/changeset.py

View file
  • Ignore whitespace
         c.sum_removed = 0
         c.lines_added = 0
         c.lines_deleted = 0
-        c.cut_off = False
+        c.cut_off = False # defines if cut off limit is reached
 
+        # Iterate over ranges (default changeset view is always one changeset)
         for changeset in c.cs_ranges:
             c.changes[changeset.raw_id] = []
             try:
             # ADDED FILES
             #==================================================================
             for node in changeset.added:
+
                 filenode_old = FileNode(node.path, '', EmptyChangeset())
                 if filenode_old.is_binary or node.is_binary:
                     diff = wrap_to_table(_('binary file'))
                     st = (0, 0)
                 else:
+                    # in this case node.size is good parameter since those are
+                    # added nodes and their size defines how many changes were
+                    # made
                     c.sum_added += node.size
                     if c.sum_added < self.cut_off_limit:
                         f_gitdiff = differ.get_gitdiff(filenode_old, node)
                         d = differ.DiffProcessor(f_gitdiff, format='gitdiff')
+
+                        st = d.stat()
                         diff = d.as_html()
-                        st = d.stat()
+
                     else:
                         diff = wrap_to_table(_('Changeset is to big and '
                                                'was cut off, see raw '
                     try:
                         filenode_old = changeset_parent.get_node(node.path)
                     except ChangesetError:
+                        log.warning('Unable to fetch parent node for diff')
                         filenode_old = FileNode(node.path, '',
                                                 EmptyChangeset())
 
                             f_gitdiff = differ.get_gitdiff(filenode_old, node)
                             d = differ.DiffProcessor(f_gitdiff,
                                                      format='gitdiff')
-                            diff = d.as_html()
                             st = d.stat()
+                            if (st[0] + st[1]) * 256 > self.cut_off_limit:
+                                diff = wrap_to_table(_('Diff is to big '
+                                                       'and was cut off, see '
+                                                       'raw diff instead'))
+                            else:
+                                diff = d.as_html()
+
+
                             if diff:
                                 c.sum_removed += len(diff)
                         else: