diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c95e3d..f972cd9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,40 +1,40 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.3.0 hooks: - id: trailing-whitespace - id: check-json - id: check-yaml - - repo: https://gitlab.com/pycqa/flake8 - rev: 4.0.1 + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 hooks: - id: flake8 - additional_dependencies: [flake8-bugbear==22.3.23] + additional_dependencies: [flake8-bugbear==22.9.23] - repo: https://github.com/codespell-project/codespell - rev: v2.1.0 + rev: v2.2.2 hooks: - id: codespell name: Check source code spelling stages: [commit] - repo: local hooks: - id: mypy name: mypy entry: mypy args: [swh] pass_filenames: false language: system types: [python] - repo: https://github.com/PyCQA/isort rev: 5.10.1 hooks: - id: isort - repo: https://github.com/python/black - rev: 22.3.0 + rev: 22.10.0 hooks: - id: black diff --git a/PKG-INFO b/PKG-INFO index 8f03d16..5f2365e 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,57 +1,57 @@ Metadata-Version: 2.1 Name: swh.loader.svn -Version: 1.3.5 +Version: 1.3.6 Summary: Software Heritage Loader SVN Home-page: https://forge.softwareheritage.org/diffusion/DLDSVN Author: Software Heritage developers Author-email: swh-devel@inria.fr Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest Project-URL: Funding, https://www.softwareheritage.org/donate Project-URL: Source, https://forge.softwareheritage.org/source/swh-loader-svn Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-loader-svn/ Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Operating System :: OS Independent Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: testing License-File: LICENSE License-File: AUTHORS swh-loader-svn ============== The Software Heritage SVN Loader is a tool and a library to walk a remote svn repository and inject into the SWH dataset all contained files that weren't known before. The main entry points are - :class:`swh.loader.svn.loader.SvnLoader` for the main svn loader which ingests content out of a remote svn repository - :class:`swh.loader.svn.loader.SvnLoaderFromDumpArchive` which mounts a repository out of a svn dump prior to ingest it. - :class:`swh.loader.svn.loader.SvnLoaderFromRemoteDump` which mounts a repository with svnrdump prior to ingest its content. # CLI run With the configuration: /tmp/loader_svn.yml: ``` storage: cls: remote args: url: http://localhost:5002/ ``` Run: ``` swh loader --config-file /tmp/loader_svn.yml \ run svn ``` diff --git a/debian/changelog b/debian/changelog index 3c3e2b8..63c1b01 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,860 +1,862 @@ -swh-loader-svn (1.3.5-1~swh1~bpo10+1) buster-swh; urgency=medium +swh-loader-svn (1.3.6-1~swh1) unstable-swh; urgency=medium - * Rebuild for buster-swh + * New upstream release 1.3.6 - (tagged by Antoine Lambert + on 2022-10-19 11:07:45 +0200) + * Upstream changes: - version 1.3.6 - -- Software Heritage autobuilder (on jenkins-debian1) Sat, 01 Oct 2022 01:42:50 +0000 + -- Software Heritage autobuilder (on jenkins-debian1) Mon, 31 Oct 2022 14:24:44 +0000 swh-loader-svn (1.3.5-1~swh1) unstable-swh; urgency=medium * New upstream release 1.3.5 - (tagged by Antoine Lambert on 2022-09-30 14:45:26 +0200) * Upstream changes: - version 1.3.5 -- Software Heritage autobuilder (on jenkins-debian1) Sat, 01 Oct 2022 01:41:06 +0000 swh-loader-svn (1.3.4-1~swh1) unstable-swh; urgency=medium * New upstream release 1.3.4 - (tagged by Antoine Lambert on 2022-09-15 17:04:40 +0200) * Upstream changes: - version 1.3.4 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 15 Sep 2022 15:11:30 +0000 swh-loader-svn (1.3.3-1~swh1) unstable-swh; urgency=medium * New upstream release 1.3.3 - (tagged by Antoine Lambert on 2022-06-01 11:49:17 +0200) * Upstream changes: - version 1.3.3 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 01 Jun 2022 09:55:53 +0000 swh-loader-svn (1.3.2-1~swh1) unstable-swh; urgency=medium * New upstream release 1.3.2 - (tagged by Antoine Lambert on 2022-04-29 12:06:51 +0200) * Upstream changes: - version 1.3.2 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 29 Apr 2022 10:11:07 +0000 swh-loader-svn (1.3.1-1~swh1) unstable-swh; urgency=medium * New upstream release 1.3.1 - (tagged by Antoine Lambert on 2022-04-21 15:24:00 +0200) * Upstream changes: - version 1.3.1 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 21 Apr 2022 13:27:38 +0000 swh-loader-svn (1.3.0-1~swh1) unstable-swh; urgency=medium * New upstream release 1.3.0 - (tagged by Antoine Lambert on 2022-03-24 13:30:17 +0100) * Upstream changes: - version 1.3.0 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 24 Mar 2022 12:34:14 +0000 swh-loader-svn (1.2.1-1~swh1) unstable-swh; urgency=medium * New upstream release 1.2.1 - (tagged by Antoine Lambert on 2022-03-09 13:57:18 +0100) * Upstream changes: - version 1.2.1 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 09 Mar 2022 13:00:41 +0000 swh-loader-svn (1.2.0-1~swh2) unstable-swh; urgency=medium * Bump new release -- Antoine R. Dumont (@ardumont) Thu, 17 Feb 2022 12:46:20 +0100 swh-loader-svn (1.2.0-1~swh1) unstable-swh; urgency=medium * New upstream release 1.2.0 - (tagged by Antoine Lambert on 2022-02-11 17:19:45 +0100) * Upstream changes: - version 1.2.0 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 11 Feb 2022 16:23:08 +0000 swh-loader-svn (1.1.1-1~swh1) unstable-swh; urgency=medium * New upstream release 1.1.1 - (tagged by Antoine Lambert on 2022-01-28 11:42:12 +0100) * Upstream changes: - version 1.1.1 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 28 Jan 2022 10:44:57 +0000 swh-loader-svn (1.1.0-1~swh1) unstable-swh; urgency=medium * New upstream release 1.1.0 - (tagged by Antoine Lambert on 2022-01-24 17:57:36 +0100) * Upstream changes: - version 1.1.0 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 24 Jan 2022 17:01:15 +0000 swh-loader-svn (1.0.0-1~swh1) unstable-swh; urgency=medium * New upstream release 1.0.0 - (tagged by Antoine Lambert on 2022-01-19 16:51:43 +0100) * Upstream changes: - version 1.0.0 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 19 Jan 2022 15:54:56 +0000 swh-loader-svn (0.10.2-1~swh1) unstable-swh; urgency=medium * New upstream release 0.10.2 - (tagged by Antoine Lambert on 2021-11-29 14:36:35 +0100) * Upstream changes: - version 0.10.2 -- Software Heritage autobuilder (on jenkins-debian1) Mon, 29 Nov 2021 13:40:41 +0000 swh-loader-svn (0.10.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.10.1 - (tagged by Antoine Lambert on 2021-11-25 15:20:27 +0100) * Upstream changes: - version 0.10.1 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 25 Nov 2021 14:26:34 +0000 swh-loader-svn (0.10.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.10.0 - (tagged by Antoine Lambert on 2021-11-19 11:58:43 +0100) * Upstream changes: - version 0.10.0 -- Software Heritage autobuilder (on jenkins-debian1) Fri, 19 Nov 2021 11:03:18 +0000 swh-loader-svn (0.9.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.9.1 - (tagged by Antoine R. Dumont (@ardumont) on 2021-11-18 14:19:23 +0100) * Upstream changes: - v0.9.1 - ra: Prevent erroneous removing of file state -- Software Heritage autobuilder (on jenkins-debian1) Thu, 18 Nov 2021 13:22:06 +0000 swh-loader-svn (0.9.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.9.0 - (tagged by Antoine Lambert on 2021-11-17 15:11:56 +0100) * Upstream changes: - version 0.9.0 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 17 Nov 2021 14:14:34 +0000 swh-loader-svn (0.8.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.8.0 - (tagged by Antoine R. Dumont (@ardumont) on 2021-11-09 12:25:09 +0100) * Upstream changes: - v0.8.0 - SvnLoaderFromRemoteDump: Drop dump when svn repository is mounted - loader: Let log statement do the formatting - svn: Modify default loader to use the same as production task -- Software Heritage autobuilder (on jenkins-debian1) Tue, 09 Nov 2021 11:27:49 +0000 swh-loader-svn (0.7.3-1~swh1) unstable-swh; urgency=medium * New upstream release 0.7.3 - (tagged by Antoine R. Dumont (@ardumont) on 2021-11-08 17:29:05 +0100) * Upstream changes: - v0.7.3 - loader: Implement post_load to check for revision divergence - ra: Fix export of non link file with svn:special property set - loader: Fix error when first revision number is not one - loader: Perform a complete reloading when detecting altered history - ra: Handle invalid values for svn:eol-style property - ra: Handle unsetting svn:special property on svn links - ra: Do not process end of lines for svn links - ra: Fix edge case in svn:eol-style property handling - loader: Rename start_from_scratch parameter to incremental - loader: Let logging instructions do the formatting - loader: Fix SvnLoaderFromDumpArchive and add test - Remove reference to deprecated swh.model.identifiers module -- Software Heritage autobuilder (on jenkins-debian1) Mon, 08 Nov 2021 16:32:19 +0000 swh-loader-svn (0.7.2-1~swh1) unstable-swh; urgency=medium * New upstream release 0.7.2 - (tagged by Antoine R. Dumont (@ardumont) on 2021-09-30 10:07:44 +0200) * Upstream changes: - v0.7.2 - SvnLoaderFromRemoteDump: Fix failed visit which should be an uneventful visit - svn: Capture svnrdump failure as not_found instead of failed - mypy: Fix errors with release >= v0.900 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 30 Sep 2021 08:10:27 +0000 swh-loader-svn (0.7.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.7.1 - (tagged by Antoine Lambert on 2021-04-29 14:31:33 +0200) * Upstream changes: - version 0.7.1 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 29 Apr 2021 12:34:51 +0000 swh-loader-svn (0.7.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.7.0 - (tagged by Antoine R. Dumont (@ardumont) on 2021-02-17 18:19:35 +0100) * Upstream changes: - v0.7.0 - loader: Expect visit_date as an optional date in constructors - Rework loader instantiation logic according to loader core api -- Software Heritage autobuilder (on jenkins-debian1) Wed, 17 Feb 2021 17:23:16 +0000 swh-loader-svn (0.6.0-1~swh2) unstable-swh; urgency=medium * Update dependencies -- Antoine R. Dumont (@ardumont) Fri, 12 Feb 2021 18:05:59 +0100 swh-loader-svn (0.6.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.6.0 - (tagged by Antoine R. Dumont (@ardumont) on 2021-02-12 17:31:53 +0100) * Upstream changes: - v0.6.0 - svn.loader: Mark visit status as not_found when relevant - svn.loader: Mark visit status as failed - Drop the retrying dependency - tox.ini: pin black to the pre-commit version (19.10b0) to avoid flip-flops -- Software Heritage autobuilder (on jenkins-debian1) Fri, 12 Feb 2021 16:33:45 +0000 swh-loader-svn (0.5.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.5.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-10-02 14:16:50 +0200) * Upstream changes: - v0.5.0 - svn.loader: Migrate away from SWHConfig mixin - tests: Don't check the number of created 'person' objects - python: Reorder imports with isort - pre- commit: Add isort hook and configuration - pre-commit: Update flake8 hook configuration -- Software Heritage autobuilder (on jenkins-debian1) Fri, 02 Oct 2020 12:17:49 +0000 swh-loader-svn (0.4.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.4.1 - (tagged by Antoine Lambert on 2020-09-08 17:48:55 +0200) * Upstream changes: - version 0.4.1 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 08 Sep 2020 15:53:11 +0000 swh-loader-svn (0.4.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.4.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-09-04 14:05:14 +0200) * Upstream changes: - v0.4.0 - Adapt storage.revision_get calls according to latest api change - Tell pytest not to recurse in dotdirs. -- Software Heritage autobuilder (on jenkins-debian1) Fri, 04 Sep 2020 12:07:00 +0000 swh-loader-svn (0.3.3-1~swh1) unstable-swh; urgency=medium * New upstream release 0.3.3 - (tagged by Antoine R. Dumont (@ardumont) on 2020-08-24 16:00:11 +0200) * Upstream changes: - v0.3.3 - svn.loader: Simplify and align incremental visit algorithm -- Software Heritage autobuilder (on jenkins-debian1) Mon, 24 Aug 2020 14:01:22 +0000 swh-loader-svn (0.3.2-1~swh1) unstable-swh; urgency=medium * New upstream release 0.3.2 - (tagged by Antoine R. Dumont (@ardumont) on 2020-07-28 08:07:12 +0200) * Upstream changes: - v0.3.2 - Migrate to setuptools-scm - Add missing conftest.py in MANIFEST.in -- Software Heritage autobuilder (on jenkins-debian1) Tue, 28 Jul 2020 06:09:53 +0000 swh-loader-svn (0.3.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.3.1 - (tagged by Antoine R. Dumont (@ardumont) on 2020-07-28 07:50:03 +0200) * Upstream changes: - v0.3.1 - loader: Update swh.storage.origin_get call to latest api change - tests: Reuse pytest fixtures from swh.loader.core - tests: Check against snapshot model object - svn.loader: Drop `build_swh_snapshot` function, oneliner used once - Fix branches types in tests - Clean up the swh.scheduler / swh.storage pytest plugin imports -- Software Heritage autobuilder (on jenkins-debian1) Tue, 28 Jul 2020 05:52:35 +0000 swh-loader-svn (0.3.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.3.0 - (tagged by David Douard on 2020-07-08 17:18:02 +0200) * Upstream changes: - v0.3.0 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 08 Jul 2020 15:22:12 +0000 swh-loader-svn (0.2.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.2.1 - (tagged by Antoine R. Dumont (@ardumont) on 2020-07-03 15:17:44 +0200) * Upstream changes: - v0.2.1 - svn.loader: Fix uneventful visit case - svn.loader: Fix edge case on mistyped snapshot - tests: Refactor to use pytest - Reuse swh.model.from_disk.iter_directory function - Migrate to Use the object's object_type field when computing objects -- Software Heritage autobuilder (on jenkins-debian1) Fri, 03 Jul 2020 13:20:20 +0000 swh-loader-svn (0.2.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.2.0 - (tagged by Antoine R. Dumont (@ardumont) on 2020-06-23 15:25:21 +0200) * Upstream changes: - v0.2.0 - loader: Read snapshot out of the last origin visit status - tests: Refactor tests to use assert_last_visit_matches -- Software Heritage autobuilder (on jenkins-debian1) Tue, 23 Jun 2020 13:26:50 +0000 swh-loader-svn (0.1.2-1~swh1) unstable-swh; urgency=medium * New upstream release 0.1.2 - (tagged by Antoine R. Dumont (@ardumont) on 2020-06-09 11:03:56 +0200) * Upstream changes: - v0.1.2 - test_loader: assert returned loader status is what we expect - Adapt to swh.model 0.3 -- Software Heritage autobuilder (on jenkins-debian1) Tue, 09 Jun 2020 09:06:01 +0000 swh-loader-svn (0.1.1-1~swh3) unstable-swh; urgency=medium * Enable build for python3.8 (Debian ships a patched subvertpy.) -- Nicolas Dandrimont Wed, 03 Jun 2020 16:27:53 +0200 swh-loader-svn (0.1.1-1~swh2) unstable-swh; urgency=medium * Force removing __init__.py files. -- Nicolas Dandrimont Wed, 03 Jun 2020 16:13:31 +0200 swh-loader-svn (0.1.1-1~swh1) unstable-swh; urgency=medium * New upstream release 0.1.1 - (tagged by Antoine Lambert on 2020-06-03 11:49:31 +0200) * Upstream changes: - version 0.1.1 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 03 Jun 2020 09:53:23 +0000 swh-loader-svn (0.1.0-1~swh1) unstable-swh; urgency=medium * New upstream release 0.1.0 - (tagged by Nicolas Dandrimont on 2020-06-02 18:54:30 +0200) * Upstream changes: - Release swh.loader.svn v0.1.0 - Blacken all files - Fix compatibility with swh.loader.core v0.1.0 - Fix parameter ordering for loader tasks -- Software Heritage autobuilder (on jenkins-debian1) Tue, 02 Jun 2020 16:58:55 +0000 swh-loader-svn (0.0.54-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.54 - (tagged by Antoine R. Dumont (@ardumont) on 2020-03-27 07:52:30 +0100) * Upstream changes: - v0.0.54 - svn.loader: Let core loader update snapshot & visit at the same time - test_loader: Add missing assertions on visit status - Fix crash on None snapshot -- Software Heritage autobuilder (on jenkins-debian1) Fri, 27 Mar 2020 06:57:15 +0000 swh-loader-svn (0.0.53-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.53 - (tagged by Antoine R. Dumont (@ardumont) on 2020-03-16 13:38:29 +0100) * Upstream changes: - v0.0.53 - Migrate to latest swh-loader- core api change - Move Person parsing to swh-model. -- Software Heritage autobuilder (on jenkins-debian1) Mon, 16 Mar 2020 12:41:14 +0000 swh-loader-svn (0.0.52-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.52 - (tagged by Antoine R. Dumont (@ardumont) on 2020-03-02 15:39:28 +0100) * Upstream changes: - v0.0.52 - loader.svn: Use swh.model objects within the loader - tox.ini: Add debugging dev tool in dedicated environment - converters: Clean up some more dead code - converters: Clean up dead code -- Software Heritage autobuilder (on jenkins-debian1) Mon, 02 Mar 2020 14:42:36 +0000 swh-loader-svn (0.0.51-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.51 - (tagged by Nicolas Dandrimont on 2020-02-19 20:01:31 +0100) * Upstream changes: - Release swh.loader.svn v0.0.51 - Ensure snapshots are properly linked by origin_visits - Update tests for swh.storage v0.0.174 -- Software Heritage autobuilder (on jenkins-debian1) Wed, 19 Feb 2020 19:20:03 +0000 swh-loader-svn (0.0.50-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.50 - (tagged by Antoine R. Dumont (@ardumont) on 2020-02-06 18:45:10 +0100) * Upstream changes: - v0.0.50 - loader.svn: Call storage's (skipped_)content_add endpoints - Fix sphinx warnings -- Software Heritage autobuilder (on jenkins-debian1) Thu, 06 Feb 2020 17:57:08 +0000 swh-loader-svn (0.0.49-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.49 - (tagged by Antoine R. Dumont (@ardumont) on 2020-01-15 15:59:52 +0100) * Upstream changes: - v0.0.49 - svn.loader: Adapt according to latest loader-core simplification -- Software Heritage autobuilder (on jenkins-debian1) Wed, 15 Jan 2020 15:03:50 +0000 swh-loader-svn (0.0.48-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.48 - (tagged by Antoine R. Dumont (@ardumont) on 2019-12-12 14:14:12 +0100) * Upstream changes: - v0.0.48 - svn.loader: Migrate to new buffer/filter behavior -- Software Heritage autobuilder (on jenkins-debian1) Thu, 12 Dec 2019 13:17:31 +0000 swh-loader-svn (0.0.47-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.47 - (tagged by Antoine R. Dumont (@ardumont) on 2019-12-12 11:18:45 +0100) * Upstream changes: - v0.0.47 - tasks: Enforce kwargs use in task message -- Software Heritage autobuilder (on jenkins-debian1) Thu, 12 Dec 2019 10:21:55 +0000 swh-loader-svn (0.0.46-1~swh2) unstable-swh; urgency=medium * Fix build for python3.7 only -- Antoine R. Dumont (@ardumont) Sat, 16 Feb 2019 02:43:37 +0100 swh-loader-svn (0.0.46-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.46 - (tagged by Antoine R. Dumont (@ardumont) on 2019-12-10 10:30:35 +0100) * Upstream changes: - v0.0.46 - tests: Migrate to use pytest- mock's mocker fixture - tasks: Use celery's shared_task decorator - loader.svn: Register svn worker - svn.tasks: Rename tasks according to production's - tasks: Adapt tasks according to the constructor unification - svn: Unify loader constructor with url as parameter - Fix a typo reported by codespell - Add a pre-commit config file - Migrate tox.ini to extras = xxx instead of deps = .[testing] - De-specify testenv:py3 - Include all requirements in MANIFEST.in -- Software Heritage autobuilder (on jenkins-debian1) Tue, 10 Dec 2019 09:38:45 +0000 swh-loader-svn (0.0.45-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.45 - (tagged by Stefano Zacchiroli on 2019-10-10 14:43:18 +0200) * Upstream changes: - v0.0.45 - * typing: minimal changes to make a no-op mypy run pass - * tox.ini: Fix py3 environment to use packaged tests - * Add attribute visit_type. - * Fix warning about pytest.mark.fs. - * add code of conduct document - * CONTRIBUTORS: add Ishan Bhanuka - * Remove unnecessary noqa - * Update dependency on swh-storage. - * Update argument name. - * Use origin urls instead of origin ids. - * update requirements - * Update coverage gitignore - * SvnLoaderFromRemoteDump: Add some debug output when svnrdump is running - * Remove debian packaging from master branch -- Software Heritage autobuilder (on jenkins-debian1) Thu, 10 Oct 2019 12:46:37 +0000 swh-loader-svn (0.0.44-1~swh3) unstable-swh; urgency=low * New upstream release (fixing the distribution) -- Antoine Romain Dumont Sat, 16 Feb 2019 02:43:37 +0100 swh-loader-svn (0.0.44-1~swh2) unstable; urgency=low * New upstream release to fix debian packaging -- Antoine Romain Dumont Sat, 16 Feb 2019 02:19:27 +0100 swh-loader-svn (0.0.44-1~swh1) unstable-swh; urgency=medium * New upstream release 0.0.44 - (tagged by David Douard on 2019-02-07 17:35:43 +0100) * Upstream changes: - v0.0.44 -- Software Heritage autobuilder (on jenkins-debian1) Thu, 07 Feb 2019 16:41:45 +0000 swh-loader-svn (0.0.42-1~swh1) unstable-swh; urgency=medium * v0.0.43 * loader: Rename default branch as HEAD * svn.tests: Refactor using loader-core mixins * setup: prepare for pypi upload * Add requirements-test.txt * docs: add title and brief module description -- Antoine R. Dumont (@ardumont) Thu, 11 Oct 2018 14:52:54 +0200 swh-loader-svn (0.0.41-1~swh1) unstable-swh; urgency=medium * v0.0.41 * Fix UnicodeDecodeError when decoding user-defined svn properties * preventing the origin ingestion to finish (T946) * Fix CR/LF issue preventing the origin ingestion to finish (T570) * svn.loader: Add more efficient loader based on remote dumps * svn.loader: Refactoring (align loader with other, name conventions, * improve maintenance, simplify some code, etc...) -- Antoine R. Dumont (@ardumont) Fri, 28 Sep 2018 12:16:31 +0200 swh-loader-svn (0.0.40-1~swh1) unstable-swh; urgency=medium * v0.0.40 * svn/loader: Remove wrong parameter name in dangling clean up call * svn/loader: Refactor: Reuse loader.core.utils.clean_dangling_folders * svn/tasks: Explicit tasks' arguments * svn/loader: Add pre-cleanup step to clean potential dangling folders * d/control: Bump to latest python3-swh.loader.core -- Antoine R. Dumont (@ardumont) Fri, 09 Mar 2018 14:51:09 +0100 swh-loader-svn (0.0.39-1~swh1) unstable-swh; urgency=medium * v0.0.39 * Improve origin_visit initialization step * Properly sandbox the prepare statement so that if it breaks, we can * update appropriately the visit with the correct status -- Antoine R. Dumont (@ardumont) Wed, 07 Mar 2018 11:31:34 +0100 swh-loader-svn (0.0.38-1~swh1) unstable-swh; urgency=medium * v0.0.38 * In failure mode, try harder to make snapshot -- Antoine R. Dumont (@ardumont) Fri, 09 Feb 2018 14:13:30 +0100 swh-loader-svn (0.0.37-1~swh1) unstable-swh; urgency=medium * v0.0.37 * swh.loader.svn: Detect eol inconsistency and make the loading fail * swh.loader.svn: Reduce log verbosity * swh.loader.svn: Migrate exception to their specific module -- Antoine R. Dumont (@ardumont) Thu, 08 Feb 2018 17:57:15 +0100 swh-loader-svn (0.0.36-1~swh1) unstable-swh; urgency=medium * v0.0.36 * swh.loader.svn: Fix corner edge case on symbolic link * swh.loader.svn: Deal with empty svn repository edge case -- Antoine R. Dumont (@ardumont) Wed, 07 Feb 2018 12:36:45 +0100 swh-loader-svn (0.0.35-1~swh1) unstable-swh; urgency=medium * Release swh.loader.svn v0.0.35 * Update to use snapshots instead of occurrences * Properly return loader status to scheduler -- Nicolas Dandrimont Tue, 06 Feb 2018 14:40:28 +0100 swh-loader-svn (0.0.34-1~swh1) unstable-swh; urgency=medium * v0.0.34 * Unify temporary directory naming -- Antoine R. Dumont (@ardumont) Fri, 15 Dec 2017 12:26:50 +0100 swh-loader-svn (0.0.33-1~swh1) unstable-swh; urgency=medium * v0.0.33 * swh.loader.svn: Add option to load a repository from scratch * swh.loader.svn.loader: Fix special symlink case -- Antoine R. Dumont (@ardumont) Fri, 08 Dec 2017 17:38:37 +0100 swh-loader-svn (0.0.32-1~swh1) unstable-swh; urgency=medium * v0.0.32 * d/control: Bump dependency to latest swh-loader-core * tests: Add commits with wrong symbolic links (broken, empty space) * ra: Fix not cleaned up path leading to file exists error * docs: add absolute anchor to documentation index -- Antoine R. Dumont (@ardumont) Wed, 08 Nov 2017 13:22:42 +0100 swh-loader-svn (0.0.31-1~swh1) unstable-swh; urgency=medium * v0.0.31 * swh.loader.svn.ra: Fix blank space in symlink path split problem * swh.loader.svn.ra: Fix missing case about existing directory * swh.loader.svn.ra: Explicit the closure * swh.loader.svn: Deal with origin creation inhibition in base class * swh.loader.svn: Remove unneeded instruction * swh.loader.svn: Fix initializing the origin multiple times * swh.loader.svn: Remove unneeded except clause * swh.loader.svn: uneventful visit is not an error -- Antoine R. Dumont (@ardumont) Tue, 24 Oct 2017 16:35:01 +0200 swh-loader-svn (0.0.30-1~swh1) unstable-swh; urgency=medium * Release swh.loader.svn version 0.0.30 * Update packaging runes -- Nicolas Dandrimont Thu, 12 Oct 2017 18:07:58 +0200 swh-loader-svn (0.0.29-1~swh1) unstable-swh; urgency=medium * v0.0.29 * swh.loader.svn.loader: Fix missing revision id key (which can lead * to an empty partial visit for example in the case of a repository * holding an svn:externals property). -- Antoine R. Dumont (@ardumont) Mon, 09 Oct 2017 16:02:23 +0200 swh-loader-svn (0.0.28-1~swh1) unstable-swh; urgency=medium * Release swh.loader.svn v0.0.28 * Replace swh.model.git with swh.model.from_disk -- Nicolas Dandrimont Fri, 06 Oct 2017 17:18:57 +0200 swh-loader-svn (0.0.27-1~swh1) unstable-swh; urgency=medium * v0.0.27 * d/control: Bump dependency to latest swh.loader.core * swh.loader.svn: Add args to raised exception in edge cases * swh-hashtree: Fix no longer existing swh.core.hashutil import * docs/: add sphinx apidoc generation skeleton -- Antoine R. Dumont (@ardumont) Tue, 03 Oct 2017 19:01:26 +0200 swh-loader-svn (0.0.26-1~swh1) unstable-swh; urgency=medium * Release swh.loader.svn 0.0.26 * update tasks to new swh.scheduler API -- Nicolas Dandrimont Mon, 12 Jun 2017 18:25:40 +0200 swh-loader-svn (0.0.25-1~swh1) unstable-swh; urgency=medium * v0.0.25 * Add blake2s256 new hash computation on content * Use gzip instead of pigz * Migrate from swh.core.hashutil to swh.model.hashutil -- Antoine R. Dumont (@ardumont) Tue, 04 Apr 2017 14:18:57 +0200 swh-loader-svn (0.0.24-1~swh1) unstable-swh; urgency=medium * v0.0.24 * Simplify loader's logic -- Antoine R. Dumont (@ardumont) Wed, 22 Feb 2017 14:09:15 +0100 swh-loader-svn (0.0.23-1~swh1) unstable-swh; urgency=medium * Release swh.loader.svn v0.0.23 * Return timestamps as pairs of integers (Close T680) -- Nicolas Dandrimont Tue, 14 Feb 2017 19:40:27 +0100 swh-loader-svn (0.0.22-1~swh1) unstable-swh; urgency=medium * v0.0.22 * Pass optionally the visit date to producer -- Antoine R. Dumont (@ardumont) Tue, 10 Jan 2017 15:03:45 +0100 swh-loader-svn (0.0.21-1~swh1) unstable-swh; urgency=medium * v0.0.21 * Use the dump's fetch date as visit date -- Antoine R. Dumont (@ardumont) Tue, 10 Jan 2017 15:03:24 +0100 swh-loader-svn (0.0.20-1~swh1) unstable-swh; urgency=medium * v0.0.20 * Fix function call -- Antoine R. Dumont (@ardumont) Fri, 06 Jan 2017 15:38:14 +0100 swh-loader-svn (0.0.19-1~swh1) unstable-swh; urgency=medium * v0.0.19 * Rename task_queue adequately * Fix - Remove empty temporary directory in corner cases * Fix generator issue when using local storage -- Antoine R. Dumont (@ardumont) Fri, 06 Jan 2017 14:10:19 +0100 swh-loader-svn (0.0.18-1~swh1) unstable-swh; urgency=medium * v0.0.18 * Add check revision hash computation divergence during loading * Add task to load a svn repository from an archive dump and load the * repository * Raise error when svn:externals keyword is encountered (T610) since * it's not dealt with yet. * Revert modifications related to svn:eol-style since no good policy has * been found yet to deal with it -- Antoine R. Dumont (@ardumont) Thu, 15 Dec 2016 10:57:26 +0100 swh-loader-svn (0.0.17-1~swh1) unstable-swh; urgency=medium * v0.0.17 * Force eol conversion when needed -- Antoine R. Dumont (@ardumont) Thu, 08 Dec 2016 18:25:55 +0100 swh-loader-svn (0.0.16-1~swh1) unstable-swh; urgency=medium * v0.0.16 * Improve origin_visit policy -- Antoine R. Dumont (@ardumont) Fri, 26 Aug 2016 15:59:31 +0200 swh-loader-svn (0.0.15-1~swh1) unstable-swh; urgency=medium * v0.0.15 * Update svn loader to register origin_visit's state -- Antoine R. Dumont (@ardumont) Wed, 24 Aug 2016 14:56:54 +0200 swh-loader-svn (0.0.14-1~swh1) unstable-swh; urgency=medium * v0.0.14 * Update svn loader to register origin_visit's state -- Antoine R. Dumont (@ardumont) Tue, 23 Aug 2016 16:38:16 +0200 swh-loader-svn (0.0.13-1~swh1) unstable-swh; urgency=medium * v0.0.13 -- Antoine R. Dumont (@ardumont) Thu, 18 Aug 2016 10:30:13 +0200 swh-loader-svn (0.0.12-1~swh1) unstable-swh; urgency=medium * v0.0.12 * Inhibit keyword expansion during export phase (svn update) -- Antoine R. Dumont (@ardumont) Wed, 06 Jul 2016 16:17:51 +0200 swh-loader-svn (0.0.11-1~swh1) unstable-swh; urgency=medium * v0.0.11 * Reschedule when error on loading an svn repository * Start from last known revision * Permit to load local mirror with remote mirror origin -- Antoine R. Dumont (@ardumont) Fri, 01 Jul 2016 16:51:37 +0200 swh-loader-svn (0.0.10-1~swh1) unstable-swh; urgency=medium * v0.0.10 * Add retry policy around britle action (connection to remote svn server) -- Antoine R. Dumont (@ardumont) Sat, 25 Jun 2016 11:30:34 +0200 swh-loader-svn (0.0.9-1~swh1) unstable-swh; urgency=medium * v0.0.9 * Restrict loader to 2 possible policies: swh, git-svn * Improve coverage * Update README -- Antoine R. Dumont (@ardumont) Fri, 24 Jun 2016 13:56:54 +0200 swh-loader-svn (0.0.8-1~swh1) unstable-swh; urgency=medium * v0.0.8 * Use remote-access approach to hash and compute hashes from svn * repository (migrate major dependency from pysvn to subvertpy) -- Antoine R. Dumont (@ardumont) Sat, 11 Jun 2016 19:55:54 +0200 swh-loader-svn (0.0.7-1~swh1) unstable-swh; urgency=medium * v0.0.7 * d/control: Bump dependency version to latest swh-model -- Antoine R. Dumont (@ardumont) Thu, 26 May 2016 16:10:32 +0200 swh-loader-svn (0.0.6-1~swh1) unstable-swh; urgency=medium * v0.0.6 * d/control: Bump swh-model dependency * Simplify ignore folder corner cases * Rework log -- Antoine R. Dumont (@ardumont) Wed, 25 May 2016 23:53:10 +0200 swh-loader-svn (0.0.5-1~swh1) unstable-swh; urgency=medium * v0.0.5 * Add svn update behavior as option (default to True) * d/control: Bump dependency version to swh-loader-core -- Antoine R. Dumont (@ardumont) Wed, 25 May 2016 12:44:35 +0200 swh-loader-svn (0.0.4-1~swh1) unstable-swh; urgency=medium * v0.0.4 * Add options for git-svn like behavior (git svn clone --no- metadata) * Ignore empty folder * Add extra-line in svn commit message * No revision metadata (beware that this break the update repo * mechanism) * Also, use @ pattern for committer/author -- Antoine R. Dumont (@ardumont) Tue, 24 May 2016 17:04:40 +0200 swh-loader-svn (0.0.3-1~swh1) unstable-swh; urgency=medium * v0.0.3 * Improve filesystem cleanup (before: left empty directory) * Use pysvn to extract uuid information (before: subprocess with subversion call) * Keep the working copy's name on the local checkout -- Antoine R. Dumont (@ardumont) Fri, 15 Apr 2016 16:10:51 +0200 swh-loader-svn (0.0.2-1~swh1) unstable-swh; urgency=medium * v0.0.2 * Update to the right swh dependencies. -- Antoine R. Dumont (@ardumont) Fri, 15 Apr 2016 13:02:04 +0200 swh-loader-svn (0.0.1-1~swh1) unstable-swh; urgency=medium * Initial release * v0.0.1 -- Antoine R. Dumont (@ardumont) Wed, 13 Apr 2016 16:46:37 +0200 diff --git a/debian/control b/debian/control index 347cc65..3b9f90a 100644 --- a/debian/control +++ b/debian/control @@ -1,40 +1,40 @@ Source: swh-loader-svn Maintainer: Software Heritage developers Section: python Priority: optional Build-Depends: debhelper (>= 9), dh-python (>= 2), python3-all, python3-click, python3-dateutil, python3-pytest, python3-pytest-mock, python3-pytest-postgresql, python3-swh.core.db.pytestplugin, python3-setuptools, python3-setuptools-scm, python3-subvertpy (>= 0.9.4~), - python3-swh.core (>= 0.0.19~), - python3-swh.loader.core (>= 0.5.9~), - python3-swh.model (>= 0.4.0~), - python3-swh.scheduler (>= 0.0.39~), - python3-swh.storage (>= 0.11.3~), + python3-swh.core (>= 2.16.1~), + python3-swh.loader.core (>= 5.0.0~), + python3-swh.model (>= 6.6.0~), + python3-swh.scheduler (>= 1.2.3~), + python3-swh.storage (>= 1.6.0~), python3-tenacity, python3-typing-extensions (>= 3.7.4~), subversion Standards-Version: 3.9.6 Homepage: https://forge.softwareheritage.org/diffusion/DLDSVN/ Package: python3-swh.loader.svn Architecture: all Depends: gzip, - python3-swh.core (>= 0.0.19~), - python3-swh.loader.core (>= 0.5.9~), - python3-swh.model (>= 0.4.0~), + python3-swh.core (>= 2.16.1~), + python3-swh.loader.core (>= 5.0.0~), + python3-swh.model (>= 6.6.0~), python3-swh.scheduler (>= 0.0.39~), - python3-swh.storage (>= 0.11.3~), + python3-swh.storage (>= 1.6.0~), subversion, ${misc:Depends}, ${python3:Depends} Description: Software Heritage Loader Svn Module in charge of loading svn repositories into swh storage. diff --git a/docs/swh-loader-svn.txt b/docs/swh-loader-svn.txt index 2f56aaa..2240044 100644 --- a/docs/swh-loader-svn.txt +++ b/docs/swh-loader-svn.txt @@ -1,195 +1,195 @@ swh-loader-svn ============== The goal is to load a svn repository's lifetime logs to swh-storage. This must be able to deal with: - unknown svn repository (resulting in a new origin) - known svn repository (starting up from the last known svn revision and update from that moment on) For a full detailed comparison between version's speed, please refer to https://forge.softwareheritage.org/diffusion/DLDSVN/browse/master/docs/comparison-git-svn-swh-svn.org. # v1 ## Description This is a first basic implementation, a proof-of-concept of sort. Based on checkout-ing on disk the svn repository at each revision and walking the tree at svn revision to compute the swh hashes and store them in swh-storage. Conclusion: It is possible but it is slow. We use git-svn to check if the hash computations were a match, and they were not. The swh hashes computation are corrects though. It's just not the same assertions as git-svn so the hashes mismatch. git-svn: - does not checkout empty folders - adds metadata at the end of the svn commit message (by default, this can be avoided but then no update, in the swh sense, is possible afterwards) - integrates the svn repository's uuid in the git revision for the commit author (author@) swh-loader-svn: - checkouts empty folder (which are then used in swh hashes) - adds metadata the git way (leveraging git's extra-header slot), so that we can deal with svn repository updates ## Pseudo ``` Checkout/Update/Export on disk the first known revision or 1 if unknown repository When revision is not 1 Check the history is altered (revision hashes won't match) If it is altered, log an error message and stop Otherwise continue Iterate over logs from revision 1 to revision head_revision The revision is now rev checkout/update/export the revision at rev walk the tree directory for that revision and compute hashes compute the revision hash send the blobs for storage in swh send the directories for storage in swh send the revision for storage in swh done Send the occurrence pointing to the last revision seen ``` ## Notes SVN checkout/update instructions are faster than export since they leverage svn diffs. But: - they do keyword expansion (so bad for diffs with external tools so bad for swh) - we need to ignore .svn folder since it's present (this needed some adaptation in code to ignore folder based on pattern so slow as well) SVN export instruction is slower than the 2 previous ones since they don't use diffs. But: - there is one option to ignore keyword expansion (good) - no folder are to be omitted during hash computation from disk (good) All in all, there is a trade-off here to choose from. Still, everything was tested (with much code adapted in the lower level api) and both are slow. # v2 ## Description The v2 is more about: - adding options to match the git-svn's hash computations - trying to improve the performance So, options are added: - remove empty folder when encountered (to ignore during hash computations) - add an extra commit line to the svn commit message - (de)activate the loader svn's update routine - (de)activate the sending of contents/directories/revisions/occurrences/releases to swh-storage - (de)activate the extra-header metadata in revision hash (thus deactivating the svn update options altogether) As this is thought as genuine implementation, we adapted the revision message to also use the repository's uuid in the author's email. Also, optimization are done as well: -- instead of walking the disk from the top leve at each revision (slow +- instead of walking the disk from the top level at each revision (slow for huge repository like svn.apache.org), compute from the svn log's changed paths between the previous revision and the current one, the lowest common path. Then, walk only that path to compute the updated hashes. Then update from that path to the top level the in-memory hashes (less i/o, less RAM are used). - in the loader-core, lifting the existing swh-storage api to filter only the missing entities on the client side (there are already filters on the server side but filtering client-side uses less RAM. Especially for blobs, since we extract the data from disk and store it in RAM, this is now done only for unknown blobs and still before updating the disk with a new revision content) - in the loader-core, cache are added as well Now the computations, with the right options, are a match with git-svn. Still, the performance against git-svn are bad. Taking a closer look at git-svn, they used a remote-access approach, that is discussing directly with the svn server and computing at the same time the hashes. That is the base for the v3 implementation. ## Pseudo Relatively to the v1, the logic does not change, only the inner implementation. # v3 ## Description This one is about performance only. Leveraging another low-level library (subvertpy) to permit the use of the same git-svn approach, the remote-access. The idea is to replay the logs and diffs on disk and compute hashes closely in time (not as close as possible though, cf. ## Note below). ## Pseudo ``` Do we know the repository (with swh-svn-update option on)? Yes, extract the last swh known revision from swh-storage set start-rev to last-swh-known-revision Export on disk the svn at start-rev Compute revision hashes (from top level tree's hashes + commit log for that revision) Does the revision hash match the one in swh-storage? (<=> Is the history altered?) No log an error message and stop Yes keep the current in-memory hashes (for the following updates steps if any) No set start-rev to 1 Set head-revision to latest svn repository's head revision When start-rev is the same as head revision, we are done. Otherwise continue Iterate over the stream of svn-logs from start-rev to head-rev The current revision is rev replay the diffs from previous rev (rev - 1) to rev and compute hashes along compute the revision hash send the blobs for storage in swh send the directories for storage in swh send the revision for storage in swh done Send the occurrence pointing to the last revision seen ``` ## Note There could be margin for improvement in the actual implementation here. We apply the diff on files first and then open the file to compute its hashes afterwards. If we'd apply the diff and compute the hashes directly, we'd gain one round-trip. Depending on the ratio files/directory, this could be significant. This approach has also the following benefits: - no keyword expansion - no need to ignore .svn folder (since it does not exist) diff --git a/requirements-swh.txt b/requirements-swh.txt index 0bbf186..d9b6f87 100644 --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -1,4 +1,4 @@ swh.storage >= 0.11.3 -swh.model >= 4.3.0 +swh.model >= 6.6.0 swh.scheduler >= 0.0.39 -swh.loader.core >= 3.0.0 +swh.loader.core >= 5.0.0 diff --git a/swh.loader.svn.egg-info/PKG-INFO b/swh.loader.svn.egg-info/PKG-INFO index 8f03d16..5f2365e 100644 --- a/swh.loader.svn.egg-info/PKG-INFO +++ b/swh.loader.svn.egg-info/PKG-INFO @@ -1,57 +1,57 @@ Metadata-Version: 2.1 Name: swh.loader.svn -Version: 1.3.5 +Version: 1.3.6 Summary: Software Heritage Loader SVN Home-page: https://forge.softwareheritage.org/diffusion/DLDSVN Author: Software Heritage developers Author-email: swh-devel@inria.fr Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest Project-URL: Funding, https://www.softwareheritage.org/donate Project-URL: Source, https://forge.softwareheritage.org/source/swh-loader-svn Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-loader-svn/ Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Operating System :: OS Independent Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: testing License-File: LICENSE License-File: AUTHORS swh-loader-svn ============== The Software Heritage SVN Loader is a tool and a library to walk a remote svn repository and inject into the SWH dataset all contained files that weren't known before. The main entry points are - :class:`swh.loader.svn.loader.SvnLoader` for the main svn loader which ingests content out of a remote svn repository - :class:`swh.loader.svn.loader.SvnLoaderFromDumpArchive` which mounts a repository out of a svn dump prior to ingest it. - :class:`swh.loader.svn.loader.SvnLoaderFromRemoteDump` which mounts a repository with svnrdump prior to ingest its content. # CLI run With the configuration: /tmp/loader_svn.yml: ``` storage: cls: remote args: url: http://localhost:5002/ ``` Run: ``` swh loader --config-file /tmp/loader_svn.yml \ run svn ``` diff --git a/swh.loader.svn.egg-info/requires.txt b/swh.loader.svn.egg-info/requires.txt index 289e712..86c1d53 100644 --- a/swh.loader.svn.egg-info/requires.txt +++ b/swh.loader.svn.egg-info/requires.txt @@ -1,17 +1,17 @@ click iso8601 subvertpy>=0.9.4 tenacity>=6.2 typing-extensions swh.storage>=0.11.3 -swh.model>=4.3.0 +swh.model>=6.6.0 swh.scheduler>=0.0.39 -swh.loader.core>=3.0.0 +swh.loader.core>=5.0.0 [testing] pytest pytest-mock pytest-postgresql swh.core[http]>=0.0.61 types-click types-python-dateutil diff --git a/swh/loader/svn/replay.py b/swh/loader/svn/replay.py index cf52f6d..96987ee 100644 --- a/swh/loader/svn/replay.py +++ b/swh/loader/svn/replay.py @@ -1,1035 +1,1021 @@ # Copyright (C) 2016-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information """Remote Access client to svn server. """ from __future__ import annotations import codecs from collections import defaultdict from dataclasses import dataclass, field from distutils.dir_util import copy_tree from itertools import chain import logging import os import shutil import tempfile from typing import ( TYPE_CHECKING, Any, BinaryIO, Callable, Dict, List, Optional, Set, Tuple, Union, cast, ) import click from subvertpy import SubversionException, delta, properties from subvertpy.ra import Auth, RemoteAccess, get_username_provider from swh.model import from_disk, hashutil from swh.model.from_disk import DiskBackedContent from swh.model.model import Content, Directory, SkippedContent if TYPE_CHECKING: from swh.loader.svn.svn import SvnRepo from swh.loader.svn.utils import ( is_recursive_external, parse_external_definition, svn_urljoin, ) _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). Args: lines: The lines to normalize eol_style: The line ending format as defined for svn:eol-style property. Acceptable values are 'native', 'CRLF', 'LF' and 'CR' Returns: Lines with endings normalized """ if eol_style in _eol_style: lines = lines.replace(_eol_style["CRLF"], _eol_style["LF"]).replace( _eol_style["CR"], _eol_style["LF"] ) if _eol_style[eol_style] != _eol_style["LF"]: lines = lines.replace(_eol_style["LF"], _eol_style[eol_style]) return lines def apply_txdelta_handler( sbuf: bytes, target_stream: BinaryIO ) -> Callable[[Any, bytes, BinaryIO], None]: """Return a function that can be called repeatedly with txdelta windows. When done, closes the target_stream. Adapted from subvertpy.delta.apply_txdelta_handler to close the stream when done. Args: sbuf: Source buffer target_stream: Target stream to write to. Returns: Function to be called to apply txdelta windows """ def apply_window( window: Any, sbuf: bytes = sbuf, target_stream: BinaryIO = target_stream ): if window is None: target_stream.close() return # Last call patch = delta.apply_txdelta_window(sbuf, window) target_stream.write(patch) return apply_window def read_svn_link(data: bytes) -> Tuple[bytes, bytes]: """Read the svn link's content. Args: data: svn link's raw content Returns: The tuple of (filetype, destination path) """ split_byte = b" " first_line = data.split(b"\n")[0] filetype, *src = first_line.split(split_byte) target = split_byte.join(src) return filetype, target def is_file_an_svnlink_p(fullpath: bytes) -> Tuple[bool, bytes]: """Determine if a filepath is an svnlink or something else. Args: fullpath: Full path to the potential symlink to check Returns: Tuple containing a boolean value to determine if it's indeed a symlink (as per svn) and the link target. """ if os.path.islink(fullpath): return False, b"" with open(fullpath, "rb") as f: filetype, src = read_svn_link(f.read()) return filetype == b"link", src def _ra_codecs_error_handler(e: UnicodeError) -> Tuple[Union[str, bytes], int]: """Subvertpy may fail to decode to utf-8 the user svn properties. As they are not used by the loader, return an empty string instead of the decoded content. Args: e: exception raised during the svn properties decoding. """ return "", cast(UnicodeDecodeError, e).end DEFAULT_FLAG = 0 EXEC_FLAG = 1 NOEXEC_FLAG = 2 SVN_PROPERTY_EOL = "svn:eol-style" @dataclass class FileState: """Persists some file states (eg. end of lines style) across revisions while replaying them.""" eol_style: Optional[str] = None """EOL state check mess""" svn_special_path_non_link_data: Optional[bytes] = None """keep track of non link file content with svn:special property set""" # default value: 0, 1: set the flag, 2: remove the exec flag executable: int = DEFAULT_FLAG """keep track if file is executable when setting svn:executable property""" link: bool = False """keep track if file is a svn link when setting svn:special property""" class FileEditor: """File Editor in charge of updating file on disk and memory objects.""" __slots__ = [ "directory", "path", "fullpath", "executable", "link", "state", "svnrepo", "editor", ] def __init__( self, directory: from_disk.Directory, rootpath: bytes, path: bytes, state: FileState, svnrepo: SvnRepo, ): self.directory = directory self.path = path self.fullpath = os.path.join(rootpath, path) self.state = state self.svnrepo = svnrepo self.editor = svnrepo.swhreplay.editor - self.editor.modified_paths.add(path) - def change_prop(self, key: str, value: str) -> None: if key == properties.PROP_EXECUTABLE: if value is None: # bit flip off self.state.executable = NOEXEC_FLAG else: self.state.executable = EXEC_FLAG elif key == properties.PROP_SPECIAL: # Possibly a symbolic link. We cannot check further at # that moment though, patch(s) not being applied yet self.state.link = value is not None elif key == SVN_PROPERTY_EOL: # backup end of line style for file self.state.eol_style = value def __make_symlink(self, src: bytes) -> None: """Convert the svnlink to a symlink on disk. This function expects self.fullpath to be a svn link. Args: src: Path to the link's source Return: tuple: The svnlink's data tuple: - type (should be only 'link') - """ os.remove(self.fullpath) os.symlink(src=src, dst=self.fullpath) def __make_svnlink(self) -> bytes: """Convert the symlink to a svnlink on disk. Return: The symlink's svnlink data (``b'type '``) """ # we replace the symlink by a svnlink # to be able to patch the file on future commits src = os.readlink(self.fullpath) os.remove(self.fullpath) sbuf = b"link " + src with open(self.fullpath, "wb") as f: f.write(sbuf) return sbuf def apply_textdelta(self, base_checksum) -> Callable[[Any, bytes, BinaryIO], None]: # if the filepath matches an external, do not apply local patch if self.path in self.editor.external_paths: return lambda *args: None if os.path.lexists(self.fullpath): if os.path.islink(self.fullpath): # svn does not deal with symlink so we transform into # real svn symlink for potential patching in later # commits sbuf = self.__make_svnlink() self.state.link = True else: with open(self.fullpath, "rb") as f: sbuf = f.read() else: sbuf = b"" t = open(self.fullpath, "wb") return apply_txdelta_handler(sbuf, target_stream=t) def close(self) -> None: """When done with the file, this is called. So the file exists and is updated, we can: - adapt accordingly its execution flag if any - compute the objects' checksums - replace the svnlink with a real symlink (for disk computation purposes) """ if self.state.link: # can only check now that the link is a real one # since patch has been applied is_link, src = is_file_an_svnlink_p(self.fullpath) if is_link: self.__make_symlink(src) elif not os.path.isdir(self.fullpath): # not a real link ... # when a file with the svn:special property set is not a svn link, # the svn export operation might extract a truncated version of it # if it is a binary file, so ensure to produce the same file as the # export operation. with open(self.fullpath, "rb") as f: content = f.read() self.svnrepo.export( os.path.join(self.svnrepo.remote_url.encode(), self.path), to=self.fullpath, peg_rev=self.editor.revnum, ignore_keywords=True, overwrite=True, ) with open(self.fullpath, "rb") as f: exported_data = f.read() if exported_data != content: # keep track of original file content in order to restore # it if the svn:special property gets unset in another revision self.state.svn_special_path_non_link_data = content elif os.path.islink(self.fullpath): # path was a symbolic link in previous revision but got the property # svn:special unset in current one, revert its content to svn link format self.__make_svnlink() elif self.state.svn_special_path_non_link_data is not None: # path was a non link file with the svn:special property previously set # and got truncated on export, restore its original content with open(self.fullpath, "wb") as f: f.write(self.state.svn_special_path_non_link_data) self.state.svn_special_path_non_link_data = None is_link = os.path.islink(self.fullpath) if not is_link: # if a link, do nothing regarding flag if self.state.executable == EXEC_FLAG: os.chmod(self.fullpath, 0o755) elif self.state.executable == NOEXEC_FLAG: os.chmod(self.fullpath, 0o644) # And now compute file's checksums if self.state.eol_style and not is_link: # ensure to normalize line endings as defined by svn:eol-style # property to get the same file checksum as after an export # or checkout operation with subversion with open(self.fullpath, "rb") as f: data = f.read() data = _normalize_line_endings(data, self.state.eol_style) mode = os.lstat(self.fullpath).st_mode self.directory[self.path] = from_disk.Content.from_bytes( mode=mode, data=data ) else: self.directory[self.path] = from_disk.Content.from_file(path=self.fullpath) ExternalDefinition = Tuple[str, Optional[int], bool] @dataclass class DirState: """Persists some directory states (eg. externals) across revisions while replaying them.""" externals: Dict[str, List[ExternalDefinition]] = field(default_factory=dict) """Map a path in the directory to a list of (external_url, revision, relative_url) targeting it""" class DirEditor: """Directory Editor in charge of updating directory hashes computation. This implementation includes empty folder in the hash computation. """ __slots__ = [ "directory", "rootpath", "path", "file_states", "dir_states", "svnrepo", "editor", "externals", ] def __init__( self, directory: from_disk.Directory, rootpath: bytes, path: bytes, file_states: Dict[bytes, FileState], dir_states: Dict[bytes, DirState], 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 self.dir_states = dir_states self.svnrepo = svnrepo self.editor = svnrepo.swhreplay.editor self.externals: Dict[str, List[ExternalDefinition]] = {} - # repository root dir has empty path - if path: - self.editor.modified_paths.add(path) - def remove_child(self, path: bytes) -> None: """Remove a path from the current objects. The path can be resolved as link, file or directory. This function takes also care of removing the link between the child and the parent. Args: path: to remove from the current objects. """ try: entry_removed = self.directory[path] except KeyError: entry_removed = None else: del self.directory[path] fpath = os.path.join(self.rootpath, path) if isinstance(entry_removed, from_disk.Directory): shutil.rmtree(fpath) else: os.remove(fpath) # when deleting a directory ensure to remove any svn property for the # file it contains as they can be added again later in another revision # without the same property set fullpath = os.path.join(self.rootpath, path) for state_path in list(self.file_states): if state_path.startswith(fullpath + b"/"): del self.file_states[state_path] - self.editor.modified_paths.discard(path) - 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, dir_states=self.dir_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) if path_bytes and path_bytes not in self.directory: self.dir_states[path_bytes] = DirState() self.directory[path_bytes] = from_disk.Directory() return DirEditor( self.directory, self.rootpath, path_bytes, self.file_states, self.dir_states, svnrepo=self.svnrepo, ) def open_file(self, path: str, *args) -> FileEditor: """Updating existing file.""" path_bytes = os.fsencode(path) self.directory[path_bytes] = from_disk.Content() fullpath = os.path.join(self.rootpath, path_bytes) return FileEditor( self.directory, rootpath=self.rootpath, path=path_bytes, state=self.file_states[fullpath], svnrepo=self.svnrepo, ) def add_file(self, path: str, *args) -> FileEditor: """Creating a new file.""" path_bytes = os.fsencode(path) self.directory[path_bytes] = from_disk.Content() fullpath = os.path.join(self.rootpath, path_bytes) self.file_states[fullpath] = FileState() return FileEditor( self.directory, self.rootpath, path_bytes, state=self.file_states[fullpath], svnrepo=self.svnrepo, ) def change_prop(self, key: str, value: str) -> None: """Change property callback on directory.""" if key == properties.PROP_EXTERNALS: logger.debug( "Setting '%s' property with value '%s' on path %s", key, value, self.path, ) self.externals = defaultdict(list) if value is not None: try: # externals are set on that directory path, parse and store them # for later processing in the close method for external in value.split("\n"): external = external.rstrip("\r") # skip empty line or comment if not external or external.startswith("#"): continue ( path, external_url, revision, relative_url, ) = parse_external_definition( external, os.fsdecode(self.path), self.svnrepo.origin_url ) self.externals[path].append( (external_url, revision, relative_url) ) except ValueError: logger.debug( "Failed to parse external: %s\n" "Externals defined on path %s will not be processed", external, self.path, ) # as the official subversion client, do not process externals in case # of parsing error self.externals = {} if not self.externals: # externals might have been unset on that directory path, # remove associated paths from the reconstructed filesystem externals = self.dir_states[self.path].externals for path in externals.keys(): self.remove_external_path(os.fsencode(path)) self.dir_states[self.path].externals = {} def delete_entry(self, path: str, revision: int) -> None: """Remove a path.""" path_bytes = os.fsencode(path) if path_bytes not in self.editor.external_paths: fullpath = os.path.join(self.rootpath, path_bytes) self.file_states.pop(fullpath, None) self.remove_child(path_bytes) def close(self): """Function called when we finish processing a repository. SVN external definitions are processed by it. """ prev_externals = self.dir_states[self.path].externals if self.externals: # externals definition list might have changed in the current replayed # revision, we need to determine if some were removed and delete the # associated paths externals = self.externals prev_externals_set = { (path, url, rev) for path in prev_externals.keys() for (url, rev, _) in prev_externals[path] } externals_set = { (path, url, rev) for path in externals.keys() for (url, rev, _) in externals[path] } old_externals = prev_externals_set - externals_set for path, _, _ in old_externals: self.remove_external_path(os.fsencode(path)) else: # some external paths might have been removed in the current replayed # revision by a delete operation on an overlapping versioned path so we # need to restore them externals = prev_externals # For each external, try to export it in reconstructed filesystem for path, externals_def in externals.items(): for i, external in enumerate(externals_def): external_url, revision, relative_url = external self.process_external( path, external_url, revision, relative_url, remove_target_path=i == 0, ) # backup externals in directory state if self.externals: self.dir_states[self.path].externals = self.externals # do operations below only when closing the root directory if self.path == b"": self.svnrepo.has_relative_externals = any( relative_url for (_, relative_url) in self.editor.valid_externals.values() ) self.svnrepo.has_recursive_externals = any( is_recursive_external( self.svnrepo.origin_url, os.fsdecode(path), external_path, external_url, ) for path, dir_state in self.dir_states.items() for external_path in dir_state.externals.keys() for (external_url, _, _) in dir_state.externals[external_path] ) if self.svnrepo.has_recursive_externals: # If the repository has recursive externals, we stop processing # externals and remove those already exported, # We will then ignore externals when exporting the revision to # check for divergence with the reconstructed filesystem. for external_path in list(self.editor.external_paths): self.remove_external_path(external_path, force=True) def process_external( self, path: str, external_url: str, revision: Optional[int], relative_url: bool, remove_target_path: bool = True, ) -> None: external = (external_url, revision, relative_url) dest_path = os.fsencode(path) dest_fullpath = os.path.join(self.path, dest_path) prev_externals = self.dir_states[self.path].externals if ( path in prev_externals and external in prev_externals[path] and dest_fullpath in self.directory ): # external already exported, nothing to do return if is_recursive_external( self.svnrepo.origin_url, os.fsdecode(self.path), path, external_url ): # recursive external, skip it return logger.debug( "Exporting external %s%s to path %s", external_url, f"@{revision}" if revision else "", dest_fullpath, ) if external not in self.editor.externals_cache: try: # try to export external in a temporary path, destination path could # be versioned and must be overridden only if the external URL is # still valid temp_dir = os.fsencode( tempfile.mkdtemp(dir=self.editor.externals_cache_dir) ) temp_path = os.path.join(temp_dir, dest_path) os.makedirs(b"/".join(temp_path.split(b"/")[:-1]), exist_ok=True) if external_url not in self.editor.dead_externals: url = external_url.rstrip("/") origin_url = self.svnrepo.origin_url.rstrip("/") if ( url.startswith(origin_url + "/") and not self.svnrepo.has_relative_externals ): url = url.replace(origin_url, self.svnrepo.remote_url) self.svnrepo.export( url, to=temp_path, peg_rev=revision, ignore_keywords=True, ) self.editor.externals_cache[external] = temp_path except SubversionException as se: # external no longer available (404) logger.debug(se) self.editor.dead_externals.add(external_url) else: temp_path = self.editor.externals_cache[external] # subversion export will always create the subdirectories of the external # path regardless the validity of the remote URL dest_path_split = dest_path.split(b"/") current_path = self.path self.add_directory(os.fsdecode(current_path)) for subpath in dest_path_split[:-1]: current_path = os.path.join(current_path, subpath) self.add_directory(os.fsdecode(current_path)) if os.path.exists(temp_path): # external successfully exported if remove_target_path: # remove previous path in from_disk model self.remove_external_path(dest_path, remove_subpaths=False) # mark external as valid self.editor.valid_externals[dest_fullpath] = ( external_url, relative_url, ) # copy exported path to reconstructed filesystem fullpath = os.path.join(self.rootpath, dest_fullpath) # update from_disk model and store external paths self.editor.external_paths[dest_fullpath] += 1 - self.editor.modified_paths.add(dest_fullpath) if os.path.isfile(temp_path): if os.path.islink(fullpath): # remove destination file if it is a link os.remove(fullpath) shutil.copy(os.fsdecode(temp_path), os.fsdecode(fullpath)) self.directory[dest_fullpath] = from_disk.Content.from_file( path=fullpath ) else: self.add_directory(os.fsdecode(dest_fullpath)) # copy_tree needs sub-directories to exist in destination for root, dirs, files in os.walk(temp_path): for dir in dirs: temp_dir_fullpath = os.path.join(root, dir) if os.path.islink(temp_dir_fullpath): # do not create folder if it's a link or copy_tree will fail continue subdir = temp_dir_fullpath.replace(temp_path + b"/", b"") self.add_directory( os.fsdecode(os.path.join(dest_fullpath, subdir)) ) copy_tree( os.fsdecode(temp_path), os.fsdecode(fullpath), preserve_symlinks=True, ) # TODO: replace code above by the line below once we use Python >= 3.8 in production # noqa # shutil.copytree(temp_path, fullpath, symlinks=True, dirs_exist_ok=True) # noqa self.directory[dest_fullpath] = from_disk.Directory.from_disk( path=fullpath ) external_paths = set() for root, dirs, files in os.walk(fullpath): external_paths.update( [ os.path.join(root.replace(self.rootpath + b"/", b""), p) for p in chain(dirs, files) ] ) for external_path in external_paths: self.editor.external_paths[external_path] += 1 - self.editor.modified_paths.update(external_paths) - # ensure hash update for the directory with externals set self.directory[self.path].update_hash(force=True) def remove_external_path( self, external_path: bytes, remove_subpaths: bool = True, force: bool = False ) -> None: """Remove a previously exported SVN external path from the reconstructed filesystem. """ fullpath = os.path.join(self.path, external_path) # decrement number of references for external path when we really remove it # (when remove_subpaths is False, we just cleanup the external path before # copying exported paths in it) if fullpath in self.editor.external_paths and remove_subpaths: self.editor.external_paths[fullpath] -= 1 if ( force or fullpath in self.editor.external_paths and self.editor.external_paths[fullpath] == 0 ): self.remove_child(fullpath) self.editor.external_paths.pop(fullpath, None) self.editor.valid_externals.pop(fullpath, None) for path in list(self.editor.external_paths): if path.startswith(fullpath + b"/"): self.editor.external_paths[path] -= 1 if self.editor.external_paths[path] == 0: self.editor.external_paths.pop(path) if remove_subpaths: subpath_split = external_path.split(b"/")[:-1] for i in reversed(range(1, len(subpath_split) + 1)): # delete external sub-directory only if it is not versioned subpath = os.path.join(self.path, b"/".join(subpath_split[0:i])) try: self.svnrepo.client.info( svn_urljoin(self.svnrepo.remote_url, os.fsdecode(subpath)), peg_revision=self.editor.revnum, revision=self.editor.revnum, ) except SubversionException: self.remove_child(subpath) else: break try: # externals can overlap with versioned files so we must restore # them after removing the path above dest_path = os.path.join(self.rootpath, fullpath) self.svnrepo.client.export( svn_urljoin(self.svnrepo.remote_url, os.fsdecode(fullpath)), to=dest_path, peg_rev=self.editor.revnum, ignore_keywords=True, ) if os.path.isfile(dest_path) or os.path.islink(dest_path): self.directory[fullpath] = from_disk.Content.from_file(path=dest_path) else: self.directory[fullpath] = from_disk.Directory.from_disk(path=dest_path) except SubversionException: pass class Editor: """Editor in charge of replaying svn events and computing objects along. This implementation accounts for empty folder during hash computations. """ def __init__( self, rootpath: bytes, directory: from_disk.Directory, svnrepo: SvnRepo, temp_dir: str, ): self.rootpath = rootpath self.directory = directory self.file_states: Dict[bytes, FileState] = defaultdict(FileState) self.dir_states: Dict[bytes, DirState] = defaultdict(DirState) self.external_paths: Dict[bytes, int] = defaultdict(int) self.valid_externals: Dict[bytes, Tuple[str, bool]] = {} self.dead_externals: Set[str] = set() self.externals_cache_dir = tempfile.mkdtemp(dir=temp_dir) self.externals_cache: Dict[ExternalDefinition, bytes] = {} self.svnrepo = svnrepo self.revnum = None - # to store the set of paths added or modified when replaying a revision - self.modified_paths: Set[bytes] = set() def set_target_revision(self, revnum) -> None: self.revnum = revnum def abort(self) -> None: pass def close(self) -> None: pass def open_root(self, base_revnum: int) -> DirEditor: - # a new revision is being replayed so clear the modified_paths set - self.modified_paths.clear() return DirEditor( self.directory, rootpath=self.rootpath, path=b"", file_states=self.file_states, dir_states=self.dir_states, svnrepo=self.svnrepo, ) class Replay: """Replay class.""" def __init__( self, conn: RemoteAccess, rootpath: bytes, svnrepo: SvnRepo, temp_dir: str, directory: Optional[from_disk.Directory] = None, ): self.conn = conn self.rootpath = rootpath if directory is None: directory = from_disk.Directory() self.directory = directory self.editor = Editor( rootpath=rootpath, directory=directory, svnrepo=svnrepo, temp_dir=temp_dir ) def replay(self, rev: int) -> from_disk.Directory: """Replay svn actions between rev and rev+1. This method updates in place the self.editor.directory, as well as the filesystem. Returns: The updated root directory """ codecs.register_error("strict", _ra_codecs_error_handler) self.conn.replay(rev, rev + 1, self.editor) codecs.register_error("strict", codecs.strict_errors) return self.editor.directory def compute_objects( self, rev: int ) -> Tuple[List[Content], List[SkippedContent], List[Directory]]: """Compute objects added or modified at revisions rev. Expects the state to be at previous revision's objects. Args: rev: The revision to start the replay from. Returns: The updated objects between rev and rev+1. Beware that this mutates the filesystem at rootpath accordingly. """ self.replay(rev) contents: List[Content] = [] skipped_contents: List[SkippedContent] = [] directories: List[Directory] = [] - directories.append(self.editor.directory.to_model()) - for path in self.editor.modified_paths: - obj = self.directory[path].to_model() + for obj_node in self.directory.collect(): + obj = obj_node.to_model() # type: ignore obj_type = obj.object_type if obj_type in (Content.object_type, DiskBackedContent.object_type): contents.append(obj.with_data()) elif obj_type == SkippedContent.object_type: skipped_contents.append(obj) elif obj_type == Directory.object_type: directories.append(obj) + else: + assert False, obj_type return contents, skipped_contents, directories @click.command() @click.option("--local-url", default="/tmp", help="local svn working copy") @click.option( "--svn-url", default="file:///home/storage/svn/repos/pkg-fox", help="svn repository's url.", ) @click.option( "--revision-start", default=1, type=click.INT, help="svn repository's starting revision.", ) @click.option( "--revision-end", default=-1, type=click.INT, help="svn repository's ending revision.", ) @click.option( "--debug/--nodebug", default=True, help="Indicates if the server should run in debug mode.", ) @click.option( "--cleanup/--nocleanup", default=True, help="Indicates whether to cleanup disk when done or not.", ) def main(local_url, svn_url, revision_start, revision_end, debug, cleanup): """Script to present how to use Replay class.""" conn = RemoteAccess(svn_url.encode("utf-8"), auth=Auth([get_username_provider()])) os.makedirs(local_url, exist_ok=True) rootpath = tempfile.mkdtemp( prefix=local_url, suffix="-" + os.path.basename(svn_url) ) rootpath = os.fsencode(rootpath) # Do not go beyond the repository's latest revision revision_end_max = conn.get_latest_revnum() if revision_end == -1: revision_end = revision_end_max revision_end = min(revision_end, revision_end_max) try: replay = Replay(conn, rootpath) for rev in range(revision_start, revision_end + 1): contents, skipped_contents, directories = replay.compute_objects(rev) print( "r%s %s (%s new contents, %s new directories)" % ( rev, hashutil.hash_to_hex(replay.directory.hash), len(contents) + len(skipped_contents), len(directories), ) ) if debug: print("%s" % rootpath.decode("utf-8")) finally: if cleanup: if os.path.exists(rootpath): shutil.rmtree(rootpath) if __name__ == "__main__": main() diff --git a/swh/loader/svn/tests/test_task.py b/swh/loader/svn/tests/test_task.py index efd88e0..ec92c35 100644 --- a/swh/loader/svn/tests/test_task.py +++ b/swh/loader/svn/tests/test_task.py @@ -1,156 +1,78 @@ # Copyright (C) 2019-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import uuid import pytest from swh.scheduler.model import ListedOrigin, Lister -from swh.scheduler.utils import create_origin_task_dict - -@pytest.fixture(autouse=True) -def celery_worker_and_swh_config(swh_scheduler_celery_worker, swh_config): - pass +NAMESPACE = "swh.loader.svn" @pytest.fixture def svn_lister(): return Lister(name="svn-lister", instance_name="example", id=uuid.uuid4()) @pytest.fixture def svn_listed_origin(svn_lister): return ListedOrigin( lister_id=svn_lister.id, url="svn://example.org/repo", visit_type="svn" ) -@pytest.fixture -def task_dict(svn_lister, svn_listed_origin): - return create_origin_task_dict(svn_listed_origin, svn_lister) - - -def test_svn_loader( - mocker, - swh_scheduler_celery_app, -): - mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoader.load") - mock_loader.return_value = {"status": "eventful"} - - res = swh_scheduler_celery_app.send_task( - "swh.loader.svn.tasks.LoadSvnRepository", - kwargs=dict( - url="some-technical-url", origin_url="origin-url", visit_date="now" - ), - ) - assert res - res.wait() - assert res.successful() - - assert res.result == {"status": "eventful"} - - +@pytest.mark.parametrize("extra_loader_arguments", [{}, {"visit_date": "now"}]) def test_svn_loader_for_listed_origin( - mocker, - swh_scheduler_celery_app, - task_dict, -): - mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoader.load") - mock_loader.return_value = {"status": "eventful"} - - res = swh_scheduler_celery_app.send_task( - "swh.loader.svn.tasks.LoadSvnRepository", - args=task_dict["arguments"]["args"], - kwargs=task_dict["arguments"]["kwargs"], - ) - assert res - res.wait() - assert res.successful() - - assert res.result == {"status": "eventful"} - - -def test_svn_loader_from_dump( - mocker, - swh_scheduler_celery_app, + loading_task_creation_for_listed_origin_test, + svn_lister, + svn_listed_origin, + extra_loader_arguments, ): - mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoaderFromDumpArchive.load") - mock_loader.return_value = {"status": "eventful"} + svn_listed_origin.extra_loader_arguments = extra_loader_arguments - res = swh_scheduler_celery_app.send_task( - "swh.loader.svn.tasks.MountAndLoadSvnRepository", - kwargs=dict(url="some-url", archive_path="some-path", visit_date="now"), + loading_task_creation_for_listed_origin_test( + loader_class_name=f"{NAMESPACE}.loader.SvnLoader", + task_function_name=f"{NAMESPACE}.tasks.LoadSvnRepository", + lister=svn_lister, + listed_origin=svn_listed_origin, ) - assert res - res.wait() - assert res.successful() - - assert res.result == {"status": "eventful"} +@pytest.mark.parametrize( + "extra_loader_arguments", + [{"archive_path": "some-path"}, {"archive_path": "some-path", "visit_date": "now"}], +) def test_svn_loader_from_dump_for_listed_origin( - mocker, - swh_scheduler_celery_app, + loading_task_creation_for_listed_origin_test, svn_lister, svn_listed_origin, + extra_loader_arguments, ): - mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoaderFromDumpArchive.load") - mock_loader.return_value = {"status": "eventful"} - - svn_listed_origin.extra_loader_arguments = {"archive_path": "some-path"} - - task_dict = create_origin_task_dict(svn_listed_origin, svn_lister) - - res = swh_scheduler_celery_app.send_task( - "swh.loader.svn.tasks.MountAndLoadSvnRepository", - args=task_dict["arguments"]["args"], - kwargs=task_dict["arguments"]["kwargs"], - ) - assert res - res.wait() - assert res.successful() + svn_listed_origin.extra_loader_arguments = extra_loader_arguments - assert res.result == {"status": "eventful"} - - -def test_svn_loader_from_remote_dump( - mocker, - swh_scheduler_celery_app, -): - mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoaderFromRemoteDump.load") - mock_loader.return_value = {"status": "eventful"} - - res = swh_scheduler_celery_app.send_task( - "swh.loader.svn.tasks.DumpMountAndLoadSvnRepository", - kwargs=dict( - url="some-remote-dump-url", origin_url="origin-url", visit_date="now" - ), + loading_task_creation_for_listed_origin_test( + loader_class_name=f"{NAMESPACE}.loader.SvnLoaderFromDumpArchive", + task_function_name=f"{NAMESPACE}.tasks.MountAndLoadSvnRepository", + lister=svn_lister, + listed_origin=svn_listed_origin, ) - assert res - res.wait() - assert res.successful() - - assert res.result == {"status": "eventful"} +@pytest.mark.parametrize("extra_loader_arguments", [{}, {"visit_date": "now"}]) def test_svn_loader_from_remote_dump_for_listed_origin( - mocker, - swh_scheduler_celery_app, - task_dict, + loading_task_creation_for_listed_origin_test, + svn_lister, + svn_listed_origin, + extra_loader_arguments, ): - mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoaderFromRemoteDump.load") - mock_loader.return_value = {"status": "eventful"} + svn_listed_origin.extra_loader_arguments = extra_loader_arguments - res = swh_scheduler_celery_app.send_task( - "swh.loader.svn.tasks.DumpMountAndLoadSvnRepository", - args=task_dict["arguments"]["args"], - kwargs=task_dict["arguments"]["kwargs"], + loading_task_creation_for_listed_origin_test( + loader_class_name=f"{NAMESPACE}.loader.SvnLoaderFromRemoteDump", + task_function_name=f"{NAMESPACE}.tasks.DumpMountAndLoadSvnRepository", + lister=svn_lister, + listed_origin=svn_listed_origin, ) - assert res - res.wait() - assert res.successful() - - assert res.result == {"status": "eventful"} diff --git a/swh/loader/svn/tests/test_utils.py b/swh/loader/svn/tests/test_utils.py index ccc3c2a..b85cb73 100644 --- a/swh/loader/svn/tests/test_utils.py +++ b/swh/loader/svn/tests/test_utils.py @@ -1,428 +1,441 @@ # Copyright (C) 2016-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import logging import os +from pathlib import Path import pty import shutil from subprocess import Popen import pytest from swh.loader.svn import utils def test_outputstream(): stdout_r, stdout_w = pty.openpty() echo = Popen(["echo", "-e", "foo\nbar\nbaz"], stdout=stdout_w) os.close(stdout_w) stdout_stream = utils.OutputStream(stdout_r) lines = [] while True: current_lines, readable = stdout_stream.read_lines() lines += current_lines if not readable: break echo.wait() os.close(stdout_r) assert lines == ["foo", "bar", "baz"] def test_init_svn_repo_from_dump(datadir, tmp_path): """Mounting svn repository out of a dump is ok""" dump_name = "penguinsdbtools2018.dump.gz" dump_path = os.path.join(datadir, dump_name) tmp_repo, repo_path = utils.init_svn_repo_from_dump( dump_path, gzip=True, cleanup_dump=False, root_dir=tmp_path ) assert os.path.exists(dump_path), "Dump path should still exists" assert os.path.exists(repo_path), "Repository should exists" +def test_init_svn_repo_from_dump_svnadmin_error(tmp_path): + """svnadmin load error should be reported in exception text""" + dump_path = os.path.join(tmp_path, "foo") + Path(dump_path).touch() + + with pytest.raises( + ValueError, + match="svnadmin: E200003: Premature end of content data in dumpstream", + ): + utils.init_svn_repo_from_dump(dump_path, cleanup_dump=False, root_dir=tmp_path) + + def test_init_svn_repo_from_dump_and_cleanup(datadir, tmp_path): """Mounting svn repository with a dump cleanup after is ok""" dump_name = "penguinsdbtools2018.dump.gz" dump_ori_path = os.path.join(datadir, dump_name) dump_path = os.path.join(tmp_path, dump_name) shutil.copyfile(dump_ori_path, dump_path) assert os.path.exists(dump_path) assert os.path.exists(dump_ori_path) tmp_repo, repo_path = utils.init_svn_repo_from_dump( dump_path, gzip=True, root_dir=tmp_path ) assert not os.path.exists(dump_path), "Dump path should no longer exists" assert os.path.exists(repo_path), "Repository should exists" assert os.path.exists(dump_ori_path), "Original dump path should still exists" def test_init_svn_repo_from_dump_and_cleanup_already_done( datadir, tmp_path, mocker, caplog ): """Mounting svn repository out of a dump is ok""" caplog.set_level(logging.INFO, "swh.loader.svn.utils") dump_name = "penguinsdbtools2018.dump.gz" dump_ori_path = os.path.join(datadir, dump_name) mock_remove = mocker.patch("os.remove") mock_remove.side_effect = FileNotFoundError dump_path = os.path.join(tmp_path, dump_name) shutil.copyfile(dump_ori_path, dump_path) assert os.path.exists(dump_path) assert os.path.exists(dump_ori_path) tmp_repo, repo_path = utils.init_svn_repo_from_dump( dump_path, gzip=True, root_dir=tmp_path ) assert os.path.exists(repo_path), "Repository should exists" assert os.path.exists(dump_ori_path), "Original dump path should still exists" assert len(caplog.record_tuples) == 1 assert "Failure to remove" in caplog.record_tuples[0][2] assert mock_remove.called def test_init_svn_repo_from_archive_dump(datadir, tmp_path): """Mounting svn repository out of an archive dump is ok""" dump_name = "penguinsdbtools2018.dump.gz" dump_path = os.path.join(datadir, dump_name) tmp_repo, repo_path = utils.init_svn_repo_from_archive_dump( dump_path, cleanup_dump=False, root_dir=tmp_path ) assert os.path.exists(dump_path), "Dump path should still exists" assert os.path.exists(repo_path), "Repository should exists" def test_init_svn_repo_from_archive_dump_and_cleanup(datadir, tmp_path): """Mounting svn repository out of a dump is ok""" dump_name = "penguinsdbtools2018.dump.gz" dump_ori_path = os.path.join(datadir, dump_name) dump_path = os.path.join(tmp_path, dump_name) shutil.copyfile(dump_ori_path, dump_path) assert os.path.exists(dump_path) assert os.path.exists(dump_ori_path) tmp_repo, repo_path = utils.init_svn_repo_from_archive_dump( dump_path, root_dir=tmp_path ) assert not os.path.exists(dump_path), "Dump path should no longer exists" assert os.path.exists(repo_path), "Repository should exists" assert os.path.exists(dump_ori_path), "Original dump path should still exists" @pytest.mark.parametrize( "base_url, paths_to_join, expected_result", [ ( "https://svn.example.org", ["repos", "test"], "https://svn.example.org/repos/test", ), ( "https://svn.example.org/", ["repos", "test"], "https://svn.example.org/repos/test", ), ( "https://svn.example.org/foo", ["repos", "test"], "https://svn.example.org/foo/repos/test", ), ( "https://svn.example.org/foo/", ["/repos", "test/"], "https://svn.example.org/foo/repos/test", ), ( "https://svn.example.org/foo", ["../bar"], "https://svn.example.org/bar", ), ], ) def test_svn_urljoin(base_url, paths_to_join, expected_result): assert utils.svn_urljoin(base_url, *paths_to_join) == expected_result @pytest.mark.parametrize( "external, dir_path, repo_url, expected_result", [ # subversion < 1.5 ( "third-party/sounds http://svn.example.com/repos/sounds", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/sounds", "http://svn.example.com/repos/sounds", None, False), ), ( "third-party/skins -r148 http://svn.example.com/skinproj", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/skins", "http://svn.example.com/skinproj", 148, False), ), ( "third-party/skins/toolkit -r21 http://svn.example.com/skin-maker", "trunk/externals", "http://svn.example.org/repos/test", ( "third-party/skins/toolkit", "http://svn.example.com/skin-maker", 21, False, ), ), # subversion >= 1.5 ( " http://svn.example.com/repos/sounds third-party/sounds", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/sounds", "http://svn.example.com/repos/sounds", None, False), ), ( "-r148 http://svn.example.com/skinproj third-party/skins", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/skins", "http://svn.example.com/skinproj", 148, False), ), ( "-r 21 http://svn.example.com/skin-maker third-party/skins/toolkit", "trunk/externals", "http://svn.example.org/repos/test", ( "third-party/skins/toolkit", "http://svn.example.com/skin-maker", 21, False, ), ), ( "http://svn.example.com/repos/sounds third-party/sounds", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/sounds", "http://svn.example.com/repos/sounds", None, False), ), ( "http://svn.example.com/skinproj@148 third-party/skins", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/skins", "http://svn.example.com/skinproj", 148, False), ), ( "http://anon:anon@svn.example.com/skin-maker@21 third-party/skins/toolkit", "trunk/externals", "http://svn.example.org/repos/test", ( "third-party/skins/toolkit", "http://anon:anon@svn.example.com/skin-maker", 21, False, ), ), ( "-r21 http://anon:anon@svn.example.com/skin-maker third-party/skins/toolkit", # noqa "trunk/externals", "http://svn.example.org/repos/test", ( "third-party/skins/toolkit", "http://anon:anon@svn.example.com/skin-maker", 21, False, ), ), ( "-r21 http://anon:anon@svn.example.com/skin-maker@21 third-party/skins/toolkit", # noqa "trunk/externals", "http://svn.example.org/repos/test", ( "third-party/skins/toolkit", "http://anon:anon@svn.example.com/skin-maker", 21, False, ), ), # subversion >= 1.5, relative external definitions ( "^/sounds third-party/sounds", "trunk/externals", "http://svn.example.org/repos/test", ( "third-party/sounds", "http://svn.example.org/repos/test/sounds", None, False, ), ), ( "/skinproj@148 third-party/skins", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/skins", "http://svn.example.org/skinproj", 148, True), ), ( "//svn.example.com/skin-maker@21 third-party/skins/toolkit", "trunk/externals", "http://svn.example.org/repos/test", ( "third-party/skins/toolkit", "http://svn.example.com/skin-maker", 21, True, ), ), ( "^/../../skin-maker@21 third-party/skins/toolkit", "trunk/externals", "http://svn.example.org/repos/test", ( "third-party/skins/toolkit", "http://svn.example.org/skin-maker", 21, True, ), ), ( "../skins skins", "trunk/externals", "http://svn.example.org/repos/test", ("skins", "http://svn.example.org/repos/test/trunk/skins", None, False), ), ( "../skins skins", "trunk/externals", "http://svn.example.org/repos/test", ("skins", "http://svn.example.org/repos/test/trunk/skins", None, False), ), # subversion >= 1.6 ( 'http://svn.thirdparty.com/repos/My%20Project "My Project"', "trunk/externals", "http://svn.example.org/repos/test", ("My Project", "http://svn.thirdparty.com/repos/My%20Project", None, False), ), ( 'http://svn.thirdparty.com/repos/My%20%20%20Project "My Project"', "trunk/externals", "http://svn.example.org/repos/test", ( "My Project", "http://svn.thirdparty.com/repos/My%20%20%20Project", None, False, ), ), ( 'http://svn.thirdparty.com/repos/%22Quotes%20Too%22 \\"Quotes\\ Too\\"', "trunk/externals", "http://svn.example.org/repos/test", ( '"Quotes Too"', "http://svn.thirdparty.com/repos/%22Quotes%20Too%22", None, False, ), ), ( 'http://svn.thirdparty.com/repos/%22Quotes%20%20%20Too%22 \\"Quotes\\ \\ \\ Too\\"', # noqa "trunk/externals", "http://svn.example.org/repos/test", ( '"Quotes Too"', "http://svn.thirdparty.com/repos/%22Quotes%20%20%20Too%22", None, False, ), ), # edge cases ( '-r1 http://svn.thirdparty.com/repos/test "trunk/PluginFramework"', "trunk/externals", "http://svn.example.org/repos/test", ("trunk/PluginFramework", "http://svn.thirdparty.com/repos/test", 1, False), ), ( "external -r 9 http://svn.thirdparty.com/repos/test", "tags", "http://svn.example.org/repos/test", ("external", "http://svn.thirdparty.com/repos/test", 9, False), ), ( "./external http://svn.thirdparty.com/repos/test", "tags", "http://svn.example.org/repos/test", ("external", "http://svn.thirdparty.com/repos/test", None, False), ), ( ".external http://svn.thirdparty.com/repos/test", "tags", "http://svn.example.org/repos/test", (".external", "http://svn.thirdparty.com/repos/test", None, False), ), ( "external/ http://svn.thirdparty.com/repos/test", "tags", "http://svn.example.org/repos/test", ("external", "http://svn.thirdparty.com/repos/test", None, False), ), ( "external ttp://svn.thirdparty.com/repos/test", "tags", "http://svn.example.org/repos/test", ("external", "ttp://svn.thirdparty.com/repos/test", None, False), ), ( "external http//svn.thirdparty.com/repos/test", "tags", "http://svn.example.org/repos/test", ("external", "http//svn.thirdparty.com/repos/test", None, False), ), ( "C:\\code\\repo\\external http://svn.thirdparty.com/repos/test", "tags", "http://svn.example.org/repos/test", ("C:coderepoexternal", "http://svn.thirdparty.com/repos/test", None, False), ), ( "C:\\\\code\\\\repo\\\\external http://svn.thirdparty.com/repos/test", "tags", "http://svn.example.org/repos/test", ( "C:\\code\\repo\\external", "http://svn.thirdparty.com/repos/test", None, False, ), ), ( "-r 123 http://svn.example.com/repos/sounds@100 third-party/sounds", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/sounds", "http://svn.example.com/repos/sounds", 123, False), ), ( "-r 123 http://svn.example.com/repos/sounds@150 third-party/sounds", "trunk/externals", "http://svn.example.org/repos/test", ("third-party/sounds", "http://svn.example.com/repos/sounds", 123, False), ), ], ) def test_parse_external_definition(external, dir_path, repo_url, expected_result): assert ( utils.parse_external_definition(external, dir_path, repo_url) == expected_result ) diff --git a/swh/loader/svn/utils.py b/swh/loader/svn/utils.py index 3319efe..b188995 100644 --- a/swh/loader/svn/utils.py +++ b/swh/loader/svn/utils.py @@ -1,325 +1,328 @@ # Copyright (C) 2016-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import errno import logging import os import re import shutil -from subprocess import PIPE, Popen, call +from subprocess import PIPE, Popen, call, run import tempfile from typing import Optional, Tuple from urllib.parse import quote, urlparse, urlunparse logger = logging.getLogger(__name__) class OutputStream: """Helper class to read lines from a program output while it is running Args: fileno (int): File descriptor of a program output stream opened in text mode """ def __init__(self, fileno): self._fileno = fileno self._buffer = "" def read_lines(self): """ Read available lines from the output stream and return them. Returns: Tuple[List[str], bool]: A tuple whose first member is the read lines and second member a boolean indicating if there are still some other lines available to read. """ try: output = os.read(self._fileno, 1000).decode() except OSError as e: if e.errno != errno.EIO: raise output = "" output = output.replace("\r\n", "\n") lines = output.split("\n") lines[0] = self._buffer + lines[0] if output: self._buffer = lines[-1] return (lines[:-1], True) else: self._buffer = "" if len(lines) == 1 and not lines[0]: lines = [] return (lines, False) def init_svn_repo_from_dump( dump_path: str, prefix: Optional[str] = None, suffix: Optional[str] = None, root_dir: str = "/tmp", gzip: bool = False, cleanup_dump: bool = True, ) -> Tuple[str, str]: """Given a path to a svn dump, initialize an svn repository with the content of said dump. Args: dump_path: The dump to the path prefix: optional prefix file name for the working directory suffix: optional suffix file name for the working directory root_dir: the root directory where the working directory is created gzip: Boolean to determine whether we treat the dump as compressed or not. cleanup_dump: Whether we want this function call to clean up the dump at the end of the repository initialization. Raises: ValueError in case of failure to run the command to uncompress and load the dump. Returns: A tuple: - temporary folder: containing the mounted repository - repo_path: path to the mounted repository inside the temporary folder """ project_name = os.path.basename(os.path.dirname(dump_path)) temp_dir = tempfile.mkdtemp(prefix=prefix, suffix=suffix, dir=root_dir) try: repo_path = os.path.join(temp_dir, project_name) # create the repository that will be loaded with the dump cmd = ["svnadmin", "create", repo_path] r = call(cmd) if r != 0: raise ValueError( "Failed to initialize empty svn repo for %s" % project_name ) read_dump_cmd = ["cat", dump_path] if gzip: read_dump_cmd = ["gzip", "-dc", dump_path] with Popen(read_dump_cmd, stdout=PIPE) as dump: # load dump and bypass properties validation as Unicode decoding errors # are already handled in loader implementation (see _ra_codecs_error_handler # in ra.py) cmd = ["svnadmin", "load", "-q", "--bypass-prop-validation", repo_path] - r = call(cmd, stdin=dump.stdout) - if r != 0: + completed_process = run( + cmd, stdin=dump.stdout, capture_output=True, text=True + ) + if completed_process.returncode != 0: raise ValueError( - "Failed to mount the svn dump for project %s" % project_name + f"Failed to mount the svn dump for project {project_name}\n" + + completed_process.stderr ) return temp_dir, repo_path except Exception as e: shutil.rmtree(temp_dir) raise e finally: if cleanup_dump: try: # At this time, the temporary svn repository is mounted from the dump or # the svn repository failed to mount. Either way, we can drop the dump. os.remove(dump_path) assert not os.path.exists(dump_path) except OSError as e: logger.warn("Failure to remove the dump %s: %s", dump_path, e) def init_svn_repo_from_archive_dump( archive_path: str, prefix: Optional[str] = None, suffix: Optional[str] = None, root_dir: str = "/tmp", cleanup_dump: bool = True, ) -> Tuple[str, str]: """Given a path to an archive containing an svn dump, initializes an svn repository with the content of the uncompressed dump. Args: archive_path: The archive svn dump path prefix: optional prefix file name for the working directory suffix: optional suffix file name for the working directory root_dir: the root directory where the working directory is created gzip: Boolean to determine whether we treat the dump as compressed or not. cleanup_dump: Whether we want this function call to clean up the dump at the end of the repository initialization. Raises: ValueError in case of failure to run the command to uncompress and load the dump. Returns: A tuple: - temporary folder: containing the mounted repository - repo_path: path to the mounted repository inside the temporary folder """ return init_svn_repo_from_dump( archive_path, prefix=prefix, suffix=suffix, root_dir=root_dir, gzip=True, cleanup_dump=cleanup_dump, ) def svn_urljoin(base_url: str, *args) -> str: """Join a base URL and a list of paths in a SVN way. For instance: - svn_urljoin("http://example.org", "foo", "bar") will return "https://example.org/foo/bar - svn_urljoin("http://example.org/foo", "../bar") will return "https://example.org/bar Args: base_url: Base URL to join paths with args: path components Returns: The joined URL """ parsed_url = urlparse(base_url) path = os.path.abspath( os.path.join(parsed_url.path or "/", *[arg.strip("/") for arg in args]) ) return f"{parsed_url.scheme}://{parsed_url.netloc}{path}" def parse_external_definition( external: str, dir_path: str, repo_url: str ) -> Tuple[str, str, Optional[int], bool]: """Parse a subversion external definition. Args: external: an external definition, extracted from the lines split of a svn:externals property value dir_path: The path of the directory in the subversion repository where the svn:externals property was set repo_url: URL of the subversion repository Returns: A tuple with the following members: - path relative to dir_path where the external should be exported - URL of the external to export - optional revision of the external to export - boolean indicating if the external URL is relative to the repository URL and targets a path not in the repository """ path = "" external_url = "" revision = None relative_url = False prev_part = None # turn multiple spaces into a single one and split on space for external_part in external.split(): if prev_part == "-r": # parse revision in the form "-r XXX" revision = int(external_part) elif external_part.startswith("-r") and external_part != "-r": # parse revision in the form "-rXXX" revision = int(external_part[2:]) elif external_part.startswith("^/"): # URL relative to the root of the repository in which the svn:externals # property is versioned external_url = svn_urljoin(repo_url, external_part[2:]) relative_url = not external_url.startswith(repo_url) elif external_part.startswith("//"): # URL relative to the scheme of the URL of the directory on which the # svn:externals property is set scheme = urlparse(repo_url).scheme external_url = f"{scheme}:{external_part}" relative_url = not external_url.startswith(repo_url) elif external_part.startswith("/"): # URL relative to the root URL of the server on which the svn:externals # property is versioned parsed_url = urlparse(repo_url) root_url = f"{parsed_url.scheme}://{parsed_url.netloc}" external_url = svn_urljoin(root_url, external_part) relative_url = not external_url.startswith(repo_url) elif external_part.startswith("../"): # URL relative to the URL of the directory on which the svn:externals # property is set external_url = svn_urljoin(repo_url, dir_path, external_part) relative_url = not external_url.startswith(repo_url) elif re.match(r"^.*:*//.*", external_part): # absolute external URL external_url = external_part # subversion >= 1.6 added a quoting and escape mechanism to the syntax so # that the path of the external working copy may contain whitespace. elif external_part.startswith('\\"'): external_split = external.split('\\"') path = [ e.replace("\\ ", " ") for e in external_split if e.startswith(external_part[2:]) ][0] path = f'"{path}"' elif external_part.endswith('\\"'): continue elif external_part.startswith('"'): external_split = external.split('"') path_prefix = external_part.strip('"') path = next(iter([e for e in external_split if e.startswith(path_prefix)])) elif external_part.endswith('"'): continue elif not external_part.startswith("\\") and external_part != "-r": # path of the external relative to dir_path path = external_part.replace("\\\\", "\\") if path == external_part: path = external_part.replace("\\", "") if path.startswith("./"): path = path.replace("./", "", 1) prev_part = external_part if "@" in external_url: # try to extract revision number if external URL is in the form # http://svn.example.org/repos/test/path@XXX url, revision_s = external_url.rsplit("@", maxsplit=1) try: # ensure revision_s can be parsed to int rev = int(revision_s) # -r XXX takes priority over @XXX revision = revision or rev external_url = url except ValueError: # handle URL like http://user@svn.example.org/ pass return (path.rstrip("/"), external_url, revision, relative_url) def is_recursive_external( origin_url: str, dir_path: str, external_path: str, external_url: str ) -> bool: """ Check if an external definition can lead to a recursive subversion export operation (https://issues.apache.org/jira/browse/SVN-1703). Args: origin_url: repository URL dir_path: path of the directory where external is defined external_path: path of the external relative to the directory external_url: external URL Returns: Whether the external definition is recursive """ parsed_origin_url = urlparse(origin_url) parsed_external_url = urlparse(external_url) external_url = urlunparse( parsed_external_url._replace(scheme=parsed_origin_url.scheme) ) return svn_urljoin(origin_url, quote(dir_path), quote(external_path)).startswith( external_url ) diff --git a/tox.ini b/tox.ini index 3bcbc8f..3505183 100644 --- a/tox.ini +++ b/tox.ini @@ -1,75 +1,76 @@ [tox] envlist=black,flake8,mypy,py3 [testenv] extras = testing deps = pytest-cov swh.scheduler[testing] >= 0.5.0 dev: pdbpp commands = pytest --cov={envsitepackagesdir}/swh/loader/svn \ {envsitepackagesdir}/swh/loader/svn \ --cov-branch {posargs} [testenv:black] skip_install = true deps = - black==22.3.0 + black==22.10.0 commands = {envpython} -m black --check swh [testenv:flake8] skip_install = true deps = - flake8==4.0.1 - flake8-bugbear==22.3.23 + flake8==5.0.4 + flake8-bugbear==22.9.23 + pycodestyle==2.9.1 commands = {envpython} -m flake8 [testenv:mypy] extras = testing deps = mypy==0.942 commands = mypy swh # build documentation outside swh-environment using the current # git HEAD of swh-docs, is executed on CI for each diff to prevent # breaking doc build [testenv:sphinx] whitelist_externals = make usedevelop = true extras = testing deps = # fetch and install swh-docs in develop mode -e git+https://forge.softwareheritage.org/source/swh-docs#egg=swh.docs setenv = SWH_PACKAGE_DOC_TOX_BUILD = 1 # turn warnings into errors SPHINXOPTS = -W commands = make -I ../.tox/sphinx/src/swh-docs/swh/ -C docs # build documentation only inside swh-environment using local state # of swh-docs package [testenv:sphinx-dev] whitelist_externals = make usedevelop = true extras = testing deps = # install swh-docs in develop mode -e ../swh-docs setenv = SWH_PACKAGE_DOC_TOX_BUILD = 1 # turn warnings into errors SPHINXOPTS = -W commands = make -I ../.tox/sphinx-dev/src/swh-docs/swh/ -C docs