Explorar o código

Fix 'Fetching objects' messages in test output

Jelmer Vernooij hai 4 meses
pai
achega
50cd8a5927
Modificáronse 7 ficheiros con 54 adicións e 18 borrados
  1. 2 0
      dulwich/cli.py
  2. 3 1
      dulwich/gc.py
  3. 2 2
      dulwich/lfs.py
  4. 5 3
      dulwich/object_store.py
  5. 0 1
      tests/__init__.py
  6. 16 4
      tests/compat/test_dumb.py
  7. 26 7
      tests/test_gc.py

+ 2 - 0
dulwich/cli.py

@@ -1133,6 +1133,7 @@ class cmd_symbolic_ref(Command):
 
             with Repo(".") as repo:
                 repo.refs.set_symbolic_ref(args.name.encode(), args.ref.encode())
+            return 0
         else:
             # Read symbolic reference
             from .repo import Repo
@@ -1144,6 +1145,7 @@ class cmd_symbolic_ref(Command):
                         logger.info(target[5:].decode())
                     else:
                         logger.info(target.decode())
+                    return 0
                 except KeyError:
                     logging.error("fatal: ref '%s' is not a symbolic ref", args.name)
                     return 1

+ 3 - 1
dulwich/gc.py

@@ -368,7 +368,9 @@ def should_run_gc(repo: "BaseRepo", config: Optional["Config"] = None) -> bool:
     return False
 
 
-def maybe_auto_gc(repo: "Repo", config: Optional["Config"] = None, progress: Optional[Callable] = None) -> bool:
+def maybe_auto_gc(
+    repo: "Repo", config: Optional["Config"] = None, progress: Optional[Callable] = None
+) -> bool:
     """Run automatic garbage collection if needed.
 
     Args:

+ 2 - 2
dulwich/lfs.py

@@ -35,8 +35,6 @@ Key components:
 import hashlib
 import json
 import logging
-
-logger = logging.getLogger(__name__)
 import os
 import tempfile
 from collections.abc import Iterable
@@ -45,6 +43,8 @@ from typing import TYPE_CHECKING, BinaryIO, Optional, Union
 from urllib.parse import urljoin, urlparse
 from urllib.request import Request, urlopen
 
+logger = logging.getLogger(__name__)
+
 if TYPE_CHECKING:
     import urllib3
 

+ 5 - 3
dulwich/object_store.py

@@ -774,7 +774,7 @@ class PackBasedObjectStore(BaseObjectStore, PackedObjectContainer):
 
         Args:
           progress: Optional progress reporting callback
-          
+
         Returns: Number of objects packed
         """
         objects: list[tuple[ShaFile, None]] = []
@@ -787,7 +787,9 @@ class PackBasedObjectStore(BaseObjectStore, PackedObjectContainer):
             self.delete_loose_object(obj.id)
         return len(objects)
 
-    def repack(self, exclude: Optional[set] = None, progress: Optional[Callable] = None) -> int:
+    def repack(
+        self, exclude: Optional[set] = None, progress: Optional[Callable] = None
+    ) -> int:
         """Repack the packs in this repository.
 
         Note that this implementation is fairly naive and currently keeps all
@@ -2515,7 +2517,7 @@ class BucketBasedObjectStore(PackBasedObjectStore):
         """Pack loose objects. Returns number of objects packed.
 
         BucketBasedObjectStore doesn't support loose objects, so this is a no-op.
