Browse Source

Don't write test.idx to current path

Jelmer Vernooij 4 months ago
parent
commit
5bd188b592

+ 6 - 2
dulwich/cli.py

@@ -120,8 +120,10 @@ class cmd_fetch_pack(Command):
             determine_wants = r.object_store.determine_wants_all
         else:
 
-            def determine_wants(refs: dict[Ref, ObjectID], depth: Optional[int] = None) -> list[ObjectID]:
-                return [y.encode('utf-8') for y in args.refs if y not in r.object_store]
+            def determine_wants(
+                refs: dict[Ref, ObjectID], depth: Optional[int] = None
+            ) -> list[ObjectID]:
+                return [y.encode("utf-8") for y in args.refs if y not in r.object_store]
 
         client.fetch(path, r, determine_wants)
 
@@ -132,8 +134,10 @@ class cmd_fetch(Command):
         dict(opts)
         client, path = get_transport_and_path(args.pop(0))
         r = Repo(".")
+
         def progress(msg: bytes) -> None:
             sys.stdout.buffer.write(msg)
+
         refs = client.fetch(path, r, progress=progress)
         print("Remote refs:")
         for item in refs.items():

+ 4 - 4
dulwich/client.py

@@ -803,7 +803,7 @@ class GitClient:
             [set[bytes], set[bytes], bool], tuple[int, Iterator[UnpackedObject]]
         ],
         progress=None,
-        ) -> SendPackResult:
+    ) -> SendPackResult:
         """Upload a pack to a remote repository.
 
         Args:
@@ -1012,7 +1012,7 @@ class GitClient:
         ref_prefix: Optional[list[Ref]] = None,
         filter_spec=None,
         protocol_version: Optional[int] = None,
-        ) -> FetchPackResult:
+    ) -> FetchPackResult:
         """Retrieve a pack from a git smart server.
 
         Args:
@@ -1147,7 +1147,7 @@ class GitClient:
         format=None,
         subdirs=None,
         prefix=None,
-        ) -> None:
+    ) -> None:
         """Retrieve an archive of the specified tree."""
         raise NotImplementedError(self.archive)
 
@@ -1948,7 +1948,7 @@ class SSHVendor:
         key_filename=None,
         ssh_command=None,
         protocol_version: Optional[int] = None,
-        ):
+    ):
         """Connect to an SSH server.
 
         Run a command remotely and return a file-like object for interaction

+ 13 - 2
dulwich/contrib/swift.py

@@ -821,7 +821,16 @@ class SwiftInfoRefsContainer(InfoRefsContainer):
         f.writelines(write_info_refs(refs, self.store))
         self.scon.put_object(self.filename, f)
 
-    def set_if_equals(self, name, old_ref, new_ref, committer=None, timestamp=None, timezone=None, message=None) -> bool:
+    def set_if_equals(
+        self,
+        name,
+        old_ref,
+        new_ref,
+        committer=None,
+        timestamp=None,
+        timezone=None,
+        message=None,
+    ) -> bool:
         """Set a refname to new_ref only if it currently equals old_ref."""
         if name == "HEAD":
             return True
@@ -833,7 +842,9 @@ class SwiftInfoRefsContainer(InfoRefsContainer):
         self._refs[name] = new_ref
         return True
 
-    def remove_if_equals(self, name, old_ref, committer=None, timestamp=None, timezone=None, message=None) -> bool:
+    def remove_if_equals(
+        self, name, old_ref, committer=None, timestamp=None, timezone=None, message=None
+    ) -> bool:
         """Remove a refname only if it currently equals old_ref."""
         if name == "HEAD":
             return True

+ 1 - 0
dulwich/graph.py

@@ -27,6 +27,7 @@ from .lru_cache import LRUCache
 
 T = TypeVar("T")
 
+
 # priority queue using builtin python minheap tools
 # why they do not have a builtin maxheap is simply ridiculous but
 # liveable with integer time stamps using negation

+ 3 - 1
dulwich/index.py

@@ -522,7 +522,9 @@ class Index:
     def items(self) -> Iterator[tuple[bytes, Union[IndexEntry, ConflictedIndexEntry]]]:
         return iter(self._byname.items())
 
-    def update(self, entries: dict[bytes, Union[IndexEntry, ConflictedIndexEntry]]) -> None:
+    def update(
+        self, entries: dict[bytes, Union[IndexEntry, ConflictedIndexEntry]]
+    ) -> None:
         for key, value in entries.items():
             self[key] = value
 

+ 3 - 1
dulwich/objects.py

@@ -868,7 +868,9 @@ class Tag(ShaFile):
                         self._message = value[:sig_idx]
                         self._signature = value[sig_idx:]
             else:
-                raise ObjectFormatException(f"Unknown field {field.decode('ascii', 'replace')}")
+                raise ObjectFormatException(
+                    f"Unknown field {field.decode('ascii', 'replace')}"
+                )
 
     def _get_object(self):
         """Get the object pointed to by this tag.

