comparison mercurial/commands.py @ 46907:ffd3e823a7e5

urlutil: extract `url` related code from `util` into the new module The new module is well fitting for this new code. And this will be useful to make the gathered code collaborate more later. Differential Revision: https://phab.mercurial-scm.org/D10374
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 12 Apr 2021 03:01:04 +0200
parents 37f49d462394
children 4452cb788404
comparison
equal deleted inserted replaced
46906:33524c46a092 46907:ffd3e823a7e5
72 wireprotoserver, 72 wireprotoserver,
73 ) 73 )
74 from .utils import ( 74 from .utils import (
75 dateutil, 75 dateutil,
76 stringutil, 76 stringutil,
77 urlutil,
77 ) 78 )
78 79
79 if pycompat.TYPE_CHECKING: 80 if pycompat.TYPE_CHECKING:
80 from typing import ( 81 from typing import (
81 List, 82 List,
4317 try: 4318 try:
4318 if b'bookmarks' not in other.listkeys(b'namespaces'): 4319 if b'bookmarks' not in other.listkeys(b'namespaces'):
4319 ui.warn(_(b"remote doesn't support bookmarks\n")) 4320 ui.warn(_(b"remote doesn't support bookmarks\n"))
4320 return 0 4321 return 0
4321 ui.pager(b'incoming') 4322 ui.pager(b'incoming')
4322 ui.status(_(b'comparing with %s\n') % util.hidepassword(source)) 4323 ui.status(_(b'comparing with %s\n') % urlutil.hidepassword(source))
4323 return bookmarks.incoming(ui, repo, other) 4324 return bookmarks.incoming(ui, repo, other)
4324 finally: 4325 finally:
4325 other.close() 4326 other.close()
4326 4327
4327 repo._subtoppath = ui.expandpath(source) 4328 repo._subtoppath = ui.expandpath(source)
4992 other = hg.peer(repo, opts, dest) 4993 other = hg.peer(repo, opts, dest)
4993 try: 4994 try:
4994 if b'bookmarks' not in other.listkeys(b'namespaces'): 4995 if b'bookmarks' not in other.listkeys(b'namespaces'):
4995 ui.warn(_(b"remote doesn't support bookmarks\n")) 4996 ui.warn(_(b"remote doesn't support bookmarks\n"))
4996 return 0 4997 return 0
4997 ui.status(_(b'comparing with %s\n') % util.hidepassword(dest)) 4998 ui.status(_(b'comparing with %s\n') % urlutil.hidepassword(dest))
4998 ui.pager(b'outgoing') 4999 ui.pager(b'outgoing')
4999 return bookmarks.outgoing(ui, repo, other) 5000 return bookmarks.outgoing(ui, repo, other)
5000 finally: 5001 finally:
5001 other.close() 5002 other.close()
5002 5003
5140 else: 5141 else:
5141 pathitems = sorted(pycompat.iteritems(ui.paths)) 5142 pathitems = sorted(pycompat.iteritems(ui.paths))
5142 5143
5143 fm = ui.formatter(b'paths', opts) 5144 fm = ui.formatter(b'paths', opts)
5144 if fm.isplain(): 5145 if fm.isplain():
5145 hidepassword = util.hidepassword 5146 hidepassword = urlutil.hidepassword
5146 else: 5147 else:
5147 hidepassword = bytes 5148 hidepassword = bytes
5148 if ui.quiet: 5149 if ui.quiet:
5149 namefmt = b'%s\n' 5150 namefmt = b'%s\n'
5150 else: 5151 else:
5390 sources = [b'default'] 5391 sources = [b'default']
5391 for source in sources: 5392 for source in sources:
5392 source, branches = hg.parseurl( 5393 source, branches = hg.parseurl(
5393 ui.expandpath(source), opts.get(b'branch') 5394 ui.expandpath(source), opts.get(b'branch')
5394 ) 5395 )
5395 ui.status(_(b'pulling from %s\n') % util.hidepassword(source)) 5396 ui.status(_(b'pulling from %s\n') % urlutil.hidepassword(source))
5396 ui.flush() 5397 ui.flush()
5397 other = hg.peer(repo, opts, source) 5398 other = hg.peer(repo, opts, source)
5398 update_conflict = None 5399 update_conflict = None
5399 try: 5400 try:
5400 revs, checkout = hg.addbranchrevs( 5401 revs, checkout = hg.addbranchrevs(
5730 _(b'default repository not configured!'), 5731 _(b'default repository not configured!'),
5731 hint=_(b"see 'hg help config.paths'"), 5732 hint=_(b"see 'hg help config.paths'"),
5732 ) 5733 )
5733 dest = path.pushloc or path.loc 5734 dest = path.pushloc or path.loc
5734 branches = (path.branch, opts.get(b'branch') or []) 5735 branches = (path.branch, opts.get(b'branch') or [])
5735 ui.status(_(b'pushing to %s\n') % util.hidepassword(dest)) 5736 ui.status(_(b'pushing to %s\n') % urlutil.hidepassword(dest))
5736 revs, checkout = hg.addbranchrevs( 5737 revs, checkout = hg.addbranchrevs(
5737 repo, repo, branches, opts.get(b'rev') 5738 repo, repo, branches, opts.get(b'rev')
5738 ) 5739 )
5739 other = hg.peer(repo, opts, dest) 5740 other = hg.peer(repo, opts, dest)
5740 5741
7233 raise 7234 raise
7234 return source, sbranch, None, None, None 7235 return source, sbranch, None, None, None
7235 revs, checkout = hg.addbranchrevs(repo, other, branches, None) 7236 revs, checkout = hg.addbranchrevs(repo, other, branches, None)
7236 if revs: 7237 if revs:
7237 revs = [other.lookup(rev) for rev in revs] 7238 revs = [other.lookup(rev) for rev in revs]
7238 ui.debug(b'comparing with %s\n' % util.hidepassword(source)) 7239 ui.debug(b'comparing with %s\n' % urlutil.hidepassword(source))
7239 repo.ui.pushbuffer() 7240 repo.ui.pushbuffer()
7240 commoninc = discovery.findcommonincoming(repo, other, heads=revs) 7241 commoninc = discovery.findcommonincoming(repo, other, heads=revs)
7241 repo.ui.popbuffer() 7242 repo.ui.popbuffer()
7242 return source, sbranch, other, commoninc, commoninc[1] 7243 return source, sbranch, other, commoninc, commoninc[1]
7243 7244
7255 dother = hg.peer(repo, {}, dest) 7256 dother = hg.peer(repo, {}, dest)
7256 except error.RepoError: 7257 except error.RepoError:
7257 if opts.get(b'remote'): 7258 if opts.get(b'remote'):
7258 raise 7259 raise
7259 return dest, dbranch, None, None 7260 return dest, dbranch, None, None
7260 ui.debug(b'comparing with %s\n' % util.hidepassword(dest)) 7261 ui.debug(b'comparing with %s\n' % urlutil.hidepassword(dest))
7261 elif sother is None: 7262 elif sother is None:
7262 # there is no explicit destination peer, but source one is invalid 7263 # there is no explicit destination peer, but source one is invalid
7263 return dest, dbranch, None, None 7264 return dest, dbranch, None, None
7264 else: 7265 else:
7265 dother = sother 7266 dother = sother
7597 ) 7598 )
7598 url = b'bundle:' + fname 7599 url = b'bundle:' + fname
7599 try: 7600 try:
7600 txnname = b'unbundle' 7601 txnname = b'unbundle'
7601 if not isinstance(gen, bundle2.unbundle20): 7602 if not isinstance(gen, bundle2.unbundle20):
7602 txnname = b'unbundle\n%s' % util.hidepassword(url) 7603 txnname = b'unbundle\n%s' % urlutil.hidepassword(url)
7603 with repo.transaction(txnname) as tr: 7604 with repo.transaction(txnname) as tr:
7604 op = bundle2.applybundle( 7605 op = bundle2.applybundle(
7605 repo, gen, tr, source=b'unbundle', url=url 7606 repo, gen, tr, source=b'unbundle', url=url
7606 ) 7607 )
7607 except error.BundleUnknownFeatureError as exc: 7608 except error.BundleUnknownFeatureError as exc: