nanoc 4.11.10 → 4.11.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f613b6428b6cfd9eb92da14ff7768e830aacae1872df99649a9ca9941026a189
4
- data.tar.gz: f208c9e15638f9745c558ec12d8a71a0bfb77744c24e735c4f9af2a20f510670
3
+ metadata.gz: 481798e39546d0e6b7e7a2a98832958b1666d8ee34b68d3dea32cd59fd99cfe0
4
+ data.tar.gz: 01b653399a15957f5562bdb10757e75efa2f8368d1d37f336836804827de02d7
5
5
  SHA512:
6
- metadata.gz: 45852ac268085e574f3b266f9ac96ec13848904ad6240a0411c46cefa21e867cc109a0ccdcdda9c9c40212e9b21de2f44338af053b6ed03b00d6a78c92de9c9e
7
- data.tar.gz: 8e949b83020fb64bdb8fecd4a233d83a5a9d52c65e57d4a4b29909dc5bd7c723ac7e6a379fb240c7d34576031bf7122caf74b6502c4b041178086385531124e5
6
+ metadata.gz: f64c2863d201a92188b92df86808d629fe498365a900d02e8658978159fb027167a009e69924b6381ddfda11653b9511de463dde6c8766e7df3c96b57591fbaa
7
+ data.tar.gz: 61f913a10ccd33ce05431194be1edfdea46c5513789399cf9e3594118477ffac5b94a22c7d2ba840744af2bf1722362ce97483aec34e9cf5bbf64e2f17d289f5
data/NEWS.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Nanoc news
2
2
 
3
+ ## 4.11.11 (2019-09-07)
4
+
5
+ Fixes:
6
+
7
+ * Made output diff more reliable (#1455, #1456)
8
+
3
9
  ## 4.11.10 (2019-08-31)
4
10
 
5
11
  Fixes:
@@ -33,6 +33,8 @@ end
33
33
  # Load general requirements
34
34
  require 'base64'
35
35
  require 'cgi'
36
+ require 'diff/lcs'
37
+ require 'diff/lcs/hunk'
36
38
  require 'digest'
37
39
  require 'English'
38
40
  require 'fiber'
@@ -52,7 +54,6 @@ require 'time'
52
54
  require 'timeout'
53
55
  require 'tomlrb'
54
56
  require 'tmpdir'
55
- require 'tty-file'
56
57
  require 'tty-platform'
57
58
  require 'tty-which'
58
59
  require 'uri'
@@ -43,9 +43,6 @@ module Nanoc
43
43
  :rep_write_started, item_rep, raw_path
44
44
  )
45
45
 
46
- # Sync (needed so that diff generator can read the old contents)
47
- Nanoc::Core::NotificationCenter.sync
48
-
49
46
  content = compiled_content_store.get(item_rep, snapshot_name)
50
47
  if content.binary?
51
48
  temp_path = content.filename
@@ -57,6 +54,13 @@ module Nanoc
57
54
  # Check whether content was modified
58
55
  is_modified = is_created || !FileUtils.identical?(raw_path, temp_path)
59
56
 
57
+ # Notify ready for diff generation
58
+ if !is_created && is_modified && !content.binary?
59
+ Nanoc::Core::NotificationCenter.post(
60
+ :rep_ready_for_diff, raw_path, File.read(raw_path), content.string
61
+ )
62
+ end
63
+
60
64
  # Write
61
65
  if is_modified
62
66
  begin
@@ -2,6 +2,53 @@
2
2
 
3
3
  module Nanoc::CLI::Commands::CompileListeners
4
4
  class DiffGenerator < Abstract
