642 |
643 |
643 if not fphid: |
644 if not fphid: |
644 raise error.Abort(b'Upload of %s failed.' % bytes(fctx)) |
645 raise error.Abort(b'Upload of %s failed.' % bytes(fctx)) |
645 |
646 |
646 return fphid |
647 return fphid |
|
648 |
|
649 |
|
650 def addoldbinary(pchange, fctx, originalfname): |
|
651 """add the metadata for the previous version of a binary file to the |
|
652 phabchange for the new version |
|
653 """ |
|
654 oldfctx = fctx.p1()[originalfname] |
|
655 if fctx.cmp(oldfctx): |
|
656 # Files differ, add the old one |
|
657 pchange.metadata[b'old:file:size'] = oldfctx.size() |
|
658 mimeguess, _enc = mimetypes.guess_type( |
|
659 encoding.unifromlocal(oldfctx.path()) |
|
660 ) |
|
661 if mimeguess: |
|
662 pchange.metadata[b'old:file:mime-type'] = pycompat.bytestr( |
|
663 mimeguess |
|
664 ) |
|
665 fphid = uploadfile(oldfctx) |
|
666 pchange.metadata[b'old:binary-phid'] = fphid |
|
667 else: |
|
668 # If it's left as IMAGE/BINARY web UI might try to display it |
|
669 pchange.fileType = DiffFileType.TEXT |
|
670 pchange.copynewmetadatatoold() |
|
671 |
|
672 |
|
673 def makebinary(pchange, fctx): |
|
674 """populate the phabchange for a binary file""" |
|
675 pchange.fileType = DiffFileType.BINARY |
|
676 fphid = uploadfile(fctx) |
|
677 pchange.metadata[b'new:binary-phid'] = fphid |
|
678 pchange.metadata[b'new:file:size'] = fctx.size() |
|
679 mimeguess, _enc = mimetypes.guess_type(encoding.unifromlocal(fctx.path())) |
|
680 if mimeguess: |
|
681 mimeguess = pycompat.bytestr(mimeguess) |
|
682 pchange.metadata[b'new:file:mime-type'] = mimeguess |
|
683 if mimeguess.startswith(b'image/'): |
|
684 pchange.fileType = DiffFileType.IMAGE |
647 |
685 |
648 |
686 |
649 def creatediff(ctx): |
687 def creatediff(ctx): |
650 """create a Differential Diff""" |
688 """create a Differential Diff""" |
651 repo = ctx.repo() |
689 repo = ctx.repo() |