Commits

Steve Borho committed db27310

status, chunks: try harder to prevent display of binary diffs

When showing working changes, provide a working context to check_max_diff() so
it can determine file size and binary status of newly added files. Also, avoid
binary diffs entirely since they are expensive to calculate (memory and CPU)
and add no value.

Closes #1322, #1288, #1262, #1113

Comments (0)

Files changed (2)

tortoisehg/hgtk/chunks.py

     return hunk
 
 
-def check_max_diff(ctx, pfile):
+def check_max_diff(ctx, wfile):
     lines = []
     try:
-        fctx = ctx.filectx(pfile)
-    except error.LookupError:
-        fctx = None
-    if fctx and fctx.size() > hglib.getmaxdiffsize(ctx._repo.ui):
+        fctx = ctx.filectx(wfile)
+        size = fctx.size()
+    except (EnvironmentError, error.LookupError):
+        return []
+    if size > hglib.getmaxdiffsize(ctx._repo.ui):
         # Fake patch that displays size warning
-        lines = ['diff --git a/%s b/%s\n' % (pfile, pfile)]
+        lines = ['diff --git a/%s b/%s\n' % (wfile, wfile)]
         lines.append(_('File is larger than the specified max size.\n'))
         lines.append(_('Hunk selection is disabled for this file.\n'))
-        lines.append('--- a/%s\n' % pfile)
-        lines.append('+++ b/%s\n' % pfile)
+        lines.append('--- a/%s\n' % wfile)
+        lines.append('+++ b/%s\n' % wfile)
+    elif '\0' in fctx.data():
+        # Fake patch that displays binary file warning
+        lines = ['diff --git a/%s b/%s\n' % (wfile, wfile)]
+        lines.append(_('File is binary.\n'))
+        lines.append(_('Hunk selection is disabled for this file.\n'))
+        lines.append('--- a/%s\n' % wfile)
+        lines.append('+++ b/%s\n' % wfile)
     return lines
 
 

tortoisehg/hgtk/status.py

         return (self._node1, self._node2)
 
     def get_ctx(self):
-        return self.repo[self._node1]
+        'Return current changectx or workingctx'
+        if self._node2 == None and not self.mqmode:
+            return self.repo[None]
+        else:
+            return self.repo[self._node1]
 
     def set_file_states(self, paths, state=True):
         for p in paths: