ruby_diff 0.1.5 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/README.txt +6 -3
- data/Rakefile +2 -2
- data/bin/ruby_diff +19 -13
- data/lib/ruby_diff.rb +2 -2
- data/lib/ruby_diff/structure_processor.rb +24 -4
- data/lib/ruby_diff/svn_feeder.rb +56 -0
- data/ruby_diff.gemspec +32 -14
- data/test/structure_processor_test.rb +43 -2
- metadata +67 -57
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -28,14 +28,17 @@ changes to instance methods. The API is likely to change drastically.
|
|
28
28
|
This is likely to change a bunch, but for the moment:
|
29
29
|
ruby_diff old_file new_file
|
30
30
|
|
31
|
-
|
31
|
+
For git repositories, etc.
|
32
32
|
ruby_diff --git HEAD --git-wd
|
33
33
|
|
34
34
|
Compare three different release tags.
|
35
35
|
ruby_diff --git v0.1 --git v0.2 --git v0.3
|
36
|
-
|
36
|
+
|
37
|
+
For subversion repositories
|
38
|
+
ruby_diff --svn http://project.svnserver.org/lib --svn BASE:lib
|
39
|
+
|
37
40
|
See help for more information.
|
38
41
|
|
39
|
-
== Contact
|
42
|
+
== Contact
|
40
43
|
Feel free to get in touch with me:
|
41
44
|
netghost@gmail.com
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ HOE = Hoe.new('ruby_diff', RubyDiff::VERSION) do |p|
|
|
11
11
|
p.remote_rdoc_dir = '' # Release to root
|
12
12
|
p.test_globs = ['test/*_test.rb']
|
13
13
|
p.summary = "a higher level diff application for analyzing changes to ruby code"
|
14
|
-
p.extra_deps << ['ParseTree', '
|
14
|
+
p.extra_deps << ['ParseTree', '~> 2.1']
|
15
15
|
end
|
16
16
|
SPEC = HOE.spec
|
17
17
|
|
@@ -30,7 +30,7 @@ namespace :git do
|
|
30
30
|
|
31
31
|
desc "Updates the manifest to match the git repository"
|
32
32
|
task :update_manifest do |t|
|
33
|
-
`git
|
33
|
+
`git ls-files > Manifest.txt`
|
34
34
|
end
|
35
35
|
|
36
36
|
desc "Pushes git repository out"
|
data/bin/ruby_diff
CHANGED
@@ -21,15 +21,13 @@ feeder_mapping = {
|
|
21
21
|
:file => FileFeeder,
|
22
22
|
:git => GitFeeder,
|
23
23
|
:git_wd => GitWorkingDirFeeder,
|
24
|
+
:svn => SVNFeeder
|
24
25
|
}
|
25
26
|
|
26
27
|
feeders = []
|
27
28
|
|
28
29
|
opts = OptionParser.new
|
29
|
-
opts.banner = "Usage: ruby_diff.rb [options]"
|
30
|
-
|
31
|
-
opts.separator ""
|
32
|
-
opts.separator "Specific options:"
|
30
|
+
opts.banner = "Usage: ruby_diff.rb [options] sources"
|
33
31
|
|
34
32
|
opts.define_head <<-HEAD
|
35
33
|
|
@@ -39,17 +37,10 @@ ruby_diff --git HEAD --git-wd ./
|
|
39
37
|
|
40
38
|
Changes between two sets of files:
|
41
39
|
ruby_diff --file old_dir --file new_dir
|
42
|
-
|
43
40
|
HEAD
|
44
41
|
|
45
|
-
opts.
|
46
|
-
|
47
|
-
}
|
48
|
-
|
49
|
-
opts.on('--verbose', "Shows more information while processing files"){
|
50
|
-
@options[:verbose] = true
|
51
|
-
}
|
52
|
-
|
42
|
+
opts.separator ""
|
43
|
+
opts.separator "Code sources:"
|
53
44
|
opts.on('--git PATH', "Use a git repository as a code source"){|path|
|
54
45
|
feeders << feeder_mapping[:git].new(path)
|
55
46
|
}
|
@@ -58,10 +49,25 @@ opts.on('--git-wd PATH', "Use the git working directory as a code source"){|path
|
|
58
49
|
feeders << feeder_mapping[:git_wd].new(path)
|
59
50
|
}
|
60
51
|
|
52
|
+
opts.on('--svn PATH', "Use a svn repository as a code source"){|path|
|
53
|
+
feeders << feeder_mapping[:svn].new(path)
|
54
|
+
}
|
55
|
+
|
61
56
|
opts.on('--file PATH', "Use a file system path as a code source"){|path|
|
62
57
|
feeders << feeder_mapping[:file].new(path)
|
63
58
|
}
|
64
59
|
|
60
|
+
|
61
|
+
opts.separator ""
|
62
|
+
opts.separator "Options:"
|
63
|
+
opts.on('--sexp', "Show the s expressions for each input (mostly for debugging)"){
|
64
|
+
@options[:sexp] = true
|
65
|
+
}
|
66
|
+
|
67
|
+
opts.on('--verbose', "Shows more information while processing files"){
|
68
|
+
@options[:verbose] = true
|
69
|
+
}
|
70
|
+
|
65
71
|
opts.on_tail('-v', '--version') { puts "ruby_diff #{RubyDiff::VERSION}" ; exit }
|
66
72
|
opts.on_tail('-h', '--help') { puts opts; exit }
|
67
73
|
|
data/lib/ruby_diff.rb
CHANGED
@@ -11,10 +11,10 @@ require 'set'
|
|
11
11
|
require 'pp'
|
12
12
|
|
13
13
|
module RubyDiff
|
14
|
-
VERSION = "0.
|
14
|
+
VERSION = "0.2"
|
15
15
|
end
|
16
16
|
|
17
17
|
# RubyDiff
|
18
|
-
%w(code_comparison structure_processor file_feeder git_support git_feeder git_working_dir_feeder).each do |name|
|
18
|
+
%w(code_comparison structure_processor file_feeder git_support git_feeder git_working_dir_feeder svn_feeder).each do |name|
|
19
19
|
require File.expand_path(File.dirname(__FILE__) + "/ruby_diff/#{name}")
|
20
20
|
end
|
@@ -124,10 +124,12 @@ class StructureProcessor < SexpProcessor
|
|
124
124
|
|
125
125
|
def process_class(exp)
|
126
126
|
name = exp.shift
|
127
|
-
super_class = exp.shift
|
127
|
+
super_class = exp.shift
|
128
128
|
body = exp.shift
|
129
129
|
|
130
|
-
|
130
|
+
name, temp_scope = process_colon2_constants(name) if name.is_a? Array
|
131
|
+
|
132
|
+
record ClassCode.new(name, temp_scope || self.scope, body) do
|
131
133
|
s(:class, name, process(super_class), process(body))
|
132
134
|
end
|
133
135
|
end
|
@@ -136,7 +138,9 @@ class StructureProcessor < SexpProcessor
|
|
136
138
|
name = exp.shift
|
137
139
|
body = exp.shift
|
138
140
|
|
139
|
-
|
141
|
+
name, temp_scope = process_colon2_constants(name) if name.is_a? Array
|
142
|
+
|
143
|
+
record ModuleCode.new(name, temp_scope || self.scope, body) do
|
140
144
|
s(:class, name, process(body))
|
141
145
|
end
|
142
146
|
end
|
@@ -186,6 +190,22 @@ class StructureProcessor < SexpProcessor
|
|
186
190
|
end
|
187
191
|
|
188
192
|
protected
|
193
|
+
# If the class is defined as: A::B::C, then get the constants and register them.
|
194
|
+
# This is rather a dirty piece of code. Fear it.
|
195
|
+
def process_colon2_constants(array)
|
196
|
+
array = array.flatten
|
197
|
+
constants = array[array.length/-2..-1]
|
198
|
+
name = constants.pop
|
199
|
+
|
200
|
+
parent = self.scope
|
201
|
+
|
202
|
+
constants.each do |c|
|
203
|
+
parent = record ModuleCode.new(c, parent, Sexp.new)
|
204
|
+
end
|
205
|
+
|
206
|
+
[name,parent]
|
207
|
+
end
|
208
|
+
|
189
209
|
def record obj
|
190
210
|
signature = obj.signature
|
191
211
|
if !self.code_objects[signature]
|
@@ -196,7 +216,7 @@ class StructureProcessor < SexpProcessor
|
|
196
216
|
self.scope_stack << self.code_objects[signature]
|
197
217
|
result = yield if block_given?
|
198
218
|
self.scope_stack.pop
|
199
|
-
result
|
219
|
+
result || obj
|
200
220
|
end
|
201
221
|
|
202
222
|
def scope
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# A Feeder reads in files for RubyDiff's processor to
|
2
|
+
# run over. FileFeeder reads them from the file system.
|
3
|
+
#
|
4
|
+
# Example Usage:
|
5
|
+
# ruby_diff --svn PREV:file.rb --svn new_version.rb
|
6
|
+
# ruby_diff --svn http://project.server.org/lib --svn .
|
7
|
+
class SVNFeeder
|
8
|
+
attr_accessor :files
|
9
|
+
attr_accessor :path
|
10
|
+
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
# Expects something in the form of PATH
|
14
|
+
# --file [PATH]
|
15
|
+
def initialize(path)
|
16
|
+
@path = path
|
17
|
+
|
18
|
+
# TODO: Add support for SVN date format
|
19
|
+
if @path =~ /^(\d+)|HEAD|BASE|COMMITTED|PREV\:/
|
20
|
+
parts = path.split(":",2)
|
21
|
+
svn_path = parts.pop
|
22
|
+
rev = parts.shift
|
23
|
+
else
|
24
|
+
svn_path = @path
|
25
|
+
rev = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
@svn_options = (rev ? "-r #{rev} " : " ")+svn_path
|
29
|
+
|
30
|
+
@file_pattern = "**/*.rb"
|
31
|
+
|
32
|
+
@files = []
|
33
|
+
|
34
|
+
svn("ls -R #{@svn_options}").each_line do |file|
|
35
|
+
file.chomp!
|
36
|
+
@files << file if File.fnmatch(@file_pattern, file)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def each
|
41
|
+
@files.each do |file|
|
42
|
+
cat_path = File.join(@svn_options, file)
|
43
|
+
yield(svn("cat #{cat_path}"), file)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# issues a command to svn
|
49
|
+
def svn command
|
50
|
+
output = `svn #{command} 2>&1`.chomp
|
51
|
+
unless $?.success?
|
52
|
+
raise RuntimeError, output
|
53
|
+
end
|
54
|
+
output
|
55
|
+
end
|
56
|
+
end
|
data/ruby_diff.gemspec
CHANGED
@@ -1,20 +1,38 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{ruby_diff}
|
3
|
-
s.version = "0.
|
4
|
-
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.
|
8
|
-
s.rubyforge_project = %q{rubydiff}
|
9
|
-
s.description = %q{}
|
3
|
+
s.version = "0.2"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Adam Sanderson"]
|
7
|
+
s.date = %q{2008-10-02}
|
10
8
|
s.default_executable = %q{ruby_diff}
|
9
|
+
s.description = %q{}
|
10
|
+
s.email = ["netghost@gmail.com"]
|
11
|
+
s.executables = ["ruby_diff"]
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
13
|
+
s.files = [".gitignore", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/ruby_diff", "lib/ruby_diff.rb", "lib/ruby_diff/code_comparison.rb", "lib/ruby_diff/file_feeder.rb", "lib/ruby_diff/git_feeder.rb", "lib/ruby_diff/git_support.rb", "lib/ruby_diff/git_working_dir_feeder.rb", "lib/ruby_diff/patterns.rb", "lib/ruby_diff/structure_processor.rb", "lib/ruby_diff/svn_feeder.rb", "ruby_diff.gemspec", "test/code_comparison_test.rb", "test/file_feeder_test.rb", "test/git_feeder_test.rb", "test/git_sample/README", "test/git_sample/book.rb", "test/git_sample/lib/chapter.rb", "test/git_working_dir_feeder_test.rb", "test/structure_processor_test.rb"]
|
11
14
|
s.has_rdoc = true
|
12
|
-
s.
|
13
|
-
s.files = [".gitignore", "README.txt", "Rakefile", "bin/ruby_diff", "lib/ruby_diff.rb", "lib/ruby_diff/code_comparison.rb", "lib/ruby_diff/file_feeder.rb", "lib/ruby_diff/git_feeder.rb", "lib/ruby_diff/patterns.rb", "lib/ruby_diff/structure_processor.rb", "ruby_diff.gemspec", "test/file_feeder_test.rb", "test/git_feeder_test.rb", "test/git_sample/README", "test/git_sample/book.rb", "test/git_sample/lib/chapter.rb", "test/structure_processor_test.rb"]
|
14
|
-
s.test_files = ["test/git_feeder_test.rb", "test/file_feeder_test.rb", "test/structure_processor_test.rb"]
|
15
|
+
s.homepage = %q{RubyDiff does higher level comparisons of ruby code.}
|
15
16
|
s.rdoc_options = ["--main", "README.txt"]
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
s.
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{rubydiff}
|
19
|
+
s.rubygems_version = %q{1.2.0}
|
20
|
+
s.summary = %q{a higher level diff application for analyzing changes to ruby code}
|
21
|
+
s.test_files = ["test/git_feeder_test.rb", "test/file_feeder_test.rb", "test/code_comparison_test.rb", "test/structure_processor_test.rb", "test/git_working_dir_feeder_test.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if current_version >= 3 then
|
28
|
+
s.add_runtime_dependency(%q<ParseTree>, ["~> 2.1"])
|
29
|
+
s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<ParseTree>, ["~> 2.1"])
|
32
|
+
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<ParseTree>, ["~> 2.1"])
|
36
|
+
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
37
|
+
end
|
20
38
|
end
|
@@ -79,13 +79,54 @@ class StructureProcessorTestCase < Test::Unit::TestCase
|
|
79
79
|
CODE
|
80
80
|
end
|
81
81
|
|
82
|
+
def test_simple_class
|
83
|
+
assert_signatures <<-CODE, ["A"], [ClassCode]
|
84
|
+
class A
|
85
|
+
end
|
86
|
+
CODE
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_class_in_module
|
90
|
+
assert_signatures <<-CODE, ["B", "B::A"], [ClassCode,ModuleCode]
|
91
|
+
module B
|
92
|
+
class A
|
93
|
+
end
|
94
|
+
end
|
95
|
+
CODE
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_namespaced_class
|
99
|
+
assert_signatures <<-CODE, ["C::B::A"], [ClassCode]
|
100
|
+
class C::B::A
|
101
|
+
end
|
102
|
+
CODE
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_namespaced_module
|
106
|
+
assert_signatures <<-CODE, ["C", "C::B", "C::B::A"], [ModuleCode]
|
107
|
+
module C::B::A
|
108
|
+
end
|
109
|
+
CODE
|
110
|
+
end
|
111
|
+
|
112
|
+
# Lets just be nuts...
|
113
|
+
def test_nested_namespaced_class
|
114
|
+
assert_signatures <<-CODE, ["C", "C::B", "C::B::A", "C::B::A::D"], [ModuleCode, ClassCode]
|
115
|
+
module C::B::A
|
116
|
+
class D
|
117
|
+
end
|
118
|
+
end
|
119
|
+
CODE
|
120
|
+
end
|
121
|
+
|
82
122
|
def assert_signatures(code, signatures, types=[MethodCode])
|
83
123
|
sexp = ParseTree.new.parse_tree_for_string(code)
|
124
|
+
serialized = sexp.pretty_inspect
|
84
125
|
processor = StructureProcessor.new()
|
85
126
|
processor.process(* sexp)
|
86
127
|
|
87
128
|
found_signatures = processor.code_objects.values.select{|co| types.include?(co.class)}.map{|key| key.signature }.sort
|
88
|
-
assert_equal signatures.sort, found_signatures
|
129
|
+
assert_equal signatures.sort, found_signatures, "Sexp was:\n#{serialized}"
|
89
130
|
end
|
90
131
|
|
91
|
-
end
|
132
|
+
end
|
metadata
CHANGED
@@ -1,34 +1,48 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: ruby_diff
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2008-06-09 00:00:00 -07:00
|
8
|
-
summary: a higher level diff application for analyzing changes to ruby code
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email:
|
12
|
-
- netghost@gmail.com
|
13
|
-
homepage: RubyDiff does higher level comparisons of ruby code.
|
14
|
-
rubyforge_project: rubydiff
|
15
|
-
description: ""
|
16
|
-
autorequire:
|
17
|
-
default_executable:
|
18
|
-
bindir: bin
|
19
|
-
has_rdoc: true
|
20
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
-
requirements:
|
22
|
-
- - ">"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.0.0
|
25
|
-
version:
|
4
|
+
version: "0.2"
|
26
5
|
platform: ruby
|
27
|
-
signing_key:
|
28
|
-
cert_chain:
|
29
|
-
post_install_message:
|
30
6
|
authors:
|
31
7
|
- Adam Sanderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-02 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ParseTree
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "2.1"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.0
|
34
|
+
version:
|
35
|
+
description: ""
|
36
|
+
email:
|
37
|
+
- netghost@gmail.com
|
38
|
+
executables:
|
39
|
+
- ruby_diff
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- README.txt
|
32
46
|
files:
|
33
47
|
- .gitignore
|
34
48
|
- History.txt
|
@@ -44,6 +58,7 @@ files:
|
|
44
58
|
- lib/ruby_diff/git_working_dir_feeder.rb
|
45
59
|
- lib/ruby_diff/patterns.rb
|
46
60
|
- lib/ruby_diff/structure_processor.rb
|
61
|
+
- lib/ruby_diff/svn_feeder.rb
|
47
62
|
- ruby_diff.gemspec
|
48
63
|
- test/code_comparison_test.rb
|
49
64
|
- test/file_feeder_test.rb
|
@@ -53,41 +68,36 @@ files:
|
|
53
68
|
- test/git_sample/lib/chapter.rb
|
54
69
|
- test/git_working_dir_feeder_test.rb
|
55
70
|
- test/structure_processor_test.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: RubyDiff does higher level comparisons of ruby code.
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options:
|
75
|
+
- --main
|
76
|
+
- README.txt
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: rubydiff
|
94
|
+
rubygems_version: 1.2.0
|
95
|
+
signing_key:
|
96
|
+
specification_version: 2
|
97
|
+
summary: a higher level diff application for analyzing changes to ruby code
|
56
98
|
test_files:
|
57
99
|
- test/git_feeder_test.rb
|
58
100
|
- test/file_feeder_test.rb
|
59
101
|
- test/code_comparison_test.rb
|
60
102
|
- test/structure_processor_test.rb
|
61
103
|
- test/git_working_dir_feeder_test.rb
|
62
|
-
rdoc_options:
|
63
|
-
- --main
|
64
|
-
- README.txt
|
65
|
-
extra_rdoc_files:
|
66
|
-
- History.txt
|
67
|
-
- Manifest.txt
|
68
|
-
- README.txt
|
69
|
-
executables:
|
70
|
-
- ruby_diff
|
71
|
-
extensions: []
|
72
|
-
|
73
|
-
requirements: []
|
74
|
-
|
75
|
-
dependencies:
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: ParseTree
|
78
|
-
version_requirement:
|
79
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 2.0.2
|
84
|
-
version:
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: hoe
|
87
|
-
version_requirement:
|
88
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
89
|
-
requirements:
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 1.5.3
|
93
|
-
version:
|