undumprevlog
50 lines
| 1.2 KiB
| text/plain
|
TextLexer
/ contrib / undumprevlog
Matt Mackall
|
r6433 | #!/usr/bin/env python | ||
# Undump a dump from dumprevlog | ||||
# $ hg init | ||||
# $ undumprevlog < repo.dump | ||||
Augie Fackler
|
r33874 | from __future__ import absolute_import, print_function | ||
Pulkit Goyal
|
r29167 | |||
Matt Mackall
|
r6433 | import sys | ||
Pulkit Goyal
|
r29167 | from mercurial import ( | ||
Matt Harbison
|
r39983 | encoding, | ||
Pulkit Goyal
|
r29167 | node, | ||
Matt Harbison
|
r39983 | pycompat, | ||
Pulkit Goyal
|
r29167 | revlog, | ||
transaction, | ||||
Pierre-Yves David
|
r31248 | vfs as vfsmod, | ||
Pulkit Goyal
|
r29167 | ) | ||
Yuya Nishihara
|
r37138 | from mercurial.utils import ( | ||
procutil, | ||||
) | ||||
Matt Mackall
|
r6433 | |||
Adrian Buehlmann
|
r6466 | for fp in (sys.stdin, sys.stdout, sys.stderr): | ||
Yuya Nishihara
|
r37138 | procutil.setbinary(fp) | ||
Adrian Buehlmann
|
r6466 | |||
Matt Harbison
|
r39983 | opener = vfsmod.vfs(b'.', False) | ||
tr = transaction.transaction(sys.stderr.write, opener, {b'store': opener}, | ||||
b"undump.journal") | ||||
Mads Kiilerich
|
r19022 | while True: | ||
Matt Mackall
|
r6433 | l = sys.stdin.readline() | ||
if not l: | ||||
break | ||||
if l.startswith("file:"): | ||||
Matt Harbison
|
r39983 | f = encoding.strtolocal(l[6:-1]) | ||
Matt Mackall
|
r6433 | r = revlog.revlog(opener, f) | ||
Matt Harbison
|
r39983 | pycompat.stdout.write(b'%s\n' % f) | ||
Matt Mackall
|
r6433 | elif l.startswith("node:"): | ||
n = node.bin(l[6:-1]) | ||||
elif l.startswith("linkrev:"): | ||||
lr = int(l[9:-1]) | ||||
elif l.startswith("parents:"): | ||||
p = l[9:-1].split() | ||||
p1 = node.bin(p[0]) | ||||
p2 = node.bin(p[1]) | ||||
elif l.startswith("length:"): | ||||
length = int(l[8:-1]) | ||||
sys.stdin.readline() # start marker | ||||
Matt Harbison
|
r39983 | d = encoding.strtolocal(sys.stdin.read(length)) | ||
Matt Mackall
|
r6433 | sys.stdin.readline() # end marker | ||
r.addrevision(d, tr, lr, p1, p2) | ||||
tr.close() | ||||