Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/algos/dir_iterators.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
# Utility module to iterate on directory trees. | # Utility module to iterate on directory trees. | ||||
# The implementation is inspired from the work of Alberto Cortés | # The implementation is inspired from the work of Alberto Cortés | ||||
# for the go-git project. For more details, you can refer to: | # for the go-git project. For more details, you can refer to: | ||||
# - this blog post: https://blog.sourced.tech/post/difftree/ | # - this blog post: https://blog.sourced.tech/post/difftree/ | ||||
# - the reference implementation in go: | # - the reference implementation in go: | ||||
# https://github.com/src-d/go-git/tree/master/utils/merkletrie | # https://github.com/src-d/go-git/tree/master/utils/merkletrie | ||||
from enum import Enum | from enum import Enum | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.model import Directory | ||||
from swh.model.identifiers import directory_identifier | |||||
# get the hash identifier for an empty directory | # get the hash identifier for an empty directory | ||||
_empty_dir_hash = hash_to_bytes(directory_identifier({"entries": []})) | _empty_dir_hash = Directory(entries=()).id | ||||
def _get_dir(storage, dir_id): | def _get_dir(storage, dir_id): | ||||
""" | """ | ||||
Return directory data from swh storage. | Return directory data from swh storage. | ||||
""" | """ | ||||
return storage.directory_ls(dir_id) if dir_id else [] | return storage.directory_ls(dir_id) if dir_id else [] | ||||
▲ Show 20 Lines • Show All 347 Lines • Show Last 20 Lines |