diff --git a/swh/loader/svn/loader.py b/swh/loader/svn/loader.py --- a/swh/loader/svn/loader.py +++ b/swh/loader/svn/loader.py @@ -456,7 +456,7 @@ False to stop. """ - data = None + if self.done: return False @@ -464,19 +464,18 @@ data = next(self.swh_revision_gen) self._load_status = "eventful" except StopIteration: - self.done = True + self.done = True # Stopping iteration self._visit_status = "full" - return False # Stopping iteration except Exception as e: # svn:external, hash divergence, i/o error... self.log.exception(e) - self.done = True + self.done = True # Stopping iteration self._visit_status = "partial" - return False # Stopping iteration - self._contents, self._skipped_contents, self._directories, rev = data - if rev: - self._last_revision = rev - self._revisions.append(rev) - return True # next svn revision + else: + self._contents, self._skipped_contents, self._directories, rev = data + if rev: + self._last_revision = rev + self._revisions.append(rev) + return not self.done def store_data(self): """We store the data accumulated in internal instance variable. If diff --git a/swh/loader/svn/ra.py b/swh/loader/svn/ra.py --- a/swh/loader/svn/ra.py +++ b/swh/loader/svn/ra.py @@ -11,6 +11,7 @@ import codecs import dataclasses +import logging import os import shutil import tempfile @@ -39,6 +40,8 @@ _eol_style = {"native": b"\n", "CRLF": b"\r\n", "LF": b"\n", "CR": b"\r"} +logger = logging.getLogger(__name__) + def _normalize_line_endings(lines: bytes, eol_style: str = "native") -> bytes: r"""Normalize line endings to unix (\\n), windows (\\r\\n) or mac (\\r). @@ -332,37 +335,26 @@ self.directory[self.path] = from_disk.Content.from_file(path=self.fullpath) -class BaseDirEditor: - """Base class implementation of dir editor. - - see :class:`DirEditor` for an implementation that hashes every - directory encountered. - - Instantiate a new class inheriting from this class and define the following - functions:: - - def update_checksum(self): - # Compute the checksums at current state - - def open_directory(self, *args): - # Update an existing folder. +class DirEditor: + """Directory Editor in charge of updating directory hashes computation. - def add_directory(self, *args): - # Add a new one. + This implementation includes empty folder in the hash computation. """ - __slots__ = ["directory", "rootpath", "svnrepo"] + __slots__ = ["directory", "rootpath", "path", "file_states", "svnrepo"] def __init__( self, directory: from_disk.Directory, rootpath: bytes, + path: bytes, file_states: Dict[bytes, FileState], svnrepo: SvnRepo, ): self.directory = directory self.rootpath = rootpath + self.path = path # build directory on init os.makedirs(rootpath, exist_ok=True) self.file_states = file_states @@ -400,14 +392,42 @@ if state_path.startswith(fullpath + b"/"): del self.file_states[state_path] - def update_checksum(self): - raise NotImplementedError("This should be implemented.") + def update_checksum(self) -> None: + """Update the root path self.path's checksums according to the + children's objects. - def open_directory(self, *args): - raise NotImplementedError("This should be implemented.") + This function is expected to be called when the folder has + been completely 'walked'. - def add_directory(self, path: str, *args): - raise NotImplementedError("This should be implemented.") + """ + pass + + def open_directory(self, path: str, *args) -> DirEditor: + """Updating existing directory. + + """ + return DirEditor( + self.directory, + rootpath=self.rootpath, + path=os.fsencode(path), + file_states=self.file_states, + svnrepo=self.svnrepo, + ) + + def add_directory(self, path: str, *args) -> DirEditor: + """Adding a new directory. + + """ + path_bytes = os.fsencode(path) + os.makedirs(os.path.join(self.rootpath, path_bytes), exist_ok=True) + self.directory[path_bytes] = from_disk.Directory() + return DirEditor( + self.directory, + rootpath=self.rootpath, + path=path_bytes, + file_states=self.file_states, + svnrepo=self.svnrepo, + ) def open_file(self, *args) -> FileEditor: """Updating existing file. @@ -445,6 +465,12 @@ """ if key == properties.PROP_EXTERNALS: + logger.debug( + "Setting '%s' property with value '%s' on path %s", + key, + value, + self.path, + ) raise ValueError("Property '%s' detected. Not implemented yet." % key) def delete_entry(self, path: str, revision: int) -> None: @@ -462,39 +488,6 @@ self.update_checksum() -class DirEditor(BaseDirEditor): - """Directory Editor in charge of updating directory hashes computation. - - This implementation includes empty folder in the hash computation. - - """ - - def update_checksum(self) -> None: - """Update the root path self.path's checksums according to the - children's objects. - - This function is expected to be called when the folder has - been completely 'walked'. - - """ - pass - - def open_directory(self, *args) -> DirEditor: - """Updating existing directory. - - """ - return self - - def add_directory(self, path: str, *args) -> DirEditor: - """Adding a new directory. - - """ - path_bytes = os.fsencode(path) - os.makedirs(os.path.join(self.rootpath, path_bytes), exist_ok=True) - self.directory[path_bytes] = from_disk.Directory() - return self - - class Editor: """Editor in charge of replaying svn events and computing objects along. @@ -526,6 +519,7 @@ return DirEditor( self.directory, rootpath=self.rootpath, + path=b"", file_states=self.file_states, svnrepo=self.svnrepo, )