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

Commit2bc2ac0

Browse files
committed
Use BaseIndexEntry named access in index/fun.py
1 parent4b6430b commit2bc2ac0

File tree

2 files changed

+38
-60
lines changed

2 files changed

+38
-60
lines changed

‎git/index/fun.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
ifTYPE_CHECKING:
5959
from .baseimportIndexFile
60+
fromgit.dbimportGitCmdObjectDB
6061
fromgit.objects.treeimportTreeCacheTup
6162
# from git.objects.fun import EntryTupOrNone
6263

@@ -149,15 +150,15 @@ def write_cache(entries: Sequence[Union[BaseIndexEntry, 'IndexEntry']], stream:
149150
# body
150151
forentryinentries:
151152
beginoffset=tell()
152-
write(entry[4])# ctime
153-
write(entry[5])# mtime
154-
path_str:str=entry[3]
153+
write(entry.ctime_bytes)# ctime
154+
write(entry.mtime_bytes)# mtime
155+
path_str=str(entry.path)
155156
path:bytes=force_bytes(path_str,encoding=defenc)
156157
plen=len(path)&CE_NAMEMASK# path length
157-
assertplen==len(path),"Path %s too long to fit into index"%entry[3]
158-
flags=plen| (entry[2]&CE_NAMEMASK_INV)# clear possible previous values
159-
write(pack(">LLLLLL20sH",entry[6],entry[7],entry[0],
160-
entry[8],entry[9],entry[10],entry[1],flags))
158+
assertplen==len(path),"Path %s too long to fit into index"%entry.path
159+
flags=plen| (entry.flags&CE_NAMEMASK_INV)# clear possible previous values
160+
write(pack(">LLLLLL20sH",entry.dev,entry.inode,entry.mode,
161+
entry.uid,entry.gid,entry.size,entry.binsha,flags))
161162
write(path)
162163
real_size= ((tell()-beginoffset+8)&~7)
163164
write(b"\0"* ((beginoffset+real_size)-tell()))
@@ -311,7 +312,7 @@ def _tree_entry_to_baseindexentry(tree_entry: 'TreeCacheTup', stage: int) -> Bas
311312
returnBaseIndexEntry((tree_entry[1],tree_entry[0],stage<<CE_STAGESHIFT,tree_entry[2]))
312313

313314

314-
defaggressive_tree_merge(odb,tree_shas:Sequence[bytes])->List[BaseIndexEntry]:
315+
defaggressive_tree_merge(odb:'GitCmdObjectDB',tree_shas:Sequence[bytes])->List[BaseIndexEntry]:
315316
"""
316317
:return: list of BaseIndexEntries representing the aggressive merge of the given
317318
trees. All valid entries are on stage 0, whereas the conflicting ones are left

‎git/index/typ.py‎

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# typing ----------------------------------------------------------------------
1313

14-
fromtypingimport (List,Sequence,TYPE_CHECKING,Tuple,cast)
14+
fromtypingimport (NamedTuple,Sequence,TYPE_CHECKING,Tuple,Union,cast)
1515

1616
fromgit.typesimportPathLike
1717

@@ -59,7 +59,23 @@ def __call__(self, stage_blob: Blob) -> bool:
5959
returnFalse
6060

6161

62-
classBaseIndexEntry(tuple):
62+
classBaseIndexEntryHelper(NamedTuple):
63+
"""Typed namedtuple to provide named attribute access for BaseIndexEntry.
64+
Needed to allow overriding __new__ in child class to preserve backwards compat."""
65+
mode:int
66+
binsha:bytes
67+
flags:int
68+
path:PathLike
69+
ctime_bytes:bytes=pack(">LL",0,0)
70+
mtime_bytes:bytes=pack(">LL",0,0)
71+
dev:int=0
72+
inode:int=0
73+
uid:int=0
74+
gid:int=0
75+
size:int=0
76+
77+
78+
classBaseIndexEntry(BaseIndexEntryHelper):
6379

6480
"""Small Brother of an index entry which can be created to describe changes
6581
done to the index in which case plenty of additional information is not required.
@@ -68,26 +84,22 @@ class BaseIndexEntry(tuple):
6884
expecting a BaseIndexEntry can also handle full IndexEntries even if they
6985
use numeric indices for performance reasons. """
7086

87+
def__new__(cls,inp_tuple:Union[Tuple[int,bytes,int,PathLike],
88+
Tuple[int,bytes,int,PathLike,bytes,bytes,int,int,int,int,int]]
89+
)->'BaseIndexEntry':
90+
"""Override __new__ to allow construction from a tuple for backwards compatibility """
91+
returnsuper().__new__(cls,*inp_tuple)
92+
7193
def__str__(self)->str:
7294
return"%o %s %i\t%s"% (self.mode,self.hexsha,self.stage,self.path)
7395

7496
def__repr__(self)->str:
7597
return"(%o, %s, %i, %s)"% (self.mode,self.hexsha,self.stage,self.path)
7698

77-
@property
78-
defmode(self)->int:
79-
""" File Mode, compatible to stat module constants """
80-
returnself[0]
81-
82-
@property
83-
defbinsha(self)->bytes:
84-
"""binary sha of the blob """
85-
returnself[1]
86-
8799
@property
88100
defhexsha(self)->str:
89101
"""hex version of our sha"""
90-
returnb2a_hex(self[1]).decode('ascii')
102+
returnb2a_hex(self.binsha).decode('ascii')
91103

92104
@property
93105
defstage(self)->int:
@@ -100,17 +112,7 @@ def stage(self) -> int:
100112
101113
:note: For more information, see http://www.kernel.org/pub/software/scm/git/docs/git-read-tree.html
102114
"""
103-
return (self[2]&CE_STAGEMASK)>>CE_STAGESHIFT
104-
105-
@property
106-
defpath(self)->str:
107-
""":return: our path relative to the repository working tree root"""
108-
returnself[3]
109-
110-
@property
111-
defflags(self)->List[str]:
112-
""":return: flags stored with this entry"""
113-
returnself[2]
115+
return (self.flags&CE_STAGEMASK)>>CE_STAGESHIFT
114116

115117
@classmethod
116118
deffrom_blob(cls,blob:Blob,stage:int=0)->'BaseIndexEntry':
@@ -136,40 +138,15 @@ def ctime(self) -> Tuple[int, int]:
136138
:return:
137139
Tuple(int_time_seconds_since_epoch, int_nano_seconds) of the
138140
file's creation time"""
139-
returncast(Tuple[int,int],unpack(">LL",self[4]))
141+
returncast(Tuple[int,int],unpack(">LL",self.ctime_bytes))
140142

141143
@property
142144
defmtime(self)->Tuple[int,int]:
143145
"""See ctime property, but returns modification time """
144-
returncast(Tuple[int,int],unpack(">LL",self[5]))
145-
146-
@property
147-
defdev(self)->int:
148-
""" Device ID """
149-
returnself[6]
150-
151-
@property
152-
definode(self)->int:
153-
""" Inode ID """
154-
returnself[7]
155-
156-
@property
157-
defuid(self)->int:
158-
""" User ID """
159-
returnself[8]
160-
161-
@property
162-
defgid(self)->int:
163-
""" Group ID """
164-
returnself[9]
165-
166-
@property
167-
defsize(self)->int:
168-
""":return: Uncompressed size of the blob """
169-
returnself[10]
146+
returncast(Tuple[int,int],unpack(">LL",self.mtime_bytes))
170147

171148
@classmethod
172-
deffrom_base(cls,base):
149+
deffrom_base(cls,base:'BaseIndexEntry')->'IndexEntry':
173150
"""
174151
:return:
175152
Minimal entry as created from the given BaseIndexEntry instance.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp