From 2cb6a4b23015c189e35d69054b6291908a640041 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnier Date: Tue, 23 Jun 2026 22:19:12 +0200 Subject: [PATCH] fix: ref_exists also checks git-svn remote ref variant for imported tags/branches --- svn_mirror/db.py | 12 +++++++++++- svn_mirror/mirror.py | 21 +-------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/svn_mirror/db.py b/svn_mirror/db.py index 48fe55d..22dcb06 100644 --- a/svn_mirror/db.py +++ b/svn_mirror/db.py @@ -103,8 +103,18 @@ class MappingDB: ).fetchall() def ref_exists(self, git_ref: str) -> bool: + # Also check the git-svn remote variant if this is a canonical ref + variants = [git_ref] + if git_ref.startswith("refs/tags/"): + variants.append("refs/remotes/origin/tags/" + git_ref[10:]) + elif git_ref == "refs/heads/master": + variants.append("refs/remotes/origin/trunk") + elif git_ref.startswith("refs/heads/"): + variants.append("refs/remotes/origin/" + git_ref[11:]) row = self.conn.execute( - "SELECT 1 FROM svn_to_git WHERE git_ref=?", (git_ref,) + "SELECT 1 FROM svn_to_git WHERE git_ref IN ({})".format( + ",".join("?" * len(variants)) + ), variants ).fetchone() return row is not None diff --git a/svn_mirror/mirror.py b/svn_mirror/mirror.py index 5a77177..dfcee7f 100644 --- a/svn_mirror/mirror.py +++ b/svn_mirror/mirror.py @@ -362,29 +362,10 @@ class Mirror: return git_ref def _write_mappings_to_db(self, mappings: List[Tuple[int, str, str, str]]): - """Bulk-insert parsed mappings into SQLite. - - Also records entries for converted refs (e.g. refs/remotes/origin/tags/* - → refs/tags/*) so that git_to_svn push logic doesn't re-push them. - """ + """Bulk-insert parsed mappings into SQLite.""" logger.info("Writing %d mapping entries to DB…", len(mappings)) for rev, sha, branch, ref in mappings: self.db.record_mapping(rev, sha, branch, ref, source="svn") - # Also record the converted ref if this is a tag - tag_prefix = "refs/remotes/origin/tags/" - if ref.startswith(tag_prefix): - tag_name = ref[len(tag_prefix):] - tag_ref = f"refs/tags/{tag_name}" - self.db.record_mapping(rev, sha, branch, tag_ref, source="svn") - # Convert branch refs too - br_prefix = "refs/remotes/origin/" - if ref.startswith(br_prefix) and not ref.startswith(tag_prefix): - rest = ref[len(br_prefix):] - if rest == "trunk": - head_ref = "refs/heads/master" - else: - head_ref = f"refs/heads/{rest}" - self.db.record_mapping(rev, sha, branch, head_ref, source="svn") logger.info("Mapping DB now has %d entries", self.db.mapping_count()) def _finalize_import_state(self):