Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/cvs/rlog.py
Show All 40 Lines | |||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
import calendar | import calendar | ||||
from collections import defaultdict | from collections import defaultdict | ||||
import logging | |||||
import re | import re | ||||
import string | import string | ||||
import time | import time | ||||
from typing import BinaryIO, Dict, List, NamedTuple, Optional, Tuple | from typing import BinaryIO, Dict, List, NamedTuple, Optional, Tuple | ||||
from swh.loader.cvs.cvs2gitdump.cvs2gitdump import ChangeSetKey | from swh.loader.cvs.cvs2gitdump.cvs2gitdump import ChangeSetKey | ||||
logger = logging.getLogger(__name__) | |||||
class revtuple(NamedTuple): | class revtuple(NamedTuple): | ||||
number: str | number: str | ||||
date: int | date: int | ||||
author: bytes | author: bytes | ||||
state: str | state: str | ||||
branches: None | branches: None | ||||
revnumstr: None | revnumstr: None | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | def parse_rlog(self, fp: BinaryIO) -> None: | ||||
while eof != _EOF_LOG and eof != _EOF_ERROR: | while eof != _EOF_LOG and eof != _EOF_ERROR: | ||||
filename, branch, taginfo, lockinfo, errmsg, eof = _parse_log_header(fp) | filename, branch, taginfo, lockinfo, errmsg, eof = _parse_log_header(fp) | ||||
revisions: Dict[str, revtuple] = {} | revisions: Dict[str, revtuple] = {} | ||||
logmsgs: Dict[str, Optional[bytes]] = {} | logmsgs: Dict[str, Optional[bytes]] = {} | ||||
path = b"" | path = b"" | ||||
if filename: | if filename: | ||||
path = filename | path = filename | ||||
elif not eof: | elif not eof: | ||||
raise ValueError("No filename found in rlog header") | logger.warning( | ||||
"No filename found in rlog header, skipping associated entry" | |||||
) | |||||
while not eof: | while not eof: | ||||
off = fp.tell() | off = fp.tell() | ||||
rev, logmsg, eof = _parse_log_entry(fp) | rev, logmsg, eof = _parse_log_entry(fp) | ||||
if rev: | if rev: | ||||
revisions[rev[0]] = rev | revisions[rev[0]] = rev | ||||
logmsgs[rev[0]] = logmsg | logmsgs[rev[0]] = logmsg | ||||
if eof != _EOF_LOG and eof != _EOF_ERROR: | if eof != _EOF_LOG and eof != _EOF_ERROR: | ||||
if path not in self.offsets.keys(): | if path not in self.offsets.keys(): | ||||
self.offsets[path] = dict() | self.offsets[path] = dict() | ||||
if rev: | if rev: | ||||
self.offsets[path][rev[0]] = off | self.offsets[path][rev[0]] = off | ||||
if path: | |||||
self._process_rlog_revisions(path, taginfo, revisions, logmsgs) | self._process_rlog_revisions(path, taginfo, revisions, logmsgs) | ||||
def getlog(self, fp: BinaryIO, path: bytes, rev: str) -> Optional[bytes]: | def getlog(self, fp: BinaryIO, path: bytes, rev: str) -> Optional[bytes]: | ||||
off = self.offsets[path][rev] | off = self.offsets[path][rev] | ||||
fp.seek(off) | fp.seek(off) | ||||
_rev, logmsg, eof = _parse_log_entry(fp) | _rev, logmsg, eof = _parse_log_entry(fp) | ||||
return logmsg | return logmsg | ||||
▲ Show 20 Lines • Show All 257 Lines • Show Last 20 Lines |