Patchwork [4,of,5] paths: merge conditions that select visibility of fields

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 9, 2016, 9:45 a.m.
Message ID <488822d5766bd4dd9a47.1452332744@mimosa>
Download mbox | patch
Permalink /patch/12622/
State Superseded
Commit 1a6fd929056f3572b596091372bf251579f41bce
Delegated to: Martin von Zweigbergk
Headers show

Comments

Yuya Nishihara - Jan. 9, 2016, 9:45 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1450015279 -32400
#      Sun Dec 13 23:01:19 2015 +0900
# Node ID 488822d5766bd4dd9a479fea4c1c513ffcc6f3c4
# Parent  2390e7462eec357b23547d2889717ec98710f9b0
paths: merge conditions that select visibility of fields

Truth table (extracted from the original implementation):

  search quiet  name path subopt
  ------ -----  ---- ---- ------
  f      f      T    T    T
  f      T      T    f    f
  T      f      f    T    f
  T      T      f    f    f

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5418,16 +5418,19 @@  def paths(ui, repo, search=None):
     else:
         pathitems = sorted(ui.paths.iteritems())
 
+    if ui.quiet:
+        namefmt = '%s\n'
+    else:
+        namefmt = '%s = '
+    showsubopts = not search and not ui.quiet
+
     for name, path in pathitems:
-        if search and not ui.quiet:
+        if not search:
+            ui.write(namefmt % name)
+        if not ui.quiet:
             ui.write("%s\n" % util.hidepassword(path.rawloc))
-        if search:
-            continue
-        if ui.quiet:
-            ui.write("%s\n" % name)
-        else:
-            ui.write("%s = %s\n" % (name, util.hidepassword(path.rawloc)))
-            for subopt, value in sorted(path.suboptions.items()):
+        for subopt, value in sorted(path.suboptions.items()):
+            if showsubopts:
                 ui.write('%s:%s = %s\n' % (name, subopt, value))
 
     if search and not pathitems: