diff mercurial/cmdutil.py @ 38080:dabc2237963c

crecord: fallback to text mode if diffs are too big for curses mode crecord uses curses.newpad to create a region that we can then scroll around in by moving the main 'screen' as a veiwport into the (probably larger than the actual screen) pad. Internally, at least in ncurses, pads are implemented using windows, which have their dimensions limited to a certain size. Depending on compilation options for ncurses, this size might be pretty small: (signed) short, or it might be larger ((signed) int). crecord wants to have enough room to have all of the contents of the main area of the chunkselector in the pad; this means that the full size with everything expanded must be less than these (undocumented, afaict) limits. It's not easy to write tests for this because the limits are platform- and installation- dependent and undocumented / unqueryable, as far as I can tell. Differential Revision: https://phab.mercurial-scm.org/D3577
author Kyle Lippincott <spectral@google.com>
date Thu, 17 May 2018 23:11:24 -0700
parents 14f4449711b8
children c974320d20b9
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu May 17 15:33:28 2018 -0700
+++ b/mercurial/cmdutil.py	Thu May 17 23:11:24 2018 -0700
@@ -197,17 +197,21 @@
     return oldwrite
 
 def filterchunks(ui, originalhunks, usecurses, testfile, operation=None):
-    if usecurses:
-        if testfile:
-            recordfn = crecordmod.testdecorator(testfile,
-                                                crecordmod.testchunkselector)
-        else:
-            recordfn = crecordmod.chunkselector
-
-        return crecordmod.filterpatch(ui, originalhunks, recordfn, operation)
-
-    else:
-        return patch.filterpatch(ui, originalhunks, operation)
+    try:
+        if usecurses:
+            if testfile:
+                recordfn = crecordmod.testdecorator(
+                    testfile, crecordmod.testchunkselector)
+            else:
+                recordfn = crecordmod.chunkselector
+
+            return crecordmod.filterpatch(ui, originalhunks, recordfn,
+                                          operation)
+    except crecordmod.fallbackerror as e:
+        ui.warn('%s\n' % e.message)
+        ui.warn(_('falling back to text mode\n'))
+
+    return patch.filterpatch(ui, originalhunks, operation)
 
 def recordfilter(ui, originalhunks, operation=None):
     """ Prompts the user to filter the originalhunks and return a list of