<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.2//EN" "document-v12.dtd">

<document>
  <header>
    <title>Tips for committers</title>
  </header>

  <body>
    <section id="overview">
      <title>Overview</title>
      <p>
        These are some tips to help committers to keep our Subversion (SVN) repository clean.
        See also
        <link href="http://www.apache.org/dev/committers.html">Committers FAQ</link>
        and
        <link href="http://www.apache.org/dev/pmc.html">PMC FAQ</link>.
      </p>
    </section>

    <section id="style">
      <title>Coding Style Guidelines</title>
      <p>
        We do not want to get too concerned about style, other than a few
        obvious things such as whitespace. Basically just follow the style
        that is already used by the files that you are working on.
        We loosely follow the
        <link href="http://java.sun.com/docs/codeconv/">Sun Java Style Guide</link>.
      </p>
    </section>

    <section id="whitespace">
      <title>Consistent whitespace</title>
      <p>
        Whitespace can cause big problems with SVN. If it is inconsistent,
        then diffs are very hard to follow - actual changes become lost in
        the noise of whitespace changes. Some developers use editors that
        attempt to automatically format the whitespace. The trouble is
        that if SVN files are inconsistent, some of those editors just
        make it worse.
      </p>
      <p>
        The solution comes in two parts:
      </p>
      <p>
        When a committer adds a new file, they need to ensure that the file 
        has the correct line endings for their own operating system, and that
        either their SVN client automatically sets the EOL settings for the 
        file based upon the file extension, or they must do:
      </p>
<source><![CDATA[svn add myfile.txt
svn propset svn:eol-style native myfile.txt
]]>
</source>
      <p>is that some committers who have a proper editor
        should occasionally correct the whitespace across all SVN files,
        applying the following rules.
      </p>

      <p>For all text files:</p>

      <ul>
        <li>Replace all tabs with spaces.</li>
        <li>No trailing whitespace.</li>
        <li>No MS-DOS line endings.</li>
        <li>Newline at end-of-file.</li>
        <li>Single whitespace between words.</li>
      </ul>

      <p>For all Java source files, as for text files plus:</p>

      <ul>
        <li>Use 4-space indentation.</li>
      </ul>

      <p>For all XML source files, as for text files plus:</p>

      <ul>
        <li>Use 2-space indentation.</li>
        <li>No whitespace at start-of-file.</li>
        <li>No whitespace at end-of-file (except of course a newline).</li>
      </ul>
    </section>

    <section id="dos2unix">
      <title>dos2unix and other control-characters</title>
      <p>
        If you are on a UNIX system, when you receive a patch from a
        contributor on Windows then do a 'dos2unix'. If you are on a
        Windows system, then ensure that you have a proper SVN client
        (it is supposed to convert to UNIX line-endings when you commit).
      </p>

      <p>
        Here is one UNIX way to find all plain-text files that have DOS
        line-endings (and maybe mixed line-endings).
        There seem to be many images and jar archives that contain
        carriage-returns, so to list only the plain-text files:
      </p>

      <source><![CDATA[
find . -type f | xargs grep -l '^M' | xargs file | \
grep -i -w text | cut -f1 -d:

To add the ^M use "Ctrl-v Ctrl-m" at the command-line.
Note that copy-and-paste will not work.
The -w can be omitted, but might then match some extra filenames.
]]></source>

      <p>
        To instead find <em>all</em> files (including images and foreign
        jar archives) that have DOS line-endings:
        <code><![CDATA[find . -type f | xargs grep -l '^M']]></code>
      </p>

      <p>
        Here is one way to find files that have <em>any</em> hidden control
        characters:
        <code>find . -type f | xargs grep -l '[[:cntrl:]]'</code>
      </p>
    </section>

    <section id="valid-xml">
      <title>Valid XML instances</title>
      <p>
        Many of us have wasted time with a broken build due to xml validation
        errors. Would all committers please either use a proper xml editor or
        validate their xdocs with one of the following commands:
      </p>
      <source>
onsgmls -c $COCOON_HOME/src/webapp/WEB-INF/entities/catalog \
-wall -wxml -s mydoc.xml
      </source>
      <source>
export SGML_CATALOG_FILES=$COCOON_HOME/src/webapp/WEB-INF/entities/catalog
xmllint --valid --catalogs --noout mydoc.xml
      </source>
      <source>
forrest validate-xdocs
      </source>
    </section>

  </body>
</document>
