Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/service.py
Show First 20 Lines • Show All 519 Lines • ▼ Show 20 Lines | if branch and branch['target_type'] == 'revision': | ||||
rev_id = branch['target'] | rev_id = branch['target'] | ||||
elif branch and branch['target_type'] == 'alias': | elif branch and branch['target_type'] == 'alias': | ||||
branch = _get_snapshot_branch(visit['snapshot'], branch['target']) | branch = _get_snapshot_branch(visit['snapshot'], branch['target']) | ||||
if branch and branch['target_type'] == 'revision': | if branch and branch['target_type'] == 'revision': | ||||
rev_id = branch['target'] | rev_id = branch['target'] | ||||
if not rev_id: | if not rev_id: | ||||
raise NotFoundExc('Revision for origin %s and branch %s not found.' | raise NotFoundExc('Revision for origin %s and branch %s not found.' | ||||
% (origin.get('url') or origin['id'], branch_name)) | % (origin.get('url'), branch_name)) | ||||
return rev_id | return rev_id | ||||
def lookup_revision_by(origin, | def lookup_revision_by(origin, | ||||
branch_name='HEAD', | branch_name='HEAD', | ||||
timestamp=None): | timestamp=None): | ||||
"""Lookup revision by origin, snapshot branch name and visit timestamp. | """Lookup revision by origin, snapshot branch name and visit timestamp. | ||||
▲ Show 20 Lines • Show All 415 Lines • ▼ Show 20 Lines | |||||
def lookup_revision_through(revision, limit=100): | def lookup_revision_through(revision, limit=100): | ||||
"""Retrieve a revision from the criterion stored in revision dictionary. | """Retrieve a revision from the criterion stored in revision dictionary. | ||||
Args: | Args: | ||||
revision: Dictionary of criterion to lookup the revision with. | revision: Dictionary of criterion to lookup the revision with. | ||||
Here are the supported combination of possible values: | Here are the supported combination of possible values: | ||||
- origin_id, branch_name, ts, sha1_git | |||||
- origin_id, branch_name, ts | |||||
- origin_url, branch_name, ts, sha1_git | - origin_url, branch_name, ts, sha1_git | ||||
- origin_url, branch_name, ts | - origin_url, branch_name, ts | ||||
- sha1_git_root, sha1_git | - sha1_git_root, sha1_git | ||||
- sha1_git | - sha1_git | ||||
Returns: | Returns: | ||||
None if the revision is not found or the actual revision. | None if the revision is not found or the actual revision. | ||||
""" | """ | ||||
if ( | if ( | ||||
'origin_url' in revision and | 'origin_url' in revision and | ||||
'branch_name' in revision and | 'branch_name' in revision and | ||||
'ts' in revision and | 'ts' in revision and | ||||
'sha1_git' in revision): | 'sha1_git' in revision): | ||||
return lookup_revision_with_context_by(revision['origin_url'], | return lookup_revision_with_context_by(revision['origin_url'], | ||||
revision['branch_name'], | revision['branch_name'], | ||||
revision['ts'], | revision['ts'], | ||||
revision['sha1_git'], | revision['sha1_git'], | ||||
limit) | limit) | ||||
if ( | 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_url' in revision and | 'origin_url' in revision and | ||||
'branch_name' in revision and | 'branch_name' in revision and | ||||
'ts' in revision): | 'ts' in revision): | ||||
return lookup_revision_by(revision['origin_url'], | return lookup_revision_by(revision['origin_url'], | ||||
revision['branch_name'], | revision['branch_name'], | ||||
revision['ts']) | revision['ts']) | ||||
if ( | 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_root' in revision and | ||||
'sha1_git' in revision): | 'sha1_git' in revision): | ||||
return lookup_revision_with_context(revision['sha1_git_root'], | return lookup_revision_with_context(revision['sha1_git_root'], | ||||
revision['sha1_git'], | revision['sha1_git'], | ||||
limit) | limit) | ||||
if 'sha1_git' in revision: | if 'sha1_git' in revision: | ||||
return lookup_revision(revision['sha1_git']) | return lookup_revision(revision['sha1_git']) | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |