Patchwork [03,of,11,V2] histedit: use 'util.ellipsis' to trim description of each changesets

login
register
mail settings
Submitter Katsunori FUJIWARA
Date July 5, 2014, 6 p.m.
Message ID <94f4e5d96bf8520766e4.1404583202@feefifofum>
Download mbox | patch
Permalink /patch/5108/
State Accepted
Commit 50fd3a36d1665495ca38ebeee747c1b29032e70b
Headers show

Comments

Katsunori FUJIWARA - July 5, 2014, 6 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1404583001 -32400
#      Sun Jul 06 02:56:41 2014 +0900
# Node ID 94f4e5d96bf8520766e456a140b586c638bb902e
# Parent  d8ef3634ea3d248fca19054f8c3af06e622eb575
histedit: use 'util.ellipsis' to trim description of each changesets

Before this patch, trimming description of each changesets in histedit
may split at intermediate multi-byte sequence.

This patch uses 'util.ellipsis' to trim description of each changesets
instead of directly slicing byte sequence.

Even though 'util.ellipsis' adds '...' as ellipsis when specified
string is trimmed (= this changes result of trimming), this patch uses
it, because:

  - it can be used without any additional 'import', and
  - ellipsis seems to be better than just trimming, for usability

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -760,7 +760,8 @@ 
     if c.description():
         summary = c.description().splitlines()[0]
     line = 'pick %s %d %s' % (c, c.rev(), summary)
-    return line[:80]  # trim to 80 chars so it's not stupidly wide in my editor
+    # trim to 80 columns so it's not stupidly wide in my editor
+    return util.ellipsis(line, 80)
 
 def verifyrules(rules, repo, ctxs):
     """Verify that there exists exactly one edit rule per given changeset.
diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
--- a/tests/test-histedit-arguments.t
+++ b/tests/test-histedit-arguments.t
@@ -227,3 +227,35 @@ 
   $ hg histedit -r 'heads(all())'
   abort: The specified revisions must have exactly one common root
   [255]
+
+Test that trimming description using multi-byte characters
+--------------------------------------------------------------------
+
+  $ python <<EOF
+  > fp = open('logfile', 'w')
+  > fp.write('12345678901234567890123456789012345678901234567890' +
+  >          '12345') # there are 5 more columns for 80 columns
+  > 
+  > # 2 x 4 = 8 columns, but 3 x 4 = 12 bytes
+  > fp.write(u'\u3042\u3044\u3046\u3048'.encode('utf-8'))
+  > 
+  > fp.close()
+  > EOF
+  $ echo xx >> x
+  $ hg --encoding utf-8 commit --logfile logfile
+
+  $ HGEDITOR=cat hg --encoding utf-8 histedit tip
+  pick 3d3ea1f3a10b 5 1234567890123456789012345678901234567890123456789012345\xe3\x81\x82... (esc)
+  
+  # Edit history between 3d3ea1f3a10b and 3d3ea1f3a10b
+  #
+  # Commits are listed from least to most recent
+  #
+  # Commands:
+  #  p, pick = use commit
+  #  e, edit = use commit, but stop for amending
+  #  f, fold = use commit, but combine it with the one above
+  #  d, drop = remove commit from history
+  #  m, mess = edit message without changing commit content
+  #
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved