Jelajahi Sumber

Complete rename to object_format and add DEFAULT_OBJECT_FORMAT constant

Jelmer Vernooij 2 bulan lalu
induk
melakukan
4ec7b1a8bd

+ 5 - 5
crates/objects/src/lib.rs

@@ -92,18 +92,18 @@ fn parse_tree_with_length(
 }
 
 #[pyfunction]
-#[pyo3(signature = (text, strict=None, hash_algorithm=None))]
+#[pyo3(signature = (text, strict=None, object_format=None))]
 fn parse_tree(
     py: Python,
     text: &[u8],
     strict: Option<bool>,
-    hash_algorithm: Option<PyObject>,
+    object_format: Option<PyObject>,
 ) -> PyResult<Vec<(PyObject, u32, PyObject)>> {
     let strict = strict.unwrap_or(false);
 
-    // Determine hash length from hash_algorithm if provided
-    if let Some(algo) = hash_algorithm {
-        // Get oid_length attribute from hash algorithm object
+    // Determine hash length from object_format if provided
+    if let Some(algo) = object_format {
+        // Get oid_length attribute from object format object
         let oid_length: usize = algo.getattr(py, "oid_length")?.extract(py)?;
         parse_tree_with_length(py, text, strict, oid_length)
     } else {

+ 5 - 5
dulwich/object_store.py

@@ -323,11 +323,11 @@ class BaseObjectStore:
         """Initialize object store.
 
         Args:
-            object_format: Hash algorithm to use (defaults to SHA1)
+            object_format: Object format to use (defaults to DEFAULT_OBJECT_FORMAT)
         """
-        from .object_format import get_object_format
+        from .object_format import DEFAULT_OBJECT_FORMAT
 
-        self.object_format = object_format if object_format else get_object_format()
+        self.object_format = object_format if object_format else DEFAULT_OBJECT_FORMAT
 
     def determine_wants_all(
         self, refs: Mapping[Ref, ObjectID], depth: int | None = None
@@ -1423,7 +1423,7 @@ class DiskObjectStore(PackBasedObjectStore):
           object_format: Hash algorithm to use (SHA1 or SHA256)
         """
         # Import here to avoid circular dependency
-        from .object_format import get_object_format
+        from .object_format import DEFAULT_OBJECT_FORMAT
 
         super().__init__(
             pack_compression_level=pack_compression_level,
@@ -1434,7 +1434,7 @@ class DiskObjectStore(PackBasedObjectStore):
             pack_depth=pack_depth,
             pack_threads=pack_threads,
             pack_big_file_threshold=pack_big_file_threshold,
-            object_format=object_format if object_format else get_object_format(),
+            object_format=object_format if object_format else DEFAULT_OBJECT_FORMAT,
         )
         self.path = path
         self.pack_dir = os.path.join(self.path, PACKDIR)

+ 3 - 5
dulwich/pack.py

@@ -3601,12 +3601,10 @@ class Pack:
             self._idx_path, object_format=object_format
         )
         self.resolve_ext_ref = resolve_ext_ref
-        # Always set object_format, defaulting to SHA1
-        from .object_format import get_object_format
+        # Always set object_format, defaulting to default
+        from .object_format import DEFAULT_OBJECT_FORMAT
 
-        self.object_format = (
-            object_format if object_format else get_object_format("sha1")
-        )
+        self.object_format = object_format if object_format else DEFAULT_OBJECT_FORMAT
 
     @classmethod
     def from_lazy_objects(

+ 6 - 6
dulwich/repo.py

@@ -1501,7 +1501,7 @@ class Repo(BaseRepo):
 
         # Determine hash algorithm from config if not already set
         if self.object_format is None:
-            from .object_format import get_object_format
+            from .object_format import DEFAULT_OBJECT_FORMAT, get_object_format
 
             if format_version == 1:
                 try:
@@ -1510,9 +1510,9 @@ class Repo(BaseRepo):
                         object_format.decode("ascii")
                     )
                 except KeyError:
-                    self.object_format = get_object_format("sha1")
+                    self.object_format = DEFAULT_OBJECT_FORMAT
             else:
-                self.object_format = get_object_format("sha1")
+                self.object_format = DEFAULT_OBJECT_FORMAT
 
         self._graftpoints = {}
         graft_file = self.get_named_file(
@@ -2536,7 +2536,7 @@ class MemoryRepo(BaseRepo):
     def __init__(self) -> None:
         """Create a new repository in memory."""
         from .config import ConfigFile
-        from .object_format import get_object_format
+        from .object_format import DEFAULT_OBJECT_FORMAT
 
         self._reflog: list[Any] = []
         refs_container = DictRefsContainer({}, logger=self._append_reflog)
@@ -2546,8 +2546,8 @@ class MemoryRepo(BaseRepo):
         self._config = ConfigFile()
         self._description: bytes | None = None
         self.filter_context = None
-        # MemoryRepo defaults to SHA1
-        self.object_format = get_object_format("sha1")
+        # MemoryRepo defaults to default object format
+        self.object_format = DEFAULT_OBJECT_FORMAT
 
     def _append_reflog(
         self,

+ 3 - 3
tests/compat/test_sha256_packs.py

@@ -62,7 +62,7 @@ class GitSHA256PackCompatibilityTests(CompatTestCase):
 
         # Open with dulwich
         repo = Repo(repo_path)
-        self.assertEqual(repo.get_hash_algorithm(), SHA256)
+        self.assertEqual(repo.object_format, SHA256)
 
         # Find pack files
         pack_dir = os.path.join(repo_path, ".git", "objects", "pack")
@@ -77,7 +77,7 @@ class GitSHA256PackCompatibilityTests(CompatTestCase):
             # Load pack index with SHA256 algorithm
             with open(idx_path, "rb") as f:
                 pack_idx = load_pack_index_file(
-                    idx_path, f, hash_algorithm=repo.get_hash_algorithm()
+                    idx_path, f, hash_algorithm=repo.object_format
                 )
 
             # Verify it's detected as SHA256
@@ -195,7 +195,7 @@ class GitSHA256PackCompatibilityTests(CompatTestCase):
             idx_path = os.path.join(pack_dir, idx_file)
             with open(idx_path, "rb") as f:
                 pack_idx = load_pack_index_file(
-                    idx_path, f, hash_algorithm=repo.get_hash_algorithm()
+                    idx_path, f, hash_algorithm=repo.object_format
                 )
 
             # Verify it's v1 with SHA256