Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca2cf10

Browse files
authored
Merge pull request#1459 from AustinScola/ascola/fix-blob-filter-types
Fix blob filter types
2 parents275c37f +da59d74 commitca2cf10

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

‎git/index/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from .typimport (
5353
BaseIndexEntry,
5454
IndexEntry,
55+
StageType,
5556
)
5657
from .utilimportTemporaryFileSwap,post_clear_cache,default_index,git_working_dir
5758

@@ -83,13 +84,12 @@
8384
fromgit.utilimportActor
8485

8586

86-
StageType=int
8787
Treeish=Union[Tree,Commit,str,bytes]
8888

8989
# ------------------------------------------------------------------------------------
9090

9191

92-
__all__= ("IndexFile","CheckoutError")
92+
__all__= ("IndexFile","CheckoutError","StageType")
9393

9494

9595
classIndexFile(LazyMixin,git_diff.Diffable,Serializable):

‎git/index/typ.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
"""Module with additional types used by the index"""
22

33
frombinasciiimportb2a_hex
4+
frompathlibimportPath
45

56
from .utilimportpack,unpack
67
fromgit.objectsimportBlob
78

89

910
# typing ----------------------------------------------------------------------
1011

11-
fromtypingimportNamedTuple,Sequence,TYPE_CHECKING,Tuple,Union,cast
12+
fromtypingimportNamedTuple,Sequence,TYPE_CHECKING,Tuple,Union,cast,List
1213

1314
fromgit.typesimportPathLike
1415

1516
ifTYPE_CHECKING:
1617
fromgit.repoimportRepo
1718

19+
StageType=int
20+
1821
# ---------------------------------------------------------------------------------
1922

20-
__all__= ("BlobFilter","BaseIndexEntry","IndexEntry")
23+
__all__= ("BlobFilter","BaseIndexEntry","IndexEntry","StageType")
2124

2225
# { Invariants
2326
CE_NAMEMASK=0x0FFF
@@ -48,12 +51,18 @@ def __init__(self, paths: Sequence[PathLike]) -> None:
4851
"""
4952
self.paths=paths
5053

51-
def__call__(self,stage_blob:Blob)->bool:
52-
path=stage_blob[1].path
53-
forpinself.paths:
54-
ifpath.startswith(p):
54+
def__call__(self,stage_blob:Tuple[StageType,Blob])->bool:
55+
blob_pathlike:PathLike=stage_blob[1].path
56+
blob_path:Path=blob_pathlikeifisinstance(blob_pathlike,Path)elsePath(blob_pathlike)
57+
forpathlikeinself.paths:
58+
path:Path=pathlikeifisinstance(pathlike,Path)elsePath(pathlike)
59+
# TODO: Change to use `PosixPath.is_relative_to` once Python 3.8 is no longer supported.
60+
filter_parts:List[str]=path.parts
61+
blob_parts:List[str]=blob_path.parts
62+
iflen(filter_parts)>len(blob_parts):
63+
continue
64+
ifall(i==jfori,jinzip(filter_parts,blob_parts)):
5565
returnTrue
56-
# END for each path in filter paths
5766
returnFalse
5867

5968

‎test/test_blob_filter.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Test the blob filter."""
2+
frompathlibimportPath
3+
fromtypingimportSequence,Tuple
4+
fromunittest.mockimportMagicMock
5+
6+
importpytest
7+
8+
fromgit.index.typimportBlobFilter,StageType
9+
fromgit.objectsimportBlob
10+
fromgit.typesimportPathLike
11+
12+
13+
# fmt: off
14+
@pytest.mark.parametrize('paths, path, expected_result', [
15+
((Path("foo"),),Path("foo"),True),
16+
((Path("foo"),),Path("foo/bar"),True),
17+
((Path("foo/bar"),),Path("foo"),False),
18+
((Path("foo"),Path("bar")),Path("foo"),True),
19+
])
20+
# fmt: on
21+
deftest_blob_filter(paths:Sequence[PathLike],path:PathLike,expected_result:bool)->None:
22+
"""Test the blob filter."""
23+
blob_filter=BlobFilter(paths)
24+
25+
binsha=MagicMock(__len__=lambdaself:20)
26+
stage_type:StageType=0
27+
blob:Blob=Blob(repo=MagicMock(),binsha=binsha,path=path)
28+
stage_blob:Tuple[StageType,Blob]= (stage_type,blob)
29+
30+
result=blob_filter(stage_blob)
31+
32+
assertresult==expected_result

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp