Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/origin_head.py
Show All 21 Lines | class OriginHeadIndexer(OriginIndexer): | ||||
def persist_index_computations(self, results, policy_update): | def persist_index_computations(self, results, policy_update): | ||||
"""Do nothing. The indexer's results are not persistent, they | """Do nothing. The indexer's results are not persistent, they | ||||
should only be piped to another indexer.""" | should only be piped to another indexer.""" | ||||
pass | pass | ||||
# Dispatch | # Dispatch | ||||
def index(self, origin): | def index(self, origin_url): | ||||
origin_id = origin['id'] | latest_snapshot = self.storage.snapshot_get_latest(origin_url) | ||||
latest_snapshot = self.storage.snapshot_get_latest(origin_id) | |||||
if latest_snapshot is None: | if latest_snapshot is None: | ||||
return None | return None | ||||
method = getattr(self, '_try_get_%s_head' % origin['type'], None) | for method in (self._try_get_vcs_head, self._try_get_head_generic, | ||||
if method is None: | self._try_get_ftp_head): | ||||
method = self._try_get_head_generic | |||||
rev_id = method(latest_snapshot) | rev_id = method(latest_snapshot) | ||||
if rev_id is None: | if rev_id is not None: | ||||
return None | return { | ||||
result = { | 'origin_url': origin_url, | ||||
'origin_id': origin_id, | |||||
'revision_id': rev_id, | 'revision_id': rev_id, | ||||
} | } | ||||
return result | |||||
# could not find a head revision | |||||
return None | |||||
douardda: why changing the behavior of head selection mechanism here?
why cannot we know at this point… | |||||
Done Inline Actions
That requires a new API endpoint in the storage, but indeed, we could (and should). vlorentz: > why cannot we know at this point which type the processed origin is?
That requires a new API… | |||||
Done Inline Actionsvlorentz: D1581 | |||||
# VCSs | # VCSs | ||||
def _try_get_vcs_head(self, snapshot): | def _try_get_vcs_head(self, snapshot): | ||||
try: | try: | ||||
branches = snapshot['branches'] | branches = snapshot['branches'] | ||||
if branches[b'HEAD']['target_type'] == 'revision': | if branches[b'HEAD']['target_type'] == 'revision': | ||||
return branches[b'HEAD']['target'] | return branches[b'HEAD']['target'] | ||||
except KeyError: | except KeyError: | ||||
return None | return None | ||||
_try_get_hg_head = _try_get_git_head = _try_get_vcs_head | |||||
# Tarballs | # Tarballs | ||||
_archive_filename_re = re.compile( | _archive_filename_re = re.compile( | ||||
rb'^' | rb'^' | ||||
rb'(?P<pkgname>.*)[-_]' | rb'(?P<pkgname>.*)[-_]' | ||||
rb'(?P<version>[0-9]+(\.[0-9])*)' | rb'(?P<version>[0-9]+(\.[0-9])*)' | ||||
rb'(?P<preversion>[-+][a-zA-Z0-9.~]+?)?' | rb'(?P<preversion>[-+][a-zA-Z0-9.~]+?)?' | ||||
rb'(?P<extension>(\.[a-zA-Z0-9]+)+)' | rb'(?P<extension>(\.[a-zA-Z0-9]+)+)' | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |
why changing the behavior of head selection mechanism here?
why cannot we know at this point which type the processed origin is?
In all cases, if this try-based solution is now mandatory, it would be nice to have it encapsulated in a generic self.get_head() method IMHO.