mercurial/exchange.py
changeset 23436 52db731b964d
parent 23382 a81c76106d90
child 23437 94e2862dbcfb
equal deleted inserted replaced
23435:486a1fe09422 23436:52db731b964d
   769         self.heads = heads
   769         self.heads = heads
   770         # bookmark pulled explicitly
   770         # bookmark pulled explicitly
   771         self.explicitbookmarks = bookmarks
   771         self.explicitbookmarks = bookmarks
   772         # do we force pull?
   772         # do we force pull?
   773         self.force = force
   773         self.force = force
   774         # the name the pull transaction
   774         # transaction manager
   775         self._trname = 'pull\n' + util.hidepassword(remote.url())
   775         self.trmanager = None
   776         # hold the transaction once created
       
   777         self._tr = None
       
   778         # set of common changeset between local and remote before pull
   776         # set of common changeset between local and remote before pull
   779         self.common = None
   777         self.common = None
   780         # set of pulled head
   778         # set of pulled head
   781         self.rheads = None
   779         self.rheads = None
   782         # list of missing changeset to fetch remotely
   780         # list of missing changeset to fetch remotely
   805             # We pulled a specific subset
   803             # We pulled a specific subset
   806             # sync on this subset
   804             # sync on this subset
   807             return self.heads
   805             return self.heads
   808 
   806 
   809     def gettransaction(self):
   807     def gettransaction(self):
   810         """get appropriate pull transaction, creating it if needed"""
   808         # deprecated; talk to trmanager directly
   811         if self._tr is None:
   809         return self.trmanager.transaction()
   812             self._tr = self.repo.transaction(self._trname)
   810 
   813             self._tr.hookargs['source'] = 'pull'
   811 class transactionmanager(object):
   814             self._tr.hookargs['url'] = self.remote.url()
   812     """An object to manages the lifecycle of a transaction
       
   813 
       
   814     It creates the transaction on demand and calls the appropriate hooks when
       
   815     closing the transaction."""
       
   816     def __init__(self, repo, source, url):
       
   817         self.repo = repo
       
   818         self.source = source
       
   819         self.url = url
       
   820         self._tr = None
       
   821 
       
   822     def transaction(self):
       
   823         """Return an open transaction object, constructing if necessary"""
       
   824         if not self._tr:
       
   825             trname = '%s\n%s' % (self.source, util.hidepassword(self.url))
       
   826             self._tr = self.repo.transaction(trname)
       
   827             self._tr.hookargs['source'] = self.source
       
   828             self._tr.hookargs['url'] = self.url
   815         return self._tr
   829         return self._tr
   816 
   830 
   817     def closetransaction(self):
   831     def close(self):
   818         """close transaction if created"""
   832         """close transaction if created"""
   819         if self._tr is not None:
   833         if self._tr is not None:
   820             repo = self.repo
   834             repo = self.repo
   821             p = lambda: self._tr.writepending() and repo.root or ""
   835             p = lambda: self._tr.writepending() and repo.root or ""
   822             repo.hook('b2x-pretransactionclose', throw=True, pending=p,
   836             repo.hook('b2x-pretransactionclose', throw=True, pending=p,
   826                 repo.hook('b2x-transactionclose', **hookargs)
   840                 repo.hook('b2x-transactionclose', **hookargs)
   827             self._tr.addpostclose('b2x-hook-transactionclose',
   841             self._tr.addpostclose('b2x-hook-transactionclose',
   828                                   lambda tr: repo._afterlock(runhooks))
   842                                   lambda tr: repo._afterlock(runhooks))
   829             self._tr.close()
   843             self._tr.close()
   830 
   844 
   831     def releasetransaction(self):
   845     def release(self):
   832         """release transaction if created"""
   846         """release transaction if created"""
   833         if self._tr is not None:
   847         if self._tr is not None:
   834             self._tr.release()
   848             self._tr.release()
   835 
   849 
   836 def pull(repo, remote, heads=None, force=False, bookmarks=()):
   850 def pull(repo, remote, heads=None, force=False, bookmarks=()):
   844             raise util.Abort(msg)
   858             raise util.Abort(msg)
   845 
   859 
   846     pullop.remotebookmarks = remote.listkeys('bookmarks')
   860     pullop.remotebookmarks = remote.listkeys('bookmarks')
   847     lock = pullop.repo.lock()
   861     lock = pullop.repo.lock()
   848     try:
   862     try:
       
   863         pullop.trmanager = transactionmanager(repo, 'pull', remote.url())
   849         _pulldiscovery(pullop)
   864         _pulldiscovery(pullop)
   850         if (pullop.repo.ui.configbool('experimental', 'bundle2-exp', False)
   865         if (pullop.repo.ui.configbool('experimental', 'bundle2-exp', False)
   851             and pullop.remote.capable('bundle2-exp')):
   866             and pullop.remote.capable('bundle2-exp')):
   852             _pullbundle2(pullop)
   867             _pullbundle2(pullop)
   853         _pullchangeset(pullop)
   868         _pullchangeset(pullop)
   854         _pullphase(pullop)
   869         _pullphase(pullop)
   855         _pullbookmarks(pullop)
   870         _pullbookmarks(pullop)
   856         _pullobsolete(pullop)
   871         _pullobsolete(pullop)
   857         pullop.closetransaction()
   872         pullop.trmanager.close()
   858     finally:
   873     finally:
   859         pullop.releasetransaction()
   874         pullop.trmanager.release()
   860         lock.release()
   875         lock.release()
   861 
   876 
   862     return pullop
   877     return pullop
   863 
   878 
   864 # list of steps to perform discovery before pull
   879 # list of steps to perform discovery before pull