everypolitician-daff 1.3.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +252 -0
  3. data/bin/daff.rb +3 -0
  4. data/lib/daff.rb +150 -0
  5. data/lib/lib/coopy/alignment.rb +307 -0
  6. data/lib/lib/coopy/cell_builder.rb +17 -0
  7. data/lib/lib/coopy/cell_info.rb +33 -0
  8. data/lib/lib/coopy/column_change.rb +16 -0
  9. data/lib/lib/coopy/combined_table.rb +127 -0
  10. data/lib/lib/coopy/combined_table_body.rb +151 -0
  11. data/lib/lib/coopy/combined_table_head.rb +103 -0
  12. data/lib/lib/coopy/compare_flags.rb +127 -0
  13. data/lib/lib/coopy/compare_table.rb +688 -0
  14. data/lib/lib/coopy/conflict_info.rb +23 -0
  15. data/lib/lib/coopy/coopy.rb +1065 -0
  16. data/lib/lib/coopy/cross_match.rb +17 -0
  17. data/lib/lib/coopy/csv.rb +290 -0
  18. data/lib/lib/coopy/diff_render.rb +339 -0
  19. data/lib/lib/coopy/diff_summary.rb +28 -0
  20. data/lib/lib/coopy/flat_cell_builder.rb +75 -0
  21. data/lib/lib/coopy/highlight_patch.rb +977 -0
  22. data/lib/lib/coopy/highlight_patch_unit.rb +38 -0
  23. data/lib/lib/coopy/index.rb +131 -0
  24. data/lib/lib/coopy/index_item.rb +37 -0
  25. data/lib/lib/coopy/index_pair.rb +96 -0
  26. data/lib/lib/coopy/json_table.rb +165 -0
  27. data/lib/lib/coopy/json_tables.rb +129 -0
  28. data/lib/lib/coopy/merger.rb +197 -0
  29. data/lib/lib/coopy/meta.rb +20 -0
  30. data/lib/lib/coopy/mover.rb +197 -0
  31. data/lib/lib/coopy/ndjson.rb +134 -0
  32. data/lib/lib/coopy/nested_cell_builder.rb +74 -0
  33. data/lib/lib/coopy/ordering.rb +54 -0
  34. data/lib/lib/coopy/property_change.rb +16 -0
  35. data/lib/lib/coopy/row.rb +11 -0
  36. data/lib/lib/coopy/row_change.rb +42 -0
  37. data/lib/lib/coopy/row_stream.rb +11 -0
  38. data/lib/lib/coopy/simple_meta.rb +314 -0
  39. data/lib/lib/coopy/simple_table.rb +345 -0
  40. data/lib/lib/coopy/simple_view.rb +70 -0
  41. data/lib/lib/coopy/sparse_sheet.rb +51 -0
  42. data/lib/lib/coopy/sql_column.rb +47 -0
  43. data/lib/lib/coopy/sql_compare.rb +605 -0
  44. data/lib/lib/coopy/sql_database.rb +21 -0
  45. data/lib/lib/coopy/sql_helper.rb +17 -0
  46. data/lib/lib/coopy/sql_table.rb +335 -0
  47. data/lib/lib/coopy/sql_table_name.rb +23 -0
  48. data/lib/lib/coopy/sql_tables.rb +128 -0
  49. data/lib/lib/coopy/sqlite_helper.rb +316 -0
  50. data/lib/lib/coopy/table.rb +24 -0
  51. data/lib/lib/coopy/table_comparison_state.rb +50 -0
  52. data/lib/lib/coopy/table_diff.rb +1185 -0
  53. data/lib/lib/coopy/table_io.rb +72 -0
  54. data/lib/lib/coopy/table_modifier.rb +40 -0
  55. data/lib/lib/coopy/table_stream.rb +102 -0
  56. data/lib/lib/coopy/table_view.rb +148 -0
  57. data/lib/lib/coopy/tables.rb +52 -0
  58. data/lib/lib/coopy/terminal_diff_render.rb +213 -0
  59. data/lib/lib/coopy/unit.rb +93 -0
  60. data/lib/lib/coopy/view.rb +20 -0
  61. data/lib/lib/coopy/viterbi.rb +177 -0
  62. data/lib/lib/haxe/ds/int_map.rb +19 -0
  63. data/lib/lib/haxe/ds/string_map.rb +19 -0
  64. data/lib/lib/haxe/format/json_parser.rb +265 -0
  65. data/lib/lib/haxe/format/json_printer.rb +240 -0
  66. data/lib/lib/haxe/imap.rb +10 -0
  67. data/lib/lib/haxe/io/bytes.rb +34 -0
  68. data/lib/lib/haxe/io/eof.rb +18 -0
  69. data/lib/lib/haxe/io/error.rb +22 -0
  70. data/lib/lib/haxe/io/output.rb +41 -0
  71. data/lib/lib/hx_overrides.rb +19 -0
  72. data/lib/lib/hx_sys.rb +74 -0
  73. data/lib/lib/lambda.rb +37 -0
  74. data/lib/lib/list.rb +36 -0
  75. data/lib/lib/math.rb +5 -0
  76. data/lib/lib/rb/boot.rb +39 -0
  77. data/lib/lib/rb/ruby_iterator.rb +50 -0
  78. data/lib/lib/reflect.rb +41 -0
  79. data/lib/lib/std.rb +12 -0
  80. data/lib/lib/string_buf.rb +19 -0
  81. data/lib/lib/sys/io/file_handle.rb +18 -0
  82. data/lib/lib/sys/io/file_output.rb +36 -0
  83. data/lib/lib/sys/io/hx_file.rb +20 -0
  84. data/lib/lib/type.rb +37 -0
  85. data/lib/lib/value_type.rb +23 -0
  86. data/lib/lib/x_list/list_iterator.rb +32 -0
  87. metadata +235 -0
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class Ndjson
6
+
7
+ def initialize(tab)
8
+ @tab = tab
9
+ @view = tab.get_cell_view
10
+ @header_row = 0
11
+ end
12
+
13
+ protected
14
+
15
+ attr_accessor :tab
16
+ attr_accessor :view
17
+ attr_accessor :columns
18
+ attr_accessor :header_row
19
+
20
+ public
21
+
22
+ def render_row(r)
23
+ row = {}
24
+ begin
25
+ _g1 = 0
26
+ _g = @tab.get_width
27
+ while(_g1 < _g)
28
+ c = _g1
29
+ _g1+=1
30
+ key = @view.to_s(@tab.get_cell(c,@header_row))
31
+ key = "@:@" if c == 0 && @header_row == 1
32
+ begin
33
+ value = @tab.get_cell(c,r)
34
+ begin
35
+ value1 = value
36
+ row[key] = value1
37
+ end
38
+ end
39
+ end
40
+ end
41
+ ::Haxe::Format::JsonPrinter._print(row,nil,nil)
42
+ end
43
+
44
+ def render
45
+ txt = ""
46
+ offset = 0
47
+ return txt if @tab.get_height == 0
48
+ return txt if @tab.get_width == 0
49
+ offset = 1 if @tab.get_cell(0,0) == "@:@"
50
+ @header_row = offset
51
+ begin
52
+ _g1 = @header_row + 1
53
+ _g = @tab.get_height
54
+ while(_g1 < _g)
55
+ r = _g1
56
+ _g1+=1
57
+ txt += self.render_row(r)
58
+ txt += "\n"
59
+ end
60
+ end
61
+ txt
62
+ end
63
+
64
+ def add_row(r,txt)
65
+ json = ::Haxe::Format::JsonParser.new(txt).parse_rec
66
+ @columns = {} if @columns == nil
67
+ w = @tab.get_width
68
+ h = @tab.get_height
69
+ resize = false
70
+ begin
71
+ _g = 0
72
+ _g1 = Reflect.fields(json)
73
+ while(_g < _g1.length)
74
+ name = _g1[_g]
75
+ _g+=1
76
+ if !@columns.include?(name)
77
+ @columns[name] = w
78
+ w+=1
79
+ resize = true
80
+ end
81
+ end
82
+ end
83
+ if r >= h
84
+ h = r + 1
85
+ resize = true
86
+ end
87
+ @tab.resize(w,h) if resize
88
+ begin
89
+ _g2 = 0
90
+ _g11 = Reflect.fields(json)
91
+ while(_g2 < _g11.length)
92
+ name1 = _g11[_g2]
93
+ _g2+=1
94
+ v = Reflect.field(json,name1)
95
+ c = @columns[name1]
96
+ @tab.set_cell(c,r,v)
97
+ end
98
+ end
99
+ end
100
+
101
+ def add_header_row(r)
102
+ names = ::Rb::RubyIterator.new(@columns.keys)
103
+ _it = names
104
+ while(_it.has_next) do
105
+ n = _it._next
106
+ @tab.set_cell(@columns[n],r,@view.to_datum(n))
107
+ end
108
+ end
109
+
110
+ def parse(txt)
111
+ @columns = nil
112
+ rows = txt.split("\n")
113
+ h = rows.length
114
+ if h == 0
115
+ @tab.clear
116
+ return
117
+ end
118
+ h-=1 if rows[h - 1] == ""
119
+ begin
120
+ _g = 0
121
+ while(_g < h)
122
+ i = _g
123
+ _g+=1
124
+ at = h - i - 1
125
+ self.add_row(at + 1,rows[at])
126
+ end
127
+ end
128
+ self.add_header_row(0)
129
+ end
130
+
131
+ haxe_me ["coopy", "Ndjson"]
132
+ end
133
+
134
+ end
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class NestedCellBuilder
6
+
7
+ def initialize
8
+ end
9
+
10
+ protected
11
+
12
+ attr_accessor :view
13
+
14
+ public
15
+
16
+ def need_separator
17
+ false
18
+ end
19
+
20
+ def set_separator(separator)
21
+ end
22
+
23
+ def set_conflict_separator(separator)
24
+ end
25
+
26
+ def set_view(view)
27
+ @view = view
28
+ end
29
+
30
+ def update(local,remote)
31
+ h = @view.make_hash
32
+ @view.hash_set(h,"before",local)
33
+ @view.hash_set(h,"after",remote)
34
+ h
35
+ end
36
+
37
+ def conflict(parent,local,remote)
38
+ h = @view.make_hash
39
+ @view.hash_set(h,"before",parent)
40
+ @view.hash_set(h,"ours",local)
41
+ @view.hash_set(h,"theirs",remote)
42
+ h
43
+ end
44
+
45
+ def marker(label)
46
+ @view.to_datum(label)
47
+ end
48
+
49
+ protected
50
+
51
+ def neg_to_null(x)
52
+ return nil if x < 0
53
+ x
54
+ end
55
+
56
+ public
57
+
58
+ def links(unit,row_like)
59
+ h = @view.make_hash
60
+ if unit.p >= -1
61
+ @view.hash_set(h,"before",self.neg_to_null(unit.p))
62
+ @view.hash_set(h,"ours",self.neg_to_null(unit.l))
63
+ @view.hash_set(h,"theirs",self.neg_to_null(unit.r))
64
+ return h
65
+ end
66
+ @view.hash_set(h,"before",self.neg_to_null(unit.l))
67
+ @view.hash_set(h,"after",self.neg_to_null(unit.r))
68
+ h
69
+ end
70
+
71
+ haxe_me ["coopy", "NestedCellBuilder"]
72
+ end
73
+
74
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class Ordering
6
+
7
+ def initialize
8
+ @order = Array.new
9
+ @ignore_parent = false
10
+ end
11
+
12
+ protected
13
+
14
+ attr_accessor :order
15
+ attr_accessor :ignore_parent
16
+
17
+ public
18
+
19
+ def add(l,r,p = -2)
20
+ p = -2 if @ignore_parent
21
+ @order.push(::Coopy::Unit.new(l,r,p))
22
+ end
23
+
24
+ def get_list
25
+ @order
26
+ end
27
+
28
+ def set_list(lst)
29
+ @order = lst
30
+ end
31
+
32
+ def to_s
33
+ txt = ""
34
+ begin
35
+ _g1 = 0
36
+ _g = @order.length
37
+ while(_g1 < _g)
38
+ i = _g1
39
+ _g1+=1
40
+ txt += ", " if i > 0
41
+ txt += @order[i].to_s
42
+ end
43
+ end
44
+ txt
45
+ end
46
+
47
+ def ignore_parent
48
+ @ignore_parent = true
49
+ end
50
+
51
+ haxe_me ["coopy", "Ordering"]
52
+ end
53
+
54
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class PropertyChange
6
+
7
+ def initialize
8
+ end
9
+
10
+ attr_accessor :prev_name
11
+ attr_accessor :name
12
+ attr_accessor :val
13
+ haxe_me ["coopy", "PropertyChange"]
14
+ end
15
+
16
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class Row
6
+ def getRowString(c) puts "Abstract Row.getRowString called" end
7
+ def isPreamble() puts "Abstract Row.isPreamble called" end
8
+ haxe_me ["coopy", "Row"]
9
+ end
10
+
11
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class RowChange
6
+
7
+ def initialize
8
+ end
9
+
10
+ attr_accessor :cond
11
+ attr_accessor :val
12
+ attr_accessor :conflicting_val
13
+ attr_accessor :conflicting_parent_val
14
+ attr_accessor :conflicted
15
+ attr_accessor :is_key
16
+ attr_accessor :action
17
+
18
+ protected
19
+
20
+ def show_map(m)
21
+ return "{}" if m == nil
22
+ txt = ""
23
+ _it = ::Rb::RubyIterator.new(m.keys)
24
+ while(_it.has_next) do
25
+ k = _it._next
26
+ txt += ", " if txt != ""
27
+ v = m[k]
28
+ txt += _hx_str(k) + "=" + _hx_str(v.to_s)
29
+ end
30
+ "{ " + _hx_str(txt) + " }"
31
+ end
32
+
33
+ public
34
+
35
+ def to_s
36
+ _hx_str(@action) + " " + _hx_str(self.show_map(@cond)) + " : " + _hx_str(self.show_map(@val))
37
+ end
38
+
39
+ haxe_me ["coopy", "RowChange"]
40
+ end
41
+
42
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class RowStream
6
+ def fetchColumns() puts "Abstract RowStream.fetchColumns called" end
7
+ def fetchRow() puts "Abstract RowStream.fetchRow called" end
8
+ haxe_me ["coopy", "RowStream"]
9
+ end
10
+
11
+ end
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class SimpleMeta
6
+
7
+ def initialize(t,has_properties = true,may_be_nested = false)
8
+ @t = t
9
+ self.row_change
10
+ self.col_change
11
+ @has_properties = has_properties
12
+ @may_be_nested = may_be_nested
13
+ @metadata = nil
14
+ @keys = nil
15
+ @row_active = false
16
+ @row_change_cache = nil
17
+ end
18
+
19
+ protected
20
+
21
+ attr_accessor :t
22
+ attr_accessor :name2row
23
+ attr_accessor :name2col
24
+ attr_accessor :has_properties
25
+ attr_accessor :metadata
26
+ attr_accessor :keys
27
+ attr_accessor :row_active
28
+ attr_accessor :row_change_cache
29
+ attr_accessor :may_be_nested
30
+
31
+ public
32
+
33
+ def store_row_changes(changes)
34
+ @row_change_cache = changes
35
+ @row_active = true
36
+ end
37
+
38
+ protected
39
+
40
+ def row_change
41
+ @name2row = nil
42
+ end
43
+
44
+ def col_change
45
+ @name2col = nil
46
+ end
47
+
48
+ def col(key)
49
+ return -1 if @t.get_height < 1
50
+ if @name2col == nil
51
+ @name2col = {}
52
+ w = @t.get_width
53
+ begin
54
+ _g = 0
55
+ while(_g < w)
56
+ c = _g
57
+ _g+=1
58
+ begin
59
+ key1 = @t.get_cell(c,0)
60
+ @name2col[key1] = c
61
+ end
62
+ end
63
+ end
64
+ end
65
+ return -1 if !@name2col.include?(key)
66
+ @name2col[key]
67
+ end
68
+
69
+ def row(key)
70
+ return -1 if @t.get_width < 1
71
+ if @name2row == nil
72
+ @name2row = {}
73
+ h = @t.get_height
74
+ begin
75
+ _g = 1
76
+ while(_g < h)
77
+ r = _g
78
+ _g+=1
79
+ begin
80
+ key1 = @t.get_cell(0,r)
81
+ @name2row[key1] = r
82
+ end
83
+ end
84
+ end
85
+ end
86
+ return -1 if !@name2row.include?(key)
87
+ @name2row[key]
88
+ end
89
+
90
+ public
91
+
92
+ def alter_columns(columns)
93
+ target = {}
94
+ wfate = 0
95
+ if @has_properties
96
+ target["@"] = wfate
97
+ wfate+=1
98
+ end
99
+ begin
100
+ _g1 = 0
101
+ _g = columns.length
102
+ while(_g1 < _g)
103
+ i = _g1
104
+ _g1+=1
105
+ col = columns[i]
106
+ target[col.prev_name] = wfate if col.prev_name != nil
107
+ wfate+=1 if col.name != nil
108
+ end
109
+ end
110
+ fate = Array.new
111
+ begin
112
+ _g11 = 0
113
+ _g2 = @t.get_width
114
+ while(_g11 < _g2)
115
+ i1 = _g11
116
+ _g11+=1
117
+ targeti = -1
118
+ name = @t.get_cell(i1,0)
119
+ targeti = target[name] if target.include?(name)
120
+ fate.push(targeti)
121
+ end
122
+ end
123
+ @t.insert_or_delete_columns(fate,wfate)
124
+ start = nil
125
+ if @has_properties
126
+ start = 1
127
+ else
128
+ start = 0
129
+ end
130
+ at = start
131
+ begin
132
+ _g12 = 0
133
+ _g3 = columns.length
134
+ while(_g12 < _g3)
135
+ i2 = _g12
136
+ _g12+=1
137
+ col1 = columns[i2]
138
+ if col1.name != nil
139
+ @t.set_cell(at,0,col1.name) if col1.name != col1.prev_name
140
+ end
141
+ at+=1 if col1.name != nil
142
+ end
143
+ end
144
+ return true if !@has_properties
145
+ self.col_change
146
+ at = start
147
+ begin
148
+ _g13 = 0
149
+ _g4 = columns.length
150
+ while(_g13 < _g4)
151
+ i3 = _g13
152
+ _g13+=1
153
+ col2 = columns[i3]
154
+ if col2.name != nil
155
+ _g21 = 0
156
+ _g31 = col2.props
157
+ while(_g21 < _g31.length)
158
+ prop = _g31[_g21]
159
+ _g21+=1
160
+ self.set_cell(col2.name,prop.name,prop.val)
161
+ end
162
+ end
163
+ at+=1 if col2.name != nil
164
+ end
165
+ end
166
+ true
167
+ end
168
+
169
+ protected
170
+
171
+ def set_cell(c,r,val)
172
+ ri = self.row(r)
173
+ return false if ri == -1
174
+ ci = self.col(c)
175
+ return false if ci == -1
176
+ @t.set_cell(ci,ri,val)
177
+ true
178
+ end
179
+
180
+ public
181
+
182
+ def add_meta_data(column,property,val)
183
+ if @metadata == nil
184
+ @metadata = {}
185
+ @keys = {}
186
+ end
187
+ if !@metadata.include?(column)
188
+ value = {}
189
+ @metadata[column] = value
190
+ end
191
+ props = @metadata[column]
192
+ begin
193
+ value1 = val
194
+ begin
195
+ value2 = value1
196
+ props[property] = value2
197
+ end
198
+ end
199
+ @keys[property] = true
200
+ end
201
+
202
+ def as_table
203
+ return @t if @has_properties && @metadata == nil
204
+ return nil if @metadata == nil
205
+ w = @t.get_width
206
+ props = Array.new
207
+ _it = ::Rb::RubyIterator.new(@keys.keys)
208
+ while(_it.has_next) do
209
+ k = _it._next
210
+ props.push(k)
211
+ end
212
+ props.sort!{|a,b| Reflect.compare(a,b)}
213
+ mt = ::Coopy::SimpleTable.new(w + 1,props.length + 1)
214
+ mt.set_cell(0,0,"@")
215
+ begin
216
+ _g = 0
217
+ while(_g < w)
218
+ x = _g
219
+ _g+=1
220
+ name = @t.get_cell(x,0)
221
+ mt.set_cell(1 + x,0,name)
222
+ next if !@metadata.include?(name)
223
+ vals = @metadata[name]
224
+ begin
225
+ _g2 = 0
226
+ _g1 = props.length
227
+ while(_g2 < _g1)
228
+ i = _g2
229
+ _g2+=1
230
+ mt.set_cell(1 + x,i + 1,vals[props[i]]) if vals.include?(props[i])
231
+ end
232
+ end
233
+ end
234
+ end
235
+ begin
236
+ _g11 = 0
237
+ _g3 = props.length
238
+ while(_g11 < _g3)
239
+ y = _g11
240
+ _g11+=1
241
+ mt.set_cell(0,y + 1,props[y])
242
+ end
243
+ end
244
+ mt
245
+ end
246
+
247
+ def clone_meta(table = nil)
248
+ result = ::Coopy::SimpleMeta.new(table)
249
+ if @metadata != nil
250
+ result.keys = {}
251
+ _it = ::Rb::RubyIterator.new(@keys.keys)
252
+ while(_it.has_next) do
253
+ k = _it._next
254
+ result.keys[k] = true
255
+ end
256
+ result.metadata = {}
257
+ _it2 = ::Rb::RubyIterator.new(@metadata.keys)
258
+ while(_it2.has_next) do
259
+ k1 = _it2._next
260
+ next if !@metadata.include?(k1)
261
+ vals = @metadata[k1]
262
+ nvals = {}
263
+ _it3 = ::Rb::RubyIterator.new(vals.keys)
264
+ while(_it3.has_next) do
265
+ p = _it3._next
266
+ value = vals[p]
267
+ begin
268
+ value1 = value
269
+ nvals[p] = value1
270
+ end
271
+ end
272
+ result.metadata[k1] = nvals
273
+ end
274
+ end
275
+ result
276
+ end
277
+
278
+ def use_for_column_changes
279
+ true
280
+ end
281
+
282
+ def use_for_row_changes
283
+ @row_active
284
+ end
285
+
286
+ def change_row(rc)
287
+ @row_change_cache.push(rc)
288
+ false
289
+ end
290
+
291
+ def apply_flags(flags)
292
+ false
293
+ end
294
+
295
+ def get_row_stream
296
+ ::Coopy::TableStream.new(@t)
297
+ end
298
+
299
+ def is_nested
300
+ @may_be_nested
301
+ end
302
+
303
+ def is_sql
304
+ false
305
+ end
306
+
307
+ def get_name
308
+ nil
309
+ end
310
+
311
+ haxe_me ["coopy", "SimpleMeta"]
312
+ end
313
+
314
+ end