Skip to content
Snippets Groups Projects
Commit 5dcbe4d9 authored by mpm's avatar mpm
Browse files

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.
parent 0b4c5cb9
No related branches found
No related tags found
No related merge requests found
......@@ -423,6 +423,14 @@
r = "?"
print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n))
elif cmd == "recover":
ui.status("rolling back any existing journal")
repo.recover()
elif cmd == "undo":
ui.status("rolling back previous transaction")
repo.recover("undo")
elif cmd == "verify":
filelinkrevs = {}
filenodes = {}
......
......@@ -297,6 +297,11 @@
return transaction(self.opener, self.join("journal"),
self.join("undo"))
def recover(self, f = "journal"):
self.lock()
if os.path.exists(self.join(f)):
return rollback(self.opener, self.join(f))
def lock(self, wait = 1):
try:
return lock.lock(self.join("lock"), 0)
......
......@@ -15,9 +15,15 @@
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
......@@ -18,13 +24,9 @@
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment