Przeglądaj źródła

Fix windows-specific test issues

Jelmer Vernooij 3 miesięcy temu
rodzic
commit
4cfe680f3f
4 zmienionych plików z 18 dodań i 54 usunięć
  1. 3 3
      Cargo.lock
  2. 0 28
      dulwich/bitmap.py
  3. 2 3
      dulwich/pack.py
  4. 13 20
      tests/compat/test_bitmap.py

+ 3 - 3
Cargo.lock

@@ -10,7 +10,7 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
 
 [[package]]
 name = "diff-tree-py"
-version = "0.24.6"
+version = "0.24.7"
 dependencies = [
  "pyo3",
 ]
@@ -50,7 +50,7 @@ dependencies = [
 
 [[package]]
 name = "objects-py"
-version = "0.24.6"
+version = "0.24.7"
 dependencies = [
  "memchr",
  "pyo3",
@@ -64,7 +64,7 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
 
 [[package]]
 name = "pack-py"
-version = "0.24.6"
+version = "0.24.7"
 dependencies = [
  "memchr",
  "pyo3",

+ 0 - 28
dulwich/bitmap.py

@@ -735,31 +735,3 @@ def write_bitmap_file(f: IO[bytes], bitmap: PackBitmap) -> None:
     if bitmap.flags & BITMAP_OPT_HASH_CACHE and bitmap.name_hash_cache:
         for hash_value in bitmap.name_hash_cache:
             f.write(struct.pack(">I", hash_value))
-
-
-def load_pack_bitmap(
-    pack_path: Union[str, os.PathLike[str]],
-    pack_index: Optional["PackIndex"] = None,
-) -> Optional[PackBitmap]:
-    """Load the bitmap file for a pack.
-
-    Args:
-        pack_path: Path to the .pack file
-        pack_index: Optional PackIndex to resolve object positions to SHAs
-
-    Returns:
-        Loaded PackBitmap or None if no bitmap exists
-    """
-    # Convert .pack to .bitmap
-    pack_str = str(pack_path)
-    if pack_str.endswith(".pack"):
-        bitmap_path = pack_str[:-5] + ".bitmap"
-    elif pack_str.endswith(".idx"):
-        bitmap_path = pack_str[:-4] + ".bitmap"
-    else:
-        bitmap_path = pack_str + ".bitmap"
-
-    if not os.path.exists(bitmap_path):
-        return None
-
-    return read_bitmap(bitmap_path, pack_index=pack_index)

+ 2 - 3
dulwich/pack.py

@@ -3536,10 +3536,9 @@ class Pack:
             ValueError: If bitmap file is invalid or corrupt
         """
         if self._bitmap is None:
-            from .bitmap import load_pack_bitmap
+            from .bitmap import read_bitmap
 
-            # load_pack_bitmap expects the pack basename (not the .bitmap path)
-            self._bitmap = load_pack_bitmap(self._basename, pack_index=self.index)
+            self._bitmap = read_bitmap(self._bitmap_path, pack_index=self.index)
         return self._bitmap
 
     def close(self) -> None:

+ 13 - 20
tests/compat/test_bitmap.py

@@ -22,14 +22,22 @@
 """Compatibility tests for git pack bitmaps."""
 
 import os
-import shutil
 import tempfile
 
+from dulwich.bitmap import (
+    BITMAP_OPT_FULL_DAG,
+    BITMAP_OPT_HASH_CACHE,
+    BITMAP_OPT_LOOKUP_TABLE,
+    BitmapEntry,
+    EWAHBitmap,
+    PackBitmap,
+    write_bitmap,
+)
 from dulwich.pack import Pack
 from dulwich.repo import Repo
 
-from .. import SkipTest, TestCase
-from .utils import require_git_version, run_git_or_fail
+from .. import TestCase
+from .utils import remove_ro, require_git_version, rmtree_ro, run_git_or_fail
 
 
 class BitmapCompatTests(TestCase):
@@ -40,7 +48,7 @@ class BitmapCompatTests(TestCase):
         # Git bitmap support was added in 2.0.0
         require_git_version((2, 0, 0))
         self._tempdir = tempfile.mkdtemp()
-        self.addCleanup(shutil.rmtree, self._tempdir)
+        self.addCleanup(rmtree_ro, self._tempdir)
 
     def _init_repo_with_bitmap(self):
         """Create a repo and generate a bitmap using git."""
@@ -79,9 +87,6 @@ class BitmapCompatTests(TestCase):
         pack_dir = os.path.join(repo_path, ".git", "objects", "pack")
         bitmap_files = [f for f in os.listdir(pack_dir) if f.endswith(".bitmap")]
 
-        if not bitmap_files:
-            raise SkipTest("Git did not generate a bitmap file")
-
         # Get the pack file (basename without extension)
         bitmap_name = bitmap_files[0]
         pack_basename = bitmap_name.replace(".bitmap", "")
@@ -183,16 +188,6 @@ class BitmapCompatTests(TestCase):
         run_git_or_fail(["repack", "-a", "-d"], cwd=None, env={"GIT_DIR": repo_path})
 
         # Now use Dulwich to write a bitmap for the pack
-        from dulwich.bitmap import (
-            BITMAP_OPT_FULL_DAG,
-            BITMAP_OPT_HASH_CACHE,
-            BITMAP_OPT_LOOKUP_TABLE,
-            BitmapEntry,
-            EWAHBitmap,
-            PackBitmap,
-            write_bitmap,
-        )
-
         pack_dir = os.path.join(repo_path, "objects", "pack")
         pack_files = [f for f in os.listdir(pack_dir) if f.endswith(".pack")]
         self.assertGreater(len(pack_files), 0, "Should have at least one pack file")
@@ -230,6 +225,7 @@ class BitmapCompatTests(TestCase):
 
         # Write the bitmap after pack is closed to avoid file locking on Windows
         bitmap_path = pack_path + ".bitmap"
+        remove_ro(bitmap_path)
         write_bitmap(bitmap_path, bitmap)
 
         # Verify git can use the repository with our bitmap
@@ -251,9 +247,6 @@ class BitmapCompatTests(TestCase):
         pack_dir = os.path.join(repo_path, ".git", "objects", "pack")
         bitmap_files = [f for f in os.listdir(pack_dir) if f.endswith(".bitmap")]
 
-        if not bitmap_files:
-            raise SkipTest("Git did not generate a bitmap file")
-
         bitmap_path = os.path.join(pack_dir, bitmap_files[0])
 
         # Read the raw file to verify header