Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90d00cf

Browse files
author
Andrey Pokrovskiy
committed
Option to skip packed_refs in iter_items()
In cases where tool only need recent-ish refs (e.g. base branch autodetect) it will save a lot of time if `packed_refs` can be excluded from search.
1 parent e3bc5d1 commit 90d00cf

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

git/refs/symbolic.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ def rename(self, new_path: PathLike, force: bool = False) -> "SymbolicReference"
661661

662662
@classmethod
663663
def _iter_items(
664-
cls: Type[T_References], repo: "Repo", common_path: Union[PathLike, None] = None
664+
cls: Type[T_References], repo: "Repo", common_path: Union[PathLike, None] = None,
665+
packed_refs: bool = True
665666
) -> Iterator[T_References]:
666667
if common_path is None:
667668
common_path = cls._common_path_default
@@ -685,10 +686,11 @@ def _iter_items(
685686
# END for each directory to walk
686687

687688
# read packed refs
688-
for _sha, rela_path in cls._iter_packed_refs(repo):
689-
if rela_path.startswith(str(common_path)):
690-
rela_paths.add(rela_path)
691-
# END relative path matches common path
689+
if packed_refs:
690+
for _sha, rela_path in cls._iter_packed_refs(repo):
691+
if rela_path.startswith(str(common_path)):
692+
rela_paths.add(rela_path)
693+
# END relative path matches common path
692694
# END packed refs reading
693695

694696
# return paths in sorted order
@@ -704,6 +706,7 @@ def iter_items(
704706
cls: Type[T_References],
705707
repo: "Repo",
706708
common_path: Union[PathLike, None] = None,
709+
packed_refs: bool = True,
707710
*args: Any,
708711
**kwargs: Any,
709712
) -> Iterator[T_References]:
@@ -723,7 +726,7 @@ def iter_items(
723726
724727
List is lexicographically sorted
725728
The returned objects represent actual subclasses, such as Head or TagReference"""
726-
return (r for r in cls._iter_items(repo, common_path) if r.__class__ == SymbolicReference or not r.is_detached)
729+
return (r for r in cls._iter_items(repo, common_path, packed_refs) if r.__class__ == SymbolicReference or not r.is_detached)
727730

728731
@classmethod
729732
def from_path(cls: Type[T_References], repo: "Repo", path: PathLike) -> T_References:

0 commit comments

Comments
 (0)