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,129 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class JsonTables
6
+
7
+ def initialize(json,flags)
8
+ @db = json
9
+ names = Reflect.field(json,"names")
10
+ allowed = nil
11
+ count = names.length
12
+ if flags != nil && flags.tables != nil
13
+ allowed = {}
14
+ begin
15
+ _g = 0
16
+ _g1 = flags.tables
17
+ while(_g < _g1.length)
18
+ name = _g1[_g]
19
+ _g+=1
20
+ allowed[name] = true
21
+ end
22
+ end
23
+ count = 0
24
+ begin
25
+ _g2 = 0
26
+ while(_g2 < names.length)
27
+ name1 = names[_g2]
28
+ _g2+=1
29
+ count+=1 if allowed.include?(name1)
30
+ end
31
+ end
32
+ end
33
+ @t = ::Coopy::SimpleTable.new(2,count + 1)
34
+ @t.set_cell(0,0,"name")
35
+ @t.set_cell(1,0,"table")
36
+ v = @t.get_cell_view
37
+ at = 1
38
+ begin
39
+ _g3 = 0
40
+ while(_g3 < names.length)
41
+ name2 = names[_g3]
42
+ _g3+=1
43
+ if allowed != nil
44
+ next if !allowed.include?(name2)
45
+ end
46
+ @t.set_cell(0,at,name2)
47
+ tab = Reflect.field(@db,"tables")
48
+ tab = Reflect.field(tab,name2)
49
+ @t.set_cell(1,at,v.wrap_table(::Coopy::JsonTable.new(tab,name2)))
50
+ at+=1
51
+ end
52
+ end
53
+ end
54
+
55
+ protected
56
+
57
+ attr_accessor :db
58
+ attr_accessor :t
59
+ attr_accessor :flags
60
+
61
+ public
62
+
63
+ def height() get_height end
64
+ def height=(__v) @height = __v end
65
+ def width() get_width end
66
+ def width=(__v) @width = __v end
67
+
68
+ def get_cell(x,y)
69
+ @t.get_cell(x,y)
70
+ end
71
+
72
+ def set_cell(x,y,c)
73
+ end
74
+
75
+ def get_cell_view
76
+ @t.get_cell_view
77
+ end
78
+
79
+ def is_resizable
80
+ false
81
+ end
82
+
83
+ def resize(w,h)
84
+ false
85
+ end
86
+
87
+ def clear
88
+ end
89
+
90
+ def insert_or_delete_rows(fate,hfate)
91
+ false
92
+ end
93
+
94
+ def insert_or_delete_columns(fate,wfate)
95
+ false
96
+ end
97
+
98
+ def trim_blank
99
+ false
100
+ end
101
+
102
+ def get_width
103
+ @t.get_width
104
+ end
105
+
106
+ def get_height
107
+ @t.get_height
108
+ end
109
+
110
+ def get_data
111
+ nil
112
+ end
113
+
114
+ def clone
115
+ nil
116
+ end
117
+
118
+ def get_meta
119
+ ::Coopy::SimpleMeta.new(self,true,true)
120
+ end
121
+
122
+ def create
123
+ nil
124
+ end
125
+
126
+ haxe_me ["coopy", "JsonTables"]
127
+ end
128
+
129
+ end
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class Merger
6
+
7
+ def initialize(parent,local,remote,flags)
8
+ @parent = parent
9
+ @local = local
10
+ @remote = remote
11
+ @flags = flags
12
+ end
13
+
14
+ # protected - in ruby this doesn't play well with static/inline methods
15
+
16
+ attr_accessor :parent
17
+ attr_accessor :local
18
+ attr_accessor :remote
19
+ attr_accessor :flags
20
+ attr_accessor :order
21
+ attr_accessor :units
22
+ attr_accessor :column_order
23
+ attr_accessor :column_units
24
+ attr_accessor :row_mix_local
25
+ attr_accessor :row_mix_remote
26
+ attr_accessor :column_mix_local
27
+ attr_accessor :column_mix_remote
28
+ attr_accessor :conflicts
29
+ attr_accessor :conflict_infos
30
+
31
+ def shuffle_dimension(dim_units,len,fate,cl,cr)
32
+ at = 0
33
+ begin
34
+ _g = 0
35
+ while(_g < dim_units.length)
36
+ cunit = dim_units[_g]
37
+ _g+=1
38
+ if cunit.p < 0
39
+ if cunit.l < 0
40
+ if cunit.r >= 0
41
+ begin
42
+ cr[cunit.r] = at
43
+ at
44
+ end
45
+ at+=1
46
+ end
47
+ else
48
+ begin
49
+ cl[cunit.l] = at
50
+ at
51
+ end
52
+ at+=1
53
+ end
54
+ elsif cunit.l >= 0
55
+ if cunit.r < 0
56
+ else
57
+ begin
58
+ cl[cunit.l] = at
59
+ at
60
+ end
61
+ at+=1
62
+ end
63
+ end
64
+ end
65
+ end
66
+ begin
67
+ _g1 = 0
68
+ while(_g1 < len)
69
+ x = _g1
70
+ _g1+=1
71
+ idx = cl[x]
72
+ if idx == nil
73
+ fate.push(-1)
74
+ else
75
+ fate.push(idx)
76
+ end
77
+ end
78
+ end
79
+ at
80
+ end
81
+
82
+ def shuffle_columns
83
+ @column_mix_local = {}
84
+ @column_mix_remote = {}
85
+ fate = Array.new
86
+ wfate = self.shuffle_dimension(@column_units,@local.get_width,fate,@column_mix_local,@column_mix_remote)
87
+ @local.insert_or_delete_columns(fate,wfate)
88
+ end
89
+
90
+ def shuffle_rows
91
+ @row_mix_local = {}
92
+ @row_mix_remote = {}
93
+ fate = Array.new
94
+ hfate = self.shuffle_dimension(@units,@local.get_height,fate,@row_mix_local,@row_mix_remote)
95
+ @local.insert_or_delete_rows(fate,hfate)
96
+ end
97
+
98
+ public
99
+
100
+ def apply
101
+ @conflicts = 0
102
+ @conflict_infos = Array.new
103
+ ct = ::Coopy::Coopy.compare_tables3(@parent,@local,@remote)
104
+ align = ct.align
105
+ @order = align.to_order
106
+ @units = @order.get_list
107
+ @column_order = align.meta.to_order
108
+ @column_units = @column_order.get_list
109
+ allow_insert = @flags.allow_insert
110
+ allow_delete = @flags.allow_delete
111
+ allow_update = @flags.allow_update
112
+ view = @parent.get_cell_view
113
+ begin
114
+ _g = 0
115
+ _g1 = @units
116
+ while(_g < _g1.length)
117
+ row = _g1[_g]
118
+ _g+=1
119
+ if row.l >= 0 && row.r >= 0 && row.p >= 0
120
+ _g2 = 0
121
+ _g3 = @column_units
122
+ while(_g2 < _g3.length)
123
+ col = _g3[_g2]
124
+ _g2+=1
125
+ if col.l >= 0 && col.r >= 0 && col.p >= 0
126
+ pcell = @parent.get_cell(col.p,row.p)
127
+ rcell = @remote.get_cell(col.r,row.r)
128
+ if !view.equals(pcell,rcell)
129
+ lcell = @local.get_cell(col.l,row.l)
130
+ if view.equals(pcell,lcell)
131
+ @local.set_cell(col.l,row.l,rcell)
132
+ else
133
+ @local.set_cell(col.l,row.l,::Coopy::Merger.make_conflicted_cell(view,pcell,lcell,rcell))
134
+ @conflicts+=1
135
+ self.add_conflict_info(row.l,col.l,view,pcell,lcell,rcell)
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+ self.shuffle_columns
144
+ self.shuffle_rows
145
+ _it = ::Rb::RubyIterator.new(@column_mix_remote.keys)
146
+ while(_it.has_next) do
147
+ x = _it._next
148
+ x2 = @column_mix_remote[x]
149
+ begin
150
+ _g4 = 0
151
+ _g11 = @units
152
+ while(_g4 < _g11.length)
153
+ unit = _g11[_g4]
154
+ _g4+=1
155
+ if unit.l >= 0 && unit.r >= 0
156
+ @local.set_cell(x2,@row_mix_local[unit.l],@remote.get_cell(x,unit.r))
157
+ elsif unit.p < 0 && unit.r >= 0
158
+ @local.set_cell(x2,@row_mix_remote[unit.r],@remote.get_cell(x,unit.r))
159
+ end
160
+ end
161
+ end
162
+ end
163
+ _it2 = ::Rb::RubyIterator.new(@row_mix_remote.keys)
164
+ while(_it2.has_next) do
165
+ y = _it2._next
166
+ y2 = @row_mix_remote[y]
167
+ begin
168
+ _g5 = 0
169
+ _g12 = @column_units
170
+ while(_g5 < _g12.length)
171
+ unit1 = _g12[_g5]
172
+ _g5+=1
173
+ @local.set_cell(@column_mix_local[unit1.l],y2,@remote.get_cell(unit1.r,y)) if unit1.l >= 0 && unit1.r >= 0
174
+ end
175
+ end
176
+ end
177
+ @conflicts
178
+ end
179
+
180
+ def get_conflict_infos
181
+ @conflict_infos
182
+ end
183
+
184
+ # protected - in ruby this doesn't play well with static/inline methods
185
+
186
+ def add_conflict_info(row,col,view,pcell,lcell,rcell)
187
+ @conflict_infos.push(::Coopy::ConflictInfo.new(row,col,view.to_s(pcell),view.to_s(lcell),view.to_s(rcell)))
188
+ end
189
+
190
+ def Merger.make_conflicted_cell(view,pcell,lcell,rcell)
191
+ view.to_datum("((( " + _hx_str(view.to_s(pcell)) + " ))) " + _hx_str(view.to_s(lcell)) + " /// " + _hx_str(view.to_s(rcell)))
192
+ end
193
+
194
+ haxe_me ["coopy", "Merger"]
195
+ end
196
+
197
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class Meta
6
+ def alterColumns(columns) puts "Abstract Meta.alterColumns called" end
7
+ def changeRow(rc) puts "Abstract Meta.changeRow called" end
8
+ def applyFlags(flags) puts "Abstract Meta.applyFlags called" end
9
+ def asTable() puts "Abstract Meta.asTable called" end
10
+ def cloneMeta(table = nil) puts "Abstract Meta.cloneMeta called" end
11
+ def useForColumnChanges() puts "Abstract Meta.useForColumnChanges called" end
12
+ def useForRowChanges() puts "Abstract Meta.useForRowChanges called" end
13
+ def getRowStream() puts "Abstract Meta.getRowStream called" end
14
+ def isNested() puts "Abstract Meta.isNested called" end
15
+ def isSql() puts "Abstract Meta.isSql called" end
16
+ def getName() puts "Abstract Meta.getName called" end
17
+ haxe_me ["coopy", "Meta"]
18
+ end
19
+
20
+ end
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class Mover
6
+
7
+ def Mover.move_units(units)
8
+ isrc = Array.new
9
+ idest = Array.new
10
+ len = units.length
11
+ ltop = -1
12
+ rtop = -1
13
+ in_src = {}
14
+ in_dest = {}
15
+ begin
16
+ _g = 0
17
+ while(_g < len)
18
+ i = _g
19
+ _g+=1
20
+ unit = units[i]
21
+ if unit.l >= 0 && unit.r >= 0
22
+ ltop = unit.l if ltop < unit.l
23
+ rtop = unit.r if rtop < unit.r
24
+ begin
25
+ in_src[unit.l] = i
26
+ i
27
+ end
28
+ begin
29
+ in_dest[unit.r] = i
30
+ i
31
+ end
32
+ end
33
+ end
34
+ end
35
+ v = nil
36
+ begin
37
+ _g1 = 0
38
+ _g2 = ltop + 1
39
+ while(_g1 < _g2)
40
+ i1 = _g1
41
+ _g1+=1
42
+ v = in_src[i1]
43
+ isrc.push(v) if v != nil
44
+ end
45
+ end
46
+ begin
47
+ _g11 = 0
48
+ _g3 = rtop + 1
49
+ while(_g11 < _g3)
50
+ i2 = _g11
51
+ _g11+=1
52
+ v = in_dest[i2]
53
+ idest.push(v) if v != nil
54
+ end
55
+ end
56
+ ::Coopy::Mover.move_without_extras(isrc,idest)
57
+ end
58
+
59
+ def Mover.move(isrc,idest)
60
+ len = isrc.length
61
+ len2 = idest.length
62
+ in_src = {}
63
+ in_dest = {}
64
+ begin
65
+ _g = 0
66
+ while(_g < len)
67
+ i = _g
68
+ _g+=1
69
+ begin
70
+ in_src[isrc[i]] = i
71
+ i
72
+ end
73
+ end
74
+ end
75
+ begin
76
+ _g1 = 0
77
+ while(_g1 < len2)
78
+ i1 = _g1
79
+ _g1+=1
80
+ begin
81
+ in_dest[idest[i1]] = i1
82
+ i1
83
+ end
84
+ end
85
+ end
86
+ src = Array.new
87
+ dest = Array.new
88
+ v = nil
89
+ begin
90
+ _g2 = 0
91
+ while(_g2 < len)
92
+ i2 = _g2
93
+ _g2+=1
94
+ v = isrc[i2]
95
+ src.push(v) if in_dest.include?(v)
96
+ end
97
+ end
98
+ begin
99
+ _g3 = 0
100
+ while(_g3 < len2)
101
+ i3 = _g3
102
+ _g3+=1
103
+ v = idest[i3]
104
+ dest.push(v) if in_src.include?(v)
105
+ end
106
+ end
107
+ ::Coopy::Mover.move_without_extras(src,dest)
108
+ end
109
+
110
+ # protected - in ruby this doesn't play well with static/inline methods
111
+
112
+ def Mover.move_without_extras(src,dest)
113
+ return nil if src.length != dest.length
114
+ return [] if src.length <= 1
115
+ len = src.length
116
+ in_src = {}
117
+ blk_len = {}
118
+ blk_src_loc = {}
119
+ blk_dest_loc = {}
120
+ begin
121
+ _g = 0
122
+ while(_g < len)
123
+ i = _g
124
+ _g+=1
125
+ begin
126
+ in_src[src[i]] = i
127
+ i
128
+ end
129
+ end
130
+ end
131
+ ct = 0
132
+ in_cursor = -2
133
+ out_cursor = 0
134
+ _next = nil
135
+ blk = -1
136
+ v = nil
137
+ while(out_cursor < len)
138
+ v = dest[out_cursor]
139
+ _next = in_src[v]
140
+ if _next != in_cursor + 1
141
+ blk = v
142
+ ct = 1
143
+ blk_src_loc[blk] = _next
144
+ blk_dest_loc[blk] = out_cursor
145
+ else
146
+ ct+=1
147
+ end
148
+ blk_len[blk] = ct
149
+ in_cursor = _next
150
+ out_cursor+=1
151
+ end
152
+ blks = Array.new
153
+ _it = ::Rb::RubyIterator.new(blk_len.keys)
154
+ while(_it.has_next) do
155
+ k = _it._next
156
+ blks.push(k)
157
+ end
158
+ blks.sort! {|a,b|
159
+ diff = blk_len[b] - blk_len[a]
160
+ diff = a - b if diff == 0
161
+ diff
162
+ }
163
+ moved = Array.new
164
+ while(blks.length > 0)
165
+ blk1 = blks.shift
166
+ blen = blks.length
167
+ ref_src_loc = blk_src_loc[blk1]
168
+ ref_dest_loc = blk_dest_loc[blk1]
169
+ i1 = blen - 1
170
+ while(i1 >= 0)
171
+ blki = blks[i1]
172
+ blki_src_loc = blk_src_loc[blki]
173
+ to_left_src = blki_src_loc < ref_src_loc
174
+ to_left_dest = blk_dest_loc[blki] < ref_dest_loc
175
+ if to_left_src != to_left_dest
176
+ ct1 = blk_len[blki]
177
+ begin
178
+ _g1 = 0
179
+ while(_g1 < ct1)
180
+ j = _g1
181
+ _g1+=1
182
+ moved.push(src[blki_src_loc])
183
+ blki_src_loc+=1
184
+ end
185
+ end
186
+ blks.slice!(i1,1)
187
+ end
188
+ i1-=1
189
+ end
190
+ end
191
+ moved
192
+ end
193
+
194
+ haxe_me ["coopy", "Mover"]
195
+ end
196
+
197
+ end