Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/service.py
Show First 20 Lines • Show All 453 Lines • ▼ Show 20 Lines | if not revision: | ||||
% rev_sha1_git) | % rev_sha1_git) | ||||
if 'message' not in revision: | if 'message' not in revision: | ||||
raise NotFoundExc('No message for revision with sha1_git %s.' | raise NotFoundExc('No message for revision with sha1_git %s.' | ||||
% rev_sha1_git) | % rev_sha1_git) | ||||
res = {'message': revision['message']} | res = {'message': revision['message']} | ||||
return res | return res | ||||
def lookup_revision_by(origin_id, | |||||
branch_name="refs/heads/master", | |||||
timestamp=None): | |||||
"""Lookup revisions by origin_id, branch_name and timestamp. | |||||
If: | |||||
- branch_name is not provided, lookup using 'refs/heads/master' as default. | |||||
- ts is not provided, use the most recent | |||||
Args: | |||||
- origin_id: origin of the revision. | |||||
- branch_name: revision's branch. | |||||
- timestamp: revision's time frame. | |||||
Yields: | |||||
The revisions matching the criterions. | |||||
Raises: | |||||
NotFoundExc if no revision corresponds to the criterion | |||||
""" | |||||
res = _first_element(storage.revision_get_by(origin_id, | |||||
branch_name, | |||||
timestamp=timestamp, | |||||
limit=1)) | |||||
if not res: | |||||
raise NotFoundExc('Revision for origin %s and branch %s not found.' | |||||
% (origin_id, branch_name)) | |||||
return converters.from_revision(res) | |||||
def lookup_revision_log(rev_sha1_git, limit): | def lookup_revision_log(rev_sha1_git, limit): | ||||
"""Return information about the revision with sha1 revision_sha1_git. | """Return information about the revision with sha1 revision_sha1_git. | ||||
Args: | Args: | ||||
revision_sha1_git: The revision's sha1 as hexadecimal | revision_sha1_git: The revision's sha1 as hexadecimal | ||||
limit: the maximum number of revisions returned | limit: the maximum number of revisions returned | ||||
Returns: | Returns: | ||||
Show All 33 Lines | revision_entries = storage.revision_log_by(origin_id, | ||||
branch_name, | branch_name, | ||||
timestamp, | timestamp, | ||||
limit=limit) | limit=limit) | ||||
if not revision_entries: | if not revision_entries: | ||||
return None | return None | ||||
return map(converters.from_revision, revision_entries) | return map(converters.from_revision, revision_entries) | ||||
def lookup_revision_with_context_by(origin_id, branch_name, ts, sha1_git, | |||||
limit=100): | |||||
"""Return information about revision sha1_git, limited to the | |||||
sub-graph of all transitive parents of sha1_git_root. | |||||
sha1_git_root being resolved through the lookup of a revision by origin_id, | |||||
branch_name and ts. | |||||
In other words, sha1_git is an ancestor of sha1_git_root. | |||||
Args: | |||||
- origin_id: origin of the revision. | |||||
- branch_name: revision's branch. | |||||
- timestamp: revision's time frame. | |||||
- sha1_git: one of sha1_git_root's ancestors. | |||||
- limit: limit the lookup to 100 revisions back. | |||||
Returns: | |||||
Pair of (root_revision, revision). | |||||
Information on sha1_git if it is an ancestor of sha1_git_root | |||||
including children leading to sha1_git_root | |||||
Raises: | |||||
- BadInputExc in case of unknown algo_hash or bad hash. | |||||
- NotFoundExc if either revision is not found or if sha1_git is not an | |||||
ancestor of sha1_git_root. | |||||
""" | |||||
rev_root = _first_element(storage.revision_get_by(origin_id, | |||||
branch_name, | |||||
timestamp=ts, | |||||
limit=1)) | |||||
if not rev_root: | |||||
raise NotFoundExc('Revision with (origin_id: %s, branch_name: %s' | |||||
', ts: %s) not found.' % (origin_id, | |||||
branch_name, | |||||
ts)) | |||||
return (converters.from_revision(rev_root), | |||||
lookup_revision_with_context(rev_root, sha1_git, limit)) | |||||
def lookup_revision_with_context(sha1_git_root, sha1_git, limit=100): | def lookup_revision_with_context(sha1_git_root, sha1_git, limit=100): | ||||
"""Return information about revision sha1_git, limited to the | """Return information about revision sha1_git, limited to the | ||||
sub-graph of all transitive parents of sha1_git_root. | sub-graph of all transitive parents of sha1_git_root. | ||||
In other words, sha1_git is an ancestor of sha1_git_root. | In other words, sha1_git is an ancestor of sha1_git_root. | ||||
Args: | Args: | ||||
sha1_git_root: latest revision. The type is either a sha1 (as an hex | sha1_git_root: latest revision. The type is either a sha1 (as an hex | ||||
▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | def lookup_latest_origin_snapshot(origin_id, allowed_statuses=None): | ||||
Returns: | Returns: | ||||
A dict filled with the snapshot content. | A dict filled with the snapshot content. | ||||
""" | """ | ||||
snapshot = storage.snapshot_get_latest(origin_id, allowed_statuses) | snapshot = storage.snapshot_get_latest(origin_id, allowed_statuses) | ||||
return converters.from_snapshot(snapshot) | return converters.from_snapshot(snapshot) | ||||
def lookup_revision_through(revision, limit=100): | |||||
"""Retrieve a revision from the criterion stored in revision dictionary. | |||||
Args: | |||||
revision: Dictionary of criterion to lookup the revision with. | |||||
Here are the supported combination of possible values: | |||||
- origin_id, branch_name, ts, sha1_git | |||||
- origin_id, branch_name, ts | |||||
- sha1_git_root, sha1_git | |||||
- sha1_git | |||||
Returns: | |||||
None if the revision is not found or the actual revision. | |||||
""" | |||||
if 'origin_id' in revision and \ | |||||
'branch_name' in revision and \ | |||||
'ts' in revision and \ | |||||
'sha1_git' in revision: | |||||
return lookup_revision_with_context_by(revision['origin_id'], | |||||
revision['branch_name'], | |||||
revision['ts'], | |||||
revision['sha1_git'], | |||||
limit) | |||||
if 'origin_id' in revision and \ | |||||
'branch_name' in revision and \ | |||||
'ts' in revision: | |||||
return lookup_revision_by(revision['origin_id'], | |||||
revision['branch_name'], | |||||
revision['ts']) | |||||
if 'sha1_git_root' in revision and \ | |||||
'sha1_git' in revision: | |||||
return lookup_revision_with_context(revision['sha1_git_root'], | |||||
revision['sha1_git'], | |||||
limit) | |||||
if 'sha1_git' in revision: | |||||
return lookup_revision(revision['sha1_git']) | |||||
# this should not happen | |||||
raise NotImplementedError('Should not happen!') | |||||
def lookup_directory_through_revision(revision, path=None, | |||||
limit=100, with_data=False): | |||||
"""Retrieve the directory information from the revision. | |||||
Args: | |||||
revision: dictionary of criterion representing a revision to lookup | |||||
path: directory's path to lookup. | |||||
limit: optional query parameter to limit the revisions log (default to | |||||
100). For now, note that this limit could impede the transitivity | |||||
conclusion about sha1_git not being an ancestor of. | |||||
with_data: indicate to retrieve the content's raw data if path resolves | |||||
to a content. | |||||
Returns: | |||||
The directory pointing to by the revision criterions at path. | |||||
""" | |||||
rev = lookup_revision_through(revision, limit) | |||||
if not rev: | |||||
raise NotFoundExc('Revision with criterion %s not found!' % revision) | |||||
return (rev['id'], | |||||
lookup_directory_with_revision(rev['id'], path, with_data)) | |||||
def vault_cook(obj_type, obj_id, email=None): | def vault_cook(obj_type, obj_id, email=None): | ||||
"""Cook a vault bundle. | """Cook a vault bundle. | ||||
""" | """ | ||||
return vault.cook(obj_type, obj_id, email=email) | return vault.cook(obj_type, obj_id, email=email) | ||||
def vault_fetch(obj_type, obj_id): | def vault_fetch(obj_type, obj_id): | ||||
"""Fetch a vault bundle. | """Fetch a vault bundle. | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |