submodule.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # config.py - Reading and writing Git config files
  2. # Copyright (C) 2011-2013 Jelmer Vernooij <jelmer@jelmer.uk>
  3. #
  4. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  5. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  6. # General Public License as public by the Free Software Foundation; version 2.0
  7. # or (at your option) any later version. You can redistribute it and/or
  8. # modify it under the terms of either of these two licenses.
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # You should have received a copy of the licenses; if not, see
  17. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  18. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  19. # License, Version 2.0.
  20. #
  21. """Working with Git submodules."""
  22. from collections.abc import Iterator
  23. from .object_store import iter_tree_contents
  24. from .objects import S_ISGITLINK
  25. def iter_cached_submodules(store, root_tree_id: bytes) -> Iterator[tuple[str, bytes]]:
  26. """Iterate over cached submodules.
  27. Args:
  28. store: Object store to iterate
  29. root_tree_id: SHA of root tree
  30. Returns:
  31. Iterator over over (path, sha) tuples
  32. """
  33. for entry in iter_tree_contents(store, root_tree_id):
  34. if S_ISGITLINK(entry.mode):
  35. yield entry.path, entry.sha