import svndump.dumpfile as dumpfile
from svndump.record import *
def sort_key(record):
if (
NodeRecord.NODE_ACTION in record.headers
and record.headers[NodeRecord.NODE_ACTION] == "delete"
):
return 0
return 1
def dump(revision: int, writer, records):
if revision:
records = sorted(records, key=sort_key)
if revision == 10661:
for record in records:
print(f" Node action is {record.headers[NodeRecord.NODE_ACTION]}")
print(f" Node path is {record.headers[NodeRecord.NODE_PATH_HEADER]}")
for record in records:
writer.write(record)
if __name__ == "__main__":
reader = dumpfile.DumpFileReader("D:/p4c/In.dmp", codec="utf-8")
writer = dumpfile.DumpFileWriter("D:/p4c/Out.dmp", codec="utf-8")
i = 0
revision = None
revision_records = []
for record in reader:
if isinstance(record, RevisionRecord):
dump(revision, writer, revision_records)
print(
f"Revision is {record.headers[RevisionRecord.REVISION_NUMBER_HEADER]}"
)
revision = int(record.headers[RevisionRecord.REVISION_NUMBER_HEADER])
revision_records = []
writer.write(record)
else:
revision_records.append(record)
dump(revision, writer, revision_records)