undumprevlog
56 lines
| 1.4 KiB
| text/plain
|
TextLexer
/ contrib / undumprevlog
Gregory Szorc
|
r46434 | #!/usr/bin/env python3 | ||
Matt Mackall
|
r6433 | # 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 | ||
Joerg Sonnenberger
|
r46729 | from mercurial.node import bin | ||
Pulkit Goyal
|
r29167 | from mercurial import ( | ||
Matt Harbison
|
r39983 | encoding, | ||
Pulkit Goyal
|
r29167 | revlog, | ||
transaction, | ||||
Pierre-Yves David
|
r31248 | vfs as vfsmod, | ||
Pulkit Goyal
|
r29167 | ) | ||
Gregory Szorc
|
r44058 | from mercurial.utils import procutil | ||
Matt Mackall
|
r6433 | |||
r47838 | from mercurial.revlogutils import ( | |||
constants as revlog_constants, | ||||
) | ||||
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) | ||
Gregory Szorc
|
r44058 | 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]) | ||
r47838 | r = revlog.revlog( | |||
opener, | ||||
target=(revlog_constants.KIND_OTHER, b'undump-revlog'), | ||||
indexfile=f, | ||||
) | ||||
Manuel Jacob
|
r45598 | procutil.stdout.write(b'%s\n' % f) | ||
Matt Mackall
|
r6433 | elif l.startswith("node:"): | ||
Joerg Sonnenberger
|
r46729 | n = bin(l[6:-1]) | ||
Matt Mackall
|
r6433 | elif l.startswith("linkrev:"): | ||
lr = int(l[9:-1]) | ||||
elif l.startswith("parents:"): | ||||
p = l[9:-1].split() | ||||
Joerg Sonnenberger
|
r46729 | p1 = bin(p[0]) | ||
p2 = bin(p[1]) | ||||
Matt Mackall
|
r6433 | elif l.startswith("length:"): | ||
length = int(l[8:-1]) | ||||
Gregory Szorc
|
r44058 | sys.stdin.readline() # start marker | ||
Matt Harbison
|
r39983 | d = encoding.strtolocal(sys.stdin.read(length)) | ||
Gregory Szorc
|
r44058 | sys.stdin.readline() # end marker | ||
Matt Mackall
|
r6433 | r.addrevision(d, tr, lr, p1, p2) | ||
tr.close() | ||||