Skip to content

Commit

Permalink
Merge pull request #66 from halostatue/misplaced-chunk-issue-65
Browse files Browse the repository at this point in the history
diff-lcs 1.4.4 - Fix broken formatting
  • Loading branch information
halostatue committed Jul 1, 2020
2 parents 99f65fd + b75e0bd commit 381ad11
Show file tree
Hide file tree
Showing 29 changed files with 565 additions and 201 deletions.
26 changes: 19 additions & 7 deletions .rubocop.yml
Expand Up @@ -7,7 +7,7 @@ AllCops:
- diff-lcs.gemspec
- research/**/*

Layout/AlignParameters:
Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation

Layout/DotPosition:
Expand All @@ -20,7 +20,7 @@ Layout/ExtraSpacing:
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Metrics/LineLength:
Layout/LineLength:
Max: 110

Naming/FileName:
Expand All @@ -30,17 +30,15 @@ Naming/FileName:
Naming/MemoizedInstanceVariableName:
Exclude: []

Naming/UncommunicativeMethodParamName:
Naming/MethodParameterName:
Exclude:
- lib/diff/lcs/internals.rb
- lib/diff/lcs/hunk.rb
- spec/spec_helper.rb

Naming/VariableNumber:
Exclude: []

Performance/Caller:
Exclude: []

Security/MarshalLoad:
Exclude: []

Expand Down Expand Up @@ -91,7 +89,7 @@ Style/RescueStandardError:
Style/SignalException:
EnforcedStyle: semantic

Layout/IndentHeredoc: { Enabled: false }
Layout/HeredocIndentation: { Enabled: false }
Metrics/AbcSize: { Enabled: false }
Metrics/BlockLength: { Enabled: false }
Metrics/BlockNesting: { Enabled: false }
Expand Down Expand Up @@ -119,3 +117,17 @@ Style/SpecialGlobalVars: { Enabled: false }
Style/SymbolArray: { Enabled: false }
Style/SymbolProc: { Enabled: false }
Style/WordArray: { Enabled: false }

Layout/EmptyLinesAroundAttributeAccessor: { Enabled: true }
Layout/SpaceAroundMethodCallOperator: { Enabled: true }
Lint/DeprecatedOpenSSLConstant: { Enabled: true }
Lint/MixedRegexpCaptureTypes: { Enabled: true }
Lint/RaiseException: { Enabled: true }
Lint/StructNewOverride: { Enabled: true }
Style/ExponentialNotation: { Enabled: true }
Style/HashEachMethods: { Enabled: true }
Style/HashTransformKeys: { Enabled: true }
Style/HashTransformValues: { Enabled: true }
Style/RedundantRegexpCharacterClass: { Enabled: true }
Style/RedundantRegexpEscape: { Enabled: true }
Style/SlicingWithRange: { Enabled: true }
132 changes: 83 additions & 49 deletions Contributing.md
@@ -1,84 +1,118 @@
## Contributing

I value any contribution to Diff::LCS you can provide: a bug report, a feature
request, or code contributions. Code contributions to Diff::LCS are especially
<del>welcome</del>encouraged. Because Diff::LCS is a complex codebase, there
are a few guidelines:

* Code changes *will not* be accepted without tests. The test suite is
written with [RSpec][].
* Match my coding style.
* Use a thoughtfully-named topic branch that contains your change. Rebase
your commits into logical chunks as necessary.
* Use [quality commit messages][].
* Do not change the version number; when your patch is accepted and a release
is made, the version will be updated at that point.
* Submit a GitHub pull request with your changes.
* New or changed behaviours require appropriate documentation.
I value any contribution to Diff::LCS you can provide: a bug report, a
feature request, or code contributions. Code contributions to Diff::LCS are
especially <del>welcome</del>encouraged. Because Diff::LCS is a complex
codebase, there are a few guidelines:

