From patchwork Sat Oct 12 01:56:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7046: phabricator: add the uploadchunks function From: phabricator X-Patchwork-Id: 42247 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Sat, 12 Oct 2019 01:56:57 +0000 Closed by commit rHG453079605242: phabricator: add the uploadchunks function (authored by Kwan). This revision was automatically updated to reflect the committed changes. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7046?vs=17077&id=17094 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7046/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7046 AFFECTED FILES hgext/phabricator.py CHANGE DETAILS To: Kwan, #hg-reviewers, indygreg Cc: indygreg, mercurial-devel diff --git a/hgext/phabricator.py b/hgext/phabricator.py --- a/hgext/phabricator.py +++ b/hgext/phabricator.py @@ -41,6 +41,7 @@ from __future__ import absolute_import +import base64 import contextlib import itertools import json @@ -579,6 +580,34 @@ ) +def uploadchunks(fctx, fphid): + """upload large binary files as separate chunks. + Phab requests chunking over 8MiB, and splits into 4MiB chunks + """ + ui = fctx.repo().ui + chunks = callconduit(ui, b'file.querychunks', {b'filePHID': fphid}) + progress = ui.makeprogress( + _(b'uploading file chunks'), unit=_(b'chunks'), total=len(chunks) + ) + for chunk in chunks: + progress.increment() + if chunk[b'complete']: + continue + bstart = int(chunk[b'byteStart']) + bend = int(chunk[b'byteEnd']) + callconduit( + ui, + b'file.uploadchunk', + { + b'filePHID': fphid, + b'byteStart': bstart, + b'data': base64.b64encode(fctx.data()[bstart:bend]), + b'dataEncoding': b'base64', + }, + ) + progress.complete() + + def creatediff(ctx): """create a Differential Diff""" repo = ctx.repo()