Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/loader.py
Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | def load_status(self): | ||||
eventful = bool(self.snapshot['branches']) | eventful = bool(self.snapshot['branches']) | ||||
return {'status': ('eventful' if eventful else 'uneventful')} | return {'status': ('eventful' if eventful else 'uneventful')} | ||||
class GitLoaderFromArchive(GitLoader): | class GitLoaderFromArchive(GitLoader): | ||||
"""Load a git repository from an archive. | """Load a git repository from an archive. | ||||
This loader ingests a git repository compressed into an archive. | |||||
The supported archive formats are ``.zip`` and ``.tar.gz``. | |||||
From an input tarball named ``my-git-repo.zip``, the following layout is | |||||
expected in it:: | |||||
my-git-repo/ | |||||
├── .git | |||||
│ ├── branches | |||||
│ ├── COMMIT_EDITMSG | |||||
│ ├── config | |||||
│ ├── description | |||||
│ ├── HEAD | |||||
... | |||||
Nevertheless, the loader is able to ingest tarballs with the following | |||||
layouts too:: | |||||
. | |||||
├── .git | |||||
│ ├── branches | |||||
│ ├── COMMIT_EDITMSG | |||||
│ ├── config | |||||
│ ├── description | |||||
│ ├── HEAD | |||||
... | |||||
or:: | |||||
other-repo-name/ | |||||
├── .git | |||||
│ ├── branches | |||||
│ ├── COMMIT_EDITMSG | |||||
│ ├── config | |||||
│ ├── description | |||||
│ ├── HEAD | |||||
... | |||||
""" | """ | ||||
def __init__(self, *args, **kwargs): | def __init__(self, *args, **kwargs): | ||||
super().__init__(*args, **kwargs) | super().__init__(*args, **kwargs) | ||||
self.temp_dir = self.repo_path = None | self.temp_dir = self.repo_path = None | ||||
def project_name_from_archive(self, archive_path): | def project_name_from_archive(self, archive_path): | ||||
"""Compute the project name from the archive's path. | """Compute the project name from the archive's path. | ||||
""" | """ | ||||
return os.path.basename(os.path.dirname(archive_path)) | archive_name = os.path.basename(archive_path) | ||||
for ext in ('.zip', '.tar.gz', '.tgz'): | |||||
if archive_name.lower().endswith(ext): | |||||
archive_name = archive_name[:-len(ext)] | |||||
break | |||||
return archive_name | |||||
def prepare_origin_visit(self, origin_url, archive_path, visit_date): | def prepare_origin_visit(self, origin_url, archive_path, visit_date): | ||||
self._prepare_origin_visit(origin_url, visit_date) | self._prepare_origin_visit(origin_url, visit_date) | ||||
def prepare(self, origin_url, archive_path, visit_date): | def prepare(self, origin_url, archive_path, visit_date): | ||||
"""1. Uncompress the archive in temporary location. | """1. Uncompress the archive in temporary location. | ||||
2. Prepare as the GitLoader does | 2. Prepare as the GitLoader does | ||||
3. Load as GitLoader does | 3. Load as GitLoader does | ||||
Show All 40 Lines |