2010-05-24 07:52:46 +04:00
|
|
|
#! ./miniruby
|
|
|
|
|
|
|
|
def diff2index(cmd, *argv)
|
2010-05-24 10:10:09 +04:00
|
|
|
lines = []
|
2010-05-24 07:52:46 +04:00
|
|
|
path = nil
|
|
|
|
`#{cmd} #{argv.join(" ")}`.split(/\n/).each do |line|
|
|
|
|
case line
|
|
|
|
when /^Index: (\S*)/, /^diff --git [a-z]\/(\S*) [a-z]\/\1/
|
|
|
|
path = $1
|
2010-05-24 10:32:53 +04:00
|
|
|
when /^@@\s*-[,\d]+ +\+(\d+)[,\d]*\s*@@(?: +([A-Za-z_][A-Za-z_0-9 ]*[A-Za-z_0-9]))?/
|
2010-05-24 10:10:09 +04:00
|
|
|
line = $1.to_i
|
2010-05-28 15:53:21 +04:00
|
|
|
ent = "\t* #{path}"
|
2010-05-24 10:10:09 +04:00
|
|
|
ent << " (#{$2})" if $2
|
|
|
|
lines << "#{ent}:"
|
2010-05-24 07:52:46 +04:00
|
|
|
end
|
|
|
|
end
|
2010-05-24 10:10:09 +04:00
|
|
|
lines.uniq!
|
|
|
|
lines.empty? ? nil : lines
|
2010-05-24 07:52:46 +04:00
|
|
|
end
|
|
|
|
|
2010-05-24 10:10:09 +04:00
|
|
|
if File.directory?(".svn")
|
|
|
|
cmd = "svn diff --diff-cmd=diff -x-pU0"
|
2010-05-28 15:53:21 +04:00
|
|
|
change = diff2index(cmd, ARGV)
|
2010-05-24 10:10:09 +04:00
|
|
|
elsif File.directory?(".git")
|
2010-05-29 03:59:55 +04:00
|
|
|
cmd = "git diff -U0"
|
2010-05-28 15:53:21 +04:00
|
|
|
change = diff2index(cmd, ARGV) || diff2index(cmd, "--cached", ARGV)
|
2010-05-24 10:10:09 +04:00
|
|
|
else
|
|
|
|
abort "does not seem to be under a vcs"
|
2010-05-24 07:52:46 +04:00
|
|
|
end
|
2010-05-28 15:53:21 +04:00
|
|
|
puts change if change
|