Subversion

Subversion is a revision control system which is very useful for managing large software projects involving multiple authors. I wrote a ruby script for managing the commits to an svn repository. It is my first ruby program, so there is lot of scope for improvement.

The way this is to be used is as follows. You make a lot of changes to your source code. As you make these changes you go on recording the changes in a CHANGELOG file which you put in the base directory of your project. This file also contains the log messages. An example of the CHANGELOG file is given below.

== 

Makefile Makefile.in src-flo/Makefile src-adj/Makefile 

Shifted some global variables to Makefile.in and made changes to all Makefiles. 

== 

src-flo/kfvs_flux.F src-flo/roe_flux.F 

Made some changes to limiter. 

== 

src-flo/geometry.f 

Put some checks for validity of point indices. 

==

You can put multiple files in a single line and they will be committed together with the same log message. To commit the changes you just run the ruby script. It reads the files and log messages from CHANGELOG and commits them to the repository. You can test the integrity of the log file by running svnci test and test for any conflicts with the repository by running svnci status, which requires network access.

#!/usr/bin/ruby# Use "svnci test" to test the consistency of CHANGELOG file without# actually committing.# Use "svnci status" to check the status of local files with those # on the svn repository. This requires network access. Always check# the status before committing to avoid conflicts.   #How many command line arguments do we have ?if ARGV.length > 1    puts "Only 0 or 1 arguments allowed"    abort end   #Read the CHANGELOG file CLOG=IO.readlines("CHANGELOG")   if CLOG.length < 4    puts "Nothing to be done or CHANGELOG is empty/incomplete"    abort end   #Check first and last line of CHANGELOG nlines = CLOG.lengthif CLOG[0] != "==\n" or CLOG[nlines-1] != "==\n"    puts "CHANGELOG file should begin and end with =="    abort end   #Read files and messages ibeg=-1 iend=-1 count=0 file=[] mess=[] exstr=[]for i in 0...CLOG.length    if CLOG[i] == "==\n" and ibeg==-1       ibeg = i + 1    end    if CLOG[i] == "==\n" and ibeg!=-1 and iend==-1       iend = i - 1    end    if ibeg != -1 and iend != -1       if iend <= ibeg          puts "CHANGELOG file is incorrect"          puts "Check near line number ",ibeg          abort       end       thisfile = CLOG[ibeg]       file[count] = thisfile.sub(/\n/,'')       thismess = ""       for j in (ibeg+1)...(iend+1)          thismess = thismess + CLOG[j]       end       mess[count]  = thismess       exstr[count] = "svn ci " + file[count] + " -F /tmp/message"       count = count + 1       ibeg  = iend + 2       iend  = -1    endend   #Perform testif ARGV.length == 1 and ARGV[0] == "test"    for i in 0...count       puts "---"       puts exstr[i]       puts mess[i]    end    abort #Check status with files on repositoryelsif ARGV.length == 1 and ARGV[0] == "status"    allfiles=" "    for i in 0...count       allfiles = allfiles + file[i] + " "    end    statstr = "svn status -u " + allfiles    system(statstr)    abort #Unknown command line argumentelsif ARGV.length == 1    puts "What do you want to do ?"    abort end   #Now commit changesfor i in 0...count    fpt = File.new("/tmp/message","w")    fpt.write(mess[i])    fpt.close    puts "---"    puts exstr[i]    system(exstr[i])end   #Clear contents of CHANGELOGsystem("rm -f CHANGELOG && touch CHANGELOG")