comparison hgext/transplant.py @ 4959:97b734fb9c6f

Use try/finally pattern to cleanup locks and transactions
author Matt Mackall <mpm@selenic.com>
date Sat, 21 Jul 2007 16:02:10 -0500
parents 059bdc8dfb9d
children 126f527b3ba3
comparison
equal deleted inserted replaced
4958:9a2a73ea6135 4959:97b734fb9c6f
94 p1, p2 = repo.dirstate.parents() 94 p1, p2 = repo.dirstate.parents()
95 pulls = [] 95 pulls = []
96 diffopts = patch.diffopts(self.ui, opts) 96 diffopts = patch.diffopts(self.ui, opts)
97 diffopts.git = True 97 diffopts.git = True
98 98
99 wlock = repo.wlock() 99 lock = wlock = None
100 lock = repo.lock()
101 try: 100 try:
101 wlock = repo.wlock()
102 lock = repo.lock()
102 for rev in revs: 103 for rev in revs:
103 node = revmap[rev] 104 node = revmap[rev]
104 revstr = '%s:%s' % (rev, revlog.short(node)) 105 revstr = '%s:%s' % (rev, revlog.short(node))
105 106
106 if self.applied(repo, node, p1): 107 if self.applied(repo, node, p1):
164 repo.pull(source, heads=pulls, lock=lock) 165 repo.pull(source, heads=pulls, lock=lock)
165 merge.update(repo, pulls[-1], False, False, None, wlock=wlock) 166 merge.update(repo, pulls[-1], False, False, None, wlock=wlock)
166 finally: 167 finally:
167 self.saveseries(revmap, merges) 168 self.saveseries(revmap, merges)
168 self.transplants.write() 169 self.transplants.write()
170 del lock, wlock
169 171
170 def filter(self, filter, changelog, patchfile): 172 def filter(self, filter, changelog, patchfile):
171 '''arbitrarily rewrite changeset before applying it''' 173 '''arbitrarily rewrite changeset before applying it'''
172 174
173 self.ui.status('filtering %s\n' % patchfile) 175 self.ui.status('filtering %s\n' % patchfile)
270 if not user or not date or not message or not parents[0]: 272 if not user or not date or not message or not parents[0]:
271 raise util.Abort(_('transplant log file is corrupt')) 273 raise util.Abort(_('transplant log file is corrupt'))
272 274
273 extra = {'transplant_source': node} 275 extra = {'transplant_source': node}
274 wlock = repo.wlock() 276 wlock = repo.wlock()
275 p1, p2 = repo.dirstate.parents() 277 try:
276 if p1 != parents[0]: 278 p1, p2 = repo.dirstate.parents()
277 raise util.Abort(_('working dir not at transplant parent %s') % 279 if p1 != parents[0]:
278 revlog.hex(parents[0])) 280 raise util.Abort(
279 if merge: 281 _('working dir not at transplant parent %s') %
280 repo.dirstate.setparents(p1, parents[1]) 282 revlog.hex(parents[0]))
281 n = repo.commit(None, message, user, date, wlock=wlock, extra=extra) 283 if merge:
282 if not n: 284 repo.dirstate.setparents(p1, parents[1])
283 raise util.Abort(_('commit failed')) 285 n = repo.commit(None, message, user, date, wlock=wlock,
284 if not merge: 286 extra=extra)
285 self.transplants.set(n, node) 287 if not n:
286 self.unlog() 288 raise util.Abort(_('commit failed'))
287 289 if not merge:
288 return n, node 290 self.transplants.set(n, node)
291 self.unlog()
292
293 return n, node
294 finally:
295 del wlock
289 296
290 def readseries(self): 297 def readseries(self):
291 nodes = [] 298 nodes = []
292 merges = [] 299 merges = []
293 cur = nodes 300 cur = nodes