mercurial/localrepo.py
branchstable
changeset 50285 473103758373
parent 50284 a43f0562220c
child 50301 9fc0d244a753
equal deleted inserted replaced
50284:a43f0562220c 50285:473103758373
  2416         ha = hex(hashutil.sha1(idbase).digest())
  2416         ha = hex(hashutil.sha1(idbase).digest())
  2417         txnid = b'TXN:' + ha
  2417         txnid = b'TXN:' + ha
  2418         self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid)
  2418         self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid)
  2419 
  2419 
  2420         self._writejournal(desc)
  2420         self._writejournal(desc)
  2421         renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
       
  2422         if report:
  2421         if report:
  2423             rp = report
  2422             rp = report
  2424         else:
  2423         else:
  2425             rp = self.ui.warn
  2424             rp = self.ui.warn
  2426         vfsmap = self.vfs_map
  2425         vfsmap = self.vfs_map
  2574             rp,
  2573             rp,
  2575             self.svfs,
  2574             self.svfs,
  2576             vfsmap,
  2575             vfsmap,
  2577             b"journal",
  2576             b"journal",
  2578             b"undo",
  2577             b"undo",
  2579             aftertrans(renames),
  2578             lambda: None,
  2580             self.store.createmode,
  2579             self.store.createmode,
  2581             validator=validate,
  2580             validator=validate,
  2582             releasefn=releasefn,
  2581             releasefn=releasefn,
  2583             checkambigfiles=_cachedfiles,
  2582             checkambigfiles=_cachedfiles,
  2584             name=desc,
  2583             name=desc,
  3547             raise error.ProgrammingError(msg % category)
  3546             raise error.ProgrammingError(msg % category)
  3548         self._sidedata_computers.setdefault(kind, {})
  3547         self._sidedata_computers.setdefault(kind, {})
  3549         self._sidedata_computers[kind][category] = (keys, computer, flags)
  3548         self._sidedata_computers[kind][category] = (keys, computer, flags)
  3550 
  3549 
  3551 
  3550 
  3552 # used to avoid circular references so destructors work
       
  3553 def aftertrans(files):
       
  3554     renamefiles = [tuple(t) for t in files]
       
  3555 
       
  3556     def a():
       
  3557         for vfs, src, dest in renamefiles:
       
  3558             # if src and dest refer to a same file, vfs.rename is a no-op,
       
  3559             # leaving both src and dest on disk. delete dest to make sure
       
  3560             # the rename couldn't be such a no-op.
       
  3561             vfs.tryunlink(dest)
       
  3562             try:
       
  3563                 vfs.rename(src, dest)
       
  3564             except FileNotFoundError:  # journal file does not yet exist
       
  3565                 pass
       
  3566 
       
  3567     return a
       
  3568 
       
  3569 
       
  3570 def undoname(fn: bytes) -> bytes:
  3551 def undoname(fn: bytes) -> bytes:
  3571     base, name = os.path.split(fn)
  3552     base, name = os.path.split(fn)
  3572     assert name.startswith(b'journal')
  3553     assert name.startswith(b'journal')
  3573     return os.path.join(base, name.replace(b'journal', b'undo', 1))
  3554     return os.path.join(base, name.replace(b'journal', b'undo', 1))
  3574 
  3555