Skip to content

Commit 06504c9

Browse files
authored
Fix pygit2 latest update compatibility (#359)
* ignore pip vulnerability * remove deprecated pygit2 GIT_OBJ_COMMIT * remove more deprectated calls and symbols * deprecated oid to id
1 parent 4e52900 commit 06504c9

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

noxfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def safety(session: nox.Session) -> None:
3737
"""Scan dependencies for insecure packages."""
3838
session.install(".[dev]")
3939
session.install("safety")
40-
session.run("safety", "check", "--full-report")
40+
session.run("safety", "check", "--full-report", "--ignore=67599")
4141

4242

4343
@nox.session

src/scmrepo/git/backend/pygit2/__init__.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def open(
7272
path = "/".join(key)
7373
blob_kwargs = {
7474
"as_path": path,
75-
"commit_id": commit.oid,
75+
"commit_id": commit.id,
7676
}
7777
blobio = BlobIO(self.obj, **blob_kwargs)
7878
if mode == "rb":
@@ -108,7 +108,7 @@ def size(self) -> int: # pylint: disable=invalid-overridden-method
108108

109109
@property
110110
def sha(self) -> str:
111-
return self.obj.hex
111+
return str(self.obj.id)
112112

113113
def scandir(self) -> Iterable["Pygit2Object"]:
114114
for entry in self.obj:
@@ -190,12 +190,13 @@ def _refdb(self):
190190
return RefdbFsBackend(self.repo)
191191

192192
def _resolve_refish(self, refish: str):
193-
from pygit2 import GIT_OBJ_COMMIT, Tag
193+
from pygit2 import Tag
194+
from pygit2.enums import ObjectType
194195

195196
commit, ref = self.repo.resolve_refish(refish)
196197
if isinstance(commit, Tag):
197198
ref = commit
198-
commit = commit.peel(GIT_OBJ_COMMIT)
199+
commit = commit.peel(ObjectType.COMMIT)
199200
return commit, ref
200201

201202
@property
@@ -395,7 +396,8 @@ def tag(
395396
annotated: bool = False,
396397
message: Optional[str] = None,
397398
):
398-
from pygit2 import GIT_OBJ_COMMIT, GitError
399+
from pygit2 import GitError
400+
from pygit2.enums import ObjectType
399401

400402
if annotated and not message:
401403
raise SCMError("message is required for annotated tag")
@@ -404,7 +406,7 @@ def tag(
404406
self.repo.create_tag(
405407
tag,
406408
target_obj.id,
407-
GIT_OBJ_COMMIT,
409+
ObjectType.COMMIT,
408410
self.committer,
409411
message or "",
410412
)
@@ -526,20 +528,21 @@ def set_ref(
526528
self.repo.create_reference_direct(name, new_ref, True, message=message)
527529

528530
def get_ref(self, name, follow: bool = True) -> Optional[str]:
529-
from pygit2 import GIT_OBJ_COMMIT, GIT_REF_SYMBOLIC, InvalidSpecError, Tag
531+
from pygit2 import InvalidSpecError, Tag
532+
from pygit2.enums import ObjectType, ReferenceType
530533

531534
try:
532535
ref = self.repo.references.get(name)
533536
except InvalidSpecError:
534537
return None
535538
if not ref:
536539
return None
537-
if follow and ref.type == GIT_REF_SYMBOLIC:
540+
if follow and ref.type == ReferenceType.SYMBOLIC:
538541
ref = ref.resolve()
539542
try:
540543
obj = self.repo[ref.target]
541544
if isinstance(obj, Tag):
542-
return str(obj.peel(GIT_OBJ_COMMIT).id)
545+
return str(obj.peel(ObjectType.COMMIT).id)
543546
except ValueError:
544547
pass
545548

@@ -841,7 +844,7 @@ def reset(self, hard: bool = False, paths: Optional[Iterable[str]] = None):
841844
if os.name == "nt":
842845
rel = rel.replace("\\", "/")
843846
obj = tree[rel]
844-
self.repo.index.add(IndexEntry(rel, obj.oid, obj.filemode))
847+
self.repo.index.add(IndexEntry(rel, obj.id, obj.filemode))
845848
self.repo.index.write()
846849
elif hard:
847850
self.repo.reset(self.repo.head.target, GIT_RESET_HARD)
@@ -1077,7 +1080,7 @@ def get_tag(self, name: str) -> Optional[Union[str, "GitTag"]]:
10771080
if isinstance(tag, Tag):
10781081
return GitTag(
10791082
tag.name,
1080-
str(tag.oid),
1083+
str(tag.id),
10811084
str(tag.target),
10821085
tag.tagger.name,
10831086
tag.tagger.email,

0 commit comments

Comments
 (0)