diff-lcs 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,11 +1,19 @@
1
- Revision history for Ruby library Diff::LCS. Unless explicitly noted otherwise,
2
- all changes are produced by Austin Ziegler <diff-lcs@halostatue.ca>.
3
-
4
- == Diff::LCS 1.1.2
5
- * Fixed a problem reported by Mauricio Fernandez in htmldiff. Future versions
6
- of Diff::LCS will be removing this program.
7
-
8
- == Diff::LCS 1.1.1
1
+ == 1.1.3 / 2011-08-27
2
+ * Converted to 'hoe' for release.
3
+ * Converted tests to RSpec 2.
4
+ * Extracted the body of htmldiff into a class available from
5
+ diff/lcs/htmldiff.
6
+ * Migrated development and issue tracking to GitHub.
7
+ * Bugs fixed:
8
+ - Eliminated the explicit use of RubyGems in both bin/htmldiff and bin/ldiff.
9
+ Resolves issue 4 (https://github.com/halostatue/diff-lcs/issues/4).
10
+ - Eliminated Ruby warnings. Resolves issue 3
11
+ (https://github.com/halostatue/diff-lcs/issues/3).
12
+
13
+ == 1.1.2 / 2004-10-20
14
+ * Fixed a problem reported by Mauricio Fernandez in htmldiff.
15
+
16
+ == 1.1.1 / 2004-09-25
9
17
  * Fixed bug #891:
10
18
  http://rubyforge.org/tracker/?func=detail&atid=407&aid=891&group_id=84
11
19
  * Fixed a problem with callback initialisation code (it assumed that all
@@ -14,33 +22,33 @@ all changes are produced by Austin Ziegler <diff-lcs@halostatue.ca>.
14
22
  * Modified the non-initialisable callbacks to have a private #new method.
15
23
  * Moved ldiff core code to Diff::LCS::Ldiff (diff/lcs/ldiff.rb).
16
24
 
17
- == Diff::LCS 1.1.0
25
+ == 1.1.0 / -
18
26
  * Eliminated the need for Diff::LCS::Event and removed it.
19
27
  * Added a contextual diff callback, Diff::LCS::ContextDiffCallback.
20
28
  * Implemented patching/unpatching for standard Diff callback output formats
21
29
  with both #diff and #sdiff.
22
30
  * Extensive documentation changes.
23
31
 
24
- == Diff::LCS 1.0.4
32
+ == 1.0.4 / -
25
33
  * Fixed a problem with bin/ldiff output, especially for unified format.
26
34
  Newlines that should have been present weren't.
27
35
  * Changed the .tar.gz installer to generate Windows batch files if ones do not
28
36
  exist already. Removed the existing batch files as they didn't work.
29
37
 
30
- == Diff::LCS 1.0.3
38
+ == 1.0.3 / -
31
39
  * Fixed a problem with #traverse_sequences where the first difference from the
32
40
  left sequence might not be appropriately captured.
33
41
 
34
- == Diff::LCS 1.0.2
42
+ == 1.0.2 / -
35
43
  * Fixed an issue with ldiff not working because actions were changed from
36
44
  symbols to strings.
37
45
 
38
- == Diff::LCS 1.0.1
46
+ == 1.0.1 / -
39
47
  * Minor modifications to the gemspec, the README.
40
48
  * Renamed the diff program to ldiff (as well as the companion batch file) so as
41
49
  to not collide with the standard diff program.
42
- * Fixed issues with RubyGEMs. Requires RubyGems > 0.6.1 or >= 0.6.1 with the
50
+ * Fixed issues with RubyGems. Requires RubyGems > 0.6.1 or >= 0.6.1 with the
43
51
  latest CVS version.
44
52
 
45
- == Diff::LCS 1.0
53
+ == 1.0 / -
46
54
  * Initial release based mostly on Perl's Algorithm::Diff.
@@ -0,0 +1,38 @@
1
+ == License
2
+
3
+ This software is available under three licenses: the GNU GPL version 2 (or at
4
+ your option, a later version), the Perl Artistic license, or the MIT license.
5
+ Note that my preference for licensing is the MIT license, but Algorithm::Diff
6
+ was dually originally licensed with the Perl Artistic and the GNU GPL ("the
7
+ same terms as Perl itself") and that the Ruby implementation hews pretty
8
+ closely to the Perl version, so I must maintain the additional licensing terms.
9
+
10
+ * Copyright 2004–2011 Austin Ziegler.
11
+ * Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk versionby
12
+ Mario I. Wolczko <mario@wolczko.com>
13
+
14
+ === MIT License
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
17
+ this software and associated documentation files (the "Software"), to deal in
18
+ the Software without restriction, including without limitation the rights to
19
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
20
+ of the Software, and to permit persons to whom the Software is furnished to do
21
+ so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
33
+
34
+ === Perl Artistic License (version 2)
35
+ See the file docs/artistic.txt in the main distribution.
36
+
37
+ === GNU GPL version 2
38
+ See the file docs/COPYING.txt in the main distribution.
@@ -0,0 +1,27 @@
1
+ History.rdoc
2
+ License.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/htmldiff
7
+ bin/ldiff
8
+ diff-lcs.gemspec
9
+ docs/COPYING.txt
10
+ docs/artistic.html
11
+ lib/diff-lcs.rb
12
+ lib/diff/lcs.rb
13
+ lib/diff/lcs/array.rb
14
+ lib/diff/lcs/block.rb
15
+ lib/diff/lcs/callbacks.rb
16
+ lib/diff/lcs/change.rb
17
+ lib/diff/lcs/htmldiff.rb
18
+ lib/diff/lcs/hunk.rb
19
+ lib/diff/lcs/ldiff.rb
20
+ lib/diff/lcs/string.rb
21
+ spec/diff_spec.rb
22
+ spec/lcs_spec.rb
23
+ spec/patch_spec.rb
24
+ spec/sdiff_spec.rb
25
+ spec/spec_helper.rb
26
+ spec/traverse_balanced_spec.rb
27
+ spec/traverse_sequences_spec.rb
@@ -0,0 +1,72 @@
1
+ = diff-lcs
2
+
3
+ == Description
4
+ Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt
5
+ longest common subsequence (LCS) algorithm to compute intelligent differences
6
+ between two sequenced enumerable containers. The implementation is based on
7
+ Mario I. Wolczko's {Smalltalk version 1.2}[ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st]
8
+ (1993) and Ned Konz's Perl version
9
+ {Algorithm::Diff 1.15}[http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15/].
10
+
11
+ This is release 1.1.3, fixing several small bugs found over the years. Version
12
+ 1.1.0 added new features, including the ability to #patch and #unpatch changes
13
+ as well as a new contextual diff callback, Diff::LCS::ContextDiffCallbacks,
14
+ that should improve the context sensitivity of patching.
15
+
16
+ This library is called Diff::LCS because of an early version of Algorithm::Diff
17
+ which was restrictively licensed. This version has seen a minor license change:
18
+ instead of being under Ruby's license as an option, the third optional license
19
+ is the MIT license.
20
+
21
+ == Where
22
+
23
+ * {GitHub}[https://github.com/halostatue/diff-lcs]
24
+
25
+ This is the new home of Diff::LCS (diff-lcs). The Ruwiki page still refers to
26
+ it, but development is not happening there any longer.
27
+
28
+ == Synopsis
29
+
30
+ Using this module is quite simple. By default, Diff::LCS does not extend
31
+ objects with the Diff::LCS interface, but will be called as if it were a
32
+ function:
33
+
34
+ require 'diff/lcs'
35
+
36
+ seq1 = %w(a b c e h j l m n p)
37
+ seq2 = %w(b c d e f j k l m r s t)
38
+
39
+ lcs = Diff::LCS.LCS(seq1, seq2)
40
+ diffs = Diff::LCS.diff(seq1, seq2)
41
+ sdiff = Diff::LCS.sdiff(seq1, seq2)
42
+ seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj)
43
+ bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj)
44
+ seq2 == Diff::LCS.patch!(seq1, diffs)
45
+ seq1 == Diff::LCS.unpatch!(seq2, diffs)
46
+ seq2 == Diff::LCS.patch!(seq1, sdiff)
47
+ seq1 == Diff::LCS.unpatch!(seq2, sdiff)
48
+
49
+ Objects can be extended with Diff::LCS:
50
+
51
+ seq1.extend(Diff::LCS)
52
+ lcs = seq1.lcs(seq2)
53
+ diffs = seq1.diff(seq2)
54
+ sdiff = seq1.sdiff(seq2)
55
+ seq = seq1.traverse_sequences(seq2, callback_obj)
56
+ bal = seq1.traverse_balanced(seq2, callback_obj)
57
+ seq2 == seq1.patch!(diffs)
58
+ seq1 == seq2.unpatch!(diffs)
59
+ seq2 == seq1.patch!(sdiff)
60
+ seq1 == seq2.unpatch!(sdiff)
61
+
62
+ By requiring 'diff/lcs/array' or 'diff/lcs/string', Array or String will be
63
+ extended for use this way.
64
+
65
+ Note that Diff::LCS requires a sequenced enumerable container, which means that
66
+ the order of enumeration is both predictable and consistent for the same set of
67
+ data. While it is theoretically possible to generate a diff for unordereded
68
+ hash, it will only be meaningful if the enumeration of the hashes is
69
+ consistent. In general, this will mean that containers that behave like String
70
+ or Array will perform best.
71
+
72
+ :include: License.rdoc
data/Rakefile CHANGED
@@ -1,116 +1,26 @@
1
- #! /usr/bin/env rake
2
- $LOAD_PATH.unshift('lib')
1
+ # -*- ruby encoding: utf-8 -*-
3
2
 
4
3
  require 'rubygems'
5
- require 'rake/gempackagetask'
6
- require 'rake/contrib/rubyforgepublisher'
7
- require 'diff/lcs'
8
- require 'archive/tar/minitar'
9
- require 'zlib'
4
+ require 'rspec'
5
+ require 'hoe'
10
6
 
11
- DISTDIR = "diff-lcs-#{Diff::LCS::VERSION}"
12
- TARDIST = "../#{DISTDIR}.tar.gz"
7
+ Hoe.plugin :doofus
8
+ Hoe.plugin :gemspec
9
+ Hoe.plugin :git
13
10
 
14
- DATE_RE = %r<(\d{4})[./-]?(\d{2})[./-]?(\d{2})(?:[\sT]?(\d{2})[:.]?(\d{2})[:.]?(\d{2})?)?>
11
+ Hoe.spec 'diff-lcs' do
12
+ self.rubyforge_name = 'ruwiki'
15
13
 
16
- if ENV['RELEASE_DATE']
17
- year, month, day, hour, minute, second = DATE_RE.match(ENV['RELEASE_DATE']).captures
18
- year ||= 0
19
- month ||= 0
20
- day ||= 0
21
- hour ||= 0
22
- minute ||= 0
23
- second ||= 0
24
- ReleaseDate = Time.mktime(year, month, day, hour, minute, second)
25
- else
26
- ReleaseDate = nil
27
- end
28
-
29
- task :test do |t|
30
- require 'test/unit/testsuite'
31
- require 'test/unit/ui/console/testrunner'
32
-
33
- runner = Test::Unit::UI::Console::TestRunner
34
-
35
- $LOAD_PATH.unshift('tests')
36
- $stderr.puts "Checking for test cases:" if t.verbose
37
- Dir['tests/*test*.rb'].each do |testcase|
38
- $stderr.puts "\t#{testcase}" if t.verbose
39
- load testcase
40
- end
41
-
42
- suite = Test::Unit::TestSuite.new
43
-
44
- ObjectSpace.each_object(Class) do |testcase|
45
- suite << testcase.suite if testcase < Test::Unit::TestCase
46
- end
47
-
48
- runner.run(suite)
49
- end
14
+ developer('Austin Ziegler', 'austin@rubyforge.org')
50
15
 
51
- spec = eval(File.read("diff-lcs.gemspec"))
52
- desc "Build the RubyGem for Diff::LCS."
53
- task :gem => [ :test ]
54
- Rake::GemPackageTask.new(spec) do |g|
55
- g.need_tar = false
56
- g.need_zip = false
57
- g.package_dir = ".."
58
- end
59
-
60
- desc "Build an Diff::LCS .tar.gz distribution."
61
- task :tar => [ TARDIST ]
62
- file TARDIST => [ :test ] do |t|
63
- current = File.basename(Dir.pwd)
64
- Dir.chdir("..") do
65
- begin
66
- files = Dir["#{current}/**/*"].select { |dd| dd !~ %r{(?:/CVS/?|~$)} }
67
- files.map! do |dd|
68
- ddnew = dd.gsub(/^#{current}/, DISTDIR)
69
- mtime = ReleaseDate || File.stat(dd).mtime
70
- if File.directory?(dd)
71
- { :name => ddnew, :mode => 0755, :dir => true, :mtime => mtime }
72
- else
73
- if dd =~ %r{bin/}
74
- mode = 0755
75
- else
76
- mode = 0644
77
- end
78
- data = File.read(dd)
79
- { :name => ddnew, :mode => mode, :data => data, :size => data.size,
80
- :mtime => mtime }
81
- end
82
- end
83
-
84
- ff = File.open(t.name.gsub(%r{^\.\./}o, ''), "wb")
85
- gz = Zlib::GzipWriter.new(ff)
86
- tw = Archive::Tar::Minitar::Writer.new(gz)
87
-
88
- files.each do |entry|
89
- if entry[:dir]
90
- tw.mkdir(entry[:name], entry)
91
- else
92
- tw.add_file_simple(entry[:name], entry) { |os| os.write(entry[:data]) }
93
- end
94
- end
95
- ensure
96
- tw.close if tw
97
- gz.close if gz
98
- end
99
- end
100
- end
101
- task TARDIST => [ :test ]
16
+ self.remote_rdoc_dir = 'diff-lcs/rdoc'
17
+ self.rsync_args << ' --exclude=statsvn/'
102
18
 
103
- def sign(file)
104
- sh %("C:\\Program Files\\Windows Privacy Tools\\GnuPG\\Gpg.exe" -ba #{file}) rescue nil
105
- end
19
+ self.history_file = 'History.rdoc'
20
+ self.readme_file = 'README.rdoc'
21
+ self.extra_rdoc_files = FileList["*.rdoc"].to_a
106
22
 
107
- task :signtar => [ :tar ] do
108
- sign TARDIST
109
- end
110
- task :signgem => [ :gem ] do
111
- sign "../#{DISTDIR}.gem"
23
+ self.extra_dev_deps << ['rspec', '~> 2.0']
112
24
  end
113
25
 
114
- desc "Build everything."
115
- task :default => [ :signtar, :signgem ] do
116
- end
26
+ # vim: syntax=ruby
@@ -1,112 +1,32 @@
1
- #!/usr/bin/env ruby
2
- #--
3
- # Copyright 2004 Austin Ziegler <diff-lcs@halostatue.ca>
4
- # adapted from:
5
- # Algorithm::Diff (Perl) by Ned Konz <perl@bike-nomad.com>
6
- # Smalltalk by Mario I. Wolczko <mario@wolczko.com>
7
- # implements McIlroy-Hunt diff algorithm
8
- #
9
- # This program is free software. It may be redistributed and/or modified under
10
- # the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
11
- # Ruby licence.
12
- #
13
- # $Id: htmldiff,v 1.6 2004/10/17 19:33:21 austin Exp $
14
- #++
1
+ #!ruby -w
2
+
3
+ require 'diff/lcs'
4
+ require 'diff/lcs/htmldiff'
15
5
 
16
6
  begin
17
- require 'rubygems'
18
- require_gem 'diff-lcs', "1.1.1"
19
- require 'diff/lcs/string'
7
+ require 'text/format'
20
8
  rescue LoadError
21
- require 'diff/lcs'
22
- require 'diff/lcs/string'
9
+ Diff::LCS::HTMLDiff.can_expand_tabs = false
23
10
  end
24
11
 
25
- require 'text/format'
12
+ if ARGV.size < 2 or ARGV.size > 3
13
+ $stderr.puts "usage: #{File.basename($0)} old new [output.html]"
14
+ $stderr.puts " #{File.basename($0)} old new > output.html"
15
+ exit 127
16
+ end
26
17
 
27
- class HTMLDiff #:nodoc:
28
- attr_accessor :output
18
+ left = IO.read(ARGV[0]).split($/)
19
+ right = IO.read(ARGV[1]).split($/)
29
20
 
30
- def initialize(output)
31
- @output = output
32
- end
21
+ options = { :title => "diff #{ARGV[0]} #{ARGV[1]}" }
33
22
 
34
- # This will be called with both lines are the same
35
- def match(event)
36
- @output << %Q|<pre class="match">#{event.old_element}</pre>\n|
37
- end
23
+ htmldiff = Diff::LCS::HTMLDiff.new(left, right, options)
38
24
 
39
- # This will be called when there is a line in A that isn't in B
40
- def discard_a(event)
41
- @output << %Q|<pre class="only_a">#{event.old_element}</pre>\n|
25
+ if ARGV[2]
26
+ File.open(ARGV[2], "w") do |f|
27
+ htmldiff.options[:output] = f
28
+ htmldiff.run
42
29
  end
43
-
44
- # This will be called when there is a line in B that isn't in A
45
- def discard_b(event)
46
- @output << %Q|<pre class="only_b">#{event.new_element}</pre>\n|
47
- end
48
- end
49
-
50
- if ARGV.size != 2
51
- puts "usage: #{File.basename($0)} old new > output.html"
52
- exit 255
30
+ else
31
+ htmldiff.run
53
32
  end
54
-
55
- hd = HTMLDiff.new($stdout)
56
- tf = Text::Format.new
57
- tf.tabstop = 4
58
-
59
- preprocess = lambda { |line| tf.expand(line.chomp) }
60
-
61
- a = IO.readlines(ARGV[0]).map(&preprocess)
62
- b = IO.readlines(ARGV[1]).map(&preprocess)
63
-
64
- $stdout.write <<-START
65
- <html>
66
- <head>
67
- <title>diff #{ARGV[0]} #{ARGV[1]}</title>
68
- <style>
69
- body { margin: 0; }
70
- .diff
71
- {
72
- border: 1px solid black;
73
- margin: 1em 2em;
74
- }
75
- pre
76
- {
77
- padding-left: 1em;
78
- margin: 0;
79
- font-family: Lucida, Courier, monospaced;
80
- white-space: pre;
81
- }
82
- .match { }
83
- .only_a
84
- {
85
- background-color: #fdd;
86
- color: red;
87
- text-decoration: line-through;
88
- }
89
- .only_b
90
- {
91
- background-color: #ddf;
92
- color: blue;
93
- border-left: 3px solid blue
94
- }
95
- h1 { margin-left: 2em; }
96
- </style>
97
- </head>
98
- <body>
99
- <h1>diff&nbsp;
100
- <span class="only_a">#{ARGV[0]}</span>&nbsp;
101
- <span class="only_b">#{ARGV[1]}</span>
102
- </h1>
103
- <div class="diff">
104
- START
105
-
106
- Diff::LCS.traverse_sequences(a, b, hd)
107
-
108
- $stdout.write <<-END
109
- </div>
110
- </body>
111
- </html>
112
- END