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

Commit82b131c

Browse files
committed
Type Traversable.traverse() better, start types of submodule
1 parent75dbf90 commit82b131c

17 files changed

+352
-156
lines changed

‎git/config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
importconfigparserascp
3131

32-
frompathlibimportPath
33-
3432
# typing-------------------------------------------------------
3533

3634
fromtypingimportAny,Callable,IO,List,Dict,Sequence,TYPE_CHECKING,Tuple,Union,cast,overload
@@ -330,7 +328,7 @@ def _acquire_lock(self) -> None:
330328
"Write-ConfigParsers can operate on a single file only, multiple files have been passed")
331329
# END single file check
332330

333-
ifisinstance(self._file_or_files, (str,Path)):# cannot narrow by os._pathlike until 3.5 dropped
331+
ifisinstance(self._file_or_files, (str,os.PathLike)):
334332
file_or_files=self._file_or_files
335333
else:
336334
file_or_files=cast(IO,self._file_or_files).name

‎git/index/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6-
fromgit.refs.referenceimportReference
6+
77
importglob
88
fromioimportBytesIO
99
importos
@@ -74,6 +74,7 @@
7474
ifTYPE_CHECKING:
7575
fromsubprocessimportPopen
7676
fromgit.repoimportRepo
77+
fromgit.refs.referenceimportReference
7778

7879

