[PATCH] histedit: Show file names in multiple line format

Yu Feng rainwoodman at gmail.com
Thu Apr 25 17:46:29 EDT 2019


# HG changeset patch
# User feyu at google.com
# Date 1556226272 25200
#      Thu Apr 25 14:04:32 2019 -0700
# Node ID d6d86496b7bc2c8120973e148f86a64aec75a25a
# Parent  5997eabc7b85f764a57fc55333dea099fc2ab1d4
histedit: Show file names in multiple line format.

This commit tweaks the format of the the commit window.
Instead of showing all file names in the same line and truncate
them at the window border, this commit shows the file names
one per line till the commit window runs out of space,
when it will put the rest of file names in a single line
and truncate.

Here is an example:

┌──────────────────────────────────┐
│changeset: 42191:0da689a60163     │
│user:      Danny Hooper <hooper at g │
│bookmark:                         │
│summary:   fix: allow fixer tools │
│files:     hgext/fix.py           │
│           > /test-fix-metadata.t │
│           tests/test-fix.t       │
│no overlap                        │
│                                  │
│                                  │
└──────────────────────────────────┘

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1227,6 +1227,13 @@ def addln(win, y, x, line, color=None):
     else:
         win.addstr(y, x, line)
 
+def _trunc_head(line, n):
+    if len(line) <= n: return line
+    return '> ' + line[-(n - 2):]
+def _trunc_tail(line, n):
+    if len(line) <= n: return line
+    return line[:n - 2] + ' >'
+
 def patchcontents(state):
     repo = state['repo']
     rule = state['rules'][state['pos']]
@@ -1284,11 +1291,23 @@ def _chisteditmain(repo, rules, stdscr):
         line = "bookmark:  {0}".format(' '.join(bms))
         win.addstr(3, 1, line[:length])
 
-        line = "files:     {0}".format(','.join(ctx.files()))
+        line = "summary:   {0}".format(ctx.description().splitlines()[0])
         win.addstr(4, 1, line[:length])
 
-        line = "summary:   {0}".format(ctx.description().splitlines()[0])
-        win.addstr(5, 1, line[:length])
+        line = "files:     "
+        win.addstr(5, 1, line)
+        fnx = 1 + len(line)
+        fnmaxx = length - fnx + 1
+        y = 5
+        fnmaxn = maxy - (1 + y) - 1
+        files = ctx.files()
+        for i, line1 in enumerate(files):
+            if len(files) > fnmaxn and i == fnmaxn - 1:
+                win.addstr(y, fnx, _trunc_tail(','.join(files[i:]), fnmaxx))
+                y = y + 1
+                break
+            win.addstr(y, fnx, _trunc_head(line1, fnmaxx))
+            y = y + 1
 
         conflicts = rule.conflicts
         if len(conflicts) > 0:
@@ -1297,7 +1316,7 @@ def _chisteditmain(repo, rules, stdscr):
         else:
             conflictstr = 'no overlap'
 
-        win.addstr(6, 1, conflictstr[:length])
+        win.addstr(y, 1, conflictstr[:length])
         win.noutrefresh()
 
     def helplines(mode):
@@ -1379,9 +1398,9 @@ pgup/K: move patch up, pgdn/J: move patc
         maxy, maxx = stdscr.getmaxyx()
         helplen = len(helplines(mode))
         return {
-            'commit': (8, maxx),
+            'commit': (12, maxx),
             'help': (helplen, maxx),
-            'main': (maxy - helplen - 8, maxx),
+            'main': (maxy - helplen - 12, maxx),
         }
 
     def drawvertwin(size, y, x):


More information about the Mercurial-devel mailing list