Skip to content

Commit

Permalink
Fix pygit2 latest update compatibility (#359)
Browse files Browse the repository at this point in the history
* ignore pip vulnerability

* remove deprecated pygit2 GIT_OBJ_COMMIT

* remove more deprectated calls and symbols

* deprecated oid to id
  • Loading branch information
shcheklein authored May 20, 2024
1 parent 4e52900 commit 06504c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def safety(session: nox.Session) -> None:
"""Scan dependencies for insecure packages."""
session.install(".[dev]")
session.install("safety")
session.run("safety", "check", "--full-report")
session.run("safety", "check", "--full-report", "--ignore=67599")


@nox.session
Expand Down
25 changes: 14 additions & 11 deletions src/scmrepo/git/backend/pygit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def open(
path = "/".join(key)
blob_kwargs = {
"as_path": path,
"commit_id": commit.oid,
"commit_id": commit.id,
}
blobio = BlobIO(self.obj, **blob_kwargs)
if mode == "rb":
Expand Down Expand Up @@ -108,7 +108,7 @@ def size(self) -> int: # pylint: disable=invalid-overridden-method

@property
def sha(self) -> str:
return self.obj.hex
return str(self.obj.id)

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

def _resolve_refish(self, refish: str):
from pygit2 import GIT_OBJ_COMMIT, Tag
from pygit2 import Tag
from pygit2.enums import ObjectType

commit, ref = self.repo.resolve_refish(refish)
if isinstance(commit, Tag):
ref = commit
commit = commit.peel(GIT_OBJ_COMMIT)
commit = commit.peel(ObjectType.COMMIT)
return commit, ref

@property
Expand Down Expand Up @@ -395,7 +396,8 @@ def tag(
annotated: bool = False,
message: Optional[str] = None,
):
from pygit2 import GIT_OBJ_COMMIT, GitError
from pygit2 import GitError
from pygit2.enums import ObjectType

if annotated and not message:
raise SCMError("message is required for annotated tag")
Expand All @@ -404,7 +406,7 @@ def tag(
self.repo.create_tag(
tag,
target_obj.id,
GIT_OBJ_COMMIT,
ObjectType.COMMIT,
self.committer,
message or "",
)
Expand Down Expand Up @@ -526,20 +528,21 @@ def set_ref(
self.repo.create_reference_direct(name, new_ref, True, message=message)

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

try:
ref = self.repo.references.get(name)
except InvalidSpecError:
return None
if not ref:
return None
if follow and ref.type == GIT_REF_SYMBOLIC:
if follow and ref.type == ReferenceType.SYMBOLIC:
ref = ref.resolve()
try:
obj = self.repo[ref.target]
if isinstance(obj, Tag):
return str(obj.peel(GIT_OBJ_COMMIT).id)
return str(obj.peel(ObjectType.COMMIT).id)
except ValueError:
pass

Expand Down Expand Up @@ -841,7 +844,7 @@ def reset(self, hard: bool = False, paths: Optional[Iterable[str]] = None):
if os.name == "nt":
rel = rel.replace("\\", "/")
obj = tree[rel]
self.repo.index.add(IndexEntry(rel, obj.oid, obj.filemode))
self.repo.index.add(IndexEntry(rel, obj.id, obj.filemode))
self.repo.index.write()
elif hard:
self.repo.reset(self.repo.head.target, GIT_RESET_HARD)
Expand Down Expand Up @@ -1077,7 +1080,7 @@ def get_tag(self, name: str) -> Optional[Union[str, "GitTag"]]:
if isinstance(tag, Tag):
return GitTag(
tag.name,
str(tag.oid),
str(tag.id),
str(tag.target),
tag.tagger.name,
tag.tagger.email,
Expand Down

0 comments on commit 06504c9

Please sign in to comment.