Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/cvs/cvs2gitdump/cvs2gitdump.py
Show All 24 Lines | |||||
# | # | ||||
# Periodic import: | # Periodic import: | ||||
# % sudo cvsync | # % sudo cvsync | ||||
# % python cvs2gitdump.py -k OpenBSD -e openbsd.org /cvs/openbsd/src \ | # % python cvs2gitdump.py -k OpenBSD -e openbsd.org /cvs/openbsd/src \ | ||||
# /git/openbsd.git > openbsd2.dump | # /git/openbsd.git > openbsd2.dump | ||||
# % git --git-dir /git/openbsd.git fast-import < openbsd2.dump | # % git --git-dir /git/openbsd.git fast-import < openbsd2.dump | ||||
# | # | ||||
from collections import defaultdict | |||||
import copy | import copy | ||||
import getopt | import getopt | ||||
import os | import os | ||||
import re | import re | ||||
import subprocess | import subprocess | ||||
import sys | import sys | ||||
import time | import time | ||||
from typing import Dict, List, Optional, Tuple, TypeVar | from typing import Dict, List, Optional, Tuple, TypeVar | ||||
▲ Show 20 Lines • Show All 335 Lines • ▼ Show 20 Lines | def walk(self, module: Optional[str] =None) -> None: | ||||
if not f[-2:] == b',v': | if not f[-2:] == b',v': | ||||
continue | continue | ||||
self.parse_file(os.path.join(root, f)) | self.parse_file(os.path.join(root, f)) | ||||
for t, c in list(self.tags.items()): | for t, c in list(self.tags.items()): | ||||
c.tags.append(t) | c.tags.append(t) | ||||
def parse_file(self, path: str) -> None: | def parse_file(self, path: str) -> None: | ||||
rtags: Dict[str, List[str]] = dict() | rtags: Dict[str, List[str]] = defaultdict(list) | ||||
rcsfile = rcsparse.rcsfile(path) | rcsfile = rcsparse.rcsfile(path) | ||||
branches = {'1': 'HEAD', '1.1.1': 'VENDOR'} | branches = {'1': 'HEAD', '1.1.1': 'VENDOR'} | ||||
for k, v_ in list(rcsfile.symbols.items()): | for k, v_ in list(rcsfile.symbols.items()): | ||||
r = v_.split('.') | r = v_.split('.') | ||||
if len(r) == 3: | if len(r) == 3: | ||||
branches[v_] = 'VENDOR' | branches[v_] = 'VENDOR' | ||||
elif len(r) >= 3 and r[-2] == '0': | elif len(r) >= 3 and r[-2] == '0': | ||||
branches['.'.join(r[:-2] + r[-1:])] = k | branches['.'.join(r[:-2] + r[-1:])] = k | ||||
if len(r) == 2 and branches[r[0]] == 'HEAD': | elif len(r) == 2 and branches.get(r[0]) == 'HEAD': | ||||
if v_ not in rtags: | |||||
rtags[v_] = list() | |||||
rtags[v_].append(k) | rtags[v_].append(k) | ||||
revs: List[Tuple[str, Tuple[str, int, str, str, List[str], str, str]]] = list(rcsfile.revs.items()) | revs: List[Tuple[str, Tuple[str, int, str, str, List[str], str, str]]] = list(rcsfile.revs.items()) | ||||
# sort by revision descending to priorize 1.1.1.1 than 1.1 | # sort by revision descending to priorize 1.1.1.1 than 1.1 | ||||
revs.sort(key=lambda a: a[1][0], reverse=True) | revs.sort(key=lambda a: a[1][0], reverse=True) | ||||
# sort by time | # sort by time | ||||
revs.sort(key=lambda a: a[1][1]) | revs.sort(key=lambda a: a[1][1]) | ||||
novendor = False | novendor = False | ||||
Show All 9 Lines | def parse_file(self, path: str) -> None: | ||||
continue | continue | ||||
last_vendor_status = v[3] | last_vendor_status = v[3] | ||||
have_initial_revision = True | have_initial_revision = True | ||||
elif len(r) == 4 and r[0] == '1' and r[1] == '1' and r[2] == '1': | elif len(r) == 4 and r[0] == '1' and r[1] == '1' and r[2] == '1': | ||||
if novendor: | if novendor: | ||||
continue | continue | ||||
last_vendor_status = v[3] | last_vendor_status = v[3] | ||||
elif len(r) == 2: | elif len(r) == 2: | ||||
# ensure revision targets head branch | |||||
branches[r[0]] = 'HEAD' | |||||
if r[0] == '1' and r[1] == '1': | if r[0] == '1' and r[1] == '1': | ||||
if have_initial_revision: | if have_initial_revision: | ||||
continue | continue | ||||
if v[3] == 'dead': | if v[3] == 'dead': | ||||
continue | continue | ||||
have_initial_revision = True | have_initial_revision = True | ||||
elif r[0] == '1' and r[1] != '1': | elif r[0] == '1' and r[1] != '1': | ||||
novendor = True | novendor = True | ||||
▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines |