Preparing for Subversion to Git migration

GEOS is slowly moving to Git, so I decided to clear the Subversion specific settings, namely the svn:keywords. The procedure is quick and based on the commands I used to perform bulk svn:keywords property update.

First, svn:keywords property is removed:

find . -path '*/.svn' -prune -o -type f -print  | xargs svn propdel -q svn:keywords

Next, line consisting of $Id$ keyword is stripped from every plain text file using a tiny script coded in Python:


#! /usr/bin/env python
import fileinput
import re
import sys

def strip_line(filename, rx):
    sys.stderr.write(filename + '\n')
    for line in fileinput.input(filename, inplace=1):
        m = re.match(rx, line)
        if m is None:
            sys.stdout.write(line)
        else:
            sys.stderr.write(line)

if len(sys.argv) < 2:
    sys.exit("Missing filename")

pattern = '^.*\$Id.*$'
rx = re.compile(pattern, re.DOTALL)
strip_line(sys.argv[1], rx)

The script is executed for every file, excluding the working copy admin area in .svn:

for f in `find . -path '*/.svn' -prune -o -type f -print`; do ~/bin/strip_line_regex.py $f; done;

Voila!

Update: Torvalds answers Does GIT has vc keywords like CVS/Subversion?

5 thoughts on “Preparing for Subversion to Git migration

  1. Guess this is the same as it is with text editors, i.e.: we all think our way is *the* right way of doing things, but I tend to prefer (readable) oneliners :

    find . -path ‘*/.svn’ -prune -o -type f | xargs ~/bin/strip_line_regex.py

    or

    find . -path ‘*/.svn’ -prune -o -type f -exec ~/bin/strip_line_regex.py {} \;

    in case it comes handy for you or someone else

  2. >>Specifically, I?d need to modify the script a bit to handle input from stdin.<<

    No. These commands are equivalent AFAIK

    What xargs (-exec) does is that it takes each line (word?) from stdin, and passes that as a parameter to the command (substitutes {} with the value)

    In these examples, the name of the file is passed as a parameter to the py script, just as before.

  3. Matt,

    This is a really stupid question I know from someone who doesn’t use GIT nor grasp why GIT is better than SVN, but how do you keep track of who made the last change in the file? Does GIT stamp that somewhere on the file automagically? Is it only visible in the repositories?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>