Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/git_bare.py
Show All 13 Lines | |||||
3. Creates a tarball of the resulting repository | 3. Creates a tarball of the resulting repository | ||||
It keeps a set of all written (or about-to-be-written) object hashes in memory | It keeps a set of all written (or about-to-be-written) object hashes in memory | ||||
to avoid downloading and writing the same objects twice. | to avoid downloading and writing the same objects twice. | ||||
""" | """ | ||||
import datetime | import datetime | ||||
import enum | import enum | ||||
import glob | |||||
import logging | import logging | ||||
import os.path | import os.path | ||||
import re | import re | ||||
import subprocess | import subprocess | ||||
import tarfile | import tarfile | ||||
import tempfile | import tempfile | ||||
from typing import Any, Dict, Iterable, Iterator, List, NoReturn, Optional, Set, Tuple | from typing import Any, Dict, Iterable, Iterator, List, NoReturn, Optional, Set, Tuple | ||||
import zlib | import zlib | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | def prepare_bundle(self): | ||||
self.repack() | self.repack() | ||||
self.write_archive() | self.write_archive() | ||||
def init_git(self) -> None: | def init_git(self) -> None: | ||||
subprocess.run(["git", "-C", self.gitdir, "init", "--bare"], check=True) | subprocess.run(["git", "-C", self.gitdir, "init", "--bare"], check=True) | ||||
self.create_object_dirs() | self.create_object_dirs() | ||||
# Remove example hooks; they take ~40KB and we don't use them | |||||
for filename in glob.glob(os.path.join(self.gitdir, "hooks", "*.sample")): | |||||
os.unlink(filename) | |||||
def create_object_dirs(self) -> None: | def create_object_dirs(self) -> None: | ||||
# Create all possible dirs ahead of time, so we don't have to check for | # Create all possible dirs ahead of time, so we don't have to check for | ||||
# existence every time. | # existence every time. | ||||
for byte in range(256): | for byte in range(256): | ||||
try: | try: | ||||
os.mkdir(os.path.join(self.gitdir, "objects", f"{byte:02x}")) | os.mkdir(os.path.join(self.gitdir, "objects", f"{byte:02x}")) | ||||
except FileExistsError: | except FileExistsError: | ||||
pass | pass | ||||
▲ Show 20 Lines • Show All 424 Lines • Show Last 20 Lines |