hgext/phabricator.py
changeset 43504 a78a65c33b5a
parent 43399 742065def6ca
child 43506 9f70512ae2cf
equal deleted inserted replaced
43503:313e3a279828 43504:a78a65c33b5a
   607     """upload large binary files as separate chunks.
   607     """upload large binary files as separate chunks.
   608     Phab requests chunking over 8MiB, and splits into 4MiB chunks
   608     Phab requests chunking over 8MiB, and splits into 4MiB chunks
   609     """
   609     """
   610     ui = fctx.repo().ui
   610     ui = fctx.repo().ui
   611     chunks = callconduit(ui, b'file.querychunks', {b'filePHID': fphid})
   611     chunks = callconduit(ui, b'file.querychunks', {b'filePHID': fphid})
   612     progress = ui.makeprogress(
   612     with ui.makeprogress(
   613         _(b'uploading file chunks'), unit=_(b'chunks'), total=len(chunks)
   613         _(b'uploading file chunks'), unit=_(b'chunks'), total=len(chunks)
   614     )
   614     ) as progress:
   615     for chunk in chunks:
   615         for chunk in chunks:
   616         progress.increment()
   616             progress.increment()
   617         if chunk[b'complete']:
   617             if chunk[b'complete']:
   618             continue
   618                 continue
   619         bstart = int(chunk[b'byteStart'])
   619             bstart = int(chunk[b'byteStart'])
   620         bend = int(chunk[b'byteEnd'])
   620             bend = int(chunk[b'byteEnd'])
   621         callconduit(
   621             callconduit(
   622             ui,
   622                 ui,
   623             b'file.uploadchunk',
   623                 b'file.uploadchunk',
   624             {
   624                 {
   625                 b'filePHID': fphid,
   625                     b'filePHID': fphid,
   626                 b'byteStart': bstart,
   626                     b'byteStart': bstart,
   627                 b'data': base64.b64encode(fctx.data()[bstart:bend]),
   627                     b'data': base64.b64encode(fctx.data()[bstart:bend]),
   628                 b'dataEncoding': b'base64',
   628                     b'dataEncoding': b'base64',
   629             },
   629                 },
   630         )
   630             )
   631     progress.complete()
       
   632 
   631 
   633 
   632 
   634 def uploadfile(fctx):
   633 def uploadfile(fctx):
   635     """upload binary files to Phabricator"""
   634     """upload binary files to Phabricator"""
   636     repo = fctx.repo()
   635     repo = fctx.repo()