Skip to content

Commit d71f980

Browse files
committedMar 28, 2024·
Deprecate IndexEntry.hex
1 parent 1af76c3 commit d71f980

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
- Fix tests on EPEL8 builds for s390x
2020
[#1283](https://github.com/libgit2/pygit2/pull/1283)
2121

22+
Deprecations:
23+
24+
- Deprecate `IndexEntry.hex`, use `str(IndexEntry.id)`
25+
2226
Breaking changes:
2327

2428
- Remove deprecated `oid.hex`, use `str(oid)`

‎docs/index_file.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Index read::
1414
Iterate over all entries of the index::
1515

1616
>>> for entry in index:
17-
... print(entry.path, entry.hex)
17+
... print(entry.path, entry.id)
1818

1919
Index write::
2020

‎docs/recipes/git-show.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Show log message
2525
Show SHA hash
2626
======================================================================
2727

28-
>>> hash = commit.hex
28+
>>> hash = str(commit.id)
2929

3030
======================================================================
3131
Show diff
@@ -51,7 +51,7 @@ Then you can make your message:
5151
>>>
5252
>>> dt = datetime.fromtimestamp(float(commit.author.time), tzinfo)
5353
>>> timestr = dt.strftime('%c %z')
54-
>>> msg = '\n'.join([f'commit {commit.tree_id.hex}',
54+
>>> msg = '\n'.join([f'commit {commit.tree_id}',
5555
... f'Author: {commit.author.name} <{commit.author.email}>',
5656
... f'Date: {timestr}',
5757
... '',

‎pygit2/index.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2424
# Boston, MA 02110-1301, USA.
2525

26+
import warnings
2627
import weakref
2728

2829
# Import from pygit2
@@ -366,14 +367,15 @@ def oid(self):
366367
@property
367368
def hex(self):
368369
"""The id of the referenced object as a hex string"""
370+
warnings.warn('Use str(entry.id)', DeprecationWarning)
369371
return str(self.id)
370372

371373
def __str__(self):
372-
return f'<path={self.path} id={self.hex} mode={self.mode}>'
374+
return f'<path={self.path} id={self.id} mode={self.mode}>'
373375

374376
def __repr__(self):
375377
t = type(self)
376-
return f'<{t.__module__}.{t.__qualname__} path={self.path} id={self.hex} mode={self.mode}>'
378+
return f'<{t.__module__}.{t.__qualname__} path={self.path} id={self.id} mode={self.mode}>'
377379

378380
def __eq__(self, other):
379381
if self is other:

‎test/test_index.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def test_read(testrepo):
5454

5555
sha = 'a520c24d85fbfc815d385957eed41406ca5a860b'
5656
assert 'hello.txt' in index
57-
assert index['hello.txt'].hex == sha
57+
assert index['hello.txt'].id == sha
5858
assert index['hello.txt'].path == 'hello.txt'
59-
assert index[1].hex == sha
59+
assert index[1].id == sha
6060

6161

6262
def test_add(testrepo):
@@ -67,7 +67,7 @@ def test_add(testrepo):
6767
index.add('bye.txt')
6868
assert 'bye.txt' in index
6969
assert len(index) == 3
70-
assert index['bye.txt'].hex == sha
70+
assert index['bye.txt'].id == sha
7171

7272

7373
def test_add_aspath(testrepo):
@@ -90,26 +90,26 @@ def test_add_all(testrepo):
9090
assert 'bye.txt' in index
9191
assert 'hello.txt' in index
9292

93-
assert index['bye.txt'].hex == sha_bye
94-
assert index['hello.txt'].hex == sha_hello
93+
assert index['bye.txt'].id == sha_bye
94+
assert index['hello.txt'].id == sha_hello
9595

9696
clear(testrepo)
9797

9898
index.add_all(['bye.t??', 'hello.*'])
9999
assert 'bye.txt' in index
100100
assert 'hello.txt' in index
101101

102-
assert index['bye.txt'].hex == sha_bye
103-
assert index['hello.txt'].hex == sha_hello
102+
assert index['bye.txt'].id == sha_bye
103+
assert index['hello.txt'].id == sha_hello
104104

105105
clear(testrepo)
106106

107107
index.add_all(['[byehlo]*.txt'])
108108
assert 'bye.txt' in index
109109
assert 'hello.txt' in index
110110

111-
assert index['bye.txt'].hex == sha_bye
112-
assert index['hello.txt'].hex == sha_hello
111+
assert index['bye.txt'].id == sha_bye
112+
assert index['hello.txt'].id == sha_hello
113113

114114

115115
def test_add_all_aspath(testrepo):
@@ -163,8 +163,8 @@ def test_iter(testrepo):
163163
assert len(list(index)) == n
164164

165165
# Compare SHAs, not IndexEntry object identity
166-
entries = [index[x].hex for x in range(n)]
167-
assert list(x.hex for x in index) == entries
166+
entries = [index[x].id for x in range(n)]
167+
assert list(x.id for x in index) == entries
168168

169169

170170
def test_mode(testrepo):
@@ -179,7 +179,7 @@ def test_mode(testrepo):
179179

180180
def test_bare_index(testrepo):
181181
index = pygit2.Index(Path(testrepo.path) / 'index')
182-
assert [x.hex for x in index] == [x.hex for x in testrepo.index]
182+
assert [x.id for x in index] == [x.id for x in testrepo.index]
183183

184184
with pytest.raises(pygit2.GitError):
185185
index.add('bye.txt')

‎test/test_refs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_references_iterator_invalid_filter(testrepo):
410410
for _ in range(4):
411411
curr_ref = repo.references_iterator_next(iter_all, 5)
412412
if curr_ref:
413-
all_refs.append((curr_ref.name, curr_ref.target.hex))
413+
all_refs.append((curr_ref.name, curr_ref.target))
414414

415415
assert all_refs == []
416416

@@ -420,7 +420,7 @@ def test_references_iterator_invalid_filter_python(testrepo):
420420
refs = []
421421
with pytest.raises(ValueError):
422422
for ref in repo.references.iterator(5):
423-
refs.append((ref.name, ref.target.hex))
423+
refs.append((ref.name, ref.target))
424424

425425

426426
def test_lookup_reference(testrepo):

‎test/test_revwalk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_hide_prefix(testrepo):
8383
def test_reset(testrepo):
8484
walker = testrepo.walk(log[0], SortMode.TIME)
8585
walker.reset()
86-
assert [x.hex for x in walker] == []
86+
assert list(walker) == []
8787

8888

8989
def test_push(testrepo):

0 commit comments

Comments
 (0)
Please sign in to comment.