Skip to content

Commit 3a044d8

Browse files
committed
Remove deprecated obj.hex, use str(obj.id)
1 parent 8698989 commit 3a044d8

15 files changed

+52
-63
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Breaking changes:
2121

2222
- Remove deprecated `oid.hex`, use `str(oid)`
23+
- Remove deprecated `object.hex`, use `str(object.id)`
2324

2425
- Remove deprecated `Repository.add_submodule(...)`, use `Repository.submodules.add(...)`
2526
- Remove deprecated `Repository.lookup_submodule(...)`, use `Repository.submodules[...]`

src/object.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,6 @@ Object_oid__get__(Object *self)
101101
return Object_id__get__(self);
102102
}
103103

104-
PyDoc_STRVAR(Object_hex__doc__,
105-
"Hexadecimal representation of the object id. This is a shortcut for\n"
106-
"Object.id.hex\n"
107-
"This attribute is deprecated, please use 'id'\n");
108-
109-
PyObject *
110-
Object_hex__get__(Object *self)
111-
{
112-
return git_oid_to_py_str(Object__id(self));
113-
}
114-
115104

116105
PyDoc_STRVAR(Object_short_id__doc__,
117106
"An unambiguous short (abbreviated) hex Oid string for the object.");
@@ -313,7 +302,6 @@ Object_richcompare(PyObject *o1, PyObject *o2, int op)
313302
PyGetSetDef Object_getseters[] = {
314303
GETTER(Object, oid),
315304
GETTER(Object, id),
316-
GETTER(Object, hex),
317305
GETTER(Object, short_id),
318306
GETTER(Object, type),
319307
GETTER(Object, type_str),

test/test_blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
def test_read_blob(testrepo):
8484
blob = testrepo[BLOB_SHA]
85-
assert blob.hex == BLOB_SHA
85+
assert str(blob.id) == BLOB_SHA
8686
assert str(blob.id) == BLOB_SHA
8787
assert isinstance(blob, pygit2.Blob)
8888
assert not blob.is_binary

test/test_commit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ def test_new_commit(barerepo):
9090
commit = repo[sha]
9191

9292
assert ObjectType.COMMIT == commit.type
93-
assert '98286caaab3f1fde5bf52c8369b2b0423bad743b' == commit.hex
93+
assert '98286caaab3f1fde5bf52c8369b2b0423bad743b' == str(commit.id)
9494
assert commit.message_encoding is None
9595
assert message == commit.message
9696
assert 12346 == commit.commit_time
9797
assert committer == commit.committer
9898
assert author == commit.author
99-
assert tree == commit.tree.hex
99+
assert tree == str(commit.tree.id)
100100
assert Oid(hex=tree) == commit.tree_id
101101
assert 1 == len(commit.parents)
102-
assert COMMIT_SHA == commit.parents[0].hex
102+
assert COMMIT_SHA == str(commit.parents[0].id)
103103
assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0]
104104

105105

@@ -124,10 +124,10 @@ def test_new_commit_encoding(barerepo):
124124
assert 12346 == commit.commit_time
125125
assert committer == commit.committer
126126
assert author == commit.author
127-
assert tree == commit.tree.hex
127+
assert tree == str(commit.tree.id)
128128
assert Oid(hex=tree) == commit.tree_id
129129
assert 1 == len(commit.parents)
130-
assert COMMIT_SHA == commit.parents[0].hex
130+
assert COMMIT_SHA == str(commit.parents[0].id)
131131
assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0]
132132

133133

test/test_commit_gpg.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ def test_commit_signing(gpgsigned):
100100
offset=-480,
101101
)
102102
tree = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
103-
parents = ['8496071c1b46c854b31185ea97743be6a8774479']
103+
parent = '8496071c1b46c854b31185ea97743be6a8774479'
104104

105105
# create commit string
106-
commit_string = repo.create_commit_string(author, committer, message, tree, parents)
106+
commit_string = repo.create_commit_string(author, committer, message, tree, [parent])
107107
assert commit_string == content
108108

109109
# create/retrieve signed commit
@@ -118,17 +118,17 @@ def test_commit_signing(gpgsigned):
118118

119119
# perform sanity checks
120120
assert ObjectType.COMMIT == commit.type
121-
assert '6569fdf71dbd99081891154641869c537784a3ba' == commit.hex
121+
assert '6569fdf71dbd99081891154641869c537784a3ba' == str(commit.id)
122122
assert commit.message_encoding is None
123123
assert message == commit.message
124124
assert 1358451456 == commit.commit_time
125125
assert committer == commit.committer
126126
assert author == commit.author
127-
assert tree == commit.tree.hex
127+
assert tree == str(commit.tree.id)
128128
assert Oid(hex=tree) == commit.tree_id
129129
assert 1 == len(commit.parents)
130-
assert parents[0] == commit.parents[0].hex
131-
assert Oid(hex=parents[0]) == commit.parent_ids[0]
130+
assert parent == str(commit.parents[0].id)
131+
assert Oid(hex=parent) == commit.parent_ids[0]
132132

133133

134134
def test_get_gpg_signature_when_unsigned(gpgsigned):

test/test_note.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646

4747

4848
def test_create_note(barerepo):
49-
annotated_id = barerepo.revparse_single('HEAD~3').hex
49+
annotated_id = barerepo.revparse_single('HEAD~3').id
5050
author = committer = Signature('Foo bar', '[email protected]', 12346, 0)
51-
note_id = barerepo.create_note(NOTE[1], author, committer, annotated_id)
51+
note_id = barerepo.create_note(NOTE[1], author, committer, str(annotated_id))
5252
assert NOTE[0] == str(note_id)
5353

