2010-05-24 07:52:46 +04:00
|
|
|
#! ./miniruby
|
|
|
|
|
2016-07-03 00:01:04 +03: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 08:55:30 +03:00
|
|
|
$:.unshift(File.expand_path("../../lib", __FILE__))
|
|
|
|
require File.expand_path("../vcs", __FILE__)
|
|
|
|
|
2010-05-24 07:52:46 +04:00
|
|
|
def diff2index(cmd, *argv)
|
2010-05-24 10:10:09 +04:00
|
|
|
lines = []
|
2010-05-24 07:52:46 +04:00
|
|
|
path = nil
|
2012-11-29 10:52:18 +04:00
|
|
|
output = `#{cmd} #{argv.join(" ")}`
|
2013-03-11 03:01:07 +04:00
|
|
|
if defined? Encoding::BINARY
|
|
|
|
output.force_encoding Encoding::BINARY
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
output.each_line do |line|
|
2010-05-24 07:52:46 +04:00
|
|
|
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
|
|
|
|
|
2016-04-01 08:55:30 +03:00
|
|
|
vcs = begin
|
|
|
|
VCS.detect(".")
|
|
|
|
rescue VCS::NotFoundError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
case vcs
|
|
|
|
when VCS::SVN
|
2010-05-24 10:10:09 +04:00
|
|
|
cmd = "svn diff --diff-cmd=diff -x-pU0"
|
2010-05-28 15:53:21 +04:00
|
|
|
change = diff2index(cmd, ARGV)
|
2016-04-01 08:55:30 +03:00
|
|
|
when VCS::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
|