-        
+
         Args:
           progress: Optional progress reporting callback (ignored)
         """

+ 0 - 1
tests/__init__.py

@@ -30,7 +30,6 @@ __all__ = [
 ]
 
 import doctest
-import logging
 import os
 import shutil
 import subprocess

+ 16 - 4
tests/compat/test_dumb.py

@@ -21,6 +21,7 @@
 
 """Compatibility tests for dumb HTTP git repositories."""
 
+import io
 import os
 import sys
 import tempfile
@@ -38,6 +39,10 @@ from tests.compat.utils import (
 )
 
 
+def no_op_progress(msg):
+    """Progress callback that does nothing."""
+
+
 class DumbHTTPRequestHandler(SimpleHTTPRequestHandler):
     """HTTP request handler for dumb git protocol."""
 
@@ -163,7 +168,8 @@ class DumbHTTPClientNoPackTests(CompatTestCase):
     )
     def test_clone_dumb(self):
         dest_path = os.path.join(self.temp_dir, "cloned")
-        repo = clone(self.server.url, dest_path)
+        # Use a dummy errstream to suppress progress output
+        repo = clone(self.server.url, dest_path, errstream=io.BytesIO())
         assert b"HEAD" in repo
 
     def test_clone_from_dumb_http(self):
@@ -183,7 +189,9 @@ class DumbHTTPClientNoPackTests(CompatTestCase):
                     sha for ref, sha in refs.items() if ref.startswith(b"refs/heads/")
                 ]
 
-            result = client.fetch("/", dest_repo, determine_wants=determine_wants)
+            result = client.fetch(
+                "/", dest_repo, determine_wants=determine_wants, progress=no_op_progress
+            )
 
             # Update refs
             for ref, sha in result.refs.items():
@@ -237,7 +245,9 @@ class DumbHTTPClientNoPackTests(CompatTestCase):
                         wants.append(sha)
                 return wants
 
-            result = client.fetch("/", dest_repo, determine_wants=determine_wants)
+            result = client.fetch(
+                "/", dest_repo, determine_wants=determine_wants, progress=no_op_progress
+            )
 
             # Update refs
             for ref, sha in result.refs.items():
@@ -282,7 +292,9 @@ class DumbHTTPClientNoPackTests(CompatTestCase):
                     if ref.startswith((b"refs/heads/", b"refs/tags/"))
                 ]
 
-            result = client.fetch("/", dest_repo, determine_wants=determine_wants)
+            result = client.fetch(
+                "/", dest_repo, determine_wants=determine_wants, progress=no_op_progress
+            )
 
             # Update refs
             for ref, sha in result.refs.items():

+ 26 - 7
tests/test_gc.py

@@ -23,7 +23,6 @@ from dulwich.repo import MemoryRepo, Repo
 
 def no_op_progress(msg):
     """Progress callback that does nothing."""
-    pass
 
 
 class GCTestCase(TestCase):
@@ -164,7 +163,9 @@ class GCTestCase(TestCase):
         self.repo.object_store.add_object(unreachable_blob)
 
         # Run garbage collection (grace_period=None means no grace period check)
-        stats = garbage_collect(self.repo, prune=True, grace_period=None, progress=no_op_progress)
+        stats = garbage_collect(
+            self.repo, prune=True, grace_period=None, progress=no_op_progress
+        )
 
         # Check results
         self.assertIsInstance(stats, GCStats)
@@ -199,7 +200,13 @@ class GCTestCase(TestCase):
         self.repo.object_store.add_object(unreachable_blob)
 
         # Run garbage collection with dry run (grace_period=None means no grace period check)
-        stats = garbage_collect(self.repo, prune=True, grace_period=None, dry_run=True, progress=no_op_progress)
+        stats = garbage_collect(
+            self.repo,
+            prune=True,
+            grace_period=None,
+            dry_run=True,
+            progress=no_op_progress,
+        )
 
         # Check that object would be pruned but still exists
         # On Windows, the repository initialization might create additional unreachable objects
@@ -219,7 +226,13 @@ class GCTestCase(TestCase):
 
         # Run garbage collection with a 1 hour grace period, but dry run to avoid packing
         # The object was just created, so it should not be pruned
-        stats = garbage_collect(self.repo, prune=True, grace_period=3600, dry_run=True, progress=no_op_progress)
+        stats = garbage_collect(
+            self.repo,
+            prune=True,
+            grace_period=3600,
+            dry_run=True,
+            progress=no_op_progress,
+        )
 
         # Check that the object was NOT pruned
         self.assertEqual(set(), stats.pruned_objects)
@@ -249,7 +262,9 @@ class GCTestCase(TestCase):
 
         # Run garbage collection with a 1 hour grace period
         # The object is 2 hours old, so it should be pruned
-        stats = garbage_collect(self.repo, prune=True, grace_period=3600, progress=no_op_progress)
+        stats = garbage_collect(
+            self.repo, prune=True, grace_period=3600, progress=no_op_progress
+        )
 
         # Check that the object was pruned
         self.assertEqual({old_blob.id}, stats.pruned_objects)
@@ -269,7 +284,9 @@ class GCTestCase(TestCase):
         self.assertIn(unreachable_blob.id, self.repo.object_store)
 
         # Run garbage collection (grace_period=None means no grace period check)
-        stats = garbage_collect(self.repo, prune=True, grace_period=None, progress=no_op_progress)
+        stats = garbage_collect(
+            self.repo, prune=True, grace_period=None, progress=no_op_progress
+        )
 
         # Check that the packed object was pruned
         self.assertEqual({unreachable_blob.id}, stats.pruned_objects)
@@ -415,7 +432,9 @@ class GCTestCase(TestCase):
             self.repo.object_store, "get_object_mtime", side_effect=KeyError
         ):
             # Run garbage collection with grace period
-            stats = garbage_collect(self.repo, prune=True, grace_period=3600, progress=no_op_progress)
+            stats = garbage_collect(
+                self.repo, prune=True, grace_period=3600, progress=no_op_progress
+            )
 
         # Object should be kept because mtime couldn't be determined
         self.assertEqual(set(), stats.pruned_objects)