wiki:HowToSVN

Version 33 (modified by hamish, 16 years ago) ( diff )

+svn prop eol-style, pdf->jpeg to be more relevant

Getting development information and code history from SVN

  • "ChangeLog" style file: install and run svn2cl
  • File history in SVN:
    cd path/to/directory/
    svn log [file.c]

    # or time reverted:
    svn log [file.c] | tac

Switch the repository

To switch from SVN 'trunk' (now GRASS 7 development) to 'develbranch_6' (now GRASS 6.4 development) use

    cd /path/to/your/local/copy/trunk
    svn switch https://svn.osgeo.org/grass/grass/branches/develbranch_6 .

The switch command preserves local, uncommitted changes.

To find other branch names, check here.

SVN usage

Checkout source code

Before making changes

  • Double check that you are using the latest revision of the development branch before embarking on any changes. Example:
    svn up raster/r.digit/

Local Diffs

  • Before committing a change or submitting a patch you should review the changes. Viewing a diff is a nice way to do that. It is preferable to keep your patches concise- needless whitespace changes or a mixture of tasks can make it difficult to spot subtle changes introduced by your change.

View changes:

    svn diff raster/r.digit/

Save patch to a file: (run from top dir not the module dir. There are many "main.c" and "description.html" files to choose from and without the directory name it is hard to figure out where your patch should be applied)

    svn diff raster/r.digit/ > fancy_new.diff

Revisit previous Diffs

You can easily check previously checked in changes:

http://trac.osgeo.org/grass/browser/grass/trunk/raster/r.digit/main.c
In upper left corner, click: 
    Last Change    Revision Log

In the source code browser directory listing you can click on a file's Rev column to see a list of all changes, then pick two versions of the file and view changes. By clicking on a revisions Chgset number you can see the changes that came with that commit (including changes to other files). By clicking on @Rev column on the "View changes" page you can see the state of the file at that revision.

When following changes with the Timeline you can click on the revision [number] to view changes.

You can get a unidiff from the small link at the bottom of each page, if you prefer that.

See also the ViewVC web interface mirror of the SVN repository. (ViewCVS)

Commits back into the repository

(must have write access)

  • SVN prefers "atomic commits", i.e. commit changes to all files affected by a change at the same time, not in a series of commits (one for each file).
  • Please make the -m commit log message meaningful. It is your chance to explain "why". If you refer to bug numbers in the form "#123" the Trac system will automatically create a link from the message to the bug report. The same is true for revision changes, e.g. "r12345".
        svn diff raster/r.digit/main.c | less
        svn commit raster/r.digit/main.c \
          -m "fix bug #123: uninitialized variable (merge r12345 from trunk)"
    

Merge between branches (backporting)

Run the command from within the target branch.

  • Example 1: pull a change from trunk into the 6.3 release branch:
        cd releasebranch_6_3/
        svn up raster/r.digit/
        svn merge -c 30749 https://svn.osgeo.org/grass/grass/trunk
        svn diff raster/r.digit/main.c
        svn commit raster/r.digit/main.c \
          -m "fix bug #456: unsafe quoting (merge from trunk, r30749)"
    

where 30749 is the revision number of the changeset you wish to backport.

  • Example 2: merge a change from the 6.4 development branch into GRASS 7 (trunk):
        cd trunk/
        svn up raster/r.digit/
        svn merge -c 31154 https://svn.osgeo.org/grass/grass/branches/develbranch_6
        svn diff raster/r.digit/main.c
        svn commit raster/r.digit/main.c
    

Forking and cloning and merging back

If you want to create a fork or clone of an existing module, use "svn copy", not e.g. "cp -r". Also the source should be repository URL rather than a working copy directory. E.g.:

cd raster
svn copy https://svn.osgeo.org/grass/grass/trunk/raster/r.watershed r.watershed.mfd

This way, you can merge the changes since the fork back into the original. Or if you decide to replace the original with the forked version, the fork will have inherited the original's history when it was created.

Note: grass-addons/ is part of the same repository as grass/, so it's possible to copy, rename, merge, etc between grass-addons/ and grass/.

Non-recursive checkout

  • SVN does not allow you to check out a single file at a time. Sometimes this can be awkward as it can force you to checkout the entire repository for the sake of changing one file in the top directory.

Solution: do a --non-recursive checkout:

    svn checkout --non-recursive https://svn.osgeo.org/grass/grass-web/trunk/ trunk/

Reverting submitted changes

While 'svn revert' is used to revert local, unsubmitted changes, the procedure differs for code already in the SVN repository. Example:

cd lib/external
# note the negative revision number:
svn merge -c -32526 https://svn.osgeo.org/grass/grass/trunk/
svn ci -m "Reverted to previous version (r32526)... reason ..." file(s)

Here, 32526 is the revision corresponding to the indenting of the trunk. Passing a negative revision to "svn merge -c" will "unmerge" that change.

File properties

SVN lets you set file properties. For example to get "$Date$" text in help pages to automatically update activate the Date keyword. Keywords are given in a space delimited string, adding a keyword requires that you include the previous keywords. As always, check with "svn diff" before committing. See "svn help" and "svn help propset" for more information.

Some common tasks:

svn propset svn:keywords "Date" description.html
svn propset svn:executable ON g.script.sh
svn propset svn:mime-type "image/jpeg" example.jpg
svn propset svn:eol-style "native" main.c

svn proplist ps/ps.map/prolog.ps
svn propget svn:mime-type ps/ps.map/prolog.ps 

See Also

Note: See TracWiki for help on using the wiki.