Commits

Angel Ezquerra committed fa8a698

filedata: perform binary, file size and line length checks when displaying patches

e8ada1a4d891 introduced a check for max line length to avoid hunging the
workbench when displaying binary files, which tend to have big "lines".

This test (and all other related tests, such as max file size and the binarity
check) were skipped when displaying pure patches. This happens when showing
unapplied patches and shelves. This result in hunging the workbench or the
shelve tool when displaying binary files. This patch fixes that problem.

Note that currently there is no simple way to tell TortoiseHg to display the
file anyway.

Also note that this code introduces a bit of code duplication, since the checks
are done on different places for patches and for regular revisions. I have not
seen an easy way to unify them since the revision check does a few things that
are unnecessary for patches.

Comments (0)

Files changed (1)

tortoisehg/hgqt/filedata.py

 
         isbfile = False
         repo = ctx._repo
+        maxdiff = repo.maxdiff
         self.flabel += u'<b>%s</b>' % hglib.tounicode(wfile)
 
         if isinstance(ctx, patchctx.patchctx):
                 self.elabel = _("exec mode has been <font color='red'>unset</font>")
             elif flags == 'l':
                 self.flabel += _(' <i>(is a symlink)</i>')
+
+            # Do not show patches that are too big or may be binary
+            p = _('Diff not displayed: ')
+            data = self.diff
+            size = len(data)
+            if (size > maxdiff):
+                self.error = p + _('File is larger than the specified max size.\n'
+                               'maxdiff = %s KB') % (maxdiff // 1024)
+            elif '\0' in data:
+                self.error = p + _('File is binary')
+            elif _exceedsMaxLineLength(data):
+                # it's incredibly slow to render long line by QScintilla
+                self.error = p + \
+                    _('File may be binary (maximum line length exceeded)')
             return
 
         if ctx2:
 
         # TODO: elif check if a subdirectory (for manifest tool)
 
-        maxdiff = repo.maxdiff
         mde = _('File or diffs not displayed: '
                 'File is larger than the specified max size.\n'
                 'maxdiff = %s KB') % (maxdiff // 1024)