mercurial/exchange.py
changeset 20477 2607a21bb40b
parent 20476 1180c6ec5695
child 20478 80628d4069be
equal deleted inserted replaced
20476:1180c6ec5695 20477:2607a21bb40b
   389         self.remote = remote
   389         self.remote = remote
   390         # revision we try to pull (None is "all")
   390         # revision we try to pull (None is "all")
   391         self.heads = heads
   391         self.heads = heads
   392         # do we force pull?
   392         # do we force pull?
   393         self.force = force
   393         self.force = force
       
   394         # the name the pull transaction
       
   395         self._trname = 'pull\n' + util.hidepassword(remote.url())
       
   396         # hold the transaction once created
       
   397         self._tr = None
       
   398 
       
   399     def gettransaction(self):
       
   400         """get appropriate pull transaction, creating it if needed"""
       
   401         if self._tr is None:
       
   402             self._tr = self.repo.transaction(self._trname)
       
   403         return self._tr
       
   404 
       
   405     def closetransaction(self):
       
   406         """close transaction if created"""
       
   407         if self._tr is not None:
       
   408             self._tr.close()
       
   409 
       
   410     def releasetransaction(self):
       
   411         """release transaction if created"""
       
   412         if self._tr is not None:
       
   413             self._tr.release()
   394 
   414 
   395 def pull(repo, remote, heads=None, force=False):
   415 def pull(repo, remote, heads=None, force=False):
   396     pullop = pulloperation(repo, remote, heads, force)
   416     pullop = pulloperation(repo, remote, heads, force)
   397     if pullop.remote.local():
   417     if pullop.remote.local():
   398         missing = set(pullop.remote.requirements) - pullop.repo.supported
   418         missing = set(pullop.remote.requirements) - pullop.repo.supported
   400             msg = _("required features are not"
   420             msg = _("required features are not"
   401                     " supported in the destination:"
   421                     " supported in the destination:"
   402                     " %s") % (', '.join(sorted(missing)))
   422                     " %s") % (', '.join(sorted(missing)))
   403             raise util.Abort(msg)
   423             raise util.Abort(msg)
   404 
   424 
   405     # don't open transaction for nothing or you break future useful
       
   406     # rollback call
       
   407     tr = None
       
   408     trname = 'pull\n' + util.hidepassword(pullop.remote.url())
       
   409     lock = pullop.repo.lock()
   425     lock = pullop.repo.lock()
   410     try:
   426     try:
   411         tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
   427         tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
   412                                            pullop.remote,
   428                                            pullop.remote,
   413                                            heads=pullop.heads,
   429                                            heads=pullop.heads,
   415         common, fetch, rheads = tmp
   431         common, fetch, rheads = tmp
   416         if not fetch:
   432         if not fetch:
   417             pullop.repo.ui.status(_("no changes found\n"))
   433             pullop.repo.ui.status(_("no changes found\n"))
   418             result = 0
   434             result = 0
   419         else:
   435         else:
   420             tr = pullop.repo.transaction(trname)
   436             # We delay the open of the transaction as late as possible so we
       
   437             # don't open transaction for nothing or you break future useful
       
   438             # rollback call
       
   439             pullop.gettransaction()
   421             if pullop.heads is None and list(common) == [nullid]:
   440             if pullop.heads is None and list(common) == [nullid]:
   422                 pullop.repo.ui.status(_("requesting all changes\n"))
   441                 pullop.repo.ui.status(_("requesting all changes\n"))
   423             elif (pullop.heads is None
   442             elif (pullop.heads is None
   424                   and pullop.remote.capable('changegroupsubset')):
   443                   and pullop.remote.capable('changegroupsubset')):
   425                 # issue1320, avoid a race if remote changed after discovery
   444                 # issue1320, avoid a race if remote changed after discovery
   463         else:
   482         else:
   464             # Remote is old or publishing all common changesets
   483             # Remote is old or publishing all common changesets
   465             # should be seen as public
   484             # should be seen as public
   466             phases.advanceboundary(pullop.repo, phases.public, subset)
   485             phases.advanceboundary(pullop.repo, phases.public, subset)
   467 
   486 
   468         def gettransaction():
   487         _pullobsolete(pullop.repo, pullop.remote,
   469             if tr is None:
   488                       pullop.gettransaction)
   470                 return pullop.repo.transaction(trname)
   489         pullop.closetransaction()
   471             return tr
       
   472 
       
   473         obstr = _pullobsolete(pullop.repo, pullop.remote, gettransaction)
       
   474         if obstr is not None:
       
   475             tr = obstr
       
   476 
       
   477         if tr is not None:
       
   478             tr.close()
       
   479     finally:
   490     finally:
   480         if tr is not None:
   491         pullop.releasetransaction()
   481             tr.release()
       
   482         lock.release()
   492         lock.release()
   483 
   493 
   484     return result
   494     return result
   485 
   495 
   486 def _pullobsolete(repo, remote, gettransaction):
   496 def _pullobsolete(repo, remote, gettransaction):