Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/ctags.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 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 | ||||
import json | import json | ||||
import subprocess | import subprocess | ||||
from typing import Any, Dict, Iterator, List, Optional, Union | from typing import Any, Dict, Iterator, List, Optional | ||||
from swh.core.config import merge_configs | from swh.core.config import merge_configs | ||||
from swh.indexer.storage import Sha1 | |||||
from swh.indexer.storage.model import ContentCtagsRow | from swh.indexer.storage.model import ContentCtagsRow | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.model import Revision | |||||
from .indexer import ContentIndexer, write_to_temp | from .indexer import ContentIndexer, write_to_temp | ||||
# Options used to compute tags | # Options used to compute tags | ||||
__FLAGS = [ | __FLAGS = [ | ||||
"--fields=+lnz", # +l: language | "--fields=+lnz", # +l: language | ||||
# +n: line number of tag definition | # +n: line number of tag definition | ||||
# +z: include the symbol's kind (function, variable, ...) | # +z: include the symbol's kind (function, variable, ...) | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | def filter(self, ids): | ||||
"""Filter out known sha1s and return only missing ones. | """Filter out known sha1s and return only missing ones. | ||||
""" | """ | ||||
yield from self.idx_storage.content_ctags_missing( | yield from self.idx_storage.content_ctags_missing( | ||||
({"id": sha1, "indexer_configuration_id": self.tool["id"],} for sha1 in ids) | ({"id": sha1, "indexer_configuration_id": self.tool["id"],} for sha1 in ids) | ||||
) | ) | ||||
def index( | def index( | ||||
self, id: Union[bytes, Dict, Revision], data: Optional[bytes] = None, **kwargs | self, id: Sha1, data: Optional[bytes] = None, **kwargs | ||||
) -> List[ContentCtagsRow]: | ) -> List[ContentCtagsRow]: | ||||
"""Index sha1s' content and store result. | """Index sha1s' content and store result. | ||||
Args: | Args: | ||||
id (bytes): content's identifier | id (bytes): content's identifier | ||||
data (bytes): raw content in bytes | data (bytes): raw content in bytes | ||||
Returns: | Returns: | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |