comparison mercurial/hgweb/webcommands.py @ 19657:145636d31bb4

hgweb: import the whole util module in webcommands instead of just one function This is to allow using other functions from this module easily.
author Alexander Plavin <alexander@plav.in>
date Tue, 03 Sep 2013 20:02:53 +0400
parents 60ce14e41faf
children bf15935b68a3
comparison
equal deleted inserted replaced
19656:60ce14e41faf 19657:145636d31bb4
7 7
8 import os, mimetypes, re, cgi, copy 8 import os, mimetypes, re, cgi, copy
9 import webutil 9 import webutil
10 from mercurial import error, encoding, archival, templater, templatefilters 10 from mercurial import error, encoding, archival, templater, templatefilters
11 from mercurial.node import short, hex, nullid 11 from mercurial.node import short, hex, nullid
12 from mercurial.util import binary 12 from mercurial import util
13 from common import paritygen, staticfile, get_contact, ErrorResponse 13 from common import paritygen, staticfile, get_contact, ErrorResponse
14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND 14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND
15 from mercurial import graphmod, patch 15 from mercurial import graphmod, patch
16 from mercurial import help as helpmod 16 from mercurial import help as helpmod
17 from mercurial import scmutil 17 from mercurial import scmutil
55 text = fctx.data() 55 text = fctx.data()
56 mt = 'application/binary' 56 mt = 'application/binary'
57 if guessmime: 57 if guessmime:
58 mt = mimetypes.guess_type(path)[0] 58 mt = mimetypes.guess_type(path)[0]
59 if mt is None: 59 if mt is None:
60 mt = binary(text) and 'application/binary' or 'text/plain' 60 mt = util.binary(text) and 'application/binary' or 'text/plain'
61 if mt.startswith('text/'): 61 if mt.startswith('text/'):
62 mt += '; charset="%s"' % encoding.encoding 62 mt += '; charset="%s"' % encoding.encoding
63 63
64 req.respond(HTTP_OK, mt, path, body=text) 64 req.respond(HTTP_OK, mt, path, body=text)
65 return [] 65 return []
67 def _filerevision(web, tmpl, fctx): 67 def _filerevision(web, tmpl, fctx):
68 f = fctx.path() 68 f = fctx.path()
69 text = fctx.data() 69 text = fctx.data()
70 parity = paritygen(web.stripecount) 70 parity = paritygen(web.stripecount)
71 71
72 if binary(text): 72 if util.binary(text):
73 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' 73 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
74 text = '(binary:%s)' % mt 74 text = '(binary:%s)' % mt
75 75
76 def lines(): 76 def lines():
77 for lineno, t in enumerate(text.splitlines(True)): 77 for lineno, t in enumerate(text.splitlines(True)):
635 context = parsecontext(req.form['context'][0]) 635 context = parsecontext(req.form['context'][0])
636 else: 636 else:
637 context = parsecontext(web.config('web', 'comparisoncontext', '5')) 637 context = parsecontext(web.config('web', 'comparisoncontext', '5'))
638 638
639 def filelines(f): 639 def filelines(f):
640 if binary(f.data()): 640 if util.binary(f.data()):
641 mt = mimetypes.guess_type(f.path())[0] 641 mt = mimetypes.guess_type(f.path())[0]
642 if not mt: 642 if not mt:
643 mt = 'application/octet-stream' 643 mt = 'application/octet-stream'
644 return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] 644 return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))]
645 return f.data().splitlines() 645 return f.data().splitlines()
693 parity = paritygen(web.stripecount) 693 parity = paritygen(web.stripecount)
694 diffopts = patch.diffopts(web.repo.ui, untrusted=True, section='annotate') 694 diffopts = patch.diffopts(web.repo.ui, untrusted=True, section='annotate')
695 695
696 def annotate(**map): 696 def annotate(**map):
697 last = None 697 last = None
698 if binary(fctx.data()): 698 if util.binary(fctx.data()):
699 mt = (mimetypes.guess_type(fctx.path())[0] 699 mt = (mimetypes.guess_type(fctx.path())[0]
700 or 'application/octet-stream') 700 or 'application/octet-stream')
701 lines = enumerate([((fctx.filectx(fctx.filerev()), 1), 701 lines = enumerate([((fctx.filectx(fctx.filerev()), 1),
702 '(binary:%s)' % mt)]) 702 '(binary:%s)' % mt)])
703 else: 703 else: