[Zope3-dev] Re: [Zope-Coders] Denying commit for carriage returns in text

Ken Manheimer klm@zope.com
Wed, 13 Nov 2002 18:19:48 -0500 (EST)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--nr68PGqN4j
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID: <Pine.LNX.4.44.0211131755562.30208@korak.zope.com>
Content-Description: message body and .signature

On Wed, 13 Nov 2002, Fred L. Drake, Jr. wrote:

> I've attached a script that could be run from CVSROOT/commitinfo that
> denies a commit if a text file contains a carriage return.  It ignores
> binary files (the -kb sticky option is set).

1. If we were to do this, i think we should limit the checks to python
   files only.  (We don't want to prevent people from checking in .bat
   files with CR line endings, do we?)

   I know that loginfo scripts are passed the directory name and then
   a funky single token of command separated fields which name the
   file, old version, and new version.  If commitinfo gets something
   similar, then it should be able to look for only .py files.

   I'm a bit worried even if we restrict the checks to just python
   files, particularly since we'll all have forgotten this hack is in
   effect when it bites someone who needs CR line endings in their
   triple-quoted strings...

2. I think this is a simpler check for lines ending with carriage return:

   grep -q $(echo -en '\r')'$') file

   It exits with 0 if any found, 1 otherwise.

I think these two bits should simplify the script a lot.  More
elaborate grep expressions (for tabs or whatever) would not
significantly increase the processing costs...

-- 
Ken
klm@zope.com

--nr68PGqN4j
Content-Type: TEXT/PLAIN; NAME="check-commit.sh"
Content-ID: <Pine.LNX.4.44.0211131755563.30208@korak.zope.com>
Content-Description: carriage returns are vile!
Content-Disposition: INLINE; FILENAME="check-commit.sh"

#! /bin/sh
REPODIR="$1"
shift

TEMPFILE="/tmp/check-commit-$$"
for FILE in "$@" ; do
    REPOFILE="$REPODIR/$FILE,v"
    if test -f "$REPOFILE" -a -f "$FILE" ; then
        if (rlog -h "$REPOFILE" \
            | grep 'keyword substitution:' \
            | sed 's/^.*: //' \
            | grep -q b); then
            echo >/dev/null
        else
            sed "s/`echo -en '\r'`//" "$FILE" >"$TEMPFILE"
            cmp "$FILE" "$TEMPFILE"
            RC=$?
            rm -f "$TEMPFILE"
            if test $RC -ne 0 ; then
                echo '***'
                echo '*** Found carriage returns in text file; commit denied!'
                echo '***'
                exit $RC
            fi
        fi
    fi
done

exit 0

--nr68PGqN4j--