riffdiff 0.9.8 → 0.9.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c8550e8dbeef2ce61955d6c4d377e3d178fb790
4
- data.tar.gz: 36fbdc8ccd7a5c1581d9ed1645e4983b6971416e
3
+ metadata.gz: 3b5b2351ff935d40977928f7b2801b10d671aae4
4
+ data.tar.gz: 04dedc13f58a3c7a47f3c0e413aa5303f0c17e4a
5
5
  SHA512:
6
- metadata.gz: 531762353008a5fa72c629dacbed075462d630dbecbfafc2c94d2aaa82c57575ce3cf0a34f1f4881aa37a8500e67a38113e58bff74eee34db5b4a6c75873b550
7
- data.tar.gz: b5ed8570458f7d8eba116eddb9d717cb1368dccbd5de481923336c78814edb01375f112da430ee6ccbc90009e370e88e9e52a9e7faaa46bd6531ec3e24f00799
6
+ metadata.gz: 6eb0d6cf89082c982896513fc25531f4cbcced1c07c8d61a7aead5bb66a3d60b50662ee0f7e9c2a92425ca2a72e70cf9db1e47935cc75be646349606e7ff66ed
7
+ data.tar.gz: 560d7da69123f98f074164d0ca1981dd0cba57c7047f93df24da26997f3d4a07f3497be0ebac09dc0c4e7750cc4a12dd32ccff55ea8f954395725b735a756ed2
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *.gem
2
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,5 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- gem 'rspec', '~> 3.0'
4
- gem 'diff-lcs', '~> 1.2.5'
5
- gem 'slop', '~> 4.1.0'
2
+ gemspec
data/README.md CHANGED
@@ -23,9 +23,9 @@ Optionally followed by...
23
23
  ... to make git show refined diffs by default.
24
24
 
25
25
  # TODO
26
- * Think about how to visualize one line changing to itself with a
27
- comma at the end plus a bunch of entirely new lines. Think of a
28
- constant array getting one or more extra members.
26
+ * When highlighting an added comma at the end of a line, followed by some added
27
+ lines, remove the leading + from the first line and don't color it. We should
28
+ still show the comma in reverse video though.
29
29
  * Think about highlighting whitespace errors like Git does
30
30
  * Think about how to visualize an added line break together with some
31
31
  indentation on the following line.
@@ -33,9 +33,6 @@ indentation on the following line.
33
33
  the REVERSE vs reversed() lines highlighted.
34
34
  * Do "git show 2ac5b06" and think about what rule we should use to
35
35
  highlight all of both "some" and "one or".
36
- * Do "git show -b 77c8f77" and think about what rule we should use to
37
- highlight the leading spaces of the "+ refined" and "+ page" lines
38
- at the end of the file.
39
36
  * Make sure we highlight the output of "git log -p" properly. If we
40
37
  get something unexpected, maybe just go back to :initial?
41
38
  * Make sure we highlight the output of "git show --stat" properly
@@ -108,3 +105,18 @@ optionally deploy as well.
108
105
  * Make a first public release
109
106
  * Running from a git clone should work even if Riff is installed
110
107
  globally on the system.
108
+ * Do `git show 0f5dd84` and think about how to visualize one line
109
+ changing to itself with a comma at the end plus a bunch of entirely
110
+ new lines. Think of a constant array getting one or more extra
111
+ members.
112
+ * Do "git show -b 77c8f77" and think about what rule we should use to
113
+ highlight the leading spaces of the "+ refined" and "+ page" lines
114
+ at the end of the file.
115
+ * Don't use --dirty for the gemspec version
116
+ * Rakefile: Refuse to package dirty sources
117
+ * Remove .bundler/config from git
118
+ * Remove bundler binstubs from Git
119
+ * Make sure we can:
120
+ * test dirty sources
121
+ * not package dirty sources
122
+ * package clean sources, dependencies not verified
data/Rakefile CHANGED
@@ -1,5 +1,10 @@
1
1
  require 'rspec/core/rake_task'
2
2
 
3
+ $LOAD_PATH.unshift File.join(__dir__, 'lib')
4
+ require 'version'
5
+
6
+ include Version
7
+
3
8
  task default: :spec
4
9
  desc 'Run the unit tests (default)'
5
10
  task spec: [:deps]
@@ -9,9 +14,7 @@ end
9
14
 
10
15
  desc 'Create a .gem package'
11
16
  task package: [:spec] do
12
- git_description = `git describe --dirty`.chomp
13
- fail 'Cannot package when there are uncommitted sources' if
14
- git_description.end_with? 'dirty'
17
+ fail 'Cannot package when there are uncommitted sources' if dirty?
15
18
 
