pre-commit hook for CR LF checking

Sabin Iacob iacobs at m0n5t3r.info
Thu Feb 28 21:43:47 GMT 2008


Ville M. Vainio wrote:
> Since bzr does not fiddle with CR LF translation between platform line
> ending formats (and since bare LF is the only format that properly
> works on all platforms), it would be handy if it shipped with plugin
> that checks the files and complains loudly if there are CR LF line
> feeds in the checkin.

I disagree; while some windows software may grok \n-only line endings, 
it's rather due to graceful error handling than "supporting" them; and 
then, what about source code (and/or text files) that are intended for a 
windows-only audience? why force them to convert back and forth between 
dos and unix line endings?

>  Likewise, if there are tabs in *.py files, it
> should complain.
>   

I have to disagree again; while tabs are not very popular, there are a 
few of us who prefer to use tabs instead of spaces when they have the 
choice. PEP 8 only forbids (rightfully) mixing the two kinds of 
indentation (like mcedit does by default, who used it knows what I'm 
talking about).

> I'm not talking about making it a default behaviour - I'm talking
> about making it as easy as possible for new users to create that
> setup, perhaps on some howto/cookbook page.

making it default behaviour would be totally unacceptable; others' view 
of the world may be different from yours, and I, for one, would 
certainly not like this.

the above being said, there is information about writing hooks at 
http://bazaar-vcs.org/WritingPlugins#invoking-plugin-functions-in-callbacks; 
the contents of a hook function could be as simple as:

import os
os.system('grep -rP "\r\n" .')

which would print the "bad" line endings; grep for '\t' to find tabs. 
IPython is your friend when navigating through bzrlib. good luck! :)



More information about the bazaar mailing list