X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbup%2Fgit.py;h=69134ac33ae4ba0df4eb6bb691b51bbf6e7572e7;hb=84cb94e1feb584ae7c67d65c27b2ff1a8e01e489;hp=73a50b88773f6585c01e264775cfe9a91c0bd120;hpb=22e2df2ce1c28e900bc06a9bac4ffd17019c22d6;p=bup.git diff --git a/lib/bup/git.py b/lib/bup/git.py index 73a50b8..69134ac 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -772,7 +772,7 @@ def _make_objcache(): # 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, @@ -918,16 +918,15 @@ class PackWriter: 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') @@ -1157,14 +1156,24 @@ def rev_parse(committish, repo_dir=None): 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)