Commits

Angel Ezquerra committed cfa8d40

hglib: add ellipsis to longsummaries when it would have exceeded the limit

Up until now the longsummary function only added an ellipsis if the longsummary
mode was disabled (i.e. if no longsummary limit was set). This revision changes
that so that if the longsummary limit is set, and the longsummary would have
exceeded the limit, an ellipsis is added to indicate that there is text in the
description that is not included on the longsummary.

Note that in order to implement this change the longsummary() function has been
partially rewritten, with the intent of removing some duplicated code.

Another small side effect of the rewrite is that any indentation and empty lines
will be removed prior to generating the long summary, which makes the
longsummary include more useful text.

Comments (0)

Files changed (1)

tortoisehg/util/hglib.py

 def longsummary(description, limit=None):
     summary = tounicode(description)
     lines = summary.splitlines()
+    if not lines:
+        return ''
+    summary = lines[0].strip()
+    add_ellipsis = False
     if limit:
-        if lines:
-            summary = lines.pop(0)
-            while len(summary) < limit and lines:
-                summary += u'  ' + lines.pop(0)
+        for raw_line in lines[1:]:
+            if len(summary) >= limit:
+                break
+            line = raw_line.strip()
+            if line:
+                summary += u'  ' + line
+        if len(summary) > limit:
+            add_ellipsis = True
             summary = summary[0:limit]
-        else:
-            summary = ''
-    else:
-        summary = lines and lines[0] or ''
-        if summary and len(lines) > 1:
-            summary += u' \u2026' # ellipsis ...
+    elif len(lines) > 1:
+        add_ellipsis = True
+    if add_ellipsis:
+        summary += u' \u2026' # ellipsis ...
     return summary
 
 def validate_synch_path(path, repo):