mercurial/commands.py
changeset 46763 954bad9c32a0
parent 46762 052ab8d0a538
child 46764 685383486d0a
equal deleted inserted replaced
46762:052ab8d0a538 46763:954bad9c32a0
  5363     ):
  5363     ):
  5364         msg = _(b'update destination required by configuration')
  5364         msg = _(b'update destination required by configuration')
  5365         hint = _(b'use hg pull followed by hg update DEST')
  5365         hint = _(b'use hg pull followed by hg update DEST')
  5366         raise error.InputError(msg, hint=hint)
  5366         raise error.InputError(msg, hint=hint)
  5367 
  5367 
  5368     source, branches = hg.parseurl(ui.expandpath(source), opts.get(b'branch'))
  5368     if True:
  5369     ui.status(_(b'pulling from %s\n') % util.hidepassword(source))
  5369         source, branches = hg.parseurl(
  5370     ui.flush()
  5370             ui.expandpath(source), opts.get(b'branch')
  5371     other = hg.peer(repo, opts, source)
       
  5372     update_conflict = None
       
  5373     try:
       
  5374         revs, checkout = hg.addbranchrevs(
       
  5375             repo, other, branches, opts.get(b'rev')
       
  5376         )
  5371         )
  5377 
  5372         ui.status(_(b'pulling from %s\n') % util.hidepassword(source))
  5378         pullopargs = {}
  5373         ui.flush()
  5379 
  5374         other = hg.peer(repo, opts, source)
  5380         nodes = None
  5375         update_conflict = None
  5381         if opts.get(b'bookmark') or revs:
  5376         try:
  5382             # The list of bookmark used here is the same used to actually update
  5377             revs, checkout = hg.addbranchrevs(
  5383             # the bookmark names, to avoid the race from issue 4689 and we do
  5378                 repo, other, branches, opts.get(b'rev')
  5384             # all lookup and bookmark queries in one go so they see the same
  5379             )
  5385             # version of the server state (issue 4700).
  5380 
  5386             nodes = []
  5381             pullopargs = {}
  5387             fnodes = []
  5382 
  5388             revs = revs or []
  5383             nodes = None
  5389             if revs and not other.capable(b'lookup'):
  5384             if opts.get(b'bookmark') or revs:
  5390                 err = _(
  5385                 # The list of bookmark used here is the same used to actually update
  5391                     b"other repository doesn't support revision lookup, "
  5386                 # the bookmark names, to avoid the race from issue 4689 and we do
  5392                     b"so a rev cannot be specified."
  5387                 # all lookup and bookmark queries in one go so they see the same
  5393                 )
  5388                 # version of the server state (issue 4700).
  5394                 raise error.Abort(err)
  5389                 nodes = []
  5395             with other.commandexecutor() as e:
  5390                 fnodes = []
  5396                 fremotebookmarks = e.callcommand(
  5391                 revs = revs or []
  5397                     b'listkeys', {b'namespace': b'bookmarks'}
  5392                 if revs and not other.capable(b'lookup'):
  5398                 )
  5393                     err = _(
  5399                 for r in revs:
  5394                         b"other repository doesn't support revision lookup, "
  5400                     fnodes.append(e.callcommand(b'lookup', {b'key': r}))
  5395                         b"so a rev cannot be specified."
  5401             remotebookmarks = fremotebookmarks.result()
       
  5402             remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks)
       
  5403             pullopargs[b'remotebookmarks'] = remotebookmarks
       
  5404             for b in opts.get(b'bookmark', []):
       
  5405                 b = repo._bookmarks.expandname(b)
       
  5406                 if b not in remotebookmarks:
       
  5407                     raise error.InputError(
       
  5408                         _(b'remote bookmark %s not found!') % b
       
  5409                     )
  5396                     )
  5410                 nodes.append(remotebookmarks[b])
  5397                     raise error.Abort(err)
  5411             for i, rev in enumerate(revs):
  5398                 with other.commandexecutor() as e:
  5412                 node = fnodes[i].result()
  5399                     fremotebookmarks = e.callcommand(
  5413                 nodes.append(node)
  5400                         b'listkeys', {b'namespace': b'bookmarks'}
  5414                 if rev == checkout:
  5401                     )
  5415                     checkout = node
  5402                     for r in revs:
  5416 
  5403                         fnodes.append(e.callcommand(b'lookup', {b'key': r}))
  5417         wlock = util.nullcontextmanager()
  5404                 remotebookmarks = fremotebookmarks.result()
  5418         if opts.get(b'update'):
  5405                 remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks)
  5419             wlock = repo.wlock()
  5406                 pullopargs[b'remotebookmarks'] = remotebookmarks
  5420         with wlock:
  5407                 for b in opts.get(b'bookmark', []):
  5421             pullopargs.update(opts.get(b'opargs', {}))
  5408                     b = repo._bookmarks.expandname(b)
  5422             modheads = exchange.pull(
  5409                     if b not in remotebookmarks:
  5423                 repo,
  5410                         raise error.InputError(
  5424                 other,
  5411                             _(b'remote bookmark %s not found!') % b
  5425                 heads=nodes,
  5412                         )
  5426                 force=opts.get(b'force'),
  5413                     nodes.append(remotebookmarks[b])
  5427                 bookmarks=opts.get(b'bookmark', ()),
  5414                 for i, rev in enumerate(revs):
  5428                 opargs=pullopargs,
  5415                     node = fnodes[i].result()
  5429                 confirm=opts.get(b'confirm'),
  5416                     nodes.append(node)
  5430             ).cgresult
  5417                     if rev == checkout:
  5431 
  5418                         checkout = node
  5432             # brev is a name, which might be a bookmark to be activated at
  5419 
  5433             # the end of the update. In other words, it is an explicit
  5420             wlock = util.nullcontextmanager()
  5434             # destination of the update
  5421             if opts.get(b'update'):
  5435             brev = None
  5422                 wlock = repo.wlock()
  5436 
  5423             with wlock:
  5437             if checkout:
  5424                 pullopargs.update(opts.get(b'opargs', {}))
  5438                 checkout = repo.unfiltered().changelog.rev(checkout)
  5425                 modheads = exchange.pull(
  5439 
  5426                     repo,
  5440                 # order below depends on implementation of
  5427                     other,
  5441                 # hg.addbranchrevs(). opts['bookmark'] is ignored,
  5428                     heads=nodes,
  5442                 # because 'checkout' is determined without it.
  5429                     force=opts.get(b'force'),
  5443                 if opts.get(b'rev'):
  5430                     bookmarks=opts.get(b'bookmark', ()),
  5444                     brev = opts[b'rev'][0]
  5431                     opargs=pullopargs,
  5445                 elif opts.get(b'branch'):
  5432                     confirm=opts.get(b'confirm'),
  5446                     brev = opts[b'branch'][0]
  5433                 ).cgresult
  5447                 else:
  5434 
  5448                     brev = branches[0]
  5435                 # brev is a name, which might be a bookmark to be activated at
  5449             repo._subtoppath = source
  5436                 # the end of the update. In other words, it is an explicit
  5450             try:
  5437                 # destination of the update
  5451                 update_conflict = postincoming(
  5438                 brev = None
  5452                     ui, repo, modheads, opts.get(b'update'), checkout, brev
  5439 
  5453                 )
  5440                 if checkout:
  5454             except error.FilteredRepoLookupError as exc:
  5441                     checkout = repo.unfiltered().changelog.rev(checkout)
  5455                 msg = _(b'cannot update to target: %s') % exc.args[0]
  5442 
  5456                 exc.args = (msg,) + exc.args[1:]
  5443                     # order below depends on implementation of
  5457                 raise
  5444                     # hg.addbranchrevs(). opts['bookmark'] is ignored,
  5458             finally:
  5445                     # because 'checkout' is determined without it.
  5459                 del repo._subtoppath
  5446                     if opts.get(b'rev'):
  5460 
  5447                         brev = opts[b'rev'][0]
  5461     finally:
  5448                     elif opts.get(b'branch'):
  5462         other.close()
  5449                         brev = opts[b'branch'][0]
       
  5450                     else:
       
  5451                         brev = branches[0]
       
  5452                 repo._subtoppath = source
       
  5453                 try:
       
  5454                     update_conflict = postincoming(
       
  5455                         ui, repo, modheads, opts.get(b'update'), checkout, brev
       
  5456                     )
       
  5457                 except error.FilteredRepoLookupError as exc:
       
  5458                     msg = _(b'cannot update to target: %s') % exc.args[0]
       
  5459                     exc.args = (msg,) + exc.args[1:]
       
  5460                     raise
       
  5461                 finally:
       
  5462                     del repo._subtoppath
       
  5463 
       
  5464         finally:
       
  5465             other.close()
  5463     if update_conflict:
  5466     if update_conflict:
  5464         return 1
  5467         return 1
  5465     else:
  5468     else:
  5466         return 0
  5469         return 0
  5467 
  5470