16
19
  system('rm -f *.gem ; gem build riffdiff.gemspec') || fail
17
20
  end
data/lib/refiner.rb CHANGED
@@ -62,7 +62,7 @@ class Refiner
62
62
  return true
63
63
  end
64
64
 
65
- def initialize(old, new)
65
+ def try_highlight(old, new)
66
66
  old_highlights = Set.new
67
67
  new_highlights = Set.new
68
68
  if should_highlight?(old, new)
@@ -73,6 +73,34 @@ class Refiner
73
73
  censor_highlights(old, new, old_highlights, new_highlights)
74
74
  end
75
75
 
76
+ return old_highlights, new_highlights
77
+ end
78
+
79
+ def try_highlight_initial_lines(old, new)
80
+ old_line_count = old.lines.count
81
+ new_line_count = new.lines.count
82
+ if old_line_count == new_line_count
83
+ return Set.new, Set.new
84
+ end
85
+
86
+ min_line_count = [old_line_count, new_line_count].min
87
+ if min_line_count == 0
88
+ return Set.new, Set.new
89
+ end
90
+
91
+ # Truncate old and new so they have the same number of lines
92
+ old = old.lines[0..(min_line_count - 1)].join
93
+ new = new.lines[0..(min_line_count - 1)].join
94
+
95
+ return try_highlight(old, new)
96
+ end
97
+
98
+ def initialize(old, new)
99
+ old_highlights, new_highlights = try_highlight(old, new)
100
+ if old_highlights.size == 0 && new_highlights.size == 0
101
+ old_highlights, new_highlights = try_highlight_initial_lines(old, new)
102
+ end
103
+
76
104
  @refined_old = DiffString.new('-', RED)
77
105
  old.each_char.with_index do |char, index|
78
106
  @refined_old.add(char, old_highlights.include?(index))
data/lib/version.rb CHANGED
@@ -2,8 +2,9 @@ require 'English'
2
2
 
3
3
  # Methods for finding out the Riff version
4
4
  module Version
5
- def git_version
6
- version = `cd #{__dir__} ; git describe --dirty 2> /dev/null`.chomp
5
+ def git_version(dirty)
6
+ dirty_flag = dirty ? '--dirty' : ''
7
+ version = `cd #{__dir__} ; git describe #{dirty_flag} 2> /dev/null`.chomp
7
8
  if $CHILD_STATUS.success?
8
9
  return version
9
10
  else
@@ -31,9 +32,17 @@ module Version
31
32
  end
32
33
 
33
34
  def version
34
- semantic_git_version = semantify_git_version(git_version)
35
+ semantic_git_version = semantify_git_version(git_version(false))
35
36
  return semantic_git_version unless semantic_git_version.nil?
36
37
 
37
38
  return rubygems_version
38
39
  end
40
+
41
+ def semantic_version
42
+ return semantify_git_version(git_version(false))
43
+ end
44
+
45
+ def dirty?
46
+ return git_version(true).include?('-dirty')
47
+ end
39
48
  end
data/riffdiff.gemspec CHANGED
@@ -1,11 +1,11 @@
1
- $LOAD_PATH.unshift File.join(File.absolute_path(__dir__), 'lib')
1
+ $LOAD_PATH.unshift File.join(__dir__, 'lib')
2
2
  require 'version'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  extend Version
6
6
 
7
7
  s.name = 'riffdiff'
8
- s.version = semantify_git_version(git_version)
8
+ s.version = semantic_version
9
9
  s.summary = 'A diff highlighter showing what parts of lines have changed'
