Show More
@@ -46,6 +46,7 b' import contextlib' | |||||
46 | import hashlib |
|
46 | import hashlib | |
47 | import itertools |
|
47 | import itertools | |
48 | import json |
|
48 | import json | |
|
49 | import mimetypes | |||
49 | import operator |
|
50 | import operator | |
50 | import re |
|
51 | import re | |
51 |
|
52 | |||
@@ -646,6 +647,43 b' def uploadfile(fctx):' | |||||
646 | return fphid |
|
647 | return fphid | |
647 |
|
648 | |||
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 | |||
|
685 | ||||
|
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() |
General Comments 0
You need to be logged in to leave comments.
Login now