diff --git a/infinitepush/__init__.py b/infinitepush/__init__.py --- a/infinitepush/__init__.py +++ b/infinitepush/__init__.py @@ -1045,8 +1045,68 @@ logger = logger[0] return logger +def oldclientprocessor(orig, repo, op, unbundler): + """ Logic to check whether this part is a bundle2 part or not in case of old + client where we don't have capability to set things at client side. + + Iterates over the bundle2 parts at time of unbundling, store a copy of each + part for later processing, grabs the bookmark from the pushkey part and + check if this is an infinitepush or not. If infinitepush, store the bundle + in the store otherwise, fallbacks to processing each part normally. + + This support of oldclient is turned of by default and can be used by setting + the config:: + + [infinitepush] + oldclient = True + """ + + bundler = bundle2.bundle20(repo.ui) + isinfinitepush = False + # a list to store copy of parts to process them again + partslist = [] + with bundle2.partiterator(repo, op, unbundler) as parts: + for part in parts: + if part.type == 'pushkey': + import pushkey + dec = pushkey.decode + namespace = dec(part.params['namespace']) + if namespace == 'bookmarks': + bname = dec(part.params['key']) + if _scratchbranchmatcher(bname): + isinfinitepush = True + + bundler.addpart(part) + partslist.append(copiedpart(part)) + + if isinfinitepush: + buf = util.chunkbuffer(bundler.getchunks()) + fd, bundlefile = tempfile.mkstemp() + try: + try: + fp = os.fdopen(fd, 'wb') + fp.write(buf.read()) + finally: + fp.close() + + # need some way to get cgparams too + storebundle(op, {}, bundlefile) + finally: + try: + os.unlink(bundlefile) + except Exception: + # we would rather see the original exception + pass + + else: + for part in partslist: + bundle2._processpart(op, part) + def processparts(orig, repo, op, unbundler): if unbundler.params.get('infinitepush') != 'True': + # shall we support old clients + if repo.ui.configbool('infinitepush', 'oldclient'): + return oldclientprocessor(orig, repo, op, unbundler) return orig(repo, op, unbundler) handleallparts = repo.ui.configbool('infinitepush', 'storeallparts')