[PATCH STABLE] mq: restrict generated patch name to 75 characters (issue5117)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Mar 9 17:25:51 EST 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1457562068 0
#      Wed Mar 09 22:21:08 2016 +0000
# Branch stable
# Node ID a9c9d62a1d662b5693b61a3a27a8e0bf3d301cb3
# Parent  b7e192240c41db8d02419b7bcd2be9a2b6194023
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r a9c9d62a1d66
mq: restrict generated patch name to 75 characters (issue5117)

Super long first line in description lead to very long file name that windows is
unhappy about. We restrict the name to 75 char to avoid the issue.

75 seems fine and leave some extra room for '__#' suffix in case of conflict.

I does not seems worthwhile to add a dedicated config option to configure the
length. It can be done in the future if there is an actual user demand for it.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1115,10 +1115,11 @@ class queue(object):
 
     def makepatchname(self, title, fallbackname):
         """Return a suitable filename for title, adding a suffix to make
         it unique in the existing list"""
         namebase = re.sub('[\s\W_]+', '_', title.lower()).strip('_')
+        namebase = namebase[:75] # avoid too long name (issue5117)
         if namebase:
             try:
                 self.checkreservedname(namebase)
             except error.Abort:
                 namebase = fallbackname
diff --git a/tests/test-mq-qimport.t b/tests/test-mq-qimport.t
--- a/tests/test-mq-qimport.t
+++ b/tests/test-mq-qimport.t
@@ -329,5 +329,14 @@ check reserved patch names
   $ hg qap
   1.diff__1
   2.diff
   taken__2
 
+check very long patch name
+
+  $ hg qpop -qa
+  patch queue now empty
+  $ echo >> b
+  $ hg commit -m 'abcdefghi pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+  $ hg qimport -r .
+  $ hg qap
+  abcdefghi_pqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi_pqrstuvwxyzabcdefg


More information about the Mercurial-devel mailing list