+ 6 - 2
dulwich/patch.py

@@ -35,7 +35,9 @@ from .pack import ObjectContainer
 FIRST_FEW_BYTES = 8000
 
 
-def write_commit_patch(f, commit, contents, progress, version=None, encoding=None) -> None:
+def write_commit_patch(
+    f, commit, contents, progress, version=None, encoding=None
+) -> None:
     """Write a individual file patch.
 
     Args:
@@ -188,7 +190,9 @@ def patch_filename(p, root):
         return root + b"/" + p
 
 
-def write_object_diff(f, store: ObjectContainer, old_file, new_file, diff_binary=False) -> None:
+def write_object_diff(
+    f, store: ObjectContainer, old_file, new_file, diff_binary=False
+) -> None:
     """Write the diff for an object.
 
     Args:

+ 2 - 2
dulwich/refs.py

@@ -336,7 +336,7 @@ class RefsContainer:
         timestamp=None,
         timezone=None,
         message=None,
-        ) -> bool:
+    ) -> bool:
         """Set a refname to new_ref only if it currently equals old_ref.
 
         This method follows all symbolic references if applicable for the
@@ -355,7 +355,7 @@ class RefsContainer:
 
     def add_if_new(
         self, name, ref, committer=None, timestamp=None, timezone=None, message=None
-        ) -> bool:
+    ) -> bool:
         """Add a new reference only if it does not already exist.
 
         Args:

+ 0 - 1
dulwich/server.py

@@ -548,7 +548,6 @@ def _all_wants_satisfied(store: ObjectContainer, haves, wants) -> bool:
 
 
 class AckGraphWalkerImpl:
-
     def __init__(self, graph_walker):
         raise NotImplementedError
 

+ 5 - 2
dulwich/web.py

@@ -546,9 +546,12 @@ class WSGIRequestHandlerLogger(WSGIRequestHandler):
             return
 
         handler = ServerHandlerLogger(
-            self.rfile, self.wfile, self.get_stderr(), self.get_environ()
+            self.rfile,
+            self.wfile,  # type: ignore
+            self.get_stderr(),
+            self.get_environ(),
         )
-        handler.request_handler = self   # type: ignore  # backpointer for logging
+        handler.request_handler = self  # type: ignore  # backpointer for logging
         handler.run(self.server.get_app())  # type: ignore
 
 

+ 3 - 1
tests/test_diff_tree.py

@@ -407,7 +407,9 @@ class TreeChangesTest(DiffTestCase):
             want_unchanged=True,
         )
 
-    def assertChangesForMergeEqual(self, expected, parent_trees, merge_tree, **kwargs) -> None:
+    def assertChangesForMergeEqual(
+        self, expected, parent_trees, merge_tree, **kwargs
+    ) -> None:
         parent_tree_ids = [t.id for t in parent_trees]
         actual = list(
             tree_changes_for_merge(self.store, parent_tree_ids, merge_tree.id, **kwargs)

+ 4 - 2
tests/test_pack.py

@@ -1295,6 +1295,8 @@ class DeltaChainIteratorTests(TestCase):
             self.assertEqual((sorted([b2.id, b3.id]),), (sorted(e.shas),))
 
     def test_ext_ref_deltified_object_based_on_itself(self) -> None:
+        td = tempfile.mkdtemp()
+        self.addCleanup(shutil.rmtree, td)
         b1_content = b"foo"
         (b1,) = self.store_blobs([b1_content])
         f = BytesIO()
@@ -1310,11 +1312,11 @@ class DeltaChainIteratorTests(TestCase):
         f.seek(0)
         packdata = PackData.from_file(f, fsize)
         packdata.create_index(
-            "test.idx",
+            td.join("test.idx"),
             version=2,
             resolve_ext_ref=self.get_raw_no_repeat,
         )
-        packindex = load_pack_index("test.idx")
+        packindex = load_pack_index(td.join("test.idx"))
         pack = Pack.from_objects(packdata, packindex)
         try:
             # Attempting to open this REF_DELTA object would loop forever