| 1 |
#!/usr/bin/env python3 |
| 2 |
# Dump revlogs as raw data stream |
| 3 |
# $ find .hg/store/ -name "*.i" | xargs dumprevlog > repo.dump |
| 4 |
|
| 5 |
|
| 6 |
import os |
| 7 |
import sys |
| 8 |
from mercurial.node import hex |
| 9 |
from mercurial import ( |
| 10 |
encoding, |
| 11 |
pycompat, |
| 12 |
revlog, |
| 13 |
) |
| 14 |
from mercurial.utils import procutil |
| 15 |
|
| 16 |
from mercurial.revlogutils import ( |
| 17 |
constants as revlog_constants, |
| 18 |
) |
| 19 |
|
| 20 |
BASE = b'/' |
| 21 |
if pycompat.iswindows: |
| 22 |
# use os.path.splitroot once we drop support for Python 3.11 |
| 23 |
pieces = os.path.splitdrive(os.getcwdb()) |
| 24 |
BASE = pieces[0] + pieces[1][0:1] |
| 25 |
|
| 26 |
|
| 27 |
for fp in (sys.stdin, sys.stdout, sys.stderr): |
| 28 |
procutil.setbinary(fp) |
| 29 |
|
| 30 |
|
| 31 |
def binopen(path, mode=b'rb'): |
| 32 |
if b'b' not in mode: |
| 33 |
mode = mode + b'b' |
| 34 |
if not os.path.isabs(path): |
| 35 |
path = BASE + path |
| 36 |
return open(path, pycompat.sysstr(mode)) |
| 37 |
|
| 38 |
|
| 39 |
binopen.options = {} |
| 40 |
binopen.filter_name = None |
| 41 |
if pycompat.iswindows: |
| 42 |
binopen.base = os.path.splitdrive(os.getcwdb())[0] |
| 43 |
else: |
| 44 |
binopen.base = b"/" |
| 45 |
binopen.read_write = False |
| 46 |
|
| 47 |
|
| 48 |
def printb(data, end=b'\n'): |
| 49 |
sys.stdout.flush() |
| 50 |
procutil.stdout.write(data + end) |
| 51 |
|
| 52 |
|
| 53 |
for f in sys.argv[1:]: |
| 54 |
absstr = os.path.abspath(f) |
| 55 |
abslocal = encoding.strtolocal(absstr) |
| 56 |
localf = os.path.relpath(abslocal, BASE) |
| 57 |
if not localf.endswith(b'.i'): |
| 58 |
print("file:", f, file=sys.stderr) |
| 59 |
print(" invalid filename", file=sys.stderr) |
| 60 |
|
| 61 |
r = revlog.revlog( |
| 62 |
binopen, |
| 63 |
target=(revlog_constants.KIND_OTHER, b'dump-revlog'), |
| 64 |
radix=localf[:-2], |
| 65 |
) |
| 66 |
print("file:", f) |
| 67 |
for i in r: |
| 68 |
n = r.node(i) |
| 69 |
p = r.parents(n) |
| 70 |
d = r.revision(n) |
| 71 |
printb(b"node: %s" % hex(n)) |
| 72 |
printb(b"linkrev: %d" % r.linkrev(i)) |
| 73 |
printb(b"parents: %s %s" % (hex(p[0]), hex(p[1]))) |
| 74 |
printb(b"length: %d" % len(d)) |
| 75 |
printb(b"-start-") |
| 76 |
printb(d) |
| 77 |
printb(b"-end-") |