Show More
@@ -43,6 +43,7 b' from __future__ import absolute_import' | |||||
43 |
|
43 | |||
44 | import base64 |
|
44 | import base64 | |
45 | import contextlib |
|
45 | import contextlib | |
|
46 | import hashlib | |||
46 | import itertools |
|
47 | import itertools | |
47 | import json |
|
48 | import json | |
48 | import operator |
|
49 | import operator | |
@@ -608,6 +609,43 b' def uploadchunks(fctx, fphid):' | |||||
608 | progress.complete() |
|
609 | progress.complete() | |
609 |
|
610 | |||
610 |
|
611 | |||
|
612 | def uploadfile(fctx): | |||
|
613 | """upload binary files to Phabricator""" | |||
|
614 | repo = fctx.repo() | |||
|
615 | ui = repo.ui | |||
|
616 | fname = fctx.path() | |||
|
617 | size = fctx.size() | |||
|
618 | fhash = pycompat.bytestr(hashlib.sha256(fctx.data()).hexdigest()) | |||
|
619 | ||||
|
620 | # an allocate call is required first to see if an upload is even required | |||
|
621 | # (Phab might already have it) and to determine if chunking is needed | |||
|
622 | allocateparams = { | |||
|
623 | b'name': fname, | |||
|
624 | b'contentLength': size, | |||
|
625 | b'contentHash': fhash, | |||
|
626 | } | |||
|
627 | filealloc = callconduit(ui, b'file.allocate', allocateparams) | |||
|
628 | fphid = filealloc[b'filePHID'] | |||
|
629 | ||||
|
630 | if filealloc[b'upload']: | |||
|
631 | ui.write(_(b'uploading %s\n') % bytes(fctx)) | |||
|
632 | if not fphid: | |||
|
633 | uploadparams = { | |||
|
634 | b'name': fname, | |||
|
635 | b'data_base64': base64.b64encode(fctx.data()), | |||
|
636 | } | |||
|
637 | fphid = callconduit(ui, b'file.upload', uploadparams) | |||
|
638 | else: | |||
|
639 | uploadchunks(fctx, fphid) | |||
|
640 | else: | |||
|
641 | ui.debug(b'server already has %s\n' % bytes(fctx)) | |||
|
642 | ||||
|
643 | if not fphid: | |||
|
644 | raise error.Abort(b'Upload of %s failed.' % bytes(fctx)) | |||
|
645 | ||||
|
646 | return fphid | |||
|
647 | ||||
|
648 | ||||
611 | def creatediff(ctx): |
|
649 | def creatediff(ctx): | |
612 | """create a Differential Diff""" |
|
650 | """create a Differential Diff""" | |
613 | repo = ctx.repo() |
|
651 | repo = ctx.repo() |
General Comments 0
You need to be logged in to leave comments.
Login now