[viewvc-dev] Re: [viewvc-users] Don't display binary files

JJ <[email protected]> Wed, 19 Nov 2008 12:59:49 -0600
Newsgroups gmane.comp.version-control.cvs.viewcvs.devel
Message-ID <eed30ed90811191059s2fc5a28cq46a954ca9945f689__30155.0526558005$1227121282$gmane$org@mail.gmail.com>
>
> JJ wrote:
> > No, that last patch I sent you doesn't add processing to determine if
> > links to diff, annotate, etc. should be shown.  I was suggesting that if
> > template modifiers don't want those links to be shown they can do so
> > using some variable based on mime types alone.
> >
> > The patch only adds the processing when actually marking up a file.  At
> > that point the file is already going to be opened anyway.  I just added
> > code to check the first 512 bytes to determine if it is viewable, to
> > avoid the embarrassing scenario where we display a bunch of binary
> > garbled characters on the page.  Granted, my code does open the file one
> > additional time in the markup view.  I'd prefer it if FileContentsPipe
> > could be modified so that we could open it once and check the first 512
> > bytes for that test but then still reset and call readlines again on the
> > already open file.
> >
> > Do you think any differently about it now?  :-)
>
> Okay, I guess I was thinking you were wanting to scan the first 512 of
> every
> file every time the prefer_markup bit was in need of calculation.  I'll
> re-examine your patch with the right frame of mind.
>
What do you of this idea?

Add a new file sitting at the same level as viewvc.conf (perhaps called
text-mime.types).  It contains a list of mime types that contain text, and
thus that should have prefer_markup set to true.  We can try to populate it
with a list of text mime types, but since it comes with ViewVC anyone can
add missing or custom mime types to it as needed.

Add a new variable to viewvc.conf called text_mime_types_file.  By default
it will be commented out, but if uncommented, the is_text function in
viewvc.py will use the mime types listed in this file to determine if it is
text, instead of just checking that the mime type begins with text/.

This approach is less expensive than opening files and checking their
contents to determine if they are binary.  It may require tweaking of the
text file as new types are discovered, but that should be pretty straight
forward and people don't have to use the functionality if they don't want.

What do you think?

JJ