comparison mercurial/commands.py @ 27726:7e9dc8bbebf6

paths: use single loop for both search=None|pattern cases This will help porting to the formatter API. This patch adds test for empty pathitems to make sure "hg paths" never say "not found!".
author Yuya Nishihara <yuya@tcha.org>
date Sun, 13 Dec 2015 22:02:32 +0900
parents 64ee5866e107
children 1a6fd929056f
comparison
equal deleted inserted replaced
27725:64ee5866e107 27726:7e9dc8bbebf6
5396 See :hg:`help urls` for more information. 5396 See :hg:`help urls` for more information.
5397 5397
5398 Returns 0 on success. 5398 Returns 0 on success.
5399 """ 5399 """
5400 if search: 5400 if search:
5401 for name, path in sorted(ui.paths.iteritems()): 5401 pathitems = [(name, path) for name, path in ui.paths.iteritems()
5402 if name == search: 5402 if name == search]
5403 if not ui.quiet:
5404 ui.write("%s\n" % util.hidepassword(path.rawloc))
5405 return
5406 if not ui.quiet:
5407 ui.warn(_("not found!\n"))
5408 return 1
5409 else: 5403 else:
5410 pathitems = sorted(ui.paths.iteritems()) 5404 pathitems = sorted(ui.paths.iteritems())
5411 5405
5412 for name, path in pathitems: 5406 for name, path in pathitems:
5407 if search and not ui.quiet:
5408 ui.write("%s\n" % util.hidepassword(path.rawloc))
5409 if search:
5410 continue
5413 if ui.quiet: 5411 if ui.quiet:
5414 ui.write("%s\n" % name) 5412 ui.write("%s\n" % name)
5415 else: 5413 else:
5416 ui.write("%s = %s\n" % (name, util.hidepassword(path.rawloc))) 5414 ui.write("%s = %s\n" % (name, util.hidepassword(path.rawloc)))
5417 for subopt, value in sorted(path.suboptions.items()): 5415 for subopt, value in sorted(path.suboptions.items()):
5418 ui.write('%s:%s = %s\n' % (name, subopt, value)) 5416 ui.write('%s:%s = %s\n' % (name, subopt, value))
5417
5418 if search and not pathitems:
5419 if not ui.quiet:
5420 ui.warn(_("not found!\n"))
5421 return 1
5422 else:
5423 return 0
5419 5424
5420 @command('phase', 5425 @command('phase',
5421 [('p', 'public', False, _('set changeset phase to public')), 5426 [('p', 'public', False, _('set changeset phase to public')),
5422 ('d', 'draft', False, _('set changeset phase to draft')), 5427 ('d', 'draft', False, _('set changeset phase to draft')),
5423 ('s', 'secret', False, _('set changeset phase to secret')), 5428 ('s', 'secret', False, _('set changeset phase to secret')),