Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/git_bare.py
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | def prepare_bundle(self): | ||||
# Load and write all the objects to disk | # Load and write all the objects to disk | ||||
self.load_objects() | self.load_objects() | ||||
# Write the root object as a ref (this step is skipped if it's a snapshot) | # Write the root object as a ref (this step is skipped if it's a snapshot) | ||||
# This must be done before repacking; git-repack ignores orphan objects. | # This must be done before repacking; git-repack ignores orphan objects. | ||||
self.write_refs() | self.write_refs() | ||||
if self.use_fsck: | |||||
self.git_fsck() | |||||
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() | |||||
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: | |||||
os.mkdir(os.path.join(self.gitdir, "objects", f"{byte:02x}")) | os.mkdir(os.path.join(self.gitdir, "objects", f"{byte:02x}")) | ||||
except FileExistsError: | |||||
pass | |||||
def repack(self) -> None: | def repack(self) -> None: | ||||
if self.use_fsck: | |||||
self.git_fsck() | |||||
# Add objects we wrote in a pack | # Add objects we wrote in a pack | ||||
subprocess.run(["git", "-C", self.gitdir, "repack"], check=True) | subprocess.run(["git", "-C", self.gitdir, "repack", "-d"], check=True) | ||||
# Remove their non-packed originals | # Remove their non-packed originals | ||||
subprocess.run(["git", "-C", self.gitdir, "prune-packed"], check=True) | subprocess.run(["git", "-C", self.gitdir, "prune-packed"], check=True) | ||||
def git_fsck(self) -> None: | def git_fsck(self) -> None: | ||||
proc = subprocess.run( | proc = subprocess.run( | ||||
["git", "-C", self.gitdir, "fsck"], | ["git", "-C", self.gitdir, "fsck"], | ||||
stdout=subprocess.PIPE, | stdout=subprocess.PIPE, | ||||
▲ Show 20 Lines • Show All 391 Lines • Show Last 20 Lines |