Edgewall Software

Ticket #2591: detect_big_changesets.patch

File detect_big_changesets.patch, 3.9 KB (added by cboos, 3 years ago)

Detect big changesets and in this case don't show the diffs in the same page. Instead, add links to more specific diff views.

  • trac/db_default.py

     
    436436  ('timeline', 'default_daysback', '30'), 
    437437  ('timeline', 'changeset_show_files', '0'), 
    438438  ('timeline', 'ticket_show_details', 'false'), 
     439  ('changeset', 'max_diff_files', '1000'), 
     440  ('changeset', 'max_diff_bytes', '100000'), 
    439441  ('browser', 'hide_properties', 'svk:merge'), 
    440442  ('wiki', 'ignore_missing_pages', 'false'), 
    441443) 
  • trac/versioncontrol/web_ui/changeset.py

     
    370370                        del changed_props[k] 
    371371            return changed_props 
    372372 
     373        def _estimate_changes(old_node, new_node): 
     374            old_size = old_node.get_content_length() 
     375            new_size = new_node.get_content_length() 
     376            return abs(old_size - new_size) 
     377 
    373378        mimeview = Mimeview(self.env) 
    374379 
    375380        def _content_changes(old_node, new_node): 
     
    409414            else: 
    410415                return [] 
    411416 
     417        max_diff_bytes = int(self.config.get('changeset', 'max_diff_bytes')) 
     418        max_diff_files = int(self.config.get('changeset', 'max_diff_files')) 
     419        diff_bytes = diff_files = 0 
     420        if max_diff_bytes or max_diff_files: 
     421            for old_node, new_node, kind, change in get_changes(): 
     422                if change == Changeset.EDIT and kind == Node.FILE: 
     423                    diff_files += 1 
     424                    diff_bytes += _estimate_changes(old_node, new_node) 
     425        show_diffs = (not max_diff_files or diff_files <= max_diff_files) and \ 
     426                     (not max_diff_bytes or diff_bytes <= max_diff_bytes or \ 
     427                      diff_files == 1)                       
     428                 
    412429        idx = 0 
    413430        for old_node, new_node, kind, change in get_changes(): 
    414431            if change != Changeset.EDIT: 
     
    420437                if props: 
    421438                    req.hdf['changeset.changes.%d.props' % idx] = props 
    422439                    show_entry = True 
    423                 if kind == Node.FILE: 
     440                if kind == Node.FILE and show_diffs: 
    424441                    diffs = _content_changes(old_node, new_node) 
    425442                    if diffs != []: 
    426443                        if diffs: 
    427444                            req.hdf['changeset.changes.%d.diff' % idx] = diffs 
    428445                        # elif None (means: manually compare to (previous)) 
    429446                        show_entry = True 
    430             if show_entry: 
     447            if show_entry or not show_diffs: 
    431448                info = _change_info(old_node, new_node, change) 
     449                if not show_diffs: 
     450                    info['diff_href'] = self.env.href.changeset( 
     451                        new_node.created_rev, new_node.created_path, 
     452                        old=old_node.created_rev, 
     453                        old_path=old_node.created_path) 
    432454                req.hdf['changeset.changes.%d' % idx] = info 
    433455            idx += 1 # the sequence should be immutable 
    434456 
  • templates/changeset.cs

     
    136136    var:item.browser_href.old ?>" title="Show original file (rev. <?cs 
    137137    var:item.rev.old ?>)"><?cs var:item.path.old ?></a>)</em></small><?cs 
    138138  /if ?><?cs 
    139   if:$ndiffs + $nprops > #0 ?> 
     139  if:item.diff_href ?> 
     140    (<a href="<?cs var:item.diff_href ?>" title="Show differences">full diff</a>)<?cs 
     141  elif:$ndiffs + $nprops > #0 ?> 
    140142    (<a href="#file<?cs var:name(item) ?>" title="Show differences"><?cs 
    141143      if:$ndiffs > #0 ?><?cs var:ndiffs ?>&nbsp;diff<?cs if:$ndiffs > #1 ?>s<?cs /if ?><?cs  
    142144      /if ?><?cs