|
@@ -22,14 +22,22 @@
|
|
|
"""Compatibility tests for git pack bitmaps."""
|
|
"""Compatibility tests for git pack bitmaps."""
|
|
|
|
|
|
|
|
import os
|
|
import os
|
|
|
-import shutil
|
|
|
|
|
import tempfile
|
|
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.pack import Pack
|
|
|
from dulwich.repo import Repo
|
|
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):
|
|
class BitmapCompatTests(TestCase):
|
|
@@ -40,7 +48,7 @@ class BitmapCompatTests(TestCase):
|
|
|
# Git bitmap support was added in 2.0.0
|
|
# Git bitmap support was added in 2.0.0
|
|
|
require_git_version((2, 0, 0))
|
|
require_git_version((2, 0, 0))
|
|
|
self._tempdir = tempfile.mkdtemp()
|
|
self._tempdir = tempfile.mkdtemp()
|
|
|
- self.addCleanup(shutil.rmtree, self._tempdir)
|
|
|
|
|
|
|
+ self.addCleanup(rmtree_ro, self._tempdir)
|
|
|
|
|
|
|
|
def _init_repo_with_bitmap(self):
|
|
def _init_repo_with_bitmap(self):
|
|
|
"""Create a repo and generate a bitmap using git."""
|
|
"""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")
|
|
pack_dir = os.path.join(repo_path, ".git", "objects", "pack")
|
|
|
bitmap_files = [f for f in os.listdir(pack_dir) if f.endswith(".bitmap")]
|
|
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)
|
|
# Get the pack file (basename without extension)
|
|
|
bitmap_name = bitmap_files[0]
|
|
bitmap_name = bitmap_files[0]
|
|
|
pack_basename = bitmap_name.replace(".bitmap", "")
|
|
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})
|
|
run_git_or_fail(["repack", "-a", "-d"], cwd=None, env={"GIT_DIR": repo_path})
|
|
|
|
|
|
|
|
# Now use Dulwich to write a bitmap for the pack
|
|
# 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_dir = os.path.join(repo_path, "objects", "pack")
|
|
|
pack_files = [f for f in os.listdir(pack_dir) if f.endswith(".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")
|
|
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
|
|
# Write the bitmap after pack is closed to avoid file locking on Windows
|
|
|
bitmap_path = pack_path + ".bitmap"
|
|
bitmap_path = pack_path + ".bitmap"
|
|
|
|
|
+ remove_ro(bitmap_path)
|
|
|
write_bitmap(bitmap_path, bitmap)
|
|
write_bitmap(bitmap_path, bitmap)
|
|
|
|
|
|
|
|
# Verify git can use the repository with our 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")
|
|
pack_dir = os.path.join(repo_path, ".git", "objects", "pack")
|
|
|
bitmap_files = [f for f in os.listdir(pack_dir) if f.endswith(".bitmap")]
|
|
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])
|
|
bitmap_path = os.path.join(pack_dir, bitmap_files[0])
|
|
|
|
|
|
|
|
# Read the raw file to verify header
|
|
# Read the raw file to verify header
|