mercurial/transaction.py
changeset 582 df8a5a0098d4
parent 573 fbfbd4e506c3
child 785 46a8dd3145cc
child 793 445970ccf57a
equal deleted inserted replaced
581:9db6d5455642 582:df8a5a0098d4
    13 
    13 
    14 import os
    14 import os
    15 import util
    15 import util
    16 
    16 
    17 class transaction:
    17 class transaction:
    18     def __init__(self, opener, journal, after = None):
    18     def __init__(self, report, opener, journal, after = None):
    19         self.journal = None
    19         self.journal = None
    20 
    20 
    21         # abort here if the journal already exists
    21         # abort here if the journal already exists
    22         if os.path.exists(journal):
    22         if os.path.exists(journal):
    23             raise "journal already exists - run hg recover"
    23             raise "journal already exists - run hg recover"
    24 
    24 
       
    25         self.report = report
    25         self.opener = opener
    26         self.opener = opener
    26         self.after = after
    27         self.after = after
    27         self.entries = []
    28         self.entries = []
    28         self.map = {}
    29         self.map = {}
    29         self.journal = journal
    30         self.journal = journal
    55         self.journal = None
    56         self.journal = None
    56 
    57 
    57     def abort(self):
    58     def abort(self):
    58         if not self.entries: return
    59         if not self.entries: return
    59 
    60 
    60         print "transaction abort!"
    61         self.report("transaction abort!\n")
    61 
    62 
    62         for f, o in self.entries:
    63         for f, o in self.entries:
    63             try:
    64             try:
    64                 self.opener(f, "a").truncate(o)
    65                 self.opener(f, "a").truncate(o)
    65             except:
    66             except:
    66                 print "failed to truncate", f
    67                 self.report("failed to truncate %s\n" % f)
    67 
    68 
    68         self.entries = []
    69         self.entries = []
    69 
    70 
    70         print "rollback completed"
    71         self.report("rollback completed\n")
    71 
    72 
    72 def rollback(opener, file):
    73 def rollback(opener, file):
    73     for l in open(file).readlines():
    74     for l in open(file).readlines():
    74         f, o = l.split('\0')
    75         f, o = l.split('\0')
    75         opener(f, "a").truncate(int(o))
    76         opener(f, "a").truncate(int(o))