daff 1.3.2 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/daff.rb +11 -2
- data/lib/lib/coopy/alignment.rb +26 -2
- data/lib/lib/coopy/combined_table.rb +127 -0
- data/lib/lib/coopy/combined_table_body.rb +151 -0
- data/lib/lib/coopy/combined_table_head.rb +103 -0
- data/lib/lib/coopy/compare_flags.rb +3 -0
- data/lib/lib/coopy/compare_table.rb +38 -2
- data/lib/lib/coopy/coopy.rb +188 -110
- data/lib/lib/coopy/csv.rb +22 -3
- data/lib/lib/coopy/diff_render.rb +38 -10
- data/lib/lib/coopy/highlight_patch.rb +1 -1
- data/lib/lib/coopy/index.rb +8 -1
- data/lib/lib/coopy/json_table.rb +165 -0
- data/lib/lib/coopy/json_tables.rb +129 -0
- data/lib/lib/coopy/meta.rb +3 -0
- data/lib/lib/coopy/simple_meta.rb +314 -0
- data/lib/lib/coopy/simple_table.rb +4 -0
- data/lib/lib/coopy/simple_view.rb +12 -0
- data/lib/lib/coopy/sql_compare.rb +114 -66
- data/lib/lib/coopy/sql_table.rb +18 -2
- data/lib/lib/coopy/sql_tables.rb +128 -0
- data/lib/lib/coopy/sqlite_helper.rb +23 -1
- data/lib/lib/coopy/table.rb +1 -0
- data/lib/lib/coopy/table_comparison_state.rb +15 -0
- data/lib/lib/coopy/table_diff.rb +115 -5
- data/lib/lib/coopy/tables.rb +52 -0
- data/lib/lib/coopy/terminal_diff_render.rb +24 -8
- data/lib/lib/coopy/view.rb +3 -0
- data/lib/lib/rb/boot.rb +19 -0
- data/lib/lib/reflect.rb +10 -0
- data/lib/lib/std.rb +12 -0
- metadata +27 -16
data/lib/lib/coopy/sql_table.rb
CHANGED
@@ -210,6 +210,10 @@ module Coopy
|
|
210
210
|
nil
|
211
211
|
end
|
212
212
|
|
213
|
+
def create
|
214
|
+
nil
|
215
|
+
end
|
216
|
+
|
213
217
|
def get_meta
|
214
218
|
self
|
215
219
|
end
|
@@ -242,7 +246,7 @@ module Coopy
|
|
242
246
|
mt = ::Coopy::SimpleTable.new(w + 1,pct)
|
243
247
|
mt.set_cell(0,0,"@")
|
244
248
|
mt.set_cell(0,1,"type")
|
245
|
-
mt.set_cell(0,2,"
|
249
|
+
mt.set_cell(0,2,"key")
|
246
250
|
begin
|
247
251
|
_g = 0
|
248
252
|
while(_g < w)
|
@@ -251,7 +255,7 @@ module Coopy
|
|
251
255
|
i = x + 1
|
252
256
|
mt.set_cell(i,0,@column_names[x])
|
253
257
|
mt.set_cell(i,1,@columns[x].type_value)
|
254
|
-
mt.set_cell(i,2,((@columns[x].primary) ?
|
258
|
+
mt.set_cell(i,2,((@columns[x].primary) ? "primary" : ""))
|
255
259
|
end
|
256
260
|
end
|
257
261
|
mt
|
@@ -283,6 +287,14 @@ module Coopy
|
|
283
287
|
self
|
284
288
|
end
|
285
289
|
|
290
|
+
def is_nested
|
291
|
+
false
|
292
|
+
end
|
293
|
+
|
294
|
+
def is_sql
|
295
|
+
true
|
296
|
+
end
|
297
|
+
|
286
298
|
def fetch_row
|
287
299
|
if @db.read
|
288
300
|
row = {}
|
@@ -313,6 +325,10 @@ module Coopy
|
|
313
325
|
@column_names
|
314
326
|
end
|
315
327
|
|
328
|
+
def get_name
|
329
|
+
@name.to_s
|
330
|
+
end
|
331
|
+
|
316
332
|
haxe_me ["coopy", "SqlTable"]
|
317
333
|
end
|
318
334
|
|
@@ -0,0 +1,128 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class SqlTables
|
6
|
+
|
7
|
+
def initialize(db,flags)
|
8
|
+
@db = db
|
9
|
+
helper = @db.get_helper
|
10
|
+
names = helper.get_table_names(db)
|
11
|
+
allowed = nil
|
12
|
+
count = names.length
|
13
|
+
if flags.tables != nil
|
14
|
+
allowed = {}
|
15
|
+
begin
|
16
|
+
_g = 0
|
17
|
+
_g1 = flags.tables
|
18
|
+
while(_g < _g1.length)
|
19
|
+
name = _g1[_g]
|
20
|
+
_g+=1
|
21
|
+
allowed[name] = true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
count = 0
|
25
|
+
begin
|
26
|
+
_g2 = 0
|
27
|
+
while(_g2 < names.length)
|
28
|
+
name1 = names[_g2]
|
29
|
+
_g2+=1
|
30
|
+
count+=1 if allowed.include?(name1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@t = ::Coopy::SimpleTable.new(2,count + 1)
|
35
|
+
@t.set_cell(0,0,"name")
|
36
|
+
@t.set_cell(1,0,"table")
|
37
|
+
v = @t.get_cell_view
|
38
|
+
at = 1
|
39
|
+
begin
|
40
|
+
_g3 = 0
|
41
|
+
while(_g3 < names.length)
|
42
|
+
name2 = names[_g3]
|
43
|
+
_g3+=1
|
44
|
+
if allowed != nil
|
45
|
+
next if !allowed.include?(name2)
|
46
|
+
end
|
47
|
+
@t.set_cell(0,at,name2)
|
48
|
+
@t.set_cell(1,at,v.wrap_table(::Coopy::SqlTable.new(db,::Coopy::SqlTableName.new(name2))))
|
49
|
+
at+=1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
attr_accessor :db
|
57
|
+
attr_accessor :t
|
58
|
+
attr_accessor :flags
|
59
|
+
|
60
|
+
public
|
61
|
+
|
62
|
+
def height() get_height end
|
63
|
+
def height=(__v) @height = __v end
|
64
|
+
def width() get_width end
|
65
|
+
def width=(__v) @width = __v end
|
66
|
+
|
67
|
+
def get_cell(x,y)
|
68
|
+
@t.get_cell(x,y)
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_cell(x,y,c)
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_cell_view
|
75
|
+
@t.get_cell_view
|
76
|
+
end
|
77
|
+
|
78
|
+
def is_resizable
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
82
|
+
def resize(w,h)
|
83
|
+
false
|
84
|
+
end
|
85
|
+
|
86
|
+
def clear
|
87
|
+
end
|
88
|
+
|
89
|
+
def insert_or_delete_rows(fate,hfate)
|
90
|
+
false
|
91
|
+
end
|
92
|
+
|
93
|
+
def insert_or_delete_columns(fate,wfate)
|
94
|
+
false
|
95
|
+
end
|
96
|
+
|
97
|
+
def trim_blank
|
98
|
+
false
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_width
|
102
|
+
@t.get_width
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_height
|
106
|
+
@t.get_height
|
107
|
+
end
|
108
|
+
|
109
|
+
def get_data
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
|
113
|
+
def clone
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
|
117
|
+
def create
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_meta
|
122
|
+
::Coopy::SimpleMeta.new(self,true,true)
|
123
|
+
end
|
124
|
+
|
125
|
+
haxe_me ["coopy", "SqlTables"]
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -118,6 +118,28 @@ module Coopy
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def attach(db,tag,resource_name)
|
121
|
+
tag_present = false
|
122
|
+
tag_correct = false
|
123
|
+
result = Array.new
|
124
|
+
q = "PRAGMA database_list"
|
125
|
+
return false if !db._begin(q,nil,["seq","name","file"])
|
126
|
+
while(db.read)
|
127
|
+
name = db.get(1)
|
128
|
+
if name == tag
|
129
|
+
tag_present = true
|
130
|
+
file = db.get(2)
|
131
|
+
tag_correct = true if file == resource_name
|
132
|
+
end
|
133
|
+
end
|
134
|
+
db._end
|
135
|
+
if tag_present
|
136
|
+
return true if tag_correct
|
137
|
+
if !db._begin("DETACH `" + _hx_str(tag) + "`",nil,[])
|
138
|
+
puts "Failed to detach " + _hx_str(tag)
|
139
|
+
return false
|
140
|
+
end
|
141
|
+
db._end
|
142
|
+
end
|
121
143
|
if !db._begin("ATTACH ? AS `" + _hx_str(tag) + "`",[resource_name],[])
|
122
144
|
puts "Failed to attach " + _hx_str(resource_name) + " as " + _hx_str(tag)
|
123
145
|
return false
|
@@ -264,7 +286,7 @@ module Coopy
|
|
264
286
|
p = _g3[_g2]
|
265
287
|
_g2+=1
|
266
288
|
next_type = p.val if p.name == "type"
|
267
|
-
next_primary = "" + _hx_str(p.val.to_s) == "
|
289
|
+
next_primary = "" + _hx_str(p.val.to_s) == "primary" if p.name == "key"
|
268
290
|
end
|
269
291
|
end
|
270
292
|
part = "" + _hx_str(c.name)
|
data/lib/lib/coopy/table.rb
CHANGED
@@ -16,6 +16,7 @@ module Coopy
|
|
16
16
|
def get_height() puts "Abstract Table.get_height called" end
|
17
17
|
def getData() puts "Abstract Table.getData called" end
|
18
18
|
def clone() puts "Abstract Table.clone called" end
|
19
|
+
def create() puts "Abstract Table.create called" end
|
19
20
|
def getMeta() puts "Abstract Table.getMeta called" end
|
20
21
|
haxe_me ["coopy", "Table"]
|
21
22
|
end
|
@@ -18,6 +18,12 @@ module Coopy
|
|
18
18
|
attr_accessor :has_same_columns
|
19
19
|
attr_accessor :has_same_columns_known
|
20
20
|
attr_accessor :compare_flags
|
21
|
+
attr_accessor :p_meta
|
22
|
+
attr_accessor :a_meta
|
23
|
+
attr_accessor :b_meta
|
24
|
+
attr_accessor :alignment
|
25
|
+
attr_accessor :children
|
26
|
+
attr_accessor :child_order
|
21
27
|
|
22
28
|
def reset
|
23
29
|
@completed = false
|
@@ -27,6 +33,15 @@ module Coopy
|
|
27
33
|
@has_same_columns = false
|
28
34
|
@has_same_columns_known = false
|
29
35
|
@compare_flags = nil
|
36
|
+
@alignment = nil
|
37
|
+
@children = nil
|
38
|
+
@child_order = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_meta
|
42
|
+
@p_meta = @p.get_meta if @p != nil && @p_meta == nil
|
43
|
+
@a_meta = @a.get_meta if @a != nil && @a_meta == nil
|
44
|
+
@b_meta = @b.get_meta if @b != nil && @b_meta == nil
|
30
45
|
end
|
31
46
|
|
32
47
|
haxe_me ["coopy", "TableComparisonState"]
|
data/lib/lib/coopy/table_diff.rb
CHANGED
@@ -51,6 +51,8 @@ module Coopy
|
|
51
51
|
attr_accessor :diff_found
|
52
52
|
attr_accessor :schema_diff_found
|
53
53
|
attr_accessor :preserve_columns
|
54
|
+
attr_accessor :nested
|
55
|
+
attr_accessor :nesting_present
|
54
56
|
|
55
57
|
public
|
56
58
|
|
@@ -319,8 +321,15 @@ module Coopy
|
|
319
321
|
@allow_insert = @flags.allow_insert
|
320
322
|
@allow_delete = @flags.allow_delete
|
321
323
|
@allow_update = @flags.allow_update
|
322
|
-
|
324
|
+
common = @a
|
325
|
+
common = @b if common == nil
|
326
|
+
common = @p if common == nil
|
327
|
+
@v = common.get_cell_view
|
323
328
|
@builder.set_view(@v)
|
329
|
+
@nested = false
|
330
|
+
meta = common.get_meta
|
331
|
+
@nested = meta.is_nested if meta != nil
|
332
|
+
@nesting_present = false
|
324
333
|
end
|
325
334
|
|
326
335
|
def scan_activity
|
@@ -448,7 +457,7 @@ module Coopy
|
|
448
457
|
if @p.get_height >= @rp_header && @b.get_height >= @rb_header
|
449
458
|
pp = @p.get_cell(cunit.lp,@rp_header)
|
450
459
|
bb = @b.get_cell(cunit.r,@rb_header)
|
451
|
-
if
|
460
|
+
if !self.is_equal(@v,pp,bb)
|
452
461
|
@have_schema = true
|
453
462
|
act = "("
|
454
463
|
act += @v.to_s(pp)
|
@@ -658,6 +667,7 @@ module Coopy
|
|
658
667
|
end
|
659
668
|
|
660
669
|
def get_meta_table(t)
|
670
|
+
return nil if t == nil
|
661
671
|
meta = t.get_meta
|
662
672
|
return nil if meta == nil
|
663
673
|
meta.as_table
|
@@ -743,13 +753,76 @@ module Coopy
|
|
743
753
|
end
|
744
754
|
end
|
745
755
|
|
756
|
+
def normalize_string(v,str)
|
757
|
+
return str if str == nil
|
758
|
+
return str if !(@flags.ignore_whitespace || @flags.ignore_case)
|
759
|
+
txt = v.to_s(str)
|
760
|
+
txt = txt.strip if @flags.ignore_whitespace
|
761
|
+
txt = txt.downcase if @flags.ignore_case
|
762
|
+
txt
|
763
|
+
end
|
764
|
+
|
746
765
|
def is_equal(v,aa,bb)
|
747
|
-
return
|
748
|
-
_r = s.strip}.call(self) == lambda{|_this_| s1 = v.to_s(bb)
|
749
|
-
_r2 = s1.strip}.call(self) if @flags.ignore_whitespace
|
766
|
+
return self.normalize_string(v,aa) == self.normalize_string(v,bb) if @flags.ignore_whitespace || @flags.ignore_case
|
750
767
|
v.equals(aa,bb)
|
751
768
|
end
|
752
769
|
|
770
|
+
def check_nesting(v,have_ll,ll,have_rr,rr,have_pp,pp,x,y)
|
771
|
+
all_tables = true
|
772
|
+
all_tables = all_tables && v.is_table(ll) if have_ll
|
773
|
+
all_tables = all_tables && v.is_table(rr) if have_rr
|
774
|
+
all_tables = all_tables && v.is_table(pp) if have_pp
|
775
|
+
return [ll,rr,pp] if !all_tables
|
776
|
+
ll_table = nil
|
777
|
+
rr_table = nil
|
778
|
+
pp_table = nil
|
779
|
+
ll_table = v.get_table(ll) if have_ll
|
780
|
+
rr_table = v.get_table(rr) if have_rr
|
781
|
+
pp_table = v.get_table(pp) if have_pp
|
782
|
+
compare = false
|
783
|
+
comp = ::Coopy::TableComparisonState.new
|
784
|
+
comp.a = ll_table
|
785
|
+
comp.b = rr_table
|
786
|
+
comp.p = pp_table
|
787
|
+
comp.compare_flags = @flags
|
788
|
+
comp.get_meta
|
789
|
+
key = nil
|
790
|
+
key = comp.a_meta.get_name if comp.a_meta != nil
|
791
|
+
key = comp.b_meta.get_name if key == nil && comp.b_meta != nil
|
792
|
+
key = _hx_str(x) + "_" + _hx_str(y) if key == nil
|
793
|
+
if @align.comp != nil
|
794
|
+
if @align.comp.children == nil
|
795
|
+
@align.comp.children = {}
|
796
|
+
@align.comp.child_order = Array.new
|
797
|
+
compare = true
|
798
|
+
else
|
799
|
+
compare = !@align.comp.children.include?(key)
|
800
|
+
end
|
801
|
+
end
|
802
|
+
if compare
|
803
|
+
@nesting_present = true
|
804
|
+
@align.comp.children[key] = comp
|
805
|
+
@align.comp.child_order.push(key)
|
806
|
+
ct = ::Coopy::CompareTable.new(comp)
|
807
|
+
ct.align
|
808
|
+
else
|
809
|
+
comp = @align.comp.children[key]
|
810
|
+
end
|
811
|
+
ll_out = nil
|
812
|
+
rr_out = nil
|
813
|
+
pp_out = nil
|
814
|
+
if comp.alignment.is_marked_as_identical || have_ll && !have_rr || have_rr && !have_ll
|
815
|
+
ll_out = "[" + _hx_str(key) + "]"
|
816
|
+
rr_out = ll_out
|
817
|
+
pp_out = ll_out
|
818
|
+
else
|
819
|
+
ll_out = "[a." + _hx_str(key) + "]" if ll != nil
|
820
|
+
rr_out = "[b." + _hx_str(key) + "]" if rr != nil
|
821
|
+
pp_out = "[p." + _hx_str(key) + "]" if pp != nil
|
822
|
+
end
|
823
|
+
[ll_out,rr_out,pp_out]
|
824
|
+
end
|
825
|
+
|
753
826
|
def scan_row(unit,output,at,i)
|
754
827
|
begin
|
755
828
|
_g1 = 0
|
@@ -788,6 +861,12 @@ module Coopy
|
|
788
861
|
end
|
789
862
|
end
|
790
863
|
end
|
864
|
+
if @nested
|
865
|
+
ndiff = self.check_nesting(@v,have_ll,ll,have_rr,rr,have_pp,pp,i,j)
|
866
|
+
ll = ndiff[0]
|
867
|
+
rr = ndiff[1]
|
868
|
+
pp = ndiff[2]
|
869
|
+
end
|
791
870
|
if have_pp
|
792
871
|
if !have_rr
|
793
872
|
dd = pp
|
@@ -986,6 +1065,33 @@ module Coopy
|
|
986
1065
|
true
|
987
1066
|
end
|
988
1067
|
|
1068
|
+
def hilite_with_nesting(output)
|
1069
|
+
base = output.add("base")
|
1070
|
+
result = self.hilite(base)
|
1071
|
+
return false if !result
|
1072
|
+
return true if @align.comp == nil
|
1073
|
+
order = @align.comp.child_order
|
1074
|
+
return true if order == nil
|
1075
|
+
output.alignment = @align
|
1076
|
+
begin
|
1077
|
+
_g = 0
|
1078
|
+
while(_g < order.length)
|
1079
|
+
name = order[_g]
|
1080
|
+
_g+=1
|
1081
|
+
child = @align.comp.children[name]
|
1082
|
+
alignment = child.alignment
|
1083
|
+
if alignment.is_marked_as_identical
|
1084
|
+
@align.comp.children[name] = nil
|
1085
|
+
next
|
1086
|
+
end
|
1087
|
+
td = ::Coopy::TableDiff.new(alignment,@flags)
|
1088
|
+
child_output = output.add(name)
|
1089
|
+
result = result && td.hilite(child_output)
|
1090
|
+
end
|
1091
|
+
end
|
1092
|
+
result
|
1093
|
+
end
|
1094
|
+
|
989
1095
|
def has_difference
|
990
1096
|
@diff_found
|
991
1097
|
end
|
@@ -994,6 +1100,10 @@ module Coopy
|
|
994
1100
|
@schema_diff_found
|
995
1101
|
end
|
996
1102
|
|
1103
|
+
def is_nested
|
1104
|
+
@nesting_present
|
1105
|
+
end
|
1106
|
+
|
997
1107
|
haxe_me ["coopy", "TableDiff"]
|
998
1108
|
end
|
999
1109
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class Tables
|
6
|
+
|
7
|
+
def initialize(template)
|
8
|
+
@template = template
|
9
|
+
@tables = {}
|
10
|
+
@table_order = Array.new
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
attr_accessor :template
|
16
|
+
attr_accessor :tables
|
17
|
+
attr_accessor :table_order
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
attr_accessor :alignment
|
22
|
+
|
23
|
+
def add(name)
|
24
|
+
t = @template.clone
|
25
|
+
@tables[name] = t
|
26
|
+
@table_order.push(name)
|
27
|
+
t
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_order
|
31
|
+
@table_order
|
32
|
+
end
|
33
|
+
|
34
|
+
def get(name)
|
35
|
+
@tables[name]
|
36
|
+
end
|
37
|
+
|
38
|
+
def one
|
39
|
+
@tables[@table_order[0]]
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_ins_del
|
43
|
+
return false if @alignment == nil
|
44
|
+
return true if @alignment.has_addition
|
45
|
+
return true if @alignment.has_removal
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
haxe_me ["coopy", "Tables"]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|