Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
GitPython/git/index/typ.py at security-fixes · gitpython-developers/GitPython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
gitpython-developers
/
GitPython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
997
Star
5.2k
Code
Issues
7
Pull requests
1
Discussions
Actions
Security and quality
35
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Files
Expand file tree
security-fixes
Breadcrumbs
GitPython
/
git
/
index
/
typ.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
215 lines (168 loc) · 6.85 KB
security-fixes
Breadcrumbs
GitPython
/
git
/
index
/
typ.py
Copy path
Top
File metadata and controls
Code
Blame
215 lines (168 loc) · 6.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
"""Additional types used by the index."""
__all__
=
[
"BlobFilter"
,
"BaseIndexEntry"
,
"IndexEntry"
,
"StageType"
]
from
binascii
import
b2a_hex
from
pathlib
import
Path
from
git
.
objects
import
Blob
from
.
util
import
pack
,
unpack
# typing ----------------------------------------------------------------------
from
typing
import
NamedTuple
,
Sequence
,
TYPE_CHECKING
,
Tuple
,
Union
,
cast
from
git
.
types
import
PathLike
if
TYPE_CHECKING
:
from
git
.
repo
import
Repo
StageType
=
int
# ---------------------------------------------------------------------------------
# { Invariants
CE_NAMEMASK
=
0x0FFF
CE_STAGEMASK
=
0x3000
CE_EXTENDED
=
0x4000
CE_VALID
=
0x8000
CE_STAGESHIFT
=
12
CE_EXT_SKIP_WORKTREE
=
0x4000
CE_EXT_INTENT_TO_ADD
=
0x2000
# } END invariants
class
BlobFilter
:
"""Predicate to be used by
:meth:`IndexFile.iter_blobs <git.index.base.IndexFile.iter_blobs>` allowing to
filter only return blobs which match the given list of directories or files.
The given paths are given relative to the repository.
"""
__slots__
=
(
"paths"
,)
def
__init__
(
self
,
paths
:
Sequence
[
PathLike
])
->
None
:
"""
:param paths:
Tuple or list of paths which are either pointing to directories or to files
relative to the current repository.
"""
self
.
paths
=
paths
def
__call__
(
self
,
stage_blob
:
Tuple
[
StageType
,
Blob
])
->
bool
:
blob_pathlike
:
PathLike
=
stage_blob
[
1
].
path
blob_path
:
Path
=
blob_pathlike
if
isinstance
(
blob_pathlike
,
Path
)
else
Path
(
blob_pathlike
)
for
pathlike
in
self
.
paths
:
path
:
Path
=
pathlike
if
isinstance
(
pathlike
,
Path
)
else
Path
(
pathlike
)
# TODO: Change to use `PosixPath.is_relative_to` once Python 3.8 is no
# longer supported.
filter_parts
=
path
.
parts
blob_parts
=
blob_path
.
parts
if
len
(
filter_parts
)
>
len
(
blob_parts
):
continue
if
all
(
i
==
j
for
i
,
j
in
zip
(
filter_parts
,
blob_parts
)):
return
True
return
False
class
BaseIndexEntryHelper
(
NamedTuple
):
"""Typed named tuple to provide named attribute access for :class:`BaseIndexEntry`.
This is needed to allow overriding ``__new__`` in child class to preserve backwards
compatibility.
"""
mode
:
int
binsha
:
bytes
flags
:
int
path
:
PathLike
ctime_bytes
:
bytes
=
pack
(
">LL"
,
0
,
0
)
mtime_bytes
:
bytes
=
pack
(
">LL"
,
0
,
0
)
dev
:
int
=
0
inode
:
int
=
0
uid
:
int
=
0
gid
:
int
=
0
size
:
int
=
0
# version 3 extended flags, only when (flags & CE_EXTENDED) is set
extended_flags
:
int
=
0
class
BaseIndexEntry
(
BaseIndexEntryHelper
):
R"""Small brother of an index entry which can be created to describe changes
done to the index in which case plenty of additional information is not required.
As the first 4 data members match exactly to the :class:`IndexEntry` type, methods
expecting a :class:`BaseIndexEntry` can also handle full :class:`IndexEntry`\s even
if they use numeric indices for performance reasons.
"""
def
__new__
(
cls
,
inp_tuple
:
Union
[
Tuple
[
int
,
bytes
,
int
,
PathLike
],
Tuple
[
int
,
bytes
,
int
,
PathLike
,
bytes
,
bytes
,
int
,
int
,
int
,
int
,
int
,
int
],
],
)
->
"BaseIndexEntry"
:
"""Override ``__new__`` to allow construction from a tuple for backwards
compatibility."""
return
super
().
__new__
(
cls
,
*
inp_tuple
)
def
__str__
(
self
)
->
str
:
return
"%o %s %i
\t
%s"
%
(
self
.
mode
,
self
.
hexsha
,
self
.
stage
,
self
.
path
)
def
__repr__
(
self
)
->
str
:
return
"(%o, %s, %i, %s)"
%
(
self
.
mode
,
self
.
hexsha
,
self
.
stage
,
self
.
path
)
@
property
def
hexsha
(
self
)
->
str
:
"""hex version of our sha"""
return
b2a_hex
(
self
.
binsha
).
decode
(
"ascii"
)
@
property
def
stage
(
self
)
->
int
:
"""Stage of the entry, either:
* 0 = default stage
* 1 = stage before a merge or common ancestor entry in case of a 3 way merge
* 2 = stage of entries from the 'left' side of the merge
* 3 = stage of entries from the 'right' side of the merge
:note:
For more information, see :manpage:`git-read-tree(1)`.
"""
return
(
self
.
flags
&
CE_STAGEMASK
)
>>
CE_STAGESHIFT
@
property
def
skip_worktree
(
self
)
->
bool
:
return
(
self
.
extended_flags
&
CE_EXT_SKIP_WORKTREE
)
>
0
@
property
def
intent_to_add
(
self
)
->
bool
:
return
(
self
.
extended_flags
&
CE_EXT_INTENT_TO_ADD
)
>
0
@
classmethod
def
from_blob
(
cls
,
blob
:
Blob
,
stage
:
int
=
0
)
->
"BaseIndexEntry"
:
""":return: Fully equipped BaseIndexEntry at the given stage"""
return
cls
((
blob
.
mode
,
blob
.
binsha
,
stage
<<
CE_STAGESHIFT
,
blob
.
path
))
def
to_blob
(
self
,
repo
:
"Repo"
)
->
Blob
:
""":return: Blob using the information of this index entry"""
return
Blob
(
repo
,
self
.
binsha
,
self
.
mode
,
self
.
path
)
class
IndexEntry
(
BaseIndexEntry
):
"""Allows convenient access to index entry data as defined in
:class:`BaseIndexEntry` without completely unpacking it.
Attributes usually accessed often are cached in the tuple whereas others are
unpacked on demand.
See the properties for a mapping between names and tuple indices.
"""
@
property
def
ctime
(
self
)
->
Tuple
[
int
,
int
]:
"""
:return:
Tuple(int_time_seconds_since_epoch, int_nano_seconds) of the
file's creation time
"""
return
cast
(
Tuple
[
int
,
int
],
unpack
(
">LL"
,
self
.
ctime_bytes
))
@
property
def
mtime
(
self
)
->
Tuple
[
int
,
int
]:
"""See :attr:`ctime` property, but returns modification time."""
return
cast
(
Tuple
[
int
,
int
],
unpack
(
">LL"
,
self
.
mtime_bytes
))
@
classmethod
def
from_base
(
cls
,
base
:
"BaseIndexEntry"
)
->
"IndexEntry"
:
"""
:return:
Minimal entry as created from the given :class:`BaseIndexEntry` instance.
Missing values will be set to null-like values.
:param base:
Instance of type :class:`BaseIndexEntry`.
"""
time
=
pack
(
">LL"
,
0
,
0
)
return
IndexEntry
((
base
.
mode
,
base
.
binsha
,
base
.
flags
,
base
.
path
,
time
,
time
,
0
,
0
,
0
,
0
,
0
))
# type: ignore[arg-type]
@
classmethod
def
from_blob
(
cls
,
blob
:
Blob
,
stage
:
int
=
0
)
->
"IndexEntry"
:
""":return: Minimal entry resembling the given blob object"""
time
=
pack
(
">LL"
,
0
,
0
)
return
IndexEntry
(
(
blob
.
mode
,
blob
.
binsha
,
stage
<<
CE_STAGESHIFT
,
blob
.
path
,
time
,
time
,
0
,
0
,
0
,
0
,
blob
.
size
,
)
# type: ignore[arg-type]
)
You can’t perform that action at this time.