Show More
@@ -423,6 +423,14 b' elif cmd == "tags":' | |||||
423 | r = "?" |
|
423 | r = "?" | |
424 | print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) |
|
424 | print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) | |
425 |
|
425 | |||
|
426 | elif cmd == "recover": | |||
|
427 | ui.status("rolling back any existing journal") | |||
|
428 | repo.recover() | |||
|
429 | ||||
|
430 | elif cmd == "undo": | |||
|
431 | ui.status("rolling back previous transaction") | |||
|
432 | repo.recover("undo") | |||
|
433 | ||||
426 | elif cmd == "verify": |
|
434 | elif cmd == "verify": | |
427 | filelinkrevs = {} |
|
435 | filelinkrevs = {} | |
428 | filenodes = {} |
|
436 | filenodes = {} |
@@ -297,6 +297,11 b' class localrepository:' | |||||
297 | return transaction(self.opener, self.join("journal"), |
|
297 | return transaction(self.opener, self.join("journal"), | |
298 | self.join("undo")) |
|
298 | self.join("undo")) | |
299 |
|
299 | |||
|
300 | def recover(self, f = "journal"): | |||
|
301 | self.lock() | |||
|
302 | if os.path.exists(self.join(f)): | |||
|
303 | return rollback(self.opener, self.join(f)) | |||
|
304 | ||||
300 | def lock(self, wait = 1): |
|
305 | def lock(self, wait = 1): | |
301 | try: |
|
306 | try: | |
302 | return lock.lock(self.join("lock"), 0) |
|
307 | return lock.lock(self.join("lock"), 0) |
@@ -15,16 +15,18 b' import os' | |||||
15 |
|
15 | |||
16 | class transaction: |
|
16 | class transaction: | |
17 | def __init__(self, opener, journal, after = None): |
|
17 | def __init__(self, opener, journal, after = None): | |
|
18 | self.journal = None | |||
|
19 | ||||
|
20 | # abort here if the journal already exists | |||
|
21 | if os.path.exists(journal): | |||
|
22 | raise "journal already exists - run hg recover" | |||
|
23 | ||||
18 | self.opener = opener |
|
24 | self.opener = opener | |
19 | self.after = after |
|
25 | self.after = after | |
20 | self.entries = [] |
|
26 | self.entries = [] | |
21 | self.map = {} |
|
27 | self.map = {} | |
22 | self.journal = journal |
|
28 | self.journal = journal | |
23 |
|
29 | |||
24 | # abort here if the journal already exists |
|
|||
25 | if os.path.exists(self.journal): |
|
|||
26 | raise "journal already exists!" |
|
|||
27 |
|
||||
28 | self.file = open(self.journal, "w") |
|
30 | self.file = open(self.journal, "w") | |
29 |
|
31 | |||
30 | def __del__(self): |
|
32 | def __del__(self): | |
@@ -63,9 +65,9 b' class transaction:' | |||||
63 |
|
65 | |||
64 | print "rollback completed" |
|
66 | print "rollback completed" | |
65 |
|
67 | |||
66 | def recover(self): |
|
68 | def rollback(opener, file): | |
67 |
|
|
69 | for l in open(file).readlines(): | |
68 |
|
|
70 | f, o = l.split('\0') | |
69 |
|
|
71 | opener(f, "a").truncate(int(o)) | |
70 |
|
|
72 | os.unlink(file) | |
71 |
|
73 |
General Comments 0
You need to be logged in to leave comments.
Login now