undumprevlog
56 lines
| 1.4 KiB
| text/plain
|
TextLexer
/ contrib / undumprevlog
|
r46434 | #!/usr/bin/env python3 | ||
|
r6433 | # Undump a dump from dumprevlog | ||
# $ hg init | ||||
# $ undumprevlog < repo.dump | ||||
|
r33874 | from __future__ import absolute_import, print_function | ||
|
r29167 | |||
|
r6433 | import sys | ||
|
r46729 | from mercurial.node import bin | ||
|
r29167 | from mercurial import ( | ||
|
r39983 | encoding, | ||
|
r29167 | revlog, | ||
transaction, | ||||
|
r31248 | vfs as vfsmod, | ||
|
r29167 | ) | ||
|
r44058 | from mercurial.utils import procutil | ||
|
r6433 | |||
r47838 | from mercurial.revlogutils import ( | |||
constants as revlog_constants, | ||||
) | ||||
|
r6466 | for fp in (sys.stdin, sys.stdout, sys.stderr): | ||
|
r37138 | procutil.setbinary(fp) | ||
|
r6466 | |||
|
r39983 | opener = vfsmod.vfs(b'.', False) | ||
|
r44058 | tr = transaction.transaction( | ||
sys.stderr.write, opener, {b'store': opener}, b"undump.journal" | ||||
) | ||||
|
r19022 | while True: | ||
|
r6433 | l = sys.stdin.readline() | ||
if not l: | ||||
break | ||||
if l.startswith("file:"): | ||||
|
r39983 | f = encoding.strtolocal(l[6:-1]) | ||
r47838 | r = revlog.revlog( | |||
opener, | ||||
target=(revlog_constants.KIND_OTHER, b'undump-revlog'), | ||||
indexfile=f, | ||||
) | ||||
|
r45598 | procutil.stdout.write(b'%s\n' % f) | ||
|
r6433 | elif l.startswith("node:"): | ||
|
r46729 | n = bin(l[6:-1]) | ||
|
r6433 | elif l.startswith("linkrev:"): | ||
lr = int(l[9:-1]) | ||||
elif l.startswith("parents:"): | ||||
p = l[9:-1].split() | ||||
|
r46729 | p1 = bin(p[0]) | ||
p2 = bin(p[1]) | ||||
|
r6433 | elif l.startswith("length:"): | ||
length = int(l[8:-1]) | ||||
|
r44058 | sys.stdin.readline() # start marker | ||
|
r39983 | d = encoding.strtolocal(sys.stdin.read(length)) | ||
|
r44058 | sys.stdin.readline() # end marker | ||
|
r6433 | r.addrevision(d, tr, lr, p1, p2) | ||
tr.close() | ||||