Mercurial > public > mercurial-scm > hg-stable
diff mercurial/transaction.py @ 162:5dcbe4d9a30c
Implement recover and undo commands
This adds an interface to transaction to rollback with a given journal file
and commands to rollback an existing .hg/journal or .hg/undo.
author | mpm@selenic.com |
---|---|
date | Thu, 26 May 2005 09:04:54 -0800 |
parents | 8d55c2d72c7c |
children | 43b8da7420a9 688d03d6997a |
line wrap: on
line diff
--- a/mercurial/transaction.py Thu May 26 08:53:04 2005 -0800 +++ b/mercurial/transaction.py Thu May 26 09:04:54 2005 -0800 @@ -15,16 +15,18 @@ class transaction: def __init__(self, opener, journal, after = None): + self.journal = None + + # abort here if the journal already exists + if os.path.exists(journal): + raise "journal already exists - run hg recover" + self.opener = opener self.after = after self.entries = [] self.map = {} self.journal = journal - # abort here if the journal already exists - if os.path.exists(self.journal): - raise "journal already exists!" - self.file = open(self.journal, "w") def __del__(self): @@ -63,9 +65,9 @@ print "rollback completed" - def recover(self): - for l in open(self.journal).readlines(): - f, o = l.split('\0') - self.opener(f, "a").truncate(int(o)) - os.unlink(self.journal) +def rollback(opener, file): + for l in open(file).readlines(): + f, o = l.split('\0') + opener(f, "a").truncate(int(o)) + os.unlink(file)