Просмотр исходного кода

Make generate_pack_data() arguments consistent and keyword-only

Jelmer Vernooij 2 месяцев назад
Родитель
Сommit
5b154847c7

+ 10 - 2
dulwich/client.py

@@ -89,7 +89,9 @@ if TYPE_CHECKING:
             self,
             have: Set[bytes],
             want: Set[bytes],
+            *,
             ofs_delta: bool = False,
+            progress: Optional[Callable[[bytes], None]] = None,
         ) -> tuple[int, Iterator[UnpackedObject]]:
             """Generate pack data for the given have and want sets."""
             ...
@@ -1531,7 +1533,8 @@ class TraditionalGitClient(GitClient):
             pack_data_count, pack_data = generate_pack_data(
                 header_handler.have,
                 header_handler.want,
-                (CAPABILITY_OFS_DELTA in negotiated_capabilities),
+                ofs_delta=(CAPABILITY_OFS_DELTA in negotiated_capabilities),
+                progress=progress,
             )
 
             if self._should_send_pack(new_refs):
@@ -2276,7 +2279,11 @@ class LocalGitClient(GitClient):
             if not want and set(new_refs.items()).issubset(set(old_refs.items())):
                 return SendPackResult(_to_optional_dict(new_refs), ref_status={})
 
-            target.object_store.add_pack_data(*generate_pack_data(set(have), set(want)))
+            target.object_store.add_pack_data(
+                *generate_pack_data(
+                    set(have), set(want), ofs_delta=True, progress=progress
+                )
+            )
 
             ref_status: dict[bytes, Optional[str]] = {}
 
@@ -3741,6 +3748,7 @@ class AbstractHttpGitClient(GitClient):
                 header_handler.have,
                 header_handler.want,
                 ofs_delta=(CAPABILITY_OFS_DELTA in negotiated_capabilities),
+                progress=progress,
             )
             if self._should_send_pack(new_refs):
                 yield from PackChunkGenerator(pack_data_count, pack_data)

+ 2 - 0
dulwich/object_store.py

@@ -495,6 +495,7 @@ class BaseObjectStore:
         self,
         have: Iterable[bytes],
         want: Iterable[bytes],
+        *,
         shallow: Optional[Set[bytes]] = None,
         progress: Optional[Callable[..., None]] = None,
         ofs_delta: bool = True,
@@ -806,6 +807,7 @@ class PackBasedObjectStore(PackCapableObjectStore, PackedObjectContainer):
         self,
         have: Iterable[bytes],
         want: Iterable[bytes],
+        *,
         shallow: Optional[Set[bytes]] = None,
         progress: Optional[Callable[..., None]] = None,
         ofs_delta: bool = True,

+ 3 - 1
dulwich/porcelain.py

