Patchwork [1,of,3] bookmarks: iterate bookmarks list even if it is known to be empty

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 4, 2014, 12:40 a.m.
Message ID <7957b516704dde10ba9b.1412383233@mimosa>
Download mbox | patch
Permalink /patch/6099/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 4, 2014, 12:40 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1412262939 -32400
#      Fri Oct 03 00:15:39 2014 +0900
# Node ID 7957b516704dde10ba9b018f6b395860e2f755af
# Parent  889789a2ca9f19755bf0d302c8671f850e42a059
bookmarks: iterate bookmarks list even if it is known to be empty

This clarifies that "no bookmarks set" is displayed in addition to the list
of bookmarks.  In JSON output, for example, [] should be written if empty,
and "no bookmarks set" message should be skipped.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -995,21 +995,20 @@  def bookmark(ui, repo, *names, **opts):
         marks = repo._bookmarks
         if len(marks) == 0:
             ui.status(_("no bookmarks set\n"))
-        else:
-            for bmark, n in sorted(marks.iteritems()):
-                current = repo._bookmarkcurrent
-                if bmark == current:
-                    prefix, label = '*', 'bookmarks.current'
-                else:
-                    prefix, label = ' ', ''
-
-                if ui.quiet:
-                    ui.write("%s\n" % bmark, label=label)
-                else:
-                    pad = " " * (25 - encoding.colwidth(bmark))
-                    ui.write(" %s %s%s %d:%s\n" % (
-                        prefix, bmark, pad, repo.changelog.rev(n), hexfn(n)),
-                        label=label)
+        for bmark, n in sorted(marks.iteritems()):
+            current = repo._bookmarkcurrent
+            if bmark == current:
+                prefix, label = '*', 'bookmarks.current'
+            else:
+                prefix, label = ' ', ''
+
+            if ui.quiet:
+                ui.write("%s\n" % bmark, label=label)
+            else:
+                pad = " " * (25 - encoding.colwidth(bmark))
+                ui.write(" %s %s%s %d:%s\n" % (
+                    prefix, bmark, pad, repo.changelog.rev(n), hexfn(n)),
+                    label=label)
 
 @command('branch',
     [('f', 'force', None,