diff4all 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +0 -0
- data/README +3 -0
- data/Rakefile +86 -0
- data/bin/diff4all +245 -0
- data/lib/diff4all.rb +1 -0
- data/lib/diff4all/version.rb +9 -0
- data/test/diff4all_test.rb +11 -0
- data/test/test_helper.rb +2 -0
- metadata +73 -0
data/CHANGELOG
ADDED
File without changes
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'fileutils'
|
10
|
+
include FileUtils
|
11
|
+
require File.join(File.dirname(__FILE__), 'lib', 'diff4all', 'version')
|
12
|
+
|
13
|
+
AUTHOR = "xoinu"
|
14
|
+
EMAIL = "xoinu@mac.com"
|
15
|
+
DESCRIPTION = "diff for all"
|
16
|
+
RUBYFORGE_PROJECT = "diff4all"
|
17
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
18
|
+
BIN_FILES = %w(diff4all)
|
19
|
+
|
20
|
+
|
21
|
+
NAME = "diff4all"
|
22
|
+
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
|
+
VERS = ENV['VERSION'] || (Diff4All::VERSION::STRING + (REV ? ".#{REV}" : ""))
|
24
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
25
|
+
RDOC_OPTS = ['--quiet', '--title', "diff4all documentation",
|
26
|
+
"--opname", "index.html",
|
27
|
+
"--line-numbers",
|
28
|
+
"--main", "README",
|
29
|
+
"--inline-source"]
|
30
|
+
|
31
|
+
desc "Packages up diff4all gem."
|
32
|
+
task :default => [:test]
|
33
|
+
task :package => [:clean]
|
34
|
+
|
35
|
+
Rake::TestTask.new("test") { |t|
|
36
|
+
t.libs << "test"
|
37
|
+
t.pattern = "test/**/*_test.rb"
|
38
|
+
t.verbose = true
|
39
|
+
}
|
40
|
+
|
41
|
+
spec =
|
42
|
+
Gem::Specification.new do |s|
|
43
|
+
s.name = NAME
|
44
|
+
s.version = VERS
|
45
|
+
s.platform = Gem::Platform::RUBY
|
46
|
+
s.has_rdoc = true
|
47
|
+
s.extra_rdoc_files = ["README", "CHANGELOG"]
|
48
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
49
|
+
s.summary = DESCRIPTION
|
50
|
+
s.description = DESCRIPTION
|
51
|
+
s.author = AUTHOR
|
52
|
+
s.email = EMAIL
|
53
|
+
s.homepage = HOMEPATH
|
54
|
+
s.executables = BIN_FILES
|
55
|
+
s.rubyforge_project = RUBYFORGE_PROJECT
|
56
|
+
s.bindir = "bin"
|
57
|
+
s.require_path = "lib"
|
58
|
+
s.autorequire = "diff4all"
|
59
|
+
|
60
|
+
s.add_dependency('diff2xml', '>=0.0.1')
|
61
|
+
#s.add_dependency('activesupport', '>=1.3.1')
|
62
|
+
#s.required_ruby_version = '>= 1.8.2'
|
63
|
+
|
64
|
+
s.files = %w(README CHANGELOG Rakefile) +
|
65
|
+
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
66
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
67
|
+
Dir.glob("examples/**/*.rb") +
|
68
|
+
Dir.glob("tools/*.rb")
|
69
|
+
|
70
|
+
# s.extensions = FileList["ext/**/extconf.rb"].to_a
|
71
|
+
end
|
72
|
+
|
73
|
+
Rake::GemPackageTask.new(spec) do |p|
|
74
|
+
p.need_tar = true
|
75
|
+
p.gem_spec = spec
|
76
|
+
end
|
77
|
+
|
78
|
+
task :install do
|
79
|
+
name = "#{NAME}-#{VERS}.gem"
|
80
|
+
sh %{rake package}
|
81
|
+
sh %{sudo gem install pkg/#{name}}
|
82
|
+
end
|
83
|
+
|
84
|
+
task :uninstall => [:clean] do
|
85
|
+
sh %{sudo gem uninstall #{NAME}}
|
86
|
+
end
|
data/bin/diff4all
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
# -*- Ruby -*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2006, xoinu
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
# * Neither the name of the Xoinu nor the names of its contributors may
|
15
|
+
# be used to endorse or promote products derived from this software
|
16
|
+
# without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
22
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
#
|
29
|
+
require 'optparse'
|
30
|
+
require 'fileutils'
|
31
|
+
require 'diff2xml/diff2html'
|
32
|
+
require 'diff2xml/diff2rss20'
|
33
|
+
require 'diff2xml/parser'
|
34
|
+
require 'net/smtp'
|
35
|
+
require 'diff4all.rb'
|
36
|
+
|
37
|
+
def print_usage
|
38
|
+
STDERR.print <<USAGE
|
39
|
+
Usage: diff4all repository cache_directory [options]
|
40
|
+
-1, --one-day alias to '-d -r<yesterday>:<today>'
|
41
|
+
-2, --two-day alias to '-d -r<the day before yesterday>:<today>'
|
42
|
+
-c, --diff-command=VAL diff command for svn (default: diff)
|
43
|
+
-d, --date let diff4all know that revision name is date
|
44
|
+
-f, --config-file=VAL specify config file (default: diff4all.conf)
|
45
|
+
-g, --generate generate a template of config file
|
46
|
+
-h, --help show this help
|
47
|
+
-l, --lines the number of extracted lines (default: 50)
|
48
|
+
-r, --revision=VAL revision to test (default: none)
|
49
|
+
-s, --scm=VAL 'svn' or 'cvs' (default: svn)
|
50
|
+
USAGE
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_conf(conf_file)
|
54
|
+
res = {}
|
55
|
+
|
56
|
+
File.open(conf_file, 'r') do |f|
|
57
|
+
f.each do |l|
|
58
|
+
l.chomp!
|
59
|
+
next if 0 == l.size
|
60
|
+
next if l.match(/^#/)
|
61
|
+
l.gsub!(/#(.*)$/, "")
|
62
|
+
l.gsub!(/[\s\t]*=[\s\t]*/, "=")
|
63
|
+
key_value = l.split('=')
|
64
|
+
res[key_value[0]] = key_value[1] ? key_value[1].gsub(/[\s\t]+$/, "") : ''
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
res
|
69
|
+
end
|
70
|
+
|
71
|
+
def send_mail(confs, title, source)
|
72
|
+
auth_type =
|
73
|
+
case confs['AUTH_TYPE']
|
74
|
+
when 'login'
|
75
|
+
:login
|
76
|
+
when 'plain'
|
77
|
+
:plain
|
78
|
+
else
|
79
|
+
:cram_md5
|
80
|
+
end
|
81
|
+
|
82
|
+
Net::SMTP::start(confs['SMTP_SERVER'], confs['SMTP_PORT_NO'],
|
83
|
+
confs['SMTP_DOMAIN'], confs['SMTP_USER'],
|
84
|
+
confs['SMTP_PASS'], auth_type) do |smtp|
|
85
|
+
smtp.open_message_stream(confs['FROM_ADDRESS'], confs['TO_ADDRESS'].split(',')) do |stream|
|
86
|
+
stream.puts "Subject: #{title}"
|
87
|
+
stream.puts "From: #{confs['FROM_NAME']} <#{confs['FROM_ADDRESS']}>"
|
88
|
+
stream.puts "To: #{confs['TO_ADDRESS']}"
|
89
|
+
stream.puts "Content-Type: text/html"
|
90
|
+
stream.puts
|
91
|
+
File.open(source, 'r') {|f| f.each {|l| stream.print(l) }}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
options = {}
|
97
|
+
|
98
|
+
OptionParser.new do |opt|
|
99
|
+
begin
|
100
|
+
opt.on('-1', '--one-day') {|v| options[:o] = v }
|
101
|
+
opt.on('-2', '--two-day') {|v| options[:t] = v }
|
102
|
+
opt.on('-c VAL', '--diff-command=VAL') {|v| options[:c] = v }
|
103
|
+
opt.on('-d', '--date') {|v| options[:d] = v }
|
104
|
+
opt.on('-f VAL', '--config-file=VAL') {|v| options[:f] = v }
|
105
|
+
opt.on('-g', '--generate') {|v| options[:g] = v }
|
106
|
+
opt.on('-h', '--help') {|v| print_usage; exit 0 }
|
107
|
+
opt.on('-l', '--lines') {|v| options[:l] = v }
|
108
|
+
opt.on('-r VAL', '--revision=VAL') {|v| options[:r] = v }
|
109
|
+
opt.on('-s VAL', '--scm=VAL') {|v| options[:s] = v }
|
110
|
+
opt.parse!(ARGV)
|
111
|
+
rescue
|
112
|
+
STDERR.puts 'ERROR: Invalid option was passed.'
|
113
|
+
print_usage
|
114
|
+
exit 0
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# -f, --config-file
|
119
|
+
|
120
|
+
conf_file = options[:f] ? options[:f] : 'diff4all.conf'
|
121
|
+
|
122
|
+
# -g, --generate
|
123
|
+
|
124
|
+
if options[:g] || !File.exist?(conf_file)
|
125
|
+
STDERR.puts "#{conf_file} was generated. Please configure this file at first."
|
126
|
+
|
127
|
+
File.open(conf_file, 'w') do |f|
|
128
|
+
f << <<CONF_OUT
|
129
|
+
#
|
130
|
+
# WWW setting
|
131
|
+
#
|
132
|
+
PUBLISH_RSS = YES # YES or NO
|
133
|
+
RSS_TITLE = Diff For All Result
|
134
|
+
RSS_DESCRIPTION = [option]
|
135
|
+
URL = [optional]
|
136
|
+
|
137
|
+
#
|
138
|
+
# Mail setting
|
139
|
+
#
|
140
|
+
PUBLISH_MAIL = NO # YES or NO
|
141
|
+
HTML_MAIL = YES # YES or NO
|
142
|
+
SMTP_SERVER = [mandatory if PUBLISH_MAIL=YES]
|
143
|
+
SMTP_PORT_NO = 25
|
144
|
+
SMTP_DOMAIN = your.domain.net
|
145
|
+
SMTP_USER = [mandatory if PUBLISH_MAIL=YES]
|
146
|
+
SMTP_PASS = [mandatory if PUBLISH_MAIL=YES]
|
147
|
+
AUTH_TYPE = login [plain, cram_md5 if PUBLISH_MAIL=YES]
|
148
|
+
FROM_ADDRESS = [mandatory if PUBLISH_MAIL=YES]
|
149
|
+
TO_ADDRESS = [mandatory if PUBLISH_MAIL=YES]
|
150
|
+
FROM_NAME = your name
|
151
|
+
CONF_OUT
|
152
|
+
end
|
153
|
+
exit 0
|
154
|
+
end
|
155
|
+
|
156
|
+
if ARGV.size < 2
|
157
|
+
STDERR.puts 'ERROR: Invalid option was passed.'
|
158
|
+
print_usage
|
159
|
+
exit 0
|
160
|
+
end
|
161
|
+
|
162
|
+
repo = ARGV.shift
|
163
|
+
target = ARGV.shift
|
164
|
+
|
165
|
+
# -c, --diff-command (svn)
|
166
|
+
|
167
|
+
diff = options[:c] ? options[:c] : 'diff'
|
168
|
+
|
169
|
+
# -l, --lines (cvs, svn)
|
170
|
+
|
171
|
+
num_extract = options[:l] ? options[:l].to_i : 50
|
172
|
+
|
173
|
+
# -r, --revision, and -1, 2
|
174
|
+
|
175
|
+
if options[:o] || options[:t]
|
176
|
+
rev_date = Time.now
|
177
|
+
rev_curr = rev_date.strftime('%Y%m%d')
|
178
|
+
|
179
|
+
if options[:t]
|
180
|
+
rev_date = rev_date - 3600*24*2
|
181
|
+
else
|
182
|
+
rev_date = rev_date - 3600*24
|
183
|
+
end
|
184
|
+
|
185
|
+
rev_prev = rev_date.strftime('%Y%m%d')
|
186
|
+
options[:d] = true
|
187
|
+
options[:r] = true
|
188
|
+
elsif options[:r] && options[:r].match(/([^\:]+)\:([^\:]+)/)
|
189
|
+
rev_curr = $2
|
190
|
+
rev_prev = $1
|
191
|
+
end
|
192
|
+
|
193
|
+
# -s, --scm
|
194
|
+
|
195
|
+
scm_command = options[:s] ? options[:s] : 'svn'
|
196
|
+
|
197
|
+
diff_lines = if scm_command.match(/cvs/)
|
198
|
+
if options[:r]
|
199
|
+
if options[:d]
|
200
|
+
`#{scm_command} diff -D #{rev_prev} -D #{rev_curr} --unified=#{num_extract} --ignore-all-space #{repo}`.split("\n")
|
201
|
+
else
|
202
|
+
`#{scm_command} diff -r #{rev_prev} -r #{rev_curr} --unified=#{num_extract} --ignore-all-space #{repo}`.split("\n")
|
203
|
+
end
|
204
|
+
else
|
205
|
+
`#{scm_command} diff --unified=#{num_extract} --ignore-all-space #{repo}`.split("\n")
|
206
|
+
end
|
207
|
+
else
|
208
|
+
if options[:r]
|
209
|
+
if options[:d]
|
210
|
+
`#{scm_command} diff #{repo} -r{#{rev_prev}}:{#{rev_curr}} --diff-cmd #{diff} -x "--unified=#{num_extract} --ignore-all-space"`.split("\n")
|
211
|
+
else
|
212
|
+
`#{scm_command} diff #{repo} -r#{rev_prev}:#{rev_curr} --diff-cmd #{diff} -x "--unified=#{num_extract} --ignore-all-space"`.split("\n")
|
213
|
+
end
|
214
|
+
else
|
215
|
+
`#{scm_command} diff #{repo} --diff-cmd #{diff} -x "--unified=#{num_extract} --ignore-all-space"`.split("\n")
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
diff_lines.delete_if {|e| e.match(/^\?/) }
|
220
|
+
|
221
|
+
if diff_lines.empty?
|
222
|
+
STDERR.puts 'There was no difference.'
|
223
|
+
exit 0
|
224
|
+
end
|
225
|
+
|
226
|
+
# Ensure that the target directory exists
|
227
|
+
|
228
|
+
FileUtils.mkdir_p(target)
|
229
|
+
|
230
|
+
project_name = File.basename(repo)
|
231
|
+
html_name = "diff_#{rev_prev}_to_#{rev_curr}.html"
|
232
|
+
html_path = target + '/' + html_name
|
233
|
+
confs = parse_conf(conf_file)
|
234
|
+
|
235
|
+
# Write HTML, RSS
|
236
|
+
|
237
|
+
File.open(html_path, 'w') {|f| Diff2Xml::Parser.new(Diff2Xml::Diff2Html.new(f, true)).parse(diff_lines) }
|
238
|
+
File.open("#{target}/diff.rss", 'w') {|f| Diff2Xml::Parser.new(Diff2Xml::Diff2Rss20.new(f, confs['URL'] + html_name, project_name)).parse(diff_lines) } if 'YES' == confs['PUBLISH_RSS']
|
239
|
+
|
240
|
+
# Send mail
|
241
|
+
|
242
|
+
if 'YES' == confs['PUBLISH_MAIL']
|
243
|
+
title = "Review Me: #{project_name} #{rev_prev} -> #{rev_curr}"
|
244
|
+
send_mail(confs, title, html_path)
|
245
|
+
end
|
data/lib/diff4all.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'diff4all/**/*.rb')].sort.each { |lib| require lib }
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: diff4all
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-08-14 00:00:00 -07:00
|
8
|
+
summary: diff for all
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: xoinu@mac.com
|
12
|
+
homepage: http://diff4all.rubyforge.org
|
13
|
+
rubyforge_project: diff4all
|
14
|
+
description: diff for all
|
15
|
+
autorequire: diff4all
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- xoinu
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- CHANGELOG
|
34
|
+
- Rakefile
|
35
|
+
- bin/diff4all
|
36
|
+
- test/diff4all_test.rb
|
37
|
+
- test/test_helper.rb
|
38
|
+
- lib/diff4all
|
39
|
+
- lib/diff4all.rb
|
40
|
+
- lib/diff4all/version.rb
|
41
|
+
test_files: []
|
42
|
+
|
43
|
+
rdoc_options:
|
44
|
+
- --quiet
|
45
|
+
- --title
|
46
|
+
- diff4all documentation
|
47
|
+
- --opname
|
48
|
+
- index.html
|
49
|
+
- --line-numbers
|
50
|
+
- --main
|
51
|
+
- README
|
52
|
+
- --inline-source
|
53
|
+
- --exclude
|
54
|
+
- ^(examples|extras)/
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README
|
57
|
+
- CHANGELOG
|
58
|
+
executables:
|
59
|
+
- diff4all
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
dependencies:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: diff2xml
|
67
|
+
version_requirement:
|
68
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.0.1
|
73
|
+
version:
|