10
10
  s.description = %{== Riff
11
11
  Riff is a wrapper around diff that highlights not only which lines have changed,
@@ -33,4 +33,13 @@ refined.
33
33
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
34
34
  s.executables = ['riff']
35
35
  s.require_paths = ['lib']
36
+
37
+ # Development is done on 2.0, and we're using at least __dir__ which requires
38
+ # Ruby 2.0.
39
+ s.required_ruby_version = '~> 2.0'
40
+
41
+ s.add_development_dependency 'rspec', '~> 3.0'
42
+
43
+ s.add_runtime_dependency 'diff-lcs', '~> 1.2.5'
44
+ s.add_runtime_dependency 'slop', '~> 4.1.0'
36
45
  end
data/spec/refiner_spec.rb CHANGED
@@ -99,6 +99,38 @@ RSpec.describe Refiner, '#new' do
99
99
  end
100
100
  end
101
101
 
102
+ context %(with one line turning into many) do
103
+ refiner = Refiner.new("abcde\n",
104
+ "abcde,\n" \
105
+ "fffff,\n" \
106
+ "ggggg\n")
107
+
108
+ it %(highlights the comma on the first line, but not the two extra lines) do
109
+ expect(refiner.refined_old.to_s).to eq(
110
+ %(#{RED}-abcde#{RESET}\n))
111
+ expect(refiner.refined_new.to_s).to eq(
112
+ %(#{GREEN}+abcde#{reversed(',')}\n) +
113
+ %(#{GREEN}+fffff,\n) +
114
+ %(#{GREEN}+ggggg#{RESET}\n))
115
+ end
116
+ end
117
+
118
+ context %(with many lines turning into one) do
119
+ refiner = Refiner.new("abcde,\n" \
120
+ "fffff,\n" \
121
+ "ggggg\n",
122
+ "abcde\n")
123
+
124
+ it %(highlights the first removed comma, but not the two removed lines) do
125
+ expect(refiner.refined_old.to_s).to eq(
126
+ %(#{RED}-abcde#{reversed(',')}\n) +
127
+ %(#{RED}-fffff,\n) +
128
+ %(#{RED}-ggggg#{RESET}\n))
129
+ expect(refiner.refined_new.to_s).to eq(
130
+ %(#{GREEN}+abcde#{RESET}\n))
131
+ end
132
+ end
133
+
102
134
  context %(with large input) do
103
135
  # A Refiner that fails if trying to collect highlights
104
136
  class NonHighlightingRefiner < Refiner
data/spec/version_spec.rb CHANGED
@@ -38,6 +38,6 @@ end
38
38
 
39
39
  RSpec.describe Version, '#git_version' do
40
40
  it "doesn't end in a newline" do
41
- expect(git_version).to(eq(git_version.chomp))
41
+ expect(git_version(false)).to(eq(git_version(false).chomp))
42
42
  end
43
43
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riffdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Walles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-30 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: diff-lcs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: slop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.1.0
13
55
  description: |
14
56
  == Riff
15
57
  Riff is a wrapper around diff that highlights not only which lines have changed,
@@ -33,20 +75,14 @@ executables:
33
75
  extensions: []
34
76
  extra_rdoc_files: []
35
77
  files:
36
- - ".bundle/config"
37
78
  - ".gitignore"
38
79
  - ".rubocop.yml"
39
80
  - Gemfile
40
- - Gemfile.lock
41
81
  - LICENSE
42
82
  - README.md
43
83
  - Rakefile
44
84
  - bin/benchmark
45
- - bin/bundler
46
- - bin/htmldiff
47
- - bin/ldiff
48
85
  - bin/riff
49
- - bin/rspec
50
86
  - lib/colors.rb
51
87
  - lib/diff_string.rb
52
88
  - lib/options.rb
@@ -73,9 +109,9 @@ require_paths:
73
109
  - lib
74
110
  required_ruby_version: !ruby/object:Gem::Requirement
75
111
  requirements:
76
- - - ">="
112
+ - - "~>"
77
113
  - !ruby/object:Gem::Version
78
- version: '0'
114
+ version: '2.0'
79
115
  required_rubygems_version: !ruby/object:Gem::Requirement
80
116
  requirements:
81
117
  - - ">="
data/.bundle/config DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_BIN: bin
data/Gemfile.lock DELETED
@@ -1,26 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- diff-lcs (1.2.5)
5
- rspec (3.2.0)
6
- rspec-core (~> 3.2.0)
7
- rspec-expectations (~> 3.2.0)
8
- rspec-mocks (~> 3.2.0)
9
- rspec-core (3.2.2)
10
- rspec-support (~> 3.2.0)
11
- rspec-expectations (3.2.0)
12
- diff-lcs (>= 1.2.0, < 2.0)
13
- rspec-support (~> 3.2.0)
14
- rspec-mocks (3.2.1)
15
- diff-lcs (>= 1.2.0, < 2.0)
16
- rspec-support (~> 3.2.0)
17
- rspec-support (3.2.2)
18
- slop (4.1.0)
19
-
20
- PLATFORMS
21
- ruby
22
-
23
- DEPENDENCIES
24
- diff-lcs (~> 1.2.5)
25
- rspec (~> 3.0)
26
- slop (~> 4.1.0)
data/bin/bundler DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'bundler' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('bundler', 'bundler')
data/bin/htmldiff DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'htmldiff' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('diff-lcs', 'htmldiff')
data/bin/ldiff DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'ldiff' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('diff-lcs', 'ldiff')
data/bin/rspec DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rspec' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rspec-core', 'rspec')