MCPcopy Create free account
hub / github.com/libgit2/pygit2 / References

Class References

pygit2/references.py:41–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40
41class References:
42 def __init__(self, repository: BaseRepository) -> None:
43 self._repository = repository
44
45 def __getitem__(self, name: str) -> 'Reference':
46 return self._repository.lookup_reference(name)
47
48 def get(self, key: str) -> 'Reference' | None:
49 try:
50 return self[key]
51 except KeyError:
52 return None
53
54 def __iter__(self) -> Iterator[str]:
55 iter = self._repository.references_iterator_init()
56 while True:
57 ref = self._repository.references_iterator_next(iter)
58 if ref:
59 yield ref.name
60 else:
61 return
62
63 def iterator(
64 self, references_return_type: ReferenceFilter = ReferenceFilter.ALL
65 ) -> Iterator['Reference']:
66 """Creates a new iterator and fetches references for a given repository.
67
68 Can also filter and pass all refs or only branches or only tags.
69
70 Parameters:
71
72 references_return_type: ReferenceFilter
73 Optional specifier to filter references. By default, all references are
74 returned.
75
76 The following values are accepted:
77 - ReferenceFilter.ALL, fetches all refs, this is the default
78 - ReferenceFilter.BRANCHES, fetches only branches
79 - ReferenceFilter.TAGS, fetches only tags
80
81 TODO: Add support for filtering by reference types notes and remotes.
82 """
83
84 # Enforce ReferenceFilter type - raises ValueError if we're given an invalid value
85 references_return_type = ReferenceFilter(references_return_type)
86
87 iter = self._repository.references_iterator_init()
88 while True:
89 ref = self._repository.references_iterator_next(
90 iter, references_return_type
91 )
92 if ref:
93 yield ref
94 else:
95 return
96
97 def create(self, name: str, target: Oid | str, force: bool = False) -> 'Reference':
98 return self._repository.create_reference(name, target, force)

Callers 1

_common_initMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…