Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 444 Lines • ▼ Show 20 Lines | def directory_entry_get_by_path(self, directory, paths): | ||||
- directory: sha1 of the top level directory | - directory: sha1 of the top level directory | ||||
- paths: path to lookup from the top level directory. From left | - paths: path to lookup from the top level directory. From left | ||||
(top) to right (bottom). | (top) to right (bottom). | ||||
Returns: | Returns: | ||||
The corresponding directory entry if found, None otherwise. | The corresponding directory entry if found, None otherwise. | ||||
""" | """ | ||||
return self._directory_entry_get_by_path(directory, paths, b'') | |||||
def _directory_entry_get_by_path(self, directory, paths, prefix): | |||||
if not paths: | if not paths: | ||||
return | return | ||||
contents = list(self.directory_ls(directory)) | contents = list(self.directory_ls(directory)) | ||||
if not contents: | if not contents: | ||||
return | return | ||||
def _get_entry(entries, name): | def _get_entry(entries, name): | ||||
for entry in entries: | for entry in entries: | ||||
if entry['name'] == name: | if entry['name'] == name: | ||||
entry = entry.copy() | |||||
entry['name'] = prefix + entry['name'] | |||||
return entry | return entry | ||||
first_item = _get_entry(contents, paths[0]) | first_item = _get_entry(contents, paths[0]) | ||||
if len(paths) == 1: | if len(paths) == 1: | ||||
return first_item | return first_item | ||||
if not first_item or first_item['type'] != 'dir': | if not first_item or first_item['type'] != 'dir': | ||||
return | return | ||||
return self.directory_entry_get_by_path( | return self._directory_entry_get_by_path( | ||||
first_item['target'], paths[1:]) | first_item['target'], paths[1:], prefix + paths[0] + b'/') | ||||
def revision_add(self, revisions): | def revision_add(self, revisions): | ||||
"""Add revisions to the storage | """Add revisions to the storage | ||||
Args: | Args: | ||||
revisions (Iterable[dict]): iterable of dictionaries representing | revisions (Iterable[dict]): iterable of dictionaries representing | ||||
the individual revisions to add. Each dict has the following | the individual revisions to add. Each dict has the following | ||||
keys: | keys: | ||||
▲ Show 20 Lines • Show All 1,062 Lines • Show Last 20 Lines |