This post originated from an RSS feed registered with Java Buzz
by Brian McCallister.
Original Post: More Fun Little Scripts
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
What the heck, another useful little script. This one is called svnrepo which does the simple thing of providing convenient svn repository munging:
#!/usr/bin/env ruby
entries = File.open("#{ENV['PWD']}/.svn/entries")
begin
escape = callcc do |escape|
entries.each_line do |line|
if line =~ /\s+url="(.+)"/
repo = $1
if ARGV.length > 0
arg = ARGV[0]
arg = arg[1, arg.length].to_i
repo = repo.reverse
arg.times do |i|
repo = repo[repo.index("/") + 1 , repo.length]
end
puts repo.reverse
else
puts repo
end
escape.call
end
end
end
rescue
puts "You backed up too far into the repo string"
exit -1
ensure
entries.close
end
The reason for this instead of just svn info | grep URL | cut -f 2 -d ' ' is backing up directories in the svn repo (svnrepo -1 or svnrepo -2 to back up one directory, or two, respectively):