From ef2394503754179a5a8157e8de8dcf8dbaeb89fe Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 2 Feb 2022 11:56:11 +0900 Subject: [PATCH] Add an option to store the last unbundled bundle --- cinnabar/hg/repo.py | 25 +++++++++++++++++++++++++ cinnabar/util.py | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cinnabar/hg/repo.py b/cinnabar/hg/repo.py index af22d2c7e..a6427edbd 100644 --- a/cinnabar/hg/repo.py +++ b/cinnabar/hg/repo.py @@ -678,10 +678,35 @@ def unbundler(bundle): chunk_type = RawRevChunk01 cg = bundle + if check_enabled('unbundler') and "GIT_DIR" in os.environ: + class BundleSaver(object): + def __init__(self, cg): + self.cg = cg + self.out = open(os.path.join( + os.environ["GIT_DIR"], "cinnabar-last-bundle"), "wb") + self.out.write(b'HG20\0\0\0\0') + self.out.write(b'\0\0\0\x1d\x0bCHANGEGROUP\0\0\0\0') + self.out.write(b'\x01\x00\x07\x02version') + self.out.write(b'01' if chunk_type is RawRevChunk01 else b'02') + + def read(self, length=None): + data = self.cg.read(length) + self.out.write(struct.pack('>l', len(data))) + self.out.write(data) + return data + + def end_bundle(self): + self.out.write(b'\0\0\0\0\0\0\0\0') + + cg = BundleSaver(cg) + yield chunks_in_changegroup(chunk_type, cg, 'changeset') yield chunks_in_changegroup(chunk_type, cg, 'manifest') yield iterate_files(chunk_type, cg) + if hasattr(cg, "end_bundle"): + cg.end_bundle() + if unbundle20 and isinstance(bundle, unbundle20): for part in parts: logging.getLogger('bundle2').warning( diff --git a/cinnabar/util.py b/cinnabar/util.py index 110088e02..14e55bfe0 100644 --- a/cinnabar/util.py +++ b/cinnabar/util.py @@ -144,7 +144,8 @@ def __call__(self, name): 'cinnabar.check', ('nodeid', 'manifests', 'helper'), ('bundle', 'files', 'memory', 'cpu', 'time', 'traceback', 'no-mercurial', - 'no-bundle2', 'cinnabarclone', 'clonebundles', 'no-version-check'), + 'no-bundle2', 'cinnabarclone', 'clonebundles', 'no-version-check', + 'unbundler'), ) experiment = ConfigSetFunc(