daff 1.2.6 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -6
  3. data/bin/daff.rb +0 -0
  4. data/lib/daff.rb +6 -0
  5. data/lib/lib/coopy/alignment.rb +146 -169
  6. data/lib/lib/coopy/cell_builder.rb +1 -1
  7. data/lib/lib/coopy/cell_info.rb +2 -1
  8. data/lib/lib/coopy/column_change.rb +16 -0
  9. data/lib/lib/coopy/compare_flags.rb +33 -5
  10. data/lib/lib/coopy/compare_table.rb +219 -99
  11. data/lib/lib/coopy/coopy.rb +205 -99
  12. data/lib/lib/coopy/csv.rb +17 -22
  13. data/lib/lib/coopy/diff_render.rb +16 -8
  14. data/lib/lib/coopy/flat_cell_builder.rb +11 -8
  15. data/lib/lib/coopy/highlight_patch.rb +363 -63
  16. data/lib/lib/coopy/highlight_patch_unit.rb +1 -1
  17. data/lib/lib/coopy/index.rb +21 -8
  18. data/lib/lib/coopy/index_item.rb +7 -3
  19. data/lib/lib/coopy/index_pair.rb +13 -10
  20. data/lib/lib/coopy/merger.rb +3 -3
  21. data/lib/lib/coopy/meta.rb +17 -0
  22. data/lib/lib/coopy/mover.rb +7 -5
  23. data/lib/lib/coopy/ndjson.rb +2 -2
  24. data/lib/lib/coopy/nested_cell_builder.rb +7 -7
  25. data/lib/lib/coopy/ordering.rb +6 -2
  26. data/lib/lib/coopy/property_change.rb +16 -0
  27. data/lib/lib/coopy/row.rb +1 -0
  28. data/lib/lib/coopy/row_change.rb +42 -0
  29. data/lib/lib/coopy/row_stream.rb +11 -0
  30. data/lib/lib/coopy/simple_table.rb +84 -30
  31. data/lib/lib/coopy/simple_view.rb +8 -8
  32. data/lib/lib/coopy/sparse_sheet.rb +1 -1
  33. data/lib/lib/coopy/sql_column.rb +22 -10
  34. data/lib/lib/coopy/sql_compare.rb +397 -85
  35. data/lib/lib/coopy/sql_database.rb +2 -0
  36. data/lib/lib/coopy/sql_helper.rb +5 -0
  37. data/lib/lib/coopy/sql_table.rb +122 -19
  38. data/lib/lib/coopy/sql_table_name.rb +1 -1
  39. data/lib/lib/coopy/sqlite_helper.rb +250 -3
  40. data/lib/lib/coopy/table.rb +1 -0
  41. data/lib/lib/coopy/table_diff.rb +643 -464
  42. data/lib/lib/coopy/table_io.rb +19 -6
  43. data/lib/lib/coopy/table_modifier.rb +1 -1
  44. data/lib/lib/coopy/table_stream.rb +102 -0
  45. data/lib/lib/coopy/terminal_diff_render.rb +4 -3
  46. data/lib/lib/coopy/unit.rb +22 -2
  47. data/lib/lib/coopy/viterbi.rb +4 -4
  48. data/lib/lib/haxe/ds/int_map.rb +1 -1
  49. data/lib/lib/haxe/ds/string_map.rb +1 -1
  50. data/lib/lib/haxe/format/json_parser.rb +1 -1
  51. data/lib/lib/haxe/format/json_printer.rb +1 -1
  52. data/lib/lib/haxe/io/bytes.rb +2 -2
  53. data/lib/lib/haxe/io/eof.rb +1 -1
  54. data/lib/lib/haxe/io/output.rb +1 -1
  55. data/lib/lib/hx_overrides.rb +1 -1
  56. data/lib/lib/hx_sys.rb +9 -5
  57. data/lib/lib/lambda.rb +3 -3
  58. data/lib/lib/list.rb +1 -1
  59. data/lib/lib/rb/ruby_iterator.rb +2 -2
  60. data/lib/lib/reflect.rb +1 -1
  61. data/lib/lib/sys/io/file_output.rb +1 -1
  62. data/lib/lib/sys/io/hx_file.rb +1 -1
  63. data/lib/lib/x_list/list_iterator.rb +2 -2
  64. metadata +29 -25
  65. data/lib/lib/coopy/table_text.rb +0 -26
  66. data/lib/lib/haxe/io/bytes_buffer.rb +0 -19
  67. data/lib/lib/haxe/io/bytes_input.rb +0 -13
  68. data/lib/lib/haxe/io/bytes_output.rb +0 -33
  69. data/lib/lib/haxe/io/input.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99676b5f3069a96639961074611e5c8c0125361a
