Re: [PATCH] Extend sample pre-commit hook to check for non ascii filenames
- From
Heiko Voigt <hvoigt@hvoigt.net>
- Date
- May 18, 2009, 11:50 UTC
- Message-ID
- <20090518115002.GA3374@heiko-voigts-macbook.local>
- In-Reply-To
- <4A113B09.6040301@viscovery.net>
On Mon, May 18, 2009 at 12:40:09PM +0200, Johannes Sixt wrote:
Show 17 quoted lines
> Heiko Voigt schrieb:
> > +# is_ascii() Tests the string given given on standard input for
> > +# printable ascii conformance. We exploit the fact that the printable
> > +# range starts at the space character and ends with tilde.
> > +is_ascii() {
> > + test -z "$(LC_ALL=C tr -d \ -~)"
> > +}
> > +
> > +if [ "$allownonascii" != "true" ]
> > +then
> > + # until git can handle non-ascii filenames gracefully
> > + # prevent them to be added into the repository
> > + if ! git diff --cached --name-only --diff-filter=A -z \
> > + | tr "\0" "\n" | is_ascii; then
>
> Will this not fail to add more than one file with allowed names? The \n is
> not removed in is_ascii(), and so the resulting string will not be empty.No currently it does not. At least on my system, but good point.
Show 5 quoted lines
> BTW, not all tr work well with NULs. See the commit message of e85fe4d8, > for example. Otherwise, I would have suggested to convert the NUL to some > allowed ASCII character, e.g. 'A'. BTW, you should really use '\0' and > '\n' (single-quotes) to guarantee that the shell does not ignore the > backslash.
Are there any problems with '\0' and tr other than swallowing of it. In case not I would just change
tr "\0" "\n" to tr -d '\0'
That way there are no '\n's left over and it doesn't matter if tr swallows the '\0'.
Waiting for further comments before sending the cleanup.
cheers Heiko