1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* tool/change_maker.rb: use external diff for -p option.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-05-24 06:10:09 +00:00
parent e16c316b52
commit c5652b9008

View file

@ -1,26 +1,29 @@
#! ./miniruby
if File.directory?(".svn")
cmd = "svn diff"
elsif File.directory?(".git")
cmd = "git diff"
else
abort "does not seem to be under a vcs"
end
def diff2index(cmd, *argv)
lines = []
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
when /^@@.*@@ +([A-Za-z_][A-Za-z_0-9 ]*[A-Za-z_0-9])/
puts "* #{path} (#{$1}):"
when /^@@\s*-\d+,\d+ +\+(\d+),\d+\s*@@(?: +([A-Za-z_][A-Za-z_0-9 ]*[A-Za-z_0-9]))?/
line = $1.to_i
ent = "* #{path}"
ent << " (#{$2})" if $2
lines << "#{ent}:"
end
end
!!path
lines.uniq!
lines.empty? ? nil : lines
end
if !diff2index(cmd, ARGV) and /^git/ =~ cmd
diff2index(cmd, "--cached", ARGV)
if File.directory?(".svn")
cmd = "svn diff --diff-cmd=diff -x-pU0"
puts diff2index(cmd, ARGV)
elsif File.directory?(".git")
cmd = "git diff"
puts diff2index(cmd, ARGV) || diff2index(cmd, "--cached", ARGV)
else
abort "does not seem to be under a vcs"
end