4
- data.tar.gz: 61f811c90251dfee2afc8f187731813aad4bece7
3
+ metadata.gz: 469baec08599142e1445a291410b340d9b621c52
4
+ data.tar.gz: f9781651f9ca2650d61a1ba5632b2e8e40543b1a
5
5
  SHA512:
6
- metadata.gz: 1ebb393d477f490c2a733cd5ea055c64cc41cd32ef52fea5df7f92f8eee5983eea96bf7c4e79a377d3765a86d497a0e6cba38b520ea46ade3f6b644f11ff6f08
7
- data.tar.gz: d70b61f7f4cb52e6e6d9a22cb9f50b8ce1c3fed78031baff2ae5c4ab1f9450131ed7a74f28abd49193dce685f107694420c7ec9d8f971953cb4257c02813ae4c
6
+ metadata.gz: cfc0aa8b457f18094e9d8ed4c9835fee504ecc9875949a4c5e74057821eae741941bf98a75c9c295b520a2f22b1add61dd5099d63f900894bbe63c31cde47888
7
+ data.tar.gz: 5a510890fe93b6b2d7c771524fe25f811f48a3addb377f97f565aa1f6507caa4069b09900c32c6c26c4242bf83b80dea94d47685472f53f733e44eecdf9333a4
data/README.md CHANGED
@@ -84,7 +84,7 @@ for `*.csv` files in your repository. Run `daff git` for instructions
84
84
  on doing this manually. Your CSV diffs and merges will get smarter,
85
85
  since git will suddenly understand about rows and columns, not just lines:
86
86
 
