Extract changed files only with SVN

I often need to get the whole directory tree of changed file. ONLY changed files. I used to do it by filtering the files in Total Commander by modification date.

Now I've just prepared small script to do that for me using SVN and SharpScript. You may tune it for your need, but here's the good starting point for that.

Requirements:

  • ScriptSharp installed in Program Files.
  • SVN client.
  • Resulting folder is always 'Changes'.
  • Place these files in the same folder that is under SVN.

 

Usage: run get-svn-status.bat (or just double click it).

get-svn-status.bat:

del svn-changes.txt
svn status >> svn-changes.txt
"C:\Program Files\Menees\SharpScript\SharpScriptConsole.exe" grabChanges.scs

 

grabChanges.scs:

using SharpScript;
using System;
using System.IO;
using System.Linq;

class Program
{
    static bool IsChange(string line) {
        char mark = line[0]; // Rip off with nulls
        // http://knaddison.com/technology/svn-status-code-cheat-sheet
        switch (mark) {
            case 'M': // Modified
            case 'A': // Added
            case 'C': // Confilict
            case 'G': // merGed from repo to working copy            
            return true;
        }
        return false;
    }
    
    public static void Main(string[] arArgs)
    {
        var folder = "Changes";
        try {
            Directory.Delete(folder, true);
        } catch(DirectoryNotFoundException) {}; // We know why
        Directory.CreateDirectory(folder);
        
        using(var fs = File.OpenText("svn-changes.txt")) {
            string line = "";
            while ((line = fs.ReadLine()) != null) {
                if (!IsChange(line)) continue;
                Script.Echo(line);
                var filePath = line.Substring(7);
                var dest = folder + "\\" + filePath;
                
                Directory.CreateDirectory(Path.GetDirectoryName(dest));                
                File.Copy(filePath, dest, true/*overwrite*/);
            }            
        }
        
        Script.Echo("Done");
    }
}

 

 

Enjoy.