Subversion File Management Tool

What Is It?

This is the tool I wrote before I learned about svn changelist.

It is a tool for ensuring the accuracy of check-ins with the Subversion content management system while at the same time increasing the speed of doing so. It is designed to:

  • simplify the command for checking in multiple files
  • help avoid missing files on check-in
  • display conflicting files

The goal is simplify command line entries for the developer. For example, you can check in all changed files with: svn ci ‘dfc8` which is shorter than listing the changed files and faster than svn ci alone. (svn ci alone has another drawback. Subversion repositories sometimes get into an odd state where some files that already exist in the repository are flagged as unknown, ’?'. If you check in using svn ci, Subversion will delete these files from the repository.)

History

The concept for this script is based on colleague Mike Glover's work with the CVS content management system.

Usage

dfc8 [-h][-c][-d path][-n][-q][-r][-u][-v]
Prints a list of files contained in .status.txt
-c: show Conflicted files (negates -q)
-d: the Directory for which to look for the status file
-h: print this Help text
-n: print the files each on a separate liNe
-q: print the files of unknown status (Question mark)
-r: Recreate a new status file
-u: dUmps the status file as is
-v: opens the status file in Vim before displaying

Typical check-in scenario:
In a typical check-in you could use dfc8 as follows:

  • Run the script to generate the list of changed files (once this is run, it is stored on disk, which is where the speed improvement comes from):
    • dfc8 -rn
  • Check for any conflicts before checking in:
    • dfc8 -cn
  • Check for any files that have not been added:
    • dfc8 -qn
  • If there were files that have not been added, and you want to add them all:
    • svn add `dfc8 -q`
  • If you added any files in the previous step, you will need to recreate the list of changed files:
    • dfc8 -rn
  • Check in the files
    • svn commit `dfc8` -m "Description of change"

The Code

#!/usr/bin/perl -w
 
#Created by Robert Gowland, 2008
#Based on work by Michael Glover
#Freely distributable, with credit
 
use Getopt::Std;
use strict;
 
my %opt = ();
my $file=".status.txt";
my $dir = ".";
my $newline = 0;
my $search_conditions = ' -v "^?"';
my $dump_file = 0;
my $Usage = "$0 [-h][-c][-d path][-n][-q][-r][-u][-v]
Prints a list of files contained in $file
    -c: show Conflicted files (negates -q)
    -d: the Directory for which to look for the status file
    -h: print this Help text
    -n: print the files each on a separate liNe
    -q: print the files of unknown status (Question mark)
    -r: Recreate a new status file
    -u: dUmps the status file as is\n
    -v: opens the status file in Vim before displaying\n";
 
#Parse options
getopts("cd:hnqruv", \%opt);
if (defined $opt{'h'})
{
    print $Usage;
    exit;
}
if (defined $opt{'r'})
{
    `svn status | grep -v $file | grep -v getDEVersionInfo.cgi > $file`;
}
if (defined $opt{'d'})
{
    $dir = $opt{'d'};
}
if (defined $opt{'n'})
{
    $newline = 1;
}
if (defined $opt{'q'})
{
    $search_conditions = '"^?"';
}
if (defined $opt{'c'})
{
    $search_conditions = '"^C"';
}
if (defined $opt{'u'})
{
    $dump_file = 1;
}
if (defined $opt{'v'})
{
    `vim $dir/$file`;
}
 
#Do the work
if ( $dump_file == 1 )
{
    print `cat $dir/$file`;
}
else
{
    my @arr = `grep $search_conditions $dir/$file | cut -c8-`;
 
    foreach my $file (@arr)
    {
        if (!$newline)
        {
            chomp $file;
        }
 
        $file =~ s/ /\\ /g;
 
        print "$file";
 
        if (!$newline)
        {
            print " ";
        }
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License