diff_gem 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +1 -1
- data/lib/diff_gem/comparer.rb +206 -11
- metadata +7 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95cf2fa62f8822068d882ac6d935f71599b6565a15a67e5b61030eb4c0c6ee22
|
|
4
|
+
data.tar.gz: ca589c18ab6ee53f0d7be63eadf446befc6ed6e4ab17c70ab09936d07ac26526
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c25207a65f7d52745afbf6853d89831fcf5de8f0c98b06f70dadea82cf1adb44e139ed02e2baa6100cddd8632b4593b7b6080a4c82ef235ab2417af430f0c186
|
|
7
|
+
data.tar.gz: f79ac1773eb481b3441a10f5766cefd7e6a2b59b2960a76c90bdc35d906d5277a5521652c4b239d4b29e4269af13ba8a296e82e4f2b09bda90d0908aa046b074
|
data/README.md
CHANGED
data/lib/diff_gem/comparer.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'fileutils'
|
|
2
|
+
require 'English'
|
|
2
3
|
|
|
3
4
|
module DiffGem
|
|
4
5
|
class Comparer
|
|
@@ -29,22 +30,216 @@ module DiffGem
|
|
|
29
30
|
private
|
|
30
31
|
|
|
31
32
|
def generate_diff(old_path, new_path)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
system("diff -r -u -N '#{old_path}' '#{new_path}'")
|
|
33
|
+
status = if windows?
|
|
34
|
+
run_windows_diff(old_path, new_path)
|
|
35
|
+
else
|
|
36
|
+
run_unix_diff(old_path, new_path)
|
|
37
|
+
end
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
# which is expected behavior
|
|
41
|
-
if $?.exitstatus > 1
|
|
42
|
-
raise Error, "Failed to generate diff (exit status: #{$?.exitstatus})"
|
|
43
|
-
end
|
|
39
|
+
handle_diff_exit(status)
|
|
44
40
|
end
|
|
45
41
|
|
|
46
42
|
def default_cache_dir
|
|
47
43
|
ENV['DIFF_GEM_CACHE_DIR'] || File.expand_path('~/.diff_gem_cache')
|
|
48
44
|
end
|
|
45
|
+
|
|
46
|
+
def windows?
|
|
47
|
+
(/mswin|mingw|cygwin|bccwin/i).match?(RUBY_PLATFORM)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def run_unix_diff(old_path, new_path)
|
|
51
|
+
# Use unified diff to closely match traditional diff output on Unix-like systems
|
|
52
|
+
system('diff', '-r', '-u', '-N', old_path.to_s, new_path.to_s)
|
|
53
|
+
$CHILD_STATUS
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def run_windows_diff(old_path, new_path)
|
|
57
|
+
script = windows_compare_script(old_path, new_path)
|
|
58
|
+
system('powershell.exe', '-NoProfile', '-Command', script)
|
|
59
|
+
$CHILD_STATUS
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def handle_diff_exit(status)
|
|
63
|
+
raise Error, 'Failed to execute diff command' if status.nil?
|
|
64
|
+
return if status.exitstatus <= 1
|
|
65
|
+
|
|
66
|
+
raise Error, "Failed to generate diff (exit status: #{status.exitstatus})"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def windows_compare_script(old_path, new_path)
|
|
70
|
+
escaped_old = escape_for_powershell(old_path)
|
|
71
|
+
escaped_new = escape_for_powershell(new_path)
|
|
72
|
+
|
|
73
|
+
<<~POWERSHELL
|
|
74
|
+
$ErrorActionPreference = 'Stop'
|
|
75
|
+
$old = '#{escaped_old}'
|
|
76
|
+
$new = '#{escaped_new}'
|
|
77
|
+
$hasDifferences = $false
|
|
78
|
+
|
|
79
|
+
function Write-Line {
|
|
80
|
+
param([string]$text)
|
|
81
|
+
[Console]::Out.WriteLine($text)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function Get-RelativePath {
|
|
85
|
+
param(
|
|
86
|
+
[string]$root,
|
|
87
|
+
[string]$full
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
$normalizedRoot = [System.IO.Path]::GetFullPath($root)
|
|
91
|
+
if (-not $normalizedRoot.EndsWith([System.IO.Path]::DirectorySeparatorChar)) {
|
|
92
|
+
$normalizedRoot += [System.IO.Path]::DirectorySeparatorChar
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
$normalizedFull = [System.IO.Path]::GetFullPath($full)
|
|
96
|
+
return $normalizedFull.Substring($normalizedRoot.Length).Replace('\\', '/')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function Get-FileMap {
|
|
100
|
+
param([string]$root)
|
|
101
|
+
|
|
102
|
+
$map = @{}
|
|
103
|
+
if (-not (Test-Path -LiteralPath $root)) {
|
|
104
|
+
return $map
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
Get-ChildItem -LiteralPath $root -File -Recurse | ForEach-Object {
|
|
108
|
+
$relative = Get-RelativePath $root $_.FullName
|
|
109
|
+
$map[$relative] = $_.FullName
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return $map
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function Read-FileLines {
|
|
116
|
+
param([string]$path)
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
return Get-Content -LiteralPath $path -ErrorAction Stop
|
|
120
|
+
} catch {
|
|
121
|
+
return $null
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function Write-DiffHeader {
|
|
126
|
+
param(
|
|
127
|
+
[Parameter(Mandatory = $true)][string]$relative,
|
|
128
|
+
[string]$oldTarget,
|
|
129
|
+
[string]$newTarget
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if (-not $oldTarget) { $oldTarget = "a/$relative" }
|
|
133
|
+
if (-not $newTarget) { $newTarget = "b/$relative" }
|
|
134
|
+
|
|
135
|
+
Write-Line "diff --git a/$relative b/$relative"
|
|
136
|
+
Write-Line "--- $oldTarget"
|
|
137
|
+
Write-Line "+++ $newTarget"
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function Write-LineDiff {
|
|
141
|
+
param(
|
|
142
|
+
[string]$oldPath,
|
|
143
|
+
[string]$newPath,
|
|
144
|
+
[string]$relative
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
$oldLines = Read-FileLines $oldPath
|
|
148
|
+
$newLines = Read-FileLines $newPath
|
|
149
|
+
|
|
150
|
+
if ($null -eq $oldLines -or $null -eq $newLines) {
|
|
151
|
+
Write-Line "Binary files differ: $relative"
|
|
152
|
+
Write-Line ''
|
|
153
|
+
return $true
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
$diff = Compare-Object -ReferenceObject $oldLines -DifferenceObject $newLines -IncludeEqual:$false
|
|
157
|
+
|
|
158
|
+
if (-not $diff) {
|
|
159
|
+
return $false
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Write-DiffHeader -relative $relative
|
|
163
|
+
|
|
164
|
+
foreach ($entry in $diff) {
|
|
165
|
+
$prefix = if ($entry.SideIndicator -eq '<=') { '-' } else { '+' }
|
|
166
|
+
$line = [string]$entry.InputObject
|
|
167
|
+
Write-Line "$prefix$line"
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
Write-Line ''
|
|
171
|
+
return $true
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
$oldFiles = Get-FileMap $old
|
|
175
|
+
$newFiles = Get-FileMap $new
|
|
176
|
+
|
|
177
|
+
$allPaths = (@($oldFiles.Keys) + @($newFiles.Keys)) | Sort-Object -Unique
|
|
178
|
+
|
|
179
|
+
foreach ($path in $allPaths) {
|
|
180
|
+
$oldExists = $oldFiles.ContainsKey($path)
|
|
181
|
+
$newExists = $newFiles.ContainsKey($path)
|
|
182
|
+
|
|
183
|
+
if (-not $oldExists -and $newExists) {
|
|
184
|
+
$newPathFull = $newFiles[$path]
|
|
185
|
+
$newLines = Read-FileLines $newPathFull
|
|
186
|
+
|
|
187
|
+
if ($null -eq $newLines) {
|
|
188
|
+
Write-Line "Binary file added: $path"
|
|
189
|
+
Write-Line ''
|
|
190
|
+
} else {
|
|
191
|
+
Write-DiffHeader -relative $path -oldTarget '/dev/null' -newTarget "b/$path"
|
|
192
|
+
|
|
193
|
+
foreach ($line in $newLines) {
|
|
194
|
+
Write-Line "+$line"
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
Write-Line ''
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
$hasDifferences = $true
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if ($oldExists -and -not $newExists) {
|
|
205
|
+
$oldPathFull = $oldFiles[$path]
|
|
206
|
+
$oldLines = Read-FileLines $oldPathFull
|
|
207
|
+
|
|
208
|
+
if ($null -eq $oldLines) {
|
|
209
|
+
Write-Line "Binary file removed: $path"
|
|
210
|
+
Write-Line ''
|
|
211
|
+
} else {
|
|
212
|
+
Write-DiffHeader -relative $path -oldTarget "a/$path" -newTarget '/dev/null'
|
|
213
|
+
|
|
214
|
+
foreach ($line in $oldLines) {
|
|
215
|
+
Write-Line "-$line"
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
Write-Line ''
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
$hasDifferences = $true
|
|
222
|
+
continue
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
$oldPathFull = $oldFiles[$path]
|
|
226
|
+
$newPathFull = $newFiles[$path]
|
|
227
|
+
|
|
228
|
+
if (Write-LineDiff -oldPath $oldPathFull -newPath $newPathFull -relative $path) {
|
|
229
|
+
$hasDifferences = $true
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if ($hasDifferences) {
|
|
234
|
+
exit 1
|
|
235
|
+
} else {
|
|
236
|
+
exit 0
|
|
237
|
+
}
|
|
238
|
+
POWERSHELL
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def escape_for_powershell(path)
|
|
242
|
+
path.to_s.gsub("'", "''")
|
|
243
|
+
end
|
|
49
244
|
end
|
|
50
245
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: diff_gem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Thomas Powell
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -55,7 +55,7 @@ dependencies:
|
|
|
55
55
|
description: A tool to download and compare the source trees of two different versions
|
|
56
56
|
of a Ruby gem, displaying differences in diff format
|
|
57
57
|
email:
|
|
58
|
-
-
|
|
58
|
+
- twilliampowell@gmail.com
|
|
59
59
|
executables:
|
|
60
60
|
- diff_gem
|
|
61
61
|
extensions: []
|
|
@@ -72,13 +72,12 @@ files:
|
|
|
72
72
|
- lib/diff_gem/gem_extractor.rb
|
|
73
73
|
- lib/diff_gem/metadata_comparer.rb
|
|
74
74
|
- lib/diff_gem/version.rb
|
|
75
|
-
homepage: https://github.com/
|
|
75
|
+
homepage: https://github.com/stringsn88keys/diff_gem
|
|
76
76
|
licenses:
|
|
77
77
|
- MIT
|
|
78
78
|
metadata:
|
|
79
|
-
homepage_uri: https://github.com/
|
|
80
|
-
|
|
81
|
-
changelog_uri: https://github.com/example/diff_gem/CHANGELOG.md
|
|
79
|
+
homepage_uri: https://github.com/stringsn88keys/diff_gem
|
|
80
|
+
changelog_uri: https://github.com/stringsn88keys/diff_gem/CHANGELOG.md
|
|
82
81
|
post_install_message:
|
|
83
82
|
rdoc_options: []
|
|
84
83
|
require_paths:
|