81 ''' |
81 ''' |
82 |
82 |
83 from mercurial import commands, cmdutil, context, filelog, localrepo |
83 from mercurial import commands, cmdutil, context, filelog, localrepo |
84 from mercurial import patch, revlog, templater, templatefilters, util |
84 from mercurial import patch, revlog, templater, templatefilters, util |
85 from mercurial.node import * |
85 from mercurial.node import * |
|
86 from mercurial.hgweb import webcommands |
86 from mercurial.i18n import _ |
87 from mercurial.i18n import _ |
87 import re, shutil, tempfile, time |
88 import mimetypes, re, shutil, tempfile, time |
88 |
89 |
89 commands.optionalrepo += ' kwdemo' |
90 commands.optionalrepo += ' kwdemo' |
90 |
91 |
91 def utcdate(date): |
92 def utcdate(date): |
92 '''Returns hgdate in cvs-like UTC format.''' |
93 '''Returns hgdate in cvs-like UTC format.''' |
490 if kwt.matcher(self.fname): |
491 if kwt.matcher(self.fname): |
491 # shrink keywords read from working dir |
492 # shrink keywords read from working dir |
492 kwshrunk = kwt.shrink(''.join(self.lines)) |
493 kwshrunk = kwt.shrink(''.join(self.lines)) |
493 self.lines = kwshrunk.splitlines(True) |
494 self.lines = kwshrunk.splitlines(True) |
494 |
495 |
|
496 def kwweb_rawfile(web, req, tmpl): |
|
497 '''Monkeypatch webcommands.rawfile so it expands keywords.''' |
|
498 path = web.cleanpath(req.form.get('file', [''])[0]) |
|
499 if not path: |
|
500 content = web.manifest(tmpl, web.changectx(req), path) |
|
501 req.respond(webcommands.HTTP_OK, web.ctype) |
|
502 return content |
|
503 try: |
|
504 fctx = web.filectx(req) |
|
505 except revlog.LookupError: |
|
506 content = web.manifest(tmpl, web.changectx(req), path) |
|
507 req.respond(webcommands.HTTP_OK, web.ctype) |
|
508 return content |
|
509 path = fctx.path() |
|
510 text = fctx.data() |
|
511 if kwt.matcher(path): |
|
512 text = kwt.expand(path, text, None) |
|
513 mt = mimetypes.guess_type(path)[0] |
|
514 if mt is None or util.binary(text): |
|
515 mt = mt or 'application/octet-stream' |
|
516 req.respond(webcommands.HTTP_OK, mt, path, len(text)) |
|
517 return [text] |
|
518 |
495 repo.__class__ = kwrepo |
519 repo.__class__ = kwrepo |
496 patch.patchfile.__init__ = kwpatchfile_init |
520 patch.patchfile.__init__ = kwpatchfile_init |
|
521 webcommands.rawfile = kwweb_rawfile |
497 |
522 |
498 |
523 |
499 cmdtable = { |
524 cmdtable = { |
500 'kwcat': |
525 'kwcat': |
501 (cat, commands.table['cat'][1], |
526 (cat, commands.table['cat'][1], |