◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
19 changes: 15 additions & 4 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,10 @@ def unmerged_blobs(self) -> Dict[PathLike, List[Tuple[StageType, Blob]]]:
stage. That is, a file removed on the 'other' branch whose entries are at
stage 3 will not have a stage 3 entry.
"""
is_unmerged_blob = lambda t: t[0] != 0
path_map: Dict[PathLike, List[Tuple[StageType, Blob]]] = {}
for stage, blob in self.iter_blobs(is_unmerged_blob):
path_map.setdefault(blob.path, []).append((stage, blob))
Expand Down Expand Up @@ -690,12 +693,17 @@ def _store_path(self, filepath: PathLike, fprogress: Callable) -> BaseIndexEntry
This must be ensured in the calling code.
"""
st = os.lstat(filepath) # Handles non-symlinks as well.
if S_ISLNK(st.st_mode):
# In PY3, readlink is a string, but we need bytes.
# In PY2, it was just OS encoded bytes, we assumed UTF-8.
open_stream: Callable[[], BinaryIO] = lambda: BytesIO(force_bytes(os.readlink(filepath), encoding=defenc))
else:
open_stream = lambda: open(filepath, "rb")
with open_stream() as stream:
fprogress(filepath, False, filepath)
istream = self.repo.odb.store(IStream(Blob.type, st.st_size, stream))
Expand Down Expand Up @@ -1336,8 +1344,11 @@ def handle_stderr(proc: "Popen[bytes]", iter_checked_out_files: Iterable[PathLik
kwargs["as_process"] = True
kwargs["istream"] = subprocess.PIPE
proc = self.repo.git.checkout_index(args, **kwargs)
# FIXME: Reading from GIL!
make_exc = lambda: GitCommandError(("git-checkout-index",) + tuple(args), 128, proc.stderr.read())
checked_out_files: List[PathLike] = []

for path in paths:
Expand Down
4 changes: 3 additions & 1 deletion git/objects/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@

# --------------------------------------------------------

cmp: Callable[[str, str], int] = lambda a, b: (a > b) - (a < b)


class TreeModifier:
Expand Down
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ lint.select = [
# "UP", # See: https://docs.astral.sh/ruff/rules/#pyupgrade-up
]
lint.extend-select = [
# "A", # See: https://pypi.org/project/flake8-builtins
"B", # See: https://pypi.org/project/flake8-bugbear
"C4", # See: https://pypi.org/project/flake8-comprehensions
"TCH004", # See: https://docs.astral.sh/ruff/rules/runtime-import-in-type-checking-block/
]
lint.ignore = [
"E203", # Whitespace before ':'
"E731", # Do not assign a `lambda` expression, use a `def`
]
lint.ignore-init-module-imports = true
lint.unfixable = [
"F401", # Module imported but unused
]
Expand Down
16 changes: 8 additions & 8 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-r requirements.txt
-r test-requirements.txt
# For additional local testing/linting - to be added elsewhere eventually.
ruff
shellcheck
pytest-icdiff
# pytest-profiling
6 changes: 5 additions & 1 deletion test/test_fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def test_tree_traversal(self):
B_old = self.rorepo.tree("1f66cfbbce58b4b552b041707a12d437cc5f400a") # old base tree

# Two very different trees.
entries = traverse_trees_recursive(odb, [B_old.binsha, H.binsha], "")
self._assert_tree_entries(entries, 2)

Expand All @@ -251,7 +252,10 @@ def test_tree_traversal(self):
self._assert_tree_entries(oentries, 2)

# Single tree.
is_no_tree = lambda i, d: i.type != "tree"
entries = traverse_trees_recursive(odb, [B.binsha], "")
assert len(entries) == len(list(B.traverse(predicate=is_no_tree)))
self._assert_tree_entries(entries, 1)
Expand Down
5 changes: 4 additions & 1 deletion test/test_index.py
Original file line number Diff line number Diff line change
@@ -330,7 +330,10 @@ def test_index_file_from_tree(self, rw_repo):
assert len([e for e in three_way_index.entries.values() if e.stage != 0])

# ITERATE BLOBS
merge_required = lambda t: t[0] != 0
merge_blobs = list(three_way_index.iter_blobs(merge_required))
assert merge_blobs
assert merge_blobs[0][0] in (1, 2, 3)
Expand Down
10 changes: 8 additions & 2 deletions test/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ def test_traverse(self):
assert len(list(root)) == len(list(root.traverse(depth=1)))

# Only choose trees.
trees_only = lambda i, d: i.type == "tree"
trees = list(root.traverse(predicate=trees_only))
assert len(trees) == len([i for i in root.traverse() if trees_only(i, 0)])

# Test prune.
lib_folder = lambda t, d: t.path == "lib"
pruned_trees = list(root.traverse(predicate=trees_only, prune=lib_folder))
assert len(pruned_trees) < len(trees)

Expand Down
Loading
Toggle all file notes Toggle all file annotations