Anonymous avatar Anonymous committed 4a5f706

The outdenting algorithm was improved for line continuations and
rst code blocks in list items.

Comments (0)

Files changed (2)

+Changelog
+---------
+
+- The outdenting algorithm was improved for line continuations and
+  rst code blocks in list items.
     changelog is included in the commit. If it is, the commit message shown
     in the editor will default to all text added to the changelog.
 
-    :copyright: 2008 by Georg Brandl.
+    :copyright: 2008 by Georg Brandl, Armin Ronacher.
     :license: BSD.
 """
+import re
+from mercurial import commands, cmdutil, extensions, patch
 
-from mercurial import commands, cmdutil, extensions, patch
+
+_bullet_re = re.compile(r'\s*[-+]\s+')
+
+
+def normalize_log(lines):
+    """Outdents newly inserted list items."""
+    last_indention = 0
+    for idx, line in enumerate(lines):
+        match = _bullet_re.match(line)
+        if match is not None:
+            last_indention = match.end()
+            lines[idx] = line[last_indention:]
+        elif last_indention:
+            if not line[:last_indention].strip():
+                lines[idx] = line[last_indention:]
+    return '\n'.join(lines)
+
 
 def new_commit(orig_commit, ui, repo, *pats, **opts):
     if opts['message'] or opts['logfile']:
             # changelog is not mentioned
             return orig_commit(ui, repo, *pats, **opts)
     logmatch = cmdutil.match(repo, [logname], {})
+
     # get diff of changelog
     log = []
     for chunk in patch.diff(repo, None, None, match=logmatch):
         for line in chunk.splitlines():
             # naive: all added lines are the changelog
             if line.startswith('+') and not line.startswith('+++'):
-                line = line[1:].strip()
-                if line: log.append(line)
-    log = '\n'.join(log)
-    # strip bullet points and whitespace on the left
-    log = log.lstrip('*- \t')
+                log.append(line[1:].rstrip().expandtabs())
+    log = normalize_log(log)
+
     # always let the user edit the message
     opts['force_editor'] = True
     opts['message'] = log
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.