Skip to content

Commit

Permalink
Don't write test.idx to current path
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Nov 20, 2024
1 parent 2bb67c8 commit 5bd188b
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 20 deletions.
8 changes: 6 additions & 2 deletions dulwich/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ def run(self, argv) -> None:
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)

Expand All @@ -132,8 +134,10 @@ def run(self, args) -> None:
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():
Expand Down
8 changes: 4 additions & 4 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def send_pack(
[set[bytes], set[bytes], bool], tuple[int, Iterator[UnpackedObject]]
],
progress=None,
) -> SendPackResult:
) -> SendPackResult:
"""Upload a pack to a remote repository.
Args:
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def fetch_pack(
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:
Expand Down Expand Up @@ -1147,7 +1147,7 @@ def archive(
format=None,
subdirs=None,
prefix=None,
) -> None:
) -> None:
"""Retrieve an archive of the specified tree."""
raise NotImplementedError(self.archive)

Expand Down Expand Up @@ -1948,7 +1948,7 @@ def run_command(
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
Expand Down
15 changes: 13 additions & 2 deletions dulwich/contrib/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,16 @@ def _write_refs(self, refs) -> None:
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
Expand All @@ -833,7 +842,9 @@ def set_if_equals(self, name, old_ref, new_ref, committer=None, timestamp=None,
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
Expand Down
1 change: 1 addition & 0 deletions dulwich/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

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
Expand Down
4 changes: 3 additions & 1 deletion dulwich/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,9 @@ def iteritems(
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

Expand Down
4 changes: 3 additions & 1 deletion dulwich/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,9 @@ def _deserialize(self, chunks) -> None:
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.
Expand Down
8 changes: 6 additions & 2 deletions dulwich/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions dulwich/refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def set_if_equals(
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
Expand All @@ -355,7 +355,7 @@ def set_if_equals(

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:
Expand Down
1 change: 0 additions & 1 deletion dulwich/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ def _all_wants_satisfied(store: ObjectContainer, haves, wants) -> bool:


class AckGraphWalkerImpl:

def __init__(self, graph_walker):
raise NotImplementedError

Expand Down
7 changes: 5 additions & 2 deletions dulwich/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,12 @@ def handle(self) -> None:
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


Expand Down
4 changes: 3 additions & 1 deletion tests/test_diff_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ def test_tree_changes_rename_detector(self) -> None:
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)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,8 @@ def test_bad_ext_ref_thin_pack(self) -> None:
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()
Expand All @@ -1310,11 +1312,11 @@ def test_ext_ref_deltified_object_based_on_itself(self) -> None:
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
Expand Down

0 comments on commit 5bd188b

Please sign in to comment.