[PATCH] rawnative file view in hg

Matt Mackall mpm at selenic.com
Tue Sep 6 13:47:24 CDT 2005

On Thu, Sep 01, 2005 at 06:09:02PM +0200, Kurt Garloff wrote:
> Hi Matt,
> I seriously started to use hg a couple of hours ago.
> (Before I only used it to pull source code from the kernel and xen.)
> Great tool, thank you!
> And I hacked my first ChangeSet to hgweb.
> In addition to raw (renamed to rawtext -- revert that bit if you dislike
> it for consistency reasons) file view, it offers a rawnative file view.
> There, hgweb does look at the file and instead of always advertising
> Content-type: text/plain it does actually call file -i and advertises
> this. If the file has some wide-spread type such as e.g. text/html or
> image/jpeg, your browser will likely render something more useful than
> in text/plain mode.
> I had implemented a hardcoded txt/html before; the credit for the idea
> to do it in a general way goes to Andreas Gruenbacher.
> You could almost use hg as a web publishing system this way :-)
> I did not find a python module that would implement the file -i
> functionality, though I have seen someone referring to a magic.tar.gz
> package that would do it. I have not been able to retrieve it, so I
> went for calling the binary and parsing it's output.
> map-rawnative is basically a copy of map-raw with one change.
> It probably could be stripped down.
> I'd like to see this merged into hg. Or get some feedback ...
> I'm not subscribed to mercurial@, so please Cc me in replies.

Hmm. Yes, this is a good concept but obviously has some portability issues.

But I think there's a straightforward solution:

>>> import mimetypes
>>> mimetypes.guess_type("foo.html")
('text/html', None)
>>> mimetypes.guess_type("foo.tar")
('application/x-tar', None)
>>> mimetypes.guess_type("foo.c")
('text/x-csrc', None)
>>> mimetypes.guess_type("foo")
(None, None)

Mathematics is the supreme nostalgia of our time.

More information about the Mercurial mailing list