- Code changes _will not_ be accepted without tests. The test suite is
written with [RSpec][].
- Match my coding style.
- Use a thoughtfully-named topic branch that contains your change. Rebase
your commits into logical chunks as necessary.
- Use [quality commit messages][].
- Do not change the version number; when your patch is accepted and a release
is made, the version will be updated at that point.
- Submit a GitHub pull request with your changes.
- New or changed behaviours require appropriate documentation.

### Test Dependencies

Diff::LCS uses Ryan Davis’s [Hoe][] to manage the release process, and it adds
a number of rake tasks. You will mostly be interested in:
Diff::LCS uses Ryan Davis’s [Hoe][] to manage the release process, and it
adds a number of rake tasks. You will mostly be interested in:

$ rake
```sh
$ rake
```

which runs the tests the same way that:

$ rake spec
$ rake travis
```sh
$ rake spec
```

will do.

To assist with the installation of the development dependencies, I have
provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file. This
will permit you to do:

$ bundle install
```sh
$ bundle install
```

to get the development dependencies. If you aleady have `hoe` installed, you
can accomplish the same thing with:

$ rake newb
```sh
$ rake newb
```

This task will install any missing dependencies, run the tests/specs, and
generate the RDoc.

You can run tests with code coverage analysis by running:

$ rake spec:coverage
```sh
$ rake spec:coverage
```

### Workflow

Here's the most direct way to get your work merged into the project:

* Fork the project.
* Clone down your fork (`git clone git://github.com/<username>/diff-lcs.git`).
* Create a topic branch to contain your change (`git checkout -b
my_awesome_feature`).
* Hack away, add tests. Not necessarily in that order.
* Make sure everything still passes by running `rake`.
* If necessary, rebase your commits into logical chunks, without errors.
* Push the branch up (`git push origin my_awesome_feature`).
* Create a pull request against halostatue/diff-lcs and describe what your
change does and the why you think it should be merged.
- Fork the project.
- Clone down your fork (`git clone git://github.com/<username>/diff-lcs.git`).
- Create a topic branch to contain your change (`git checkout -b my_awesome_feature`).
- Hack away, add tests. Not necessarily in that order.
- Make sure everything still passes by running `rake`.
- If necessary, rebase your commits into logical chunks, without errors.
- Push the branch up (`git push origin my_awesome_feature`).
- Create a pull request against halostatue/diff-lcs and describe what your
change does and the why you think it should be merged.

### Contributors

* Austin Ziegler created Diff::LCS.

Thanks to everyone else who has contributed to Diff::LCS:

* Kenichi Kamiya
* Michael Granger
* Vít Ondruch
* Jon Rowe
* Koichi Ito
* Josef Strzibny
* Josh Bronson
* Mark Friedgan
* Akinori MUSHA

[Rspec]: http://rspec.info/documentation/
- Austin Ziegler created Diff::LCS.

Thanks to everyone else who has contributed code or bug reports to Diff::LCS:

- @ginriki
- @joshbronson
- @kevinmook
- @mckaz
- Akinori Musha
- Artem Ignatyev
- Brandon Fish
- Camille Drapier
- Cédric Boutillier
- Gregg Kellogg
- Jagdeep Singh
- Jason Gladish
- Jon Rowe
- Josef Strzibny
- Josep (@apuratepp)
- Josh Bronson
- Jun Aruga
- Kenichi Kamiya
- Kensuke Nagae
- Kevin Ansfield
- Koichi Ito
- Mark Friedgan
- Michael Granger
- Myron Marston
- Nicolas Leger
- Oleg Orlov
- Paul Kunysch
- Pete Higgins
- Peter Wagenet
- Philippe Lafoucrière
- Ryan Lovelett
- Scott Steele
- Simon Courtois
- Tomas Jura
- Vít Ondruch

