# bup-gc assumes that it can disable all PackWriter activities
# (bloom/midx/cache) via the constructor and close() arguments.
-class PackWriter:
+class PackWriter(object):
"""Writes Git objects inside a pack file."""
def __init__(self, objcache_maker=_make_objcache, compression_level=1,
run_midx=True, on_pack_finish=None,
def _end(self, run_midx=True, abort=False):
# Ignores run_midx during abort
- if not self.file:
- return None
+ self.parentfd, pfd, = None, self.parentfd
self.file, f = None, self.file
self.idx, idx = None, self.idx
- self.parentfd, pfd, = None, self.parentfd
-
try:
with nullcontext_if_not(self.objcache), \
finalized(pfd, lambda x: x is not None and os.close(x)), \
- f:
+ nullcontext_if_not(f):
+ if not f:
+ return None
if abort:
os.unlink(self.filename + b'.pack')
return None
-def update_ref(refname, newval, oldval, repo_dir=None):
- """Update a repository reference."""
- if not oldval:
- oldval = b''
+def update_ref(refname, newval, oldval, repo_dir=None, force=False):
+ """Update a repository reference.
+
+ With force=True, don't care about the previous ref (oldval);
+ with force=False oldval must be either a sha1 or None (for an
+ entirely new branch)
+ """
+ if force:
+ assert oldval is None
+ oldarg = []
+ elif not oldval:
+ oldarg = [b'']
+ else:
+ oldarg = [hexlify(oldval)]
assert refname.startswith(b'refs/heads/') \
or refname.startswith(b'refs/tags/')
p = subprocess.Popen([b'git', b'update-ref', refname,
- hexlify(newval), hexlify(oldval)],
+ hexlify(newval)] + oldarg,
env=_gitenv(repo_dir),
close_fds=True)
_git_wait(b'git update-ref', p)