2010-05-23 23:52:46 -04:00
|
|
|
#! ./miniruby
|
|
|
|
|
|
|
|
def diff2index(cmd, *argv)
|
2010-05-24 02:10:09 -04:00
|
|
|
lines = []
|
2010-05-23 23:52:46 -04:00
|
|
|
path = nil
|
2012-11-29 01:52:18 -05:00
|
|
|
output = `#{cmd} #{argv.join(" ")}`
|
|
|
|
output.force_encoding Encoding::BINARY
|
|
|
|
output.each_line do |line|
|
2010-05-23 23:52:46 -04:00
|
|
|
case line
|
|
|
|
when /^Index: (\S*)/, /^diff --git [a-z]\/(\S*) [a-z]\/\1/
|
|
|
|
path = $1
|
2010-05-24 02: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 02:10:09 -04:00
|
|
|
line = $1.to_i
|
2010-05-28 07:53:21 -04:00
|
|
|
ent = "\t* #{path}"
|
2010-05-24 02:10:09 -04:00
|
|
|
ent << " (#{$2})" if $2
|
|
|
|
lines << "#{ent}:"
|
2010-05-23 23:52:46 -04:00
|
|
|
end
|
|
|
|
end
|
2010-05-24 02:10:09 -04:00
|
|
|
lines.uniq!
|
|
|
|
lines.empty? ? nil : lines
|
2010-05-23 23:52:46 -04:00
|
|
|
end
|
|
|
|
|
2012-09-16 04:47:53 -04:00
|
|
|
if `svnversion` =~ /^\d+/
|
2010-05-24 02:10:09 -04:00
|
|
|
cmd = "svn diff --diff-cmd=diff -x-pU0"
|
2010-05-28 07:53:21 -04:00
|
|
|
change = diff2index(cmd, ARGV)
|
2010-05-24 02:10:09 -04:00
|
|
|
elsif File.directory?(".git")
|
2010-05-28 19:59:55 -04:00
|
|
|
cmd = "git diff -U0"
|
2010-05-28 07:53:21 -04:00
|
|
|
change = diff2index(cmd, ARGV) || diff2index(cmd, "--cached", ARGV)
|
2010-05-24 02:10:09 -04:00
|
|
|
else
|
|
|
|
abort "does not seem to be under a vcs"
|
2010-05-23 23:52:46 -04:00
|
|
|
end
|
2010-05-28 07:53:21 -04:00
|
|
|
puts change if change
|