7980
StageType=int
@@ -1191,7 +1192,7 @@ def handle_stderr(proc: 'Popen[bytes]', iter_checked_out_files: Iterable[PathLik
11911192
assert"Should not reach this point"
11921193

11931194
@default_index
1194-
defreset(self,commit:Union[Commit,Reference,str]='HEAD',working_tree:bool=False,
1195+
defreset(self,commit:Union[Commit,'Reference',str]='HEAD',working_tree:bool=False,
11951196
paths:Union[None,Iterable[PathLike]]=None,
11961197
head:bool=False,**kwargs:Any)->'IndexFile':
11971198
"""Reset the index to reflect the tree at the given commit. This will not

‎git/objects/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717

1818
fromtypingimportAny,TYPE_CHECKING,Optional,Union
1919

20-
fromgit.typesimportPathLike
20+
fromgit.typesimportPathLike,Commit_ish
2121

2222
ifTYPE_CHECKING:
2323
fromgit.repoimportRepo
2424
fromgitdb.baseimportOStream
25-
from .treeimportTree
26-
from .blobimportBlob
27-
from .tagimportTagObject
28-
from .commitimportCommit
25+
# from .tree import Tree, Blob, Commit, TagObject
2926

3027
# --------------------------------------------------------------------------
3128

@@ -71,7 +68,7 @@ def new(cls, repo: 'Repo', id): # @ReservedAssignment
7168
returnrepo.rev_parse(str(id))
7269

7370
@classmethod
74-
defnew_from_sha(cls,repo:'Repo',sha1:bytes)->Union['Commit','TagObject','Tree','Blob']:
71+
defnew_from_sha(cls,repo:'Repo',sha1:bytes)->Commit_ish:
7572
"""
7673
:return: new object instance of a type appropriate to represent the given
7774
binary sha1

‎git/objects/commit.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
#
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6-
76
fromgitdbimportIStream
87
fromgit.utilimport (
98
hex_to_bin,
109
Actor,
11-
IterableObj,
1210
Stats,
1311
finalize_process
1412
)
@@ -17,8 +15,8 @@
1715
from .treeimportTree
1816
from .importbase
1917
from .utilimport (
20-
Traversable,
2118
Serializable,
19+
TraversableIterableObj,
2220
parse_date,
2321
altz_to_utctz_str,
2422
parse_actor_and_date,
@@ -36,18 +34,25 @@
3634
fromioimportBytesIO
3735
importlogging
3836

39-
fromtypingimportList,Tuple,Union,TYPE_CHECKING
37+
38+
# typing ------------------------------------------------------------------
39+
40+
fromtypingimportAny,Iterator,List,Sequence,Tuple,Union,TYPE_CHECKING
41+
42+
fromgit.typesimportPathLike
4043

4144
ifTYPE_CHECKING:
4245
fromgit.repoimportRepo
4346

47+
# ------------------------------------------------------------------------
48+
4449
log=logging.getLogger('git.objects.commit')
4550
log.addHandler(logging.NullHandler())
4651

4752
__all__= ('Commit', )
4853

4954

50-
classCommit(base.Object,IterableObj,Diffable,Traversable,Serializable):
55+
classCommit(base.Object,TraversableIterableObj,Diffable,Serializable):
5156

5257
"""Wraps a git Commit object.
5358
@@ -73,7 +78,8 @@ class Commit(base.Object, IterableObj, Diffable, Traversable, Serializable):
7378
"message","parents","encoding","gpgsig")
7479
_id_attribute_="hexsha"
7580

76-
def__init__(self,repo,binsha,tree=None,author=None,authored_date=None,author_tz_offset=None,
81+
def__init__(self,repo,binsha,tree=None,author:Union[Actor,None]=None,
82+
authored_date=None,author_tz_offset=None,
7783
committer=None,committed_date=None,committer_tz_offset=None,
7884
message=None,parents:Union[Tuple['Commit', ...],List['Commit'],None]=None,
7985
encoding=None,gpgsig=None):
@@ -139,7 +145,7 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
139145
self.gpgsig=gpgsig
140146

141147
@classmethod
142-
def_get_intermediate_items(cls,commit:'Commit')->Tuple['Commit', ...]:# type: ignore ## cos overriding super
148+
def_get_intermediate_items(cls,commit:'Commit')->Tuple['Commit', ...]:
143149
returntuple(commit.parents)
144150

145151
@classmethod
@@ -225,7 +231,9 @@ def name_rev(self):
225231
returnself.repo.git.name_rev(self)
226232

227233
@classmethod
228-
defiter_items(cls,repo,rev,paths='',**kwargs):
234+
defiter_items(cls,repo:'Repo',rev,# type: ignore
235+
paths:Union[PathLike,Sequence[PathLike]]='',**kwargs:Any
236+
)->Iterator['Commit']:
229237
"""Find all commits matching the given criteria.
230238
231239
:param repo: is the Repo
@@ -245,15 +253,23 @@ def iter_items(cls, repo, rev, paths='', **kwargs):
245253

246254
# use -- in any case, to prevent possibility of ambiguous arguments
247255
# see https://github.com/gitpython-developers/GitPython/issues/264
248-
args= ['--']
256+
257+
args_list:List[Union[PathLike,Sequence[PathLike]]]= ['--']
258+
249259
ifpaths:
250-
args.extend((paths, ))
260+
paths_tup:Tuple[PathLike, ...]
261+
ifisinstance(paths, (str,os.PathLike)):
262+
paths_tup= (paths, )
263+
else:
264+
paths_tup=tuple(paths)
265+
266+
args_list.extend(paths_tup)
251267
# END if paths
252268

253-
proc=repo.git.rev_list(rev,args,as_process=True,**kwargs)
269+
proc=repo.git.rev_list(rev,args_list,as_process=True,**kwargs)
254270
returncls._iter_from_process_or_stream(repo,proc)
255271

256-
defiter_parents(self,paths='',**kwargs):
272+
defiter_parents(self,paths:Union[PathLike,Sequence[PathLike]]='',**kwargs)->Iterator['Commit']:
257273
"""Iterate _all_ parents of this commit.
258274
259275
:param paths:
@@ -269,7 +285,7 @@ def iter_parents(self, paths='', **kwargs):
269285

270286
returnself.iter_items(self.repo,self,paths,**kwargs)
271287

272-
@property
288+
@property
273289
defstats(self):
274290
"""Create a git stat from changes between this commit and its first parent
275291
or from all changes done if this is the very first commit.
@@ -286,7 +302,7 @@ def stats(self):
286302
text=self.repo.git.diff(self.parents[0].hexsha,self.hexsha,'--',numstat=True)
287303
returnStats._list_from_string(self.repo,text)
288304

289-
@classmethod
305+
@classmethod
290306
def_iter_from_process_or_stream(cls,repo,proc_or_stream):
291307
"""Parse out commit information into a list of Commit objects
292308
We expect one-line per commit, and parse the actual commit information directly
@@ -317,7 +333,7 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
317333
ifhasattr(proc_or_stream,'wait'):
318334
finalize_process(proc_or_stream)
319335

320-
@classmethod
336+
@classmethod
321337
defcreate_from_tree(cls,repo,tree,message,parent_commits=None,head=False,author=None,committer=None,
322338
author_date=None,commit_date=None):
323339
"""Commit the given tree, creating a commit object.

‎git/objects/output.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp