Skip to content

Commit 82e470a

Browse files
mikhaininabn
authored andcommitted
Update dulwich, move prefix logic to _normalise()
1 parent 9c34ee1 commit 82e470a

File tree

3 files changed

+64
-90
lines changed

3 files changed

+64
-90
lines changed

poetry.lock

Lines changed: 49 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ poetry-core = { git = "https://github.com/python-poetry/poetry-core.git", branch
3535
build = "^1.2.1"
3636
cachecontrol = { version = "^0.14.0", extras = ["filecache"] }
3737
cleo = "^2.1.0"
38-
dulwich = "^0.22.1"
38+
dulwich = "^0.22.6"
3939
fastjsonschema = "^2.18.0"
4040
importlib-metadata = { version = ">=4.4", python = "<3.10" }
4141
installer = "^0.7.0"

src/poetry/vcs/git/backend.py

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from dulwich.config import parse_submodules
1919
from dulwich.errors import NotGitRepository
2020
from dulwich.index import IndexEntry
21-
from dulwich.objects import Commit
2221
from dulwich.refs import ANNOTATED_TAG_SUFFIX
2322
from dulwich.repo import Repo
2423

@@ -55,14 +54,14 @@ class GitRefSpec:
5554
tag: str | None = None
5655
ref: bytes = dataclasses.field(default_factory=lambda: b"HEAD")
5756

58-
def resolve(self, remote_refs: FetchPackResult) -> None:
57+
def resolve(self, remote_refs: FetchPackResult, repo: Repo) -> None:
5958
"""
6059
Resolve the ref using the provided remote refs.
6160
"""
62-
self._normalise(remote_refs=remote_refs)
61+
self._normalise(remote_refs=remote_refs, repo=repo)
6362
self._set_head(remote_refs=remote_refs)
6463

65-
def _normalise(self, remote_refs: FetchPackResult) -> None:
64+
def _normalise(self, remote_refs: FetchPackResult, repo: Repo) -> None:
6665
"""
6766
Internal helper method to determine if given revision is
6867
1. a branch or tag; if so, set corresponding properties.
@@ -99,7 +98,12 @@ def _normalise(self, remote_refs: FetchPackResult) -> None:
9998
for sha in remote_refs.refs.values():
10099
if sha.startswith(short_sha):
101100
self.revision = sha.decode("utf-8")
102-
break
101+
return
102+
103+
# no heads with such SHA, let's check all objects
104+
for sha in repo.object_store.iter_prefix(short_sha):
105+
self.revision = sha.decode("utf-8")
106+
return
103107

104108
def _set_head(self, remote_refs: FetchPackResult) -> None:
105109
"""
@@ -270,7 +274,7 @@ def _clone(cls, url: str, refspec: GitRefSpec, target: Path) -> Repo:
270274
)
271275

272276
try:
273-
refspec.resolve(remote_refs=remote_refs)
277+
refspec.resolve(remote_refs=remote_refs, repo=local)
274278
except KeyError: # branch / ref does not exist
275279
raise PoetryConsoleError(
276280
f"Failed to clone {url} at '{refspec.key}', verify ref exists on"
@@ -314,38 +318,13 @@ def _clone(cls, url: str, refspec: GitRefSpec, target: Path) -> Repo:
314318
if isinstance(e, AssertionError) and "Invalid object name" not in str(e):
315319
raise
316320

317-
short_ref_found = False
318-
319-
if refspec.is_sha_short:
320-
commit = cls._find_object_by_sha_prefix(local, refspec.key.encode())
321-
if commit is not None:
322-
logger.debug(
323-
"\nResolved short SHA <c2>%s</c2> as <c2>%s</c2>",
324-
refspec.key,
325-
commit.id,
326-
)
327-
local.refs[b"HEAD"] = commit.id
328-
with local:
329-
local.reset_index()
330-
short_ref_found = True
331-
332-
if not short_ref_found:
333-
raise PoetryConsoleError(
334-
f"Failed to clone {url} at '{refspec.key}', verify ref exists on"
335-
" remote."
336-
)
321+
raise PoetryConsoleError(
322+
f"Failed to clone {url} at '{refspec.key}', verify ref exists on"
323+
" remote."
324+
)
337325

338326
return local
339327

340-
@classmethod
341-
def _find_object_by_sha_prefix(cls, repo: Repo, sha_prefix: bytes) -> Commit | None:
342-
for sha in repo.object_store:
343-
if sha.startswith(sha_prefix):
344-
obj = repo.object_store[sha]
345-
if isinstance(obj, Commit):
346-
return obj
347-
return None
348-
349328
@classmethod
350329
def _clone_submodules(cls, repo: Repo) -> None:
351330
"""

0 commit comments

Comments
 (0)