Chip's Tips for Developers

Contains coding, but not narcotic.

Ruby script to parse a version log file and update source files

March 18th, 2007 1:23:32 pm pst by Sterling Camden

Working remotely via VPN on a big project presents some challenges, not the least of which is keeping your local source files up to date with the thousands of version control archives. Running a script to check all of the remote archives against your local sources can take a lot of time and bandwidth. Yet, if you don’t stay up to date, how will you know if your changes will be compatible with the latest version? You’d really like to know exactly which archives have been modified and just check those against your local copies.

One such project I work on uses PVCS for version control. PVCS writes a log file for all modifications to the archives. Each entry in the log contains the name of the archive file (full path), the person who made the modification, the date, time, and nature of the modification — all comma-delimited. So, I wrote a handy little Ruby script (which you can download below) to read the log, looking for updates on or after a specified date. For those it finds, it spawns a PVCS ‘get’ command using -u (update only if more recent) and -n (answer ‘n’ to any prompts, such as “a writable version exists, overwrite?”).

Even if you don’t have a need for such a script yourself, you might find some interesting features of Ruby in this example. Or, if you’re a better Rubyist than I, maybe you could show me how to make this script even more elegant.

The archives are stored in a directory structure that mirrors the source file directory structure on the local machine. Development occurs on both *nix and Windows workstations, so the root of the archive path in the log may be ‘/usr/archive’ or a drive letter mapped over Samba. Thus, we must strip off any of these archive path prefixes, and then add our local source root, in order to know where each source file needs to go.

To avoid duplication of effort, we use a hash keyed on the full archive path (with root prefix stripped). The corresponding value in the hash is an array containing the archive directory and the filename.

See the comments within the script for further information and usage instructions.

Posted in Ruby, Unix, Wildly popular, Windows | 1 Comment » RSS 2.0 | Sphere it!

One Response to “Ruby script to parse a version log file and update source files”

  1. [...] I wrote a quick and dirty clean Ruby script to scan the log for entries in which a new revision was put on or after a specified date. It weeds [...]

Leave a Reply

Better Tag Cloud