5454
# check the note blob

test/test_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_obj(obj, msg):
136136
tree = commit.tree
137137
test_obj(tree, f'tree#{tree.id}')
138138
for entry in tree:
139-
test_obj(testrepo[entry.hex], f'entry={entry.name}#{entry.hex}')
139+
test_obj(testrepo[entry.id], f'entry={entry.name}#{entry.id}')
140140

141141

142142
def test_repr(testrepo):

test/test_refs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def test_refs_list(testrepo):
6060

6161
def test_head(testrepo):
6262
head = testrepo.head
63-
assert LAST_COMMIT == testrepo[head.target].hex
64-
assert LAST_COMMIT == testrepo[head.raw_target].hex
63+
assert LAST_COMMIT == str(testrepo[head.target].id)
64+
assert LAST_COMMIT == str(testrepo[head.raw_target].id)
6565

6666

6767
def test_refs_getitem(testrepo):
@@ -484,27 +484,27 @@ def test_resolve_refish(testrepo):
484484

485485
commit, ref = repo.resolve_refish('refs/heads/i18n')
486486
assert ref.name == 'refs/heads/i18n'
487-
assert commit.hex == '5470a671a80ac3789f1a6a8cefbcf43ce7af0563'
487+
assert str(commit.id) == '5470a671a80ac3789f1a6a8cefbcf43ce7af0563'
488488

489489
commit, ref = repo.resolve_refish('master')
490490
assert ref.name == 'refs/heads/master'
491-
assert commit.hex == LAST_COMMIT
491+
assert str(commit.id) == LAST_COMMIT
492492

493493
commit, ref = repo.resolve_refish('origin/master')
494494
assert ref.name == 'refs/remotes/origin/master'
495-
assert commit.hex == LAST_COMMIT
495+
assert str(commit.id) == LAST_COMMIT
496496

497497
commit, ref = repo.resolve_refish('version1')
498498
assert ref.name == 'refs/tags/version1'
499-
assert commit.hex == LAST_COMMIT
499+
assert str(commit.id) == LAST_COMMIT
500500

501501
commit, ref = repo.resolve_refish(LAST_COMMIT)
502502
assert ref is None
503-
assert commit.hex == LAST_COMMIT
503+
assert str(commit.id) == LAST_COMMIT
504504

505505
commit, ref = repo.resolve_refish('HEAD~1')
506506
assert ref is None
507-
assert commit.hex == '5ebeeebb320790caf276b9fc8b24546d63316533'
507+
assert str(commit.id) == '5ebeeebb320790caf276b9fc8b24546d63316533'
508508

509509

510510
def test_reference_get_sha(testrepo):

test/test_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_checkout_ref(testrepo):
8585

8686
head = testrepo.head
8787
head = testrepo[head.target]
88-
assert head.hex == str(ref_i18n.target)
88+
assert head.id == ref_i18n.target
8989
assert 'new' in head.tree
9090
assert 'bye.txt' not in testrepo.status()
9191

@@ -180,7 +180,7 @@ def test_checkout_branch(testrepo):
180180

181181
head = testrepo.head
182182
head = testrepo[head.target]
183-
assert head.hex == str(branch_i18n.target)
183+
assert head.id == branch_i18n.target
184184
assert 'new' in head.tree
185185
assert 'bye.txt' not in testrepo.status()
186186

test/test_repository_bare.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,24 @@ def test_iterable(barerepo):
115115
def test_lookup_blob(barerepo):
116116
with pytest.raises(TypeError):
117117
barerepo[123]
118-
assert barerepo[BLOB_OID].hex == BLOB_HEX
118+
assert str(barerepo[BLOB_OID].id) == BLOB_HEX
119119
a = barerepo[BLOB_HEX]
120120
assert b'a contents\n' == a.read_raw()
121-
assert BLOB_HEX == a.hex
121+
assert BLOB_HEX == str(a.id)
122122
assert ObjectType.BLOB == a.type
123123

124124

125125
def test_lookup_blob_prefix(barerepo):
126126
a = barerepo[BLOB_HEX[:5]]
127127
assert b'a contents\n' == a.read_raw()
128-
assert BLOB_HEX == a.hex
128+
assert BLOB_HEX == str(a.id)
129129
assert ObjectType.BLOB == a.type
130130

131131

132132
def test_lookup_commit(barerepo):
133133
commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10'
134134
commit = barerepo[commit_sha]
135-
assert commit_sha == commit.hex
135+
assert commit_sha == str(commit.id)
136136
assert ObjectType.COMMIT == commit.type
137137
assert commit.message == (
138138
'Second test data commit.\n\n' 'This commit has some additional text.\n'
@@ -144,7 +144,7 @@ def test_lookup_commit_prefix(barerepo):
144144
commit_sha_prefix = commit_sha[:7]
145145
too_short_prefix = commit_sha[:3]
146146
commit = barerepo[commit_sha_prefix]
147-
assert commit_sha == commit.hex
147+
assert commit_sha == str(commit.id)
148148
assert ObjectType.COMMIT == commit.type
149149
assert (
150150
'Second test data commit.\n\n'
@@ -183,7 +183,7 @@ def test_get_workdir(barerepo):
183183

184184
def test_revparse_single(barerepo):
185185
parent = barerepo.revparse_single('HEAD^')
186-
assert parent.hex == PARENT_SHA
186+
assert str(parent.id) == PARENT_SHA
187187

188188

189189
def test_hash(barerepo):

0 commit comments

Comments
 (0)