@@ -3048,12 +3048,14 @@ def push(
             def generate_pack_data_wrapper(
                 have: AbstractSet[bytes],
                 want: AbstractSet[bytes],
+                *,
                 ofs_delta: bool = False,
+                progress: Optional[Callable[..., None]] = None,
             ) -> tuple[int, Iterator[UnpackedObject]]:
                 # Wrap to match the expected signature
                 # Convert AbstractSet to set since generate_pack_data expects set
                 return r.generate_pack_data(
-                    set(have), set(want), progress=None, ofs_delta=ofs_delta
+                    set(have), set(want), progress=progress, ofs_delta=ofs_delta
                 )
 
             result = client.send_pack(

+ 6 - 1
dulwich/repo.py

@@ -673,6 +673,8 @@ class BaseRepo:
         self,
         have: set[ObjectID],
         want: set[ObjectID],
+        *,
+        shallow: Optional[set[ObjectID]] = None,
         progress: Optional[Callable[[str], None]] = None,
         ofs_delta: Optional[bool] = None,
     ) -> tuple[int, Iterator["UnpackedObject"]]:
@@ -681,13 +683,16 @@ class BaseRepo:
         Args:
           have: List of SHA1s of objects that should not be sent
           want: List of SHA1s of objects that should be sent
+          shallow: Set of shallow commit SHA1s to skip (defaults to repo's shallow commits)
           ofs_delta: Whether OFS deltas can be included
           progress: Optional progress reporting method
         """
+        if shallow is None:
+            shallow = self.get_shallow()
         return self.object_store.generate_pack_data(
             have,
             want,
-            shallow=self.get_shallow(),
+            shallow=shallow,
             progress=progress,
             ofs_delta=ofs_delta if ofs_delta is not None else DEFAULT_OFS_DELTA,
         )

+ 1 - 1
examples/rename-branch.py

@@ -16,7 +16,7 @@ args = parser.parse_args()
 client, path = get_transport_and_path_from_url(args.url)
 
 
-def generate_pack_data(*args, **kwargs):
+def generate_pack_data(have, want, *, ofs_delta=False, progress=None):
     return pack_objects_to_data([])
 
 

+ 24 - 8
tests/compat/test_client.py

@@ -92,10 +92,14 @@ class DulwichClientTestBase:
 
             # Wrap generate_pack_data to match expected signature
             def generate_pack_data_wrapper(
-                have: set[bytes], want: set[bytes], ofs_delta: bool = False
+                have: set[bytes],
+                want: set[bytes],
+                *,
+                ofs_delta: bool = False,
+                progress=None,
             ) -> tuple[int, Iterator]:
                 return src.generate_pack_data(
-                    have, want, progress=None, ofs_delta=ofs_delta
+                    have, want, progress=progress, ofs_delta=ofs_delta
                 )
 
             c.send_pack(
@@ -150,10 +154,14 @@ class DulwichClientTestBase:
 
             # Wrap generate_pack_data to match expected signature
             def generate_pack_data_wrapper(
-                have: set[bytes], want: set[bytes], ofs_delta: bool = False
+                have: set[bytes],
+                want: set[bytes],
+                *,
+                ofs_delta: bool = False,
+                progress=None,
             ) -> tuple[int, Iterator]:
                 return local.generate_pack_data(
-                    have, want, progress=None, ofs_delta=ofs_delta
+                    have, want, progress=progress, ofs_delta=ofs_delta
                 )
 
             c.send_pack(remote_path, lambda _: sendrefs, generate_pack_data_wrapper)
@@ -170,10 +178,14 @@ class DulwichClientTestBase:
 
             # Wrap generate_pack_data to match expected signature
             def generate_pack_data_wrapper(
-                have: set[bytes], want: set[bytes], ofs_delta: bool = False
+                have: set[bytes],
+                want: set[bytes],
+                *,
+                ofs_delta: bool = False,
+                progress=None,
             ) -> tuple[int, Iterator]:
                 return src.generate_pack_data(
-                    have, want, progress=None, ofs_delta=ofs_delta
+                    have, want, progress=progress, ofs_delta=ofs_delta
                 )
 
             c.send_pack(
@@ -211,10 +223,14 @@ class DulwichClientTestBase:
 
         # Wrap generate_pack_data to match expected signature
         def generate_pack_data_wrapper(
-            have: set[bytes], want: set[bytes], ofs_delta: bool = False
+            have: set[bytes],
+            want: set[bytes],
+            *,
+            ofs_delta: bool = False,
+            progress=None,
         ) -> tuple[int, Iterator]:
             return src.generate_pack_data(
-                have, want, progress=None, ofs_delta=ofs_delta
+                have, want, progress=progress, ofs_delta=ofs_delta
             )
 
         return sendrefs, generate_pack_data_wrapper

+ 7 - 7
tests/test_client.py

@@ -358,7 +358,7 @@ class GitClientTests(TestCase):
                 b"refs/foo/bar": commit.id,
             }
 
-        def generate_pack_data(have, want, ofs_delta=False, progress=None):
+        def generate_pack_data(have, want, *, ofs_delta=False, progress=None):
             return pack_objects_to_data(
                 [
                     (commit, None),
@@ -385,7 +385,7 @@ class GitClientTests(TestCase):
         def update_refs(refs):
             return {b"refs/heads/master": b"310ca9477129b8586fa2afc779c1f57cf64bba6c"}
 
-        def generate_pack_data(have, want, ofs_delta=False, progress=None):
+        def generate_pack_data(have, want, *, ofs_delta=False, progress=None):
             return 0, []
 
         self.client.send_pack(b"/", update_refs, generate_pack_data)
@@ -405,7 +405,7 @@ class GitClientTests(TestCase):
         def update_refs(refs):
             return {b"refs/heads/master": b"0" * 40}
 
-        def generate_pack_data(have, want, ofs_delta=False, progress=None):
+        def generate_pack_data(have, want, *, ofs_delta=False, progress=None):
             return 0, []
 
         self.client.send_pack(b"/", update_refs, generate_pack_data)
@@ -429,7 +429,7 @@ class GitClientTests(TestCase):
         def update_refs(refs):
             return {b"refs/heads/master": b"0" * 40}
 
-        def generate_pack_data(have, want, ofs_delta=False, progress=None):
+        def generate_pack_data(have, want, *, ofs_delta=False, progress=None):
             return 0, []
 
         self.client.send_pack(b"/", update_refs, generate_pack_data)
@@ -456,7 +456,7 @@ class GitClientTests(TestCase):
                 b"refs/heads/master": b"310ca9477129b8586fa2afc779c1f57cf64bba6c",
             }
 
-        def generate_pack_data(have, want, ofs_delta=False, progress=None):
+        def generate_pack_data(have, want, *, ofs_delta=False, progress=None):
             return 0, []
 
         f = BytesIO()
@@ -496,7 +496,7 @@ class GitClientTests(TestCase):
                 b"refs/heads/master": b"310ca9477129b8586fa2afc779c1f57cf64bba6c",
             }
 
-        def generate_pack_data(have, want, ofs_delta=False, progress=None):
+        def generate_pack_data(have, want, *, ofs_delta=False, progress=None):
             return pack_objects_to_data(
                 [
                     (commit, None),
@@ -533,7 +533,7 @@ class GitClientTests(TestCase):
         def update_refs(refs):
             return {b"refs/heads/master": b"0" * 40}
 
-        def generate_pack_data(have, want, ofs_delta=False, progress=None):
+        def generate_pack_data(have, want, *, ofs_delta=False, progress=None):
             return 0, []
 
         result = self.client.send_pack(b"/", update_refs, generate_pack_data)

+ 1 - 1
tests/test_porcelain.py

@@ -5267,7 +5267,7 @@ class PushTests(PorcelainTestCase):
         )
 
         self.assertEqual(b"", outstream.getvalue())
-        self.assertTrue(re.match(b"Push to .* successful.\n", errstream.getvalue()))
+        self.assertTrue(re.search(b"Push to .* successful.\n", errstream.getvalue()))
 
     def test_push_returns_sendpackresult(self) -> None:
         """Test that push returns a SendPackResult with per-ref information."""