fix: ref_exists also checks git-svn remote ref variant for imported tags/branches

This commit is contained in:
2026-06-23 22:19:12 +02:00
parent 4d6326231b
commit 2cb6a4b230
2 changed files with 12 additions and 21 deletions
+11 -1
View File
@@ -103,8 +103,18 @@ class MappingDB:
).fetchall() ).fetchall()
def ref_exists(self, git_ref: str) -> bool: 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( 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() ).fetchone()
return row is not None return row is not None
+1 -20
View File
@@ -362,29 +362,10 @@ class Mirror:
return git_ref return git_ref
def _write_mappings_to_db(self, mappings: List[Tuple[int, str, str, str]]): def _write_mappings_to_db(self, mappings: List[Tuple[int, str, str, str]]):
"""Bulk-insert parsed mappings into SQLite. """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.
"""
logger.info("Writing %d mapping entries to DB…", len(mappings)) logger.info("Writing %d mapping entries to DB…", len(mappings))
for rev, sha, branch, ref in mappings: for rev, sha, branch, ref in mappings:
self.db.record_mapping(rev, sha, branch, ref, source="svn") 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()) logger.info("Mapping DB now has %d entries", self.db.mapping_count())
def _finalize_import_state(self): def _finalize_import_state(self):