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

Commit1b16037

Browse files
committed
second pass of adding types
1 parent559ddb3 commit1b16037

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

‎git/refs/symbolic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SymbolicReference(object):
4545
_remote_common_path_default="refs/remotes"
4646
_id_attribute_="name"
4747

48-
def__init__(self,repo,path):
48+
def__init__(self,repo,path,check_path=None):
4949
self.repo=repo
5050
self.path=path
5151

‎git/remote.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@
3636

3737
# typing-------------------------------------------------------
3838

39-
fromtypingimportAny,Callable,Optional,TYPE_CHECKING,Union,overload
39+
fromtypingimportAny,Callable,Dict,Optional,TYPE_CHECKING,Union,cast,overload
4040

4141
fromgit.typesimportPathLike,Literal
4242

4343
ifTYPE_CHECKING:
4444
fromgit.repo.baseimportRepo
4545
fromgit.objects.commitimportCommit
46+
fromgit.objects.blobimportBlob
47+
fromgit.objects.treeimportTree
48+
fromgit.objects.tagimportTagObject
4649

50+
flagKeyLiteral=Literal[' ','!','+','-','*','=','t']
4751
# -------------------------------------------------------------
4852

4953
log=logging.getLogger('git.remote')
@@ -131,7 +135,7 @@ class PushInfo(object):
131135
'=':UP_TO_DATE,
132136
'!':ERROR}
133137

134-
def__init__(self,flags:int,local_ref:Union[SymbolicReference,None],remote_ref_string:str,remote,
138+
def__init__(self,flags:int,local_ref:Union[SymbolicReference,None],remote_ref_string:str,remote:'Remote',
135139
old_commit:Optional[str]=None,summary:str='')->None:
136140
""" Initialize a new instance
137141
local_ref: HEAD | Head | RemoteReference | TagReference | Reference | SymbolicReference | None """
@@ -143,7 +147,7 @@ def __init__(self, flags: int, local_ref: Union[SymbolicReference, None], remote
143147
self.summary=summary
144148

145149
@property
146-
defold_commit(self)->Optional[bool]:
150+
defold_commit(self)->Union[str,SymbolicReference,'Commit','TagObject','Blob','Tree',None]:
147151
returnself._old_commit_shaandself._remote.repo.commit(self._old_commit_sha)orNone
148152

149153
@property
@@ -246,7 +250,7 @@ class FetchInfo(object):
246250
'=':HEAD_UPTODATE,
247251
' ':FAST_FORWARD,
248252
'-':TAG_UPDATE,
249-
}
253+
}# type: Dict[flagKeyLiteral, int]
250254

251255
@classmethod
252256
defrefresh(cls)->Literal[True]:
@@ -297,7 +301,7 @@ def commit(self) -> 'Commit':
297301
returnself.ref.commit
298302

299303
@classmethod
300-
def_from_line(cls,repo,line,fetch_line):
304+
def_from_line(cls,repo:Repo,line:str,fetch_line)->'FetchInfo':
301305
"""Parse information from the given line as returned by git-fetch -v
302306
and return a new FetchInfo object representing this information.
303307
@@ -319,7 +323,9 @@ def _from_line(cls, repo, line, fetch_line):
319323
raiseValueError("Failed to parse line: %r"%line)
320324

321325
# parse lines
322-
control_character,operation,local_remote_ref,remote_local_ref,note=match.groups()
326+
control_character,operation,local_remote_ref,remote_local_ref_str,note=match.groups()
327+
control_character=cast(flagKeyLiteral,control_character)# can do this neater once 3.5 dropped
328+
323329
try:
324330
_new_hex_sha,_fetch_operation,fetch_note=fetch_line.split("\t")
325331
ref_type_name,fetch_note=fetch_note.split(' ',1)
@@ -359,7 +365,7 @@ def _from_line(cls, repo, line, fetch_line):
359365
# the fetch result is stored in FETCH_HEAD which destroys the rule we usually
360366
# have. In that case we use a symbolic reference which is detached
361367
ref_type=None
362-
ifremote_local_ref=="FETCH_HEAD":
368+
ifremote_local_ref_str=="FETCH_HEAD":
363369
ref_type=SymbolicReference
364370
elifref_type_name=="tag"oris_tag_operation:
365371
# the ref_type_name can be branch, whereas we are still seeing a tag operation. It happens during
@@ -387,21 +393,21 @@ def _from_line(cls, repo, line, fetch_line):
387393
# by the 'ref/' prefix. Otherwise even a tag could be in refs/remotes, which is when it will have the
388394
# 'tags/' subdirectory in its path.
389395
# We don't want to test for actual existence, but try to figure everything out analytically.
390-
ref_path=None
391-
remote_local_ref=remote_local_ref.strip()
392-
ifremote_local_ref.startswith(Reference._common_path_default+"/"):
396+
ref_path=None# type: Optional[PathLike]
397+
remote_local_ref_str=remote_local_ref_str.strip()
398+
ifremote_local_ref_str.startswith(Reference._common_path_default+"/"):
393399
# always use actual type if we get absolute paths
394400
# Will always be the case if something is fetched outside of refs/remotes (if its not a tag)
395-
ref_path=remote_local_ref
401+
ref_path=remote_local_ref_str
396402
ifref_typeisnotTagReferenceandnot \
397-
remote_local_ref.startswith(RemoteReference._common_path_default+"/"):
403+
remote_local_ref_str.startswith(RemoteReference._common_path_default+"/"):
398404
ref_type=Reference
399405
# END downgrade remote reference
400-
elifref_typeisTagReferenceand'tags/'inremote_local_ref:
406+
elifref_typeisTagReferenceand'tags/'inremote_local_ref_str:
401407
# even though its a tag, it is located in refs/remotes
402-
ref_path=join_path(RemoteReference._common_path_default,remote_local_ref)
408+
ref_path=join_path(RemoteReference._common_path_default,remote_local_ref_str)
403409
else:
404-
ref_path=join_path(ref_type._common_path_default,remote_local_ref)
410+
ref_path=join_path(ref_type._common_path_default,remote_local_ref_str)
405411
# END obtain refpath
406412

407413
# even though the path could be within the git conventions, we make

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp