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

Fix 'Fetching objects' messages in test output

Jelmer Vernooij 4 месяцев назад
Родитель
Сommit
50cd8a5927
7 измененных файлов с 54 добавлено и 18 удалено
  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:
             with Repo(".") as repo:
                 repo.refs.set_symbolic_ref(args.name.encode(), args.ref.encode())
                 repo.refs.set_symbolic_ref(args.name.encode(), args.ref.encode())
+            return 0
         else:
         else:
             # Read symbolic reference
             # Read symbolic reference
             from .repo import Repo
             from .repo import Repo
@@ -1144,6 +1145,7 @@ class cmd_symbolic_ref(Command):
                         logger.info(target[5:].decode())
                         logger.info(target[5:].decode())
                     else:
                     else:
                         logger.info(target.decode())
                         logger.info(target.decode())
+                    return 0
                 except KeyError:
                 except KeyError:
                     logging.error("fatal: ref '%s' is not a symbolic ref", args.name)
                     logging.error("fatal: ref '%s' is not a symbolic ref", args.name)
                     return 1
                     return 1

+ 3 - 1
dulwich/gc.py

@@ -368,7 +368,9 @@ def should_run_gc(repo: "BaseRepo", config: Optional["Config"] = None) -> bool:
     return False
     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.
     """Run automatic garbage collection if needed.
 
 
     Args:
     Args:

+ 2 - 2
dulwich/lfs.py

@@ -35,8 +35,6 @@ Key components:
 import hashlib
 import hashlib
 import json
 import json
 import logging
 import logging
-
-logger = logging.getLogger(__name__)
 import os
 import os
 import tempfile
 import tempfile
 from collections.abc import Iterable
 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.parse import urljoin, urlparse
 from urllib.request import Request, urlopen
 from urllib.request import Request, urlopen
 
 
+logger = logging.getLogger(__name__)
+
 if TYPE_CHECKING:
 if TYPE_CHECKING:
     import urllib3
     import urllib3
 
 

+ 5 - 3
dulwich/object_store.py

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

+ 0 - 1
tests/__init__.py

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

+ 16 - 4
tests/compat/test_dumb.py

@@ -21,6 +21,7 @@
 
 
 """Compatibility tests for dumb HTTP git repositories."""
 """Compatibility tests for dumb HTTP git repositories."""
 
 
+import io
 import os
 import os
 import sys
 import sys
 import tempfile
 import tempfile
@@ -38,6 +39,10 @@ from tests.compat.utils import (
 )
 )
 
 
 
 
+def no_op_progress(msg):
+    """Progress callback that does nothing."""
+
+
 class DumbHTTPRequestHandler(SimpleHTTPRequestHandler):
 class DumbHTTPRequestHandler(SimpleHTTPRequestHandler):
     """HTTP request handler for dumb git protocol."""
     """HTTP request handler for dumb git protocol."""
 
 
@@ -163,7 +168,8 @@ class DumbHTTPClientNoPackTests(CompatTestCase):
     )
     )
     def test_clone_dumb(self):
     def test_clone_dumb(self):
         dest_path = os.path.join(self.temp_dir, "cloned")
         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
         assert b"HEAD" in repo
 
 
     def test_clone_from_dumb_http(self):
     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/")
                     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
             # Update refs
             for ref, sha in result.refs.items():
             for ref, sha in result.refs.items():
@@ -237,7 +245,9 @@ class DumbHTTPClientNoPackTests(CompatTestCase):
                         wants.append(sha)
                         wants.append(sha)
                 return wants
                 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
             # Update refs
             for ref, sha in result.refs.items():
             for ref, sha in result.refs.items():
@@ -282,7 +292,9 @@ class DumbHTTPClientNoPackTests(CompatTestCase):
                     if ref.startswith((b"refs/heads/", b"refs/tags/"))
                     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
             # Update refs
             for ref, sha in result.refs.items():
             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):
 def no_op_progress(msg):
     """Progress callback that does nothing."""
     """Progress callback that does nothing."""
-    pass
 
 
 
 
 class GCTestCase(TestCase):
 class GCTestCase(TestCase):
@@ -164,7 +163,9 @@ class GCTestCase(TestCase):
         self.repo.object_store.add_object(unreachable_blob)
         self.repo.object_store.add_object(unreachable_blob)
 
 
         # Run garbage collection (grace_period=None means no grace period check)
         # 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
         # Check results
         self.assertIsInstance(stats, GCStats)
         self.assertIsInstance(stats, GCStats)
@@ -199,7 +200,13 @@ class GCTestCase(TestCase):
         self.repo.object_store.add_object(unreachable_blob)
         self.repo.object_store.add_object(unreachable_blob)
 
 
         # Run garbage collection with dry run (grace_period=None means no grace period check)
         # 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
         # Check that object would be pruned but still exists
         # On Windows, the repository initialization might create additional unreachable objects
         # 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
         # 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
         # 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
         # Check that the object was NOT pruned
         self.assertEqual(set(), stats.pruned_objects)
         self.assertEqual(set(), stats.pruned_objects)
@@ -249,7 +262,9 @@ class GCTestCase(TestCase):
 
 
         # Run garbage collection with a 1 hour grace period
         # Run garbage collection with a 1 hour grace period
         # The object is 2 hours old, so it should be pruned
         # 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
         # Check that the object was pruned
         self.assertEqual({old_blob.id}, stats.pruned_objects)
         self.assertEqual({old_blob.id}, stats.pruned_objects)
@@ -269,7 +284,9 @@ class GCTestCase(TestCase):
         self.assertIn(unreachable_blob.id, self.repo.object_store)
         self.assertIn(unreachable_blob.id, self.repo.object_store)
 
 
         # Run garbage collection (grace_period=None means no grace period check)
         # 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
         # Check that the packed object was pruned
         self.assertEqual({unreachable_blob.id}, stats.pruned_objects)
         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
             self.repo.object_store, "get_object_mtime", side_effect=KeyError
         ):
         ):
             # Run garbage collection with grace period
             # 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
         # Object should be kept because mtime couldn't be determined
         self.assertEqual(set(), stats.pruned_objects)
         self.assertEqual(set(), stats.pruned_objects)