2010-05-23 23:52:46 -04:00
|
|
|
#! ./miniruby
|
|
|
|
|
2016-07-02 17:01:04 -04:00
|
|
|
# Used by "make change" to generate a list of files for a Changelog entry.
|
|
|
|
# Run it via "make change" in the Ruby root directory.
|
|
|
|
|
2016-04-01 01:55:30 -04:00
|
|
|
$:.unshift(File.expand_path("../../lib", __FILE__))
|
|
|
|
require File.expand_path("../vcs", __FILE__)
|
|
|
|
|
2010-05-23 23:52:46 -04:00
|
|
|
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(" ")}`
|
2013-03-10 19:01:07 -04:00
|
|
|
if defined? Encoding::BINARY
|
|
|
|
output.force_encoding Encoding::BINARY
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
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
|
|
|
|
|
2016-04-01 01:55:30 -04:00
|
|
|
vcs = begin
|
|
|
|
VCS.detect(".")
|
|
|
|
rescue VCS::NotFoundError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
case vcs
|
|
|
|
when VCS::SVN
|
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)
|
2016-04-01 01:55:30 -04:00
|
|
|
when VCS::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
|