File fix_dulwich_compatibility.patch of Package mercurial-extension-hg-git

# HG changeset patch
# User Antonio Muci <a.mux@inwind.it>
# Date 1766182484 -3600
#      Fri Dec 19 23:14:44 2025 +0100
# Node ID e54301fcf92a86da2011c9dcbf49739460e3c53f
# Parent  1c168e428a2205827c4c412d1f8e041be1c7cb93
# EXP-Topic dulwich-0.25
compat: use PEELED_TAG_SUFFIX instead of ANNOTATED_TAG_SUFFIX

Starting from our oldest supported dulwich (0.22.8), and until 0.24.10,
ANNOTATED_TAG_SUFFIX has been an alias for PEELED_TAG_SUFFIX (see sources later
on).

Dulwich 0.25.0 is going to remove support for the alias and move
PEELED_TAG_SUFFIX in another module. Let's address the aliasing in this first
commit. The next one will add compatibility with both old and recent dulwich
(>= 0.25.0).

No functional changes.

Source:
- https://github.com/jelmer/dulwich/blob/dulwich-0.22.8/dulwich/refs.py#L47
- https://github.com/jelmer/dulwich/blob/dulwich-0.24.10/dulwich/refs.py#L62

diff --git a/hggit/git2hg.py b/hggit/git2hg.py
--- a/hggit/git2hg.py
+++ b/hggit/git2hg.py
@@ -6,9 +6,9 @@
 from dulwich import config as dul_config
 from dulwich.objects import Commit, Tag
 from dulwich.refs import (
-    ANNOTATED_TAG_SUFFIX,
     LOCAL_BRANCH_PREFIX,
     LOCAL_TAG_PREFIX,
+    PEELED_TAG_SUFFIX,
 )
 from mercurial.i18n import _
 
@@ -306,7 +306,7 @@
                     raise error.RepoLookupError(msg)
     else:
         for ref, sha in refs.items():
-            if not ref.endswith(ANNOTATED_TAG_SUFFIX) and (
+            if not ref.endswith(PEELED_TAG_SUFFIX) and (
                 ref.startswith(LOCAL_BRANCH_PREFIX)
                 or ref.startswith(LOCAL_TAG_PREFIX)
                 or ref == b'HEAD'
diff --git a/hggit/git_handler.py b/hggit/git_handler.py
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -10,9 +10,9 @@
 from dulwich.objects import Blob, Commit, Tag, Tree, parse_timezone
 from dulwich.pack import apply_delta
 from dulwich.refs import (
-    ANNOTATED_TAG_SUFFIX,
     LOCAL_BRANCH_PREFIX,
     LOCAL_TAG_PREFIX,
+    PEELED_TAG_SUFFIX,
 )
 from dulwich.repo import Repo, check_ref_format
 from dulwich import client
@@ -1638,8 +1638,8 @@
             # pull tags pointing to known revisions, including
             # annotated tags
             for ref, sha in refs.items():
-                if ref.endswith(ANNOTATED_TAG_SUFFIX) and sha in self._map_git:
-                    actual_ref = ref[: -len(ANNOTATED_TAG_SUFFIX)]
+                if ref.endswith(PEELED_TAG_SUFFIX) and sha in self._map_git:
+                    actual_ref = ref[: -len(PEELED_TAG_SUFFIX)]
                     filteredrefs.setdefault(actual_ref, refs[actual_ref])
 
             return [x for x in filteredrefs.values() if x not in self.git]
@@ -1855,7 +1855,7 @@
         repotags = self.repo.tags()
         new_refs = {}
         for k in refs:
-            if k.endswith(ANNOTATED_TAG_SUFFIX) or not k.startswith(
+            if k.endswith(PEELED_TAG_SUFFIX) or not k.startswith(
                 LOCAL_TAG_PREFIX
             ):
                 continue
@@ -2036,7 +2036,7 @@
 
         for ref_name, sha in refs.items():
             if (
-                ref_name.endswith(ANNOTATED_TAG_SUFFIX)
+                ref_name.endswith(PEELED_TAG_SUFFIX)
                 or sha not in self.git.object_store
             ):
                 # the sha points to a peeled tag; we should either
# HG changeset patch
# User Antonio Muci <a.mux@inwind.it>
# Date 1766181797 -3600
#      Fri Dec 19 23:03:17 2025 +0100
# Node ID fa37b51caafa972e2fa54b86afc723f21c647ced
# Parent  e54301fcf92a86da2011c9dcbf49739460e3c53f
# EXP-Topic dulwich-0.25
compat: support dulwich 0.25

In dulwich 0.24.10 ANNOTATED_TAG_SUFFIX was already an alias for
PEELED_TAG_SUFFIX. We stopped relying on the alias in the previous commit.

Dulwich 0.25.0 removed the alias, and moved PEELED_TAG_SUFFIX from dulwich.refs
to dulwich.protocol.

This commit centralizes in hggit.compat a backward compatiblity fix for
supporting PEELED_TAG_SUFFIX in dulwich <=0.24.10 and >=0.25.10.

The tests that broke on dulwich 0.25.0 and that are now fixed are
test-url-parsing.py and test-doctest.py.

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -107,7 +107,7 @@
       - ALPINE: "3.19"
         DULWICH:
           - "0.22.1"
-          - "0.24.9"
+          - "0.25.0"
 
 # Test that the tests pass against the current branches
 Development:
diff --git a/hggit/compat.py b/hggit/compat.py
--- a/hggit/compat.py
+++ b/hggit/compat.py
@@ -10,3 +10,11 @@
 
     def delete_loose_object(object_store: PackBasedObjectStore, sha: bytes):
         object_store._remove_loose_object(sha)
+
+
+try:
+    # dulwich >= 0.25.0
+    from dulwich.protocol import PEELED_TAG_SUFFIX
+except ImportError:
+    # dulwich <= 0.24.10
+    from dulwich.refs import PEELED_TAG_SUFFIX
diff --git a/hggit/git2hg.py b/hggit/git2hg.py
--- a/hggit/git2hg.py
+++ b/hggit/git2hg.py
@@ -8,7 +8,6 @@
 from dulwich.refs import (
     LOCAL_BRANCH_PREFIX,
     LOCAL_TAG_PREFIX,
-    PEELED_TAG_SUFFIX,
 )
 from mercurial.i18n import _
 
@@ -17,6 +16,7 @@
 from mercurial import phases
 
 from . import config
+from .compat import PEELED_TAG_SUFFIX
 
 
 def get_public(ui, refs, remote_names):
diff --git a/hggit/git_handler.py b/hggit/git_handler.py
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -12,7 +12,6 @@
 from dulwich.refs import (
     LOCAL_BRANCH_PREFIX,
     LOCAL_TAG_PREFIX,
-    PEELED_TAG_SUFFIX,
 )
 from dulwich.repo import Repo, check_ref_format
 from dulwich import client
@@ -43,6 +42,7 @@
 from . import git2hg
 from . import hg2git
 from . import util
+from .compat import PEELED_TAG_SUFFIX
 from .overlay import overlayrepo
 
 REMOTE_BRANCH_PREFIX = b'refs/remotes/'
openSUSE Build Service is sponsored by