Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pygit2 latest update compatibility #359

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



@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
Loading