5
+ class Differ
6
+ def initialize(path, str_a, str_b)
7
+ @path = path
8
+ @str_a = str_a
9
+ @str_b = str_b
10
+ end
11
+
12
+ def call
13
+ run
14
+ end
15
+
16
+ private
17
+
18
+ def run
19
+ lines_a = @str_a.lines.map(&:chomp)
20
+ lines_b = @str_b.lines.map(&:chomp)
21
+
22
+ diffs = Diff::LCS.diff(lines_a, lines_b)
23
+
24
+ # Find hunks
25
+ hunks = []
26
+ file_length_difference = 0
27
+ diffs.each do |piece|
28
+ hunk = Diff::LCS::Hunk.new(lines_a, lines_b, piece, 3, file_length_difference)
29
+ file_length_difference = hunk.file_length_difference
30
+ hunks << hunk
31
+ end
32
+
33
+ # Merge hunks
34
+ merged_hunks = []
35
+ hunks.each do |hunk|
36
+ merged = merged_hunks.any? && hunk.merge(merged_hunks.last)
37
+ merged_hunks << hunk unless merged
38
+ end
39
+
40
+ # Output hunks
41
+ output = +''
42
+ output << "--- #{@path}\n"
43
+ output << "+++ #{@path}\n"
44
+ merged_hunks.each do |hunk|
45
+ output << hunk.diff(:unified) << "\n"
46
+ end
47
+
48
+ output
49
+ end
50
+ end
51
+
5
52
  # @see Listener#enable_for?
6
53
  def self.enable_for?(command_runner, site)
7
54
  site.config[:enable_output_diff] || command_runner.options[:diff]
@@ -10,20 +57,9 @@ module Nanoc::CLI::Commands::CompileListeners
10
57
  # @see Listener#start
11
58
  def start
12
59
  setup_diffs
13
- old_contents = {}
14
60
 
15
- on(:rep_write_started) do |rep, path|
16
- old_contents[rep] = File.file?(path) ? File.read(path) : nil
17
- end
18
-
19
- on(:rep_write_ended) do |rep, binary, path, _is_created, _is_modified|
20
- unless binary
21
- new_contents = File.file?(path) ? File.read(path) : nil
22
- if old_contents[rep] && new_contents
23
- generate_diff_for(path, old_contents[rep], new_contents)
24
- end
25
- old_contents.delete(rep)
26
- end
61
+ on(:rep_ready_for_diff) do |raw_path, old_content, new_content|
62
+ generate_diff_for(raw_path, old_content, new_content)
27
63
  end
28
64
  end
29
65
 
@@ -55,7 +91,7 @@ module Nanoc::CLI::Commands::CompileListeners
55
91
  end
56
92
 
57
93
  # Generate diff
58
- diff = ['--- ' + path, '+++ ' + path, diff_strings(old_content, new_content)].join("\n")
94
+ diff = Differ.new(path, old_content, new_content).call
59
95
 
60
96
  # Write diff
61
97
  @diff_lock.synchronize do
@@ -63,25 +99,5 @@ module Nanoc::CLI::Commands::CompileListeners
63
99
  end
64
100
  end
65
101
  end
66
-
67
- def diff_strings(str_a, str_b)
68
- # Create files
69
- Tempfile.open('old') do |old_file|
70
- Tempfile.open('new') do |new_file|
71
- # Write files
72
- old_file.write(str_a)
73
- old_file.flush
74
- new_file.write(str_b)
75
- new_file.flush
76
-
77
- # Diff
78
- TTY::File.diff_files(old_file.path, new_file.path, verbose: false)
79
- end
80
- end
81
- rescue Errno::ENOENT
82
- warn 'Failed to run `diff`, so no diff with the previously compiled ' \
83
- 'content will be available.'
84
- nil
85
- end
86
102
  end
87
103
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nanoc
4
4
  # The current Nanoc version.
5
- VERSION = '4.11.10'
5
+ VERSION = '4.11.11'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.11.10
4
+ version: 4.11.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-31 00:00:00.000000000 Z
11
+ date: 2019-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -52,20 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: diff-lcs
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: nanoc-core
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - '='
60
74
  - !ruby/object:Gem::Version
61
- version: 4.11.10
75
+ version: 4.11.11
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - '='
67
81
  - !ruby/object:Gem::Version
68
- version: 4.11.10
82
+ version: 4.11.11
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: parallel
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,20 +122,6 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0.8'
111
- - !ruby/object:Gem::Dependency
112
- name: tty-file
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '0.7'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '0.7'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: tty-platform
127
127
  requirement: !ruby/object:Gem::Requirement