[rspec]: http://rspec.info/documentation/
[quality commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[Hoe]: https://github.com/seattlerb/hoe
[hoe]: https://github.com/seattlerb/hoe
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -6,14 +6,15 @@
source 'https://rubygems.org/'

if RUBY_VERSION < '1.9'
gem 'hoe', '~> 3.20'
gem 'rake', '< 11'
gem 'rdoc', '< 4'
gem 'hoe', '~> 3.20'

gem 'ruby-debug'
elsif RUBY_VERSION >= '2.0'
if RUBY_ENGINE == 'ruby'
gem 'simplecov', '~> 0.18'

gem 'byebug'
end
end
Expand Down
41 changes: 41 additions & 0 deletions History.md
@@ -1,5 +1,42 @@
# History

## 1.4.4 / 2020-07-01

- Fixed an issue reported by Jun Aruga in the Diff::LCS::Ldiff binary text
detection. [#44][]
- Fixed a theoretical issue reported by Jun Aruga in Diff::LCS::Hunk to raise
a more useful exception. [#43][]
- Added documentation that should address custom object issues as reported in
[#35][].

- Fixed more diff errors, in part reported in [#65][].

- The use of `Numeric#abs` is incorrect in `Diff::LCS::Block#diff_size`.
The diff size _must_ be accurate for correct change placement.
- When selecting @max_diff_size in Diff::LCS::Hunk, choose it based on
`block.diff_size.abs`.
- Made a number of changes that will, unfortunately, increase allocations
at the cost of being safe with frozen strings.
- Add some knowledge that when `Diff::LCS::Hunk#diff` is called, that we
are processing the _last_ hunk, so some changes will be made to how the
output is generated.

- `old`, `ed`, and `reverse_ed` formats have no differences.
- `unified` format will report `\ No newline at end of file` given the
correct conditions, at most once. Unified range reporting also
differs for the last hunk such that the `length` of the range is
reduced by one.
- `context` format will report `\No newline at end of file` given the
correct conditions, up to once per "file". Context range reporting also
differs for the last hunk such that the `end` part of the range is
reduced by one to a minimum of one.

- Added a bunch more tests for the cases above, and fixed `hunk_spec.rb` so
that the phrase being compared isn't nonsense French.

- Updated formatting.
- Added a Rake task to assist with manual testing on Ruby 1.8.

## 1.4.3 / 2020-06-29

- Fixed several issues with the 1.4 on Rubies older than 2.0. Some of this was
Expand Down Expand Up @@ -263,8 +300,11 @@
[#29]: https://github.com/halostatue/diff-lcs/pull/29
[#33]: https://github.com/halostatue/diff-lcs/issues/33
[#34]: https://github.com/halostatue/diff-lcs/pull/34
[#35]: https://github.com/halostatue/diff-lcs/issues/35
[#36]: https://github.com/halostatue/diff-lcs/pull/36
[#38]: https://github.com/halostatue/diff-lcs/issues/38
[#43]: https://github.com/halostatue/diff-lcs/issues/43
[#44]: https://github.com/halostatue/diff-lcs/issues/44
[#47]: https://github.com/halostatue/diff-lcs/pull/47
[#48]: https://github.com/halostatue/diff-lcs/issues/48
[#49]: https://github.com/halostatue/diff-lcs/pull/49
Expand All @@ -276,3 +316,4 @@
[#60]: https://github.com/halostatue/diff-lcs/issues/60
[#61]: https://github.com/halostatue/diff-lcs/pull/61
[#63]: https://github.com/halostatue/diff-lcs/issues/63
[#65]: https://github.com/halostatue/diff-lcs/issues/65
29 changes: 23 additions & 6 deletions Rakefile
Expand Up @@ -10,18 +10,19 @@ Hoe.plugin :gemspec2
Hoe.plugin :git

if RUBY_VERSION < '1.9'
class Array
class Array #:nodoc:
def to_h
Hash[*self.flatten(1)]
Hash[*flatten(1)]
end
end

class Gem::Specification
def metadata=(*)
end
class Gem::Specification #:nodoc:
def metadata=(*); end

def default_value(*); end
end

class Object
class Object #:nodoc:
def caller_locations(*)
[]
end
Expand Down Expand Up @@ -55,3 +56,19 @@ if RUBY_VERSION >= '2.0' && RUBY_ENGINE == 'ruby'
end
end
end

task :ruby18 do
puts <<-MESSAGE
You are starting a barebones Ruby 1.8 docker environment. You will need to
do the following:
- mv Gemfile.lock{,.v2}
- gem install bundler --version 1.17.2 --no-ri --no-rdoc
- ruby -S bundle
- rake
Don't forget to restore your Gemfile.lock after testing.
MESSAGE
sh "docker run -it --rm -v #{Dir.pwd}:/root/diff-lcs bellbind/docker-ruby18-rails2 bash -l"
end
8 changes: 4 additions & 4 deletions diff-lcs.gemspec
@@ -1,16 +1,16 @@
# -*- encoding: utf-8 -*-
# stub: diff-lcs 1.4.3 ruby lib
# stub: diff-lcs 1.4.4 ruby lib

Gem::Specification.new do |s|
s.name = "diff-lcs".freeze
s.version = "1.4.3"
s.version = "1.4.4"

s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.metadata = { "bug_tracker_uri" => "https://github.com/halostatue/diff-lcs/issues", "homepage_uri" => "https://github.com/halostatue/diff-lcs", "source_code_uri" => "https://github.com/halostatue/diff-lcs" } if s.respond_to? :metadata=
s.require_paths = ["lib".freeze]
s.authors = ["Austin Ziegler".freeze]
s.date = "2020-06-29"
s.description = "Diff::LCS computes the difference between two Enumerable sequences using the\nMcIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities\nto create a simple HTML diff output format and a standard diff-like tool.\n\nThis is release 1.4, providing a simple extension that allows for\nDiff::LCS::Change objects to be treated implicitly as arrays. Ruby versions\nbelow 2.5 are soft-deprecated.\n\nThis means that older versions are no longer part of the CI test suite. If any\nchanges have been introduced that break those versions, bug reports and patches\nwill be accepted, but it will be up to the reporter to verify any fixes prior\nto release. A future release will completely break compatibility.".freeze
s.date = "2020-07-01"
s.description = "Diff::LCS computes the difference between two Enumerable sequences using the\nMcIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities\nto create a simple HTML diff output format and a standard diff-like tool.\n\nThis is release 1.4.3, providing a simple extension that allows for\nDiff::LCS::Change objects to be treated implicitly as arrays and fixes a\nnumber of formatting issues.\n\nRuby versions below 2.5 are soft-deprecated, which means that older versions\nare no longer part of the CI test suite. If any changes have been introduced\nthat break those versions, bug reports and patches will be accepted, but it\nwill be up to the reporter to verify any fixes prior to release. The next\nmajor release will completely break compatibility.".freeze
s.email = ["halostatue@gmail.com".freeze]
s.executables = ["htmldiff".freeze, "ldiff".freeze]
s.extra_rdoc_files = ["Code-of-Conduct.md".freeze, "Contributing.md".freeze, "History.md".freeze, "License.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "docs/COPYING.txt".freeze, "docs/artistic.txt".freeze]
Expand Down
9 changes: 8 additions & 1 deletion lib/diff/lcs.rb
Expand Up @@ -49,7 +49,7 @@ module Diff; end unless defined? Diff # rubocop:disable Style/Documentation
# a x b y c z p d q
# a b c a x b y c z
module Diff::LCS
VERSION = '1.4.3'
VERSION = '1.4.4'
end

require 'diff/lcs/callbacks'
Expand All @@ -60,6 +60,13 @@ module Diff::LCS # rubocop:disable Style/Documentation
# +self+ and +other+. See Diff::LCS#lcs.
#
# lcs = seq1.lcs(seq2)
#
# A note when using objects: Diff::LCS only works properly when each object
# can be used as a key in a Hash, which typically means that the objects must
# implement Object#eql? in a way that two identical values compare
# identically for key purposes. That is:
#
# O.new('a').eql?(O.new('a')) == true
def lcs(other, &block) #:yields self[i] if there are matched subsequences:
Diff::LCS.lcs(self, other, &block)
end
Expand Down

0 comments on commit 381ad11

Please sign in to comment.