87
- ![Example CSV diff](scripts/diff.png)
87
+ ![Example CSV diff](http://paulfitz.github.io/daff-doc/images/daff_vs_diff.png)
88
88
 
89
89
  The library
90
90
  -----------
@@ -181,7 +181,6 @@ patcher.apply();
181
181
  For other languages, you should find sample code in
182
182
  the packages on the [Releases](https://github.com/paulfitz/daff/releases) page.
183
183
 
184
-
185
184
  Supported languages
186
185
  -------------------
187
186
 
@@ -198,10 +197,10 @@ can be translated reasonably well into at least the following languages:
198
197
 
199
198
  Some translations are done for you on the
200
199
  [Releases](https://github.com/paulfitz/daff/releases) page.
201
- To make another translation,
202
- follow the
203
- [Haxe getting started tutorial](http://haxe.org/doc/start) for the
204
- language you care about, then do one of:
200
+ To make another translation, or to compile from source
201
+ first follow the [Haxe getting started tutorial](http://haxe.org/doc/start) for the
202
+ language you care about. At the time of writing, if you are on OSX, you should
203
+ install haxe using `brew install haxe --HEAD`. Then do one of:
205
204
 
206
205
  ```
207
206
  make js
@@ -236,6 +235,7 @@ Reading material
236
235
 
237
236
  * http://dataprotocols.org/tabular-diff-format/ : a specification of the diff format we use.
238
237
  * http://theodi.org/blog/csvhub-github-diffs-for-csv-files : using this library with github.
238
+ * https://github.com/ropensci/unconf/issues/19 : a thread about diffing data in which daff shows up in at least four guises (see if you can spot them all).
239
239
  * http://theodi.org/blog/adapting-git-simple-data : using this library with gitlab.
240
240
  * http://okfnlabs.org/blog/2013/08/08/diffing-and-patching-data.html : a summary of where the library came from.
241
241
  * http://blog.okfn.org/2013/07/02/git-and-github-for-data/ : a post about storing small data in git/github.
File without changes
@@ -52,6 +52,7 @@ require_relative 'lib/type'
52
52
  require_relative 'lib/coopy/alignment'
53
53
  require_relative 'lib/coopy/cell_builder'
54
54
  require_relative 'lib/coopy/cell_info'
55
+ require_relative 'lib/coopy/column_change'
55
56
  require_relative 'lib/coopy/compare_flags'
56
57
  require_relative 'lib/coopy/compare_table'
57
58
  require_relative 'lib/coopy/coopy'
@@ -66,10 +67,14 @@ require_relative 'lib/coopy/index'
66
67
  require_relative 'lib/coopy/index_item'
67
68
  require_relative 'lib/coopy/index_pair'
68
69
  require_relative 'lib/coopy/merger'
70
+ require_relative 'lib/coopy/meta'
69
71
  require_relative 'lib/coopy/mover'
70
72
  require_relative 'lib/coopy/ndjson'
71
73
  require_relative 'lib/coopy/nested_cell_builder'
72
74
  require_relative 'lib/coopy/ordering'
75
+ require_relative 'lib/coopy/property_change'
76
+ require_relative 'lib/coopy/row_change'
77
+ require_relative 'lib/coopy/row_stream'
73
78
  require_relative 'lib/coopy/table'
74
79
  require_relative 'lib/coopy/simple_table'
75
80
  require_relative 'lib/coopy/view'
@@ -86,6 +91,7 @@ require_relative 'lib/coopy/table_comparison_state'
86
91
  require_relative 'lib/coopy/table_diff'
87
92
  require_relative 'lib/coopy/table_io'
88
93
  require_relative 'lib/coopy/table_modifier'
94
+ require_relative 'lib/coopy/table_stream'
89
95
  require_relative 'lib/coopy/terminal_diff_render'
90
96
  require_relative 'lib/coopy/unit'
91
97
  require_relative 'lib/coopy/viterbi'
@@ -55,8 +55,8 @@ module Coopy
55
55
  end
56
56
 
57
57
  def link(a,b)
58
- @map_a2b[a] = b
59
- @map_b2a[b] = a
58
+ @map_a2b[a] = b if a != -1
59
+ @map_b2a[b] = a if b != -1
60
60
  @map_count+=1
61
61
  end
62
62
 
@@ -66,23 +66,25 @@ module Coopy
66
66
  end
67
67
 
68
68
  def get_index_columns
69
- return @index_columns
69
+ @index_columns
70
70
  end
71
71
 
72
72
  def a2b(a)
73
- return @map_a2b[a]
73
+ @map_a2b[a]
74
74
  end
75
75
 
76
76
  def b2a(b)
77
- return @map_b2a[b]
77
+ @map_b2a[b]
78
78
  end
79
79
 
80
80
  def count
81
- return @map_count
81
+ @map_count
82
82
  end
83
83
 
84
84
  def to_s
85
- return "" + "not implemented yet"
85
+ result = "" + "not implemented yet" + " // " + "not implemented yet"
86
+ result += " (" + _hx_str(@reference.to_s) + ")" if @reference != nil
87
+ result
86
88
  end
87
89
 
88
90
  def to_order
@@ -93,7 +95,7 @@ module Coopy
93
95
  end
94
96
  @order_cache = self.to_order3 if @order_cache == nil
95
97
  @order_cache_has_reference = true if @reference != nil
96
- return @order_cache
98
+ @order_cache
97
99
  end
98
100
 
99
101
  def add_to_order(l,r,p = -2)
@@ -103,201 +105,176 @@ module Coopy
103
105
  end
104
106
 
105
107
  def get_source
106
- return @ta
108
+ @ta
107
109
  end
108
110
 
109
111
  def get_target
110
- return @tb
112
+ @tb
111
113
  end
112
114
 
113
115
  def get_source_header
114
- return @ia
116
+ @ia
115
117
  end
116
118
 
117
119
  def get_target_header
118
- return @ib
120
+ @ib
119
121
  end
120
122
 
121
123
  protected
122
124
 
123
125
  def to_order3
124
- ref = @reference
125
- if ref == nil
126
- ref = ::Coopy::Alignment.new
127
- ref.range(@ha,@ha)
128
- ref.tables(@ta,@ta)
129
- begin
130
- _g1 = 0
131
- _g = @ha
132
- while(_g1 < _g)
133
- i = _g1
134
- _g1+=1
135
- ref.link(i,i)
126
+ order = Array.new
127
+ if @reference == nil
128
+ _it = ::Rb::RubyIterator.new(@map_a2b.keys)
129
+ while(_it.has_next) do
130
+ k = _it._next
131
+ unit = ::Coopy::Unit.new
132
+ unit.l = k
133
+ unit.r = self.a2b(k)
134
+ order.push(unit)
135
+ end
136
+ _it2 = ::Rb::RubyIterator.new(@map_b2a.keys)
137
+ while(_it2.has_next) do
138
+ k1 = _it2._next
139
+ if self.b2a(k1) == -1
140
+ unit1 = ::Coopy::Unit.new
141
+ unit1.l = -1
142
+ unit1.r = k1
143
+ order.push(unit1)
136
144
  end
137
145
  end
138
- end
139
- order = ::Coopy::Ordering.new
140
- order.ignore_parent if @reference == nil
141
- xp = 0
142
- xl = 0
143
- xr = 0
144
- hp = @ha
145
- hl = ref.hb
146
- hr = @hb
147
- vp = {}
148
- vl = {}
149
- vr = {}
150
- begin
151
- _g2 = 0
152
- while(_g2 < hp)
153
- i1 = _g2
154
- _g2+=1
155
- vp[i1] = i1
146
+ else
147
+ _it3 = ::Rb::RubyIterator.new(@map_a2b.keys)
148
+ while(_it3.has_next) do
149
+ k2 = _it3._next
150
+ unit2 = ::Coopy::Unit.new
151
+ unit2.p = k2
152
+ unit2.l = @reference.a2b(k2)
153
+ unit2.r = self.a2b(k2)
154
+ order.push(unit2)
156
155
  end
157
- end
158
- begin
159
- _g3 = 0
160
- while(_g3 < hl)
161
- i2 = _g3
162
- _g3+=1
163
- vl[i2] = i2
156
+ _it4 = ::Rb::RubyIterator.new(@reference.map_b2a.keys)
157
+ while(_it4.has_next) do
158
+ k3 = _it4._next
159
+ if @reference.b2a(k3) == -1
160
+ unit3 = ::Coopy::Unit.new
161
+ unit3.p = -1
162
+ unit3.l = k3
163
+ unit3.r = -1
164
+ order.push(unit3)
165
+ end
164
166
  end
165
- end
166
- begin
167
- _g4 = 0
168
- while(_g4 < hr)
169
- i3 = _g4
170
- _g4+=1
171
- vr[i3] = i3
167
+ _it5 = ::Rb::RubyIterator.new(@map_b2a.keys)
168
+ while(_it5.has_next) do
169
+ k4 = _it5._next
170
+ if self.b2a(k4) == -1
171
+ unit4 = ::Coopy::Unit.new
172
+ unit4.p = -1
173
+ unit4.l = -1
174
+ unit4.r = k4
175
+ order.push(unit4)
176
+ end
172
177
  end
173
178
  end
174
- ct_vp = hp
175
- ct_vl = hl
176
- ct_vr = hr
177
- prev = -1
178
- ct = 0
179
- max_ct = (hp + hl + hr) * 10
180
- while(ct_vp > 0 || ct_vl > 0 || ct_vr > 0)
181
- ct+=1
182
- if ct > max_ct
183
- puts "Ordering took too long, something went wrong"
184
- break
185
- end
186
- xp = 0 if xp >= hp
187
- xl = 0 if xl >= hl
188
- xr = 0 if xr >= hr
189
- if xp < hp && ct_vp > 0
190
- if self.a2b(xp) == nil && ref.a2b(xp) == nil
191
- if vp.include?(xp)
192
- order.add(-1,-1,xp)
193
- prev = xp
194
- vp.delete(xp)
195
- ct_vp-=1
196
- end
197
- xp+=1
198
- next
179
+ top = order.length
180
+ remotes = Array.new
181
+ locals = Array.new
182
+ begin
183
+ _g = 0
184
+ while(_g < top)
185
+ o = _g
186
+ _g+=1
187
+ if order[o].r >= 0
188
+ remotes.push(o)
189
+ else
190
+ locals.push(o)
199
191
  end
200
192
  end
201
- zl = nil
202
- zr = nil
203
- if xl < hl && ct_vl > 0
204
- zl = ref.b2a(xl)
205
- if zl == nil
206
- if vl.include?(xl)
207
- order.add(xl,-1,-1)
208
- vl.delete(xl)
209
- ct_vl-=1
210
- end
211
- xl+=1
212
- next
193
+ end
194
+ remote_sort = lambda {|a,b|
195
+ order[a].r - order[b].r
196
+ }
197
+ local_sort = lambda {|a1,b1|
198
+ return 0 if a1 == b1
199
+ return order[a1].l - order[b1].l if order[a1].l >= 0 && order[b1].l >= 0
200
+ return 1 if order[a1].l >= 0
201
+ return -1 if order[b1].l >= 0
202
+ a1 - b1
203
+ }
204
+ if @reference != nil
205
+ remote_sort = lambda {|a2,b2|
206
+ return 0 if a2 == b2
207
+ o1 = order[a2].r - order[b2].r
208
+ if order[a2].p >= 0 && order[b2].p >= 0
209
+ o2 = order[a2].p - order[b2].p
210
+ return o1 if o1 * o2 < 0
211
+ o3 = order[a2].l - order[b2].l
212
+ return o3
213
213
  end
214
- end
215
- if xr < hr && ct_vr > 0
216
- zr = self.b2a(xr)
217
- if zr == nil
218
- if vr.include?(xr)
219
- order.add(-1,xr,-1)
220
- vr.delete(xr)
221
- ct_vr-=1
214
+ o1
215
+ }
216
+ local_sort = lambda {|a3,b3|
217
+ return 0 if a3 == b3
218
+ if order[a3].l >= 0 && order[b3].l >= 0
219
+ o11 = order[a3].l - order[b3].l
220
+ if order[a3].p >= 0 && order[b3].p >= 0
221
+ o21 = order[a3].p - order[b3].p
222
+ return o11 if o11 * o21 < 0
223
+ return o21
222
224
  end
223
- xr+=1
224
- next
225
225
  end
226
- end
227
- if zl != nil
228
- if self.a2b(zl) == nil
229
- if vl.include?(xl)
230
- order.add(xl,-1,zl)
231
- prev = zl
232
- vp.delete(zl)
233
- ct_vp-=1
234
- vl.delete(xl)
235
- ct_vl-=1
236
- xp = zl + 1
226
+ return 1 if order[a3].l >= 0
227
+ return -1 if order[b3].l >= 0
228
+ a3 - b3
229
+ }
230
+ end
231
+ remotes.sort!{|a,b| remote_sort.call(a,b)}
232
+ locals.sort!{|a,b| local_sort.call(a,b)}
233
+ revised_order = Array.new
234
+ at_r = 0
235
+ at_l = 0
236
+ begin
237
+ _g1 = 0
238
+ while(_g1 < top)
239
+ o4 = _g1
240
+ _g1+=1
241
+ if at_r < remotes.length && at_l < locals.length
242
+ ur = order[remotes[at_r]]
243
+ ul = order[locals[at_l]]
244
+ if ul.l == -1 && ul.p >= 0 && ur.p >= 0
245
+ if ur.p > ul.p
246
+ revised_order.push(ul)
247
+ at_l+=1
248
+ next
249
+ end
250
+ elsif ur.l > ul.l
251
+ revised_order.push(ul)
252
+ at_l+=1
253
+ next
237
254
  end
238
- xl+=1
255
+ revised_order.push(ur)
256
+ at_r+=1
239
257
  next
240
258
  end
241
- end
242
- if zr != nil
243
- if ref.a2b(zr) == nil
244
- if vr.include?(xr)
245
- order.add(-1,xr,zr)
246
- prev = zr
247
- vp.delete(zr)
248
- ct_vp-=1
249
- vr.delete(xr)
250
- ct_vr-=1
251
- xp = zr + 1
252
- end
253
- xr+=1
259
+ if at_r < remotes.length
260
+ ur1 = order[remotes[at_r]]
261
+ revised_order.push(ur1)
262
+ at_r+=1
254
263
  next
255
264
  end
256
- end
257
- if zl != nil && zr != nil && self.a2b(zl) != nil && ref.a2b(zr) != nil
258
- if zl == prev + 1 || zr != prev + 1
259
- if vr.include?(xr)
260
- order.add(ref.a2b(zr),xr,zr)
261
- prev = zr
262
- vp.delete(zr)
263
- ct_vp-=1
264
- begin
265
- key = ref.a2b(zr)
266
- vl.delete(key)
267
- end
268
- ct_vl-=1
269
- vr.delete(xr)
270
- ct_vr-=1
271
- xp = zr + 1
272
- xl = ref.a2b(zr) + 1
273
- end
274
- xr+=1
275
- next
276
- else
277
- if vl.include?(xl)
278
- order.add(xl,self.a2b(zl),zl)
279
- prev = zl
280
- vp.delete(zl)
281
- ct_vp-=1
282
- vl.delete(xl)
283
- ct_vl-=1
284
- begin
285
- key1 = self.a2b(zl)
286
- vr.delete(key1)
287
- end
288
- ct_vr-=1
289
- xp = zl + 1
290
- xr = self.a2b(zl) + 1
291
- end
292
- xl+=1
265
+ if at_l < locals.length
266
+ ul1 = order[locals[at_l]]
267
+ revised_order.push(ul1)
268
+ at_l+=1
293
269
  next
294
270
  end
295
271
  end
296
- xp+=1
297
- xl+=1
298
- xr+=1
299
272
  end
300
- return order
273
+ order = revised_order
274
+ result = ::Coopy::Ordering.new
275
+ result.set_list(order)
276
+ result.ignore_parent if @reference == nil
277
+ result
301
278
  end
302
279
 
303
280
  haxe_me ["coopy", "Alignment"]