daff 1.1.2
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.
- data/bin/daff.rb +3 -0
- data/lib/daff.rb +95 -0
- data/lib/lib/coopy/alignment.rb +409 -0
- data/lib/lib/coopy/bag.rb +10 -0
- data/lib/lib/coopy/cell_info.rb +29 -0
- data/lib/lib/coopy/change.rb +48 -0
- data/lib/lib/coopy/change_type.rb +21 -0
- data/lib/lib/coopy/compare.rb +98 -0
- data/lib/lib/coopy/compare_flags.rb +46 -0
- data/lib/lib/coopy/compare_table.rb +402 -0
- data/lib/lib/coopy/coopy.rb +414 -0
- data/lib/lib/coopy/cross_match.rb +16 -0
- data/lib/lib/coopy/csv.rb +181 -0
- data/lib/lib/coopy/diff_render.rb +254 -0
- data/lib/lib/coopy/highlight_patch.rb +651 -0
- data/lib/lib/coopy/highlight_patch_unit.rb +37 -0
- data/lib/lib/coopy/index.rb +101 -0
- data/lib/lib/coopy/index_item.rb +20 -0
- data/lib/lib/coopy/index_pair.rb +87 -0
- data/lib/lib/coopy/mover.rb +195 -0
- data/lib/lib/coopy/ordering.rb +49 -0
- data/lib/lib/coopy/report.rb +23 -0
- data/lib/lib/coopy/row.rb +9 -0
- data/lib/lib/coopy/simple_cell.rb +23 -0
- data/lib/lib/coopy/simple_table.rb +242 -0
- data/lib/lib/coopy/simple_view.rb +41 -0
- data/lib/lib/coopy/sparse_sheet.rb +50 -0
- data/lib/lib/coopy/table.rb +17 -0
- data/lib/lib/coopy/table_comparison_state.rb +32 -0
- data/lib/lib/coopy/table_diff.rb +738 -0
- data/lib/lib/coopy/table_io.rb +33 -0
- data/lib/lib/coopy/table_modifier.rb +39 -0
- data/lib/lib/coopy/table_text.rb +25 -0
- data/lib/lib/coopy/unit.rb +70 -0
- data/lib/lib/coopy/view.rb +14 -0
- data/lib/lib/coopy/viewed_datum.rb +37 -0
- data/lib/lib/coopy/viterbi.rb +172 -0
- data/lib/lib/coopy/workspace.rb +22 -0
- data/lib/lib/haxe/ds/int_map.rb +14 -0
- data/lib/lib/haxe/ds/string_map.rb +14 -0
- data/lib/lib/haxe/format/json_parser.rb +264 -0
- data/lib/lib/haxe/format/json_printer.rb +239 -0
- data/lib/lib/haxe/io/bytes.rb +33 -0
- data/lib/lib/haxe/io/eof.rb +17 -0
- data/lib/lib/haxe/io/error.rb +21 -0
- data/lib/lib/haxe/io/output.rb +40 -0
- data/lib/lib/haxe/log.rb +16 -0
- data/lib/lib/hx_overrides.rb +18 -0
- data/lib/lib/imap.rb +6 -0
- data/lib/lib/lambda.rb +36 -0
- data/lib/lib/list.rb +42 -0
- data/lib/lib/rb/boot.rb +19 -0
- data/lib/lib/rb/ruby_iterator.rb +49 -0
- data/lib/lib/reflect.rb +29 -0
- data/lib/lib/string_buf.rb +14 -0
- data/lib/lib/sys.rb +19 -0
- data/lib/lib/sys/io/file.rb +19 -0
- data/lib/lib/sys/io/file_handle.rb +17 -0
- data/lib/lib/sys/io/file_output.rb +35 -0
- data/lib/lib/type.rb +32 -0
- data/lib/lib/value_type.rb +22 -0
- metadata +181 -0
@@ -0,0 +1,254 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class DiffRender
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@text_to_insert = Array.new
|
9
|
+
@open = false
|
10
|
+
@pretty_arrows = true
|
11
|
+
end
|
12
|
+
|
13
|
+
# protected - in ruby this doesn't play well with static/inline methods
|
14
|
+
|
15
|
+
attr_accessor :text_to_insert
|
16
|
+
attr_accessor :td_open
|
17
|
+
attr_accessor :td_close
|
18
|
+
attr_accessor :open
|
19
|
+
attr_accessor :pretty_arrows
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
def use_pretty_arrows(flag)
|
24
|
+
@pretty_arrows = flag
|
25
|
+
end
|
26
|
+
|
27
|
+
# protected - in ruby this doesn't play well with static/inline methods
|
28
|
+
|
29
|
+
def insert(str)
|
30
|
+
@text_to_insert.push(str)
|
31
|
+
end
|
32
|
+
|
33
|
+
def begin_table
|
34
|
+
self.insert("<table>\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
def begin_row(mode)
|
38
|
+
@td_open = "<td"
|
39
|
+
@td_close = "</td>"
|
40
|
+
row_class = ""
|
41
|
+
if mode == "header"
|
42
|
+
@td_open = "<th"
|
43
|
+
@td_close = "</th>"
|
44
|
+
else
|
45
|
+
row_class = mode
|
46
|
+
end
|
47
|
+
tr = "<tr>"
|
48
|
+
tr = "<tr class=\"" + _hx_str(row_class) + "\">" if row_class != ""
|
49
|
+
self.insert(tr)
|
50
|
+
end
|
51
|
+
|
52
|
+
def insert_cell(txt,mode)
|
53
|
+
cell_decorate = ""
|
54
|
+
cell_decorate = " class=\"" + _hx_str(mode) + "\"" if mode != ""
|
55
|
+
self.insert(_hx_str(@td_open) + _hx_str(cell_decorate) + ">")
|
56
|
+
self.insert(txt)
|
57
|
+
self.insert(@td_close)
|
58
|
+
end
|
59
|
+
|
60
|
+
def end_row
|
61
|
+
self.insert("</tr>\n")
|
62
|
+
end
|
63
|
+
|
64
|
+
def end_table
|
65
|
+
self.insert("</table>\n")
|
66
|
+
end
|
67
|
+
|
68
|
+
public
|
69
|
+
|
70
|
+
def html
|
71
|
+
return @text_to_insert.join("")
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_s
|
75
|
+
return self.html
|
76
|
+
end
|
77
|
+
|
78
|
+
def render(rows)
|
79
|
+
return if rows.get_width == 0 || rows.get_height == 0
|
80
|
+
render = self
|
81
|
+
render.begin_table
|
82
|
+
change_row = -1
|
83
|
+
tt = ::Coopy::TableText.new(rows)
|
84
|
+
cell = ::Coopy::CellInfo.new
|
85
|
+
corner = tt.get_cell_text(0,0)
|
86
|
+
off = nil
|
87
|
+
if corner == "@:@"
|
88
|
+
off = 1
|
89
|
+
else
|
90
|
+
off = 0
|
91
|
+
end
|
92
|
+
if off > 0
|
93
|
+
return if rows.get_width <= 1 || rows.get_height <= 1
|
94
|
+
end
|
95
|
+
begin
|
96
|
+
_g1 = 0
|
97
|
+
_g = rows.get_height
|
98
|
+
while(_g1 < _g)
|
99
|
+
row = _g1
|
100
|
+
_g1+=1
|
101
|
+
open = false
|
102
|
+
txt = tt.get_cell_text(off,row)
|
103
|
+
txt = "" if txt == nil
|
104
|
+
::Coopy::DiffRender.examine_cell(0,row,txt,"",txt,corner,cell)
|
105
|
+
row_mode = cell.category
|
106
|
+
change_row = row if row_mode == "spec"
|
107
|
+
render.begin_row(row_mode)
|
108
|
+
begin
|
109
|
+
_g3 = 0
|
110
|
+
_g2 = rows.get_width
|
111
|
+
while(_g3 < _g2)
|
112
|
+
c = _g3
|
113
|
+
_g3+=1
|
114
|
+
::Coopy::DiffRender.examine_cell(c,row,tt.get_cell_text(c,row),((change_row >= 0) ? tt.get_cell_text(c,change_row) : ""),txt,corner,cell)
|
115
|
+
render.insert_cell(((@pretty_arrows) ? cell.pretty_value : cell.value),cell.category_given_tr)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
render.end_row
|
119
|
+
end
|
120
|
+
end
|
121
|
+
render.end_table
|
122
|
+
end
|
123
|
+
|
124
|
+
def sample_css
|
125
|
+
return ".highlighter .add { \n background-color: #7fff7f;\n}\n\n.highlighter .remove { \n background-color: #ff7f7f;\n}\n\n.highlighter td.modify { \n background-color: #7f7fff;\n}\n\n.highlighter td.conflict { \n background-color: #f00;\n}\n\n.highlighter .spec { \n background-color: #aaa;\n}\n\n.highlighter .move { \n background-color: #ffa;\n}\n\n.highlighter .null { \n color: #888;\n}\n\n.highlighter table { \n border-collapse:collapse;\n}\n\n.highlighter td, .highlighter th {\n border: 1px solid #2D4068;\n padding: 3px 7px 2px;\n}\n\n.highlighter th, .highlighter .header { \n background-color: #aaf;\n font-weight: bold;\n padding-bottom: 4px;\n padding-top: 5px;\n text-align:left;\n}\n\n.highlighter tr:first-child td {\n border-top: 1px solid #2D4068;\n}\n\n.highlighter td:first-child { \n border-left: 1px solid #2D4068;\n}\n\n.highlighter td {\n empty-cells: show;\n}\n"
|
126
|
+
end
|
127
|
+
|
128
|
+
def complete_html
|
129
|
+
@text_to_insert.insert(0,"<html>\n<meta charset='utf-8'>\n<head>\n<style TYPE='text/css'>\n")
|
130
|
+
@text_to_insert.insert(1,self.sample_css)
|
131
|
+
@text_to_insert.insert(2,"</style>\n</head>\n<body>\n<div class='highlighter'>\n")
|
132
|
+
@text_to_insert.push("</div>\n</body>\n</html>\n")
|
133
|
+
end
|
134
|
+
|
135
|
+
def DiffRender.examine_cell(x,y,value,vcol,vrow,vcorner,cell)
|
136
|
+
cell.category = ""
|
137
|
+
cell.category_given_tr = ""
|
138
|
+
cell.separator = ""
|
139
|
+
cell.conflicted = false
|
140
|
+
cell.updated = false
|
141
|
+
cell.pvalue = cell.lvalue = cell.rvalue = nil
|
142
|
+
cell.value = value
|
143
|
+
cell.value = "" if cell.value == nil
|
144
|
+
cell.pretty_value = cell.value
|
145
|
+
vrow = "" if vrow == nil
|
146
|
+
vcol = "" if vcol == nil
|
147
|
+
removed_column = false
|
148
|
+
cell.category = "move" if vrow == ":"
|
149
|
+
if (vcol.index("+++",nil || 0) || -1) >= 0
|
150
|
+
cell.category_given_tr = cell.category = "add"
|
151
|
+
elsif (vcol.index("---",nil || 0) || -1) >= 0
|
152
|
+
cell.category_given_tr = cell.category = "remove"
|
153
|
+
removed_column = true
|
154
|
+
end
|
155
|
+
if vrow == "!"
|
156
|
+
cell.category = "spec"
|
157
|
+
elsif vrow == "@@"
|
158
|
+
cell.category = "header"
|
159
|
+
elsif vrow == "+++"
|
160
|
+
cell.category = "add" if !removed_column
|
161
|
+
elsif vrow == "---"
|
162
|
+
cell.category = "remove"
|
163
|
+
elsif (vrow.index("->",nil || 0) || -1) >= 0
|
164
|
+
if !removed_column
|
165
|
+
tokens = vrow.split("!")
|
166
|
+
full = vrow
|
167
|
+
part = tokens[1]
|
168
|
+
part = full if part == nil
|
169
|
+
if (cell.value.index(part,nil || 0) || -1) >= 0
|
170
|
+
cat = "modify"
|
171
|
+
div = part
|
172
|
+
if part != full
|
173
|
+
if (cell.value.index(full,nil || 0) || -1) >= 0
|
174
|
+
div = full
|
175
|
+
cat = "conflict"
|
176
|
+
cell.conflicted = true
|
177
|
+
end
|
178
|
+
end
|
179
|
+
cell.updated = true
|
180
|
+
cell.separator = div
|
181
|
+
if cell.pretty_value == div
|
182
|
+
tokens = ["",""]
|
183
|
+
else
|
184
|
+
tokens = cell.pretty_value.split(div)
|
185
|
+
end
|
186
|
+
pretty_tokens = tokens
|
187
|
+
if tokens.length >= 2
|
188
|
+
pretty_tokens[0] = ::Coopy::DiffRender.mark_spaces(tokens[0],tokens[1])
|
189
|
+
pretty_tokens[1] = ::Coopy::DiffRender.mark_spaces(tokens[1],tokens[0])
|
190
|
+
end
|
191
|
+
if tokens.length >= 3
|
192
|
+
ref = pretty_tokens[0]
|
193
|
+
pretty_tokens[0] = ::Coopy::DiffRender.mark_spaces(ref,tokens[2])
|
194
|
+
pretty_tokens[2] = ::Coopy::DiffRender.mark_spaces(tokens[2],ref)
|
195
|
+
end
|
196
|
+
cell.pretty_value = pretty_tokens.join([8594].pack("U"))
|
197
|
+
cell.category_given_tr = cell.category = cat
|
198
|
+
offset = nil
|
199
|
+
if cell.conflicted
|
200
|
+
offset = 1
|
201
|
+
else
|
202
|
+
offset = 0
|
203
|
+
end
|
204
|
+
cell.lvalue = tokens[offset]
|
205
|
+
cell.rvalue = tokens[offset + 1]
|
206
|
+
cell.pvalue = tokens[0] if cell.conflicted
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def DiffRender.mark_spaces(sl,sr)
|
213
|
+
return sl if sl == sr
|
214
|
+
return sl if sl == nil || sr == nil
|
215
|
+
slc = sl.gsub(" ","")
|
216
|
+
src = sr.gsub(" ","")
|
217
|
+
return sl if slc != src
|
218
|
+
slo = String.new("")
|
219
|
+
il = 0
|
220
|
+
ir = 0
|
221
|
+
while(il < sl.length)
|
222
|
+
cl = sl[il]
|
223
|
+
cr = ""
|
224
|
+
cr = sr[ir] if ir < sr.length
|
225
|
+
if cl == cr
|
226
|
+
slo += cl
|
227
|
+
il+=1
|
228
|
+
ir+=1
|
229
|
+
elsif cr == " "
|
230
|
+
ir+=1
|
231
|
+
else
|
232
|
+
slo += [9251].pack("U")
|
233
|
+
il+=1
|
234
|
+
end
|
235
|
+
end
|
236
|
+
return slo
|
237
|
+
end
|
238
|
+
|
239
|
+
def DiffRender.render_cell(tt,x,y)
|
240
|
+
cell = ::Coopy::CellInfo.new
|
241
|
+
corner = tt.get_cell_text(0,0)
|
242
|
+
off = nil
|
243
|
+
if corner == "@:@"
|
244
|
+
off = 1
|
245
|
+
else
|
246
|
+
off = 0
|
247
|
+
end
|
248
|
+
::Coopy::DiffRender.examine_cell(x,y,tt.get_cell_text(x,y),tt.get_cell_text(x,off),tt.get_cell_text(off,y),corner,cell)
|
249
|
+
return cell
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
@@ -0,0 +1,651 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class HighlightPatch
|
6
|
+
|
7
|
+
def initialize(source,patch)
|
8
|
+
@source = source
|
9
|
+
@patch = patch
|
10
|
+
@view = patch.get_cell_view
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
attr_accessor :source
|
16
|
+
attr_accessor :patch
|
17
|
+
attr_accessor :view
|
18
|
+
attr_accessor :csv
|
19
|
+
attr_accessor :header
|
20
|
+
attr_accessor :header_pre
|
21
|
+
attr_accessor :header_post
|
22
|
+
attr_accessor :header_rename
|
23
|
+
attr_accessor :header_move
|
24
|
+
attr_accessor :modifier
|
25
|
+
attr_accessor :current_row
|
26
|
+
attr_accessor :payload_col
|
27
|
+
attr_accessor :payload_top
|
28
|
+
attr_accessor :mods
|
29
|
+
attr_accessor :cmods
|
30
|
+
attr_accessor :row_info
|
31
|
+
attr_accessor :cell_info
|
32
|
+
attr_accessor :rc_offset
|
33
|
+
attr_accessor :indexes
|
34
|
+
attr_accessor :source_in_patch_col
|
35
|
+
attr_accessor :patch_in_source_col
|
36
|
+
attr_accessor :patch_in_source_row
|
37
|
+
attr_accessor :last_source_row
|
38
|
+
attr_accessor :actions
|
39
|
+
attr_accessor :row_permutation
|
40
|
+
attr_accessor :row_permutation_rev
|
41
|
+
attr_accessor :col_permutation
|
42
|
+
attr_accessor :col_permutation_rev
|
43
|
+
attr_accessor :have_dropped_columns
|
44
|
+
|
45
|
+
public
|
46
|
+
|
47
|
+
def reset
|
48
|
+
@header = {}
|
49
|
+
@header_pre = {}
|
50
|
+
@header_post = {}
|
51
|
+
@header_rename = {}
|
52
|
+
@header_move = nil
|
53
|
+
@modifier = {}
|
54
|
+
@mods = Array.new
|
55
|
+
@cmods = Array.new
|
56
|
+
@csv = ::Coopy::Csv.new
|
57
|
+
@rc_offset = 0
|
58
|
+
@current_row = -1
|
59
|
+
@row_info = ::Coopy::CellInfo.new
|
60
|
+
@cell_info = ::Coopy::CellInfo.new
|
61
|
+
@source_in_patch_col = @patch_in_source_col = nil
|
62
|
+
@patch_in_source_row = {}
|
63
|
+
@indexes = nil
|
64
|
+
@last_source_row = -1
|
65
|
+
@actions = Array.new
|
66
|
+
@row_permutation = nil
|
67
|
+
@row_permutation_rev = nil
|
68
|
+
@col_permutation = nil
|
69
|
+
@col_permutation_rev = nil
|
70
|
+
@have_dropped_columns = false
|
71
|
+
end
|
72
|
+
|
73
|
+
def apply
|
74
|
+
self.reset
|
75
|
+
return true if @patch.get_width < 2
|
76
|
+
return true if @patch.get_height < 1
|
77
|
+
@payload_col = 1 + @rc_offset
|
78
|
+
@payload_top = @patch.get_width
|
79
|
+
corner = @patch.get_cell_view.to_s(@patch.get_cell(0,0))
|
80
|
+
if corner == "@:@"
|
81
|
+
@rc_offset = 1
|
82
|
+
else
|
83
|
+
@rc_offset = 0
|
84
|
+
end
|
85
|
+
begin
|
86
|
+
_g1 = 0
|
87
|
+
_g = @patch.get_height
|
88
|
+
while(_g1 < _g)
|
89
|
+
r = _g1
|
90
|
+
_g1+=1
|
91
|
+
str = @view.to_s(@patch.get_cell(@rc_offset,r))
|
92
|
+
@actions.push(((str != nil) ? str : ""))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
begin
|
96
|
+
_g11 = 0
|
97
|
+
_g2 = @patch.get_height
|
98
|
+
while(_g11 < _g2)
|
99
|
+
r1 = _g11
|
100
|
+
_g11+=1
|
101
|
+
self.apply_row(r1)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
self.finish_rows
|
105
|
+
self.finish_columns
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
|
109
|
+
protected
|
110
|
+
|
111
|
+
def need_source_columns
|
112
|
+
return if @source_in_patch_col != nil
|
113
|
+
@source_in_patch_col = {}
|
114
|
+
@patch_in_source_col = {}
|
115
|
+
av = @source.get_cell_view
|
116
|
+
begin
|
117
|
+
_g1 = 0
|
118
|
+
_g = @source.get_width
|
119
|
+
while(_g1 < _g)
|
120
|
+
i = _g1
|
121
|
+
_g1+=1
|
122
|
+
name = av.to_s(@source.get_cell(i,0))
|
123
|
+
at = @header_pre[name]
|
124
|
+
next if at == nil
|
125
|
+
@source_in_patch_col[i] = at
|
126
|
+
@patch_in_source_col[at] = i
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def need_source_index
|
132
|
+
return if @indexes != nil
|
133
|
+
state = ::Coopy::TableComparisonState.new
|
134
|
+
state.a = @source
|
135
|
+
state.b = @source
|
136
|
+
comp = ::Coopy::CompareTable.new
|
137
|
+
comp.store_indexes
|
138
|
+
comp.attach(state)
|
139
|
+
comp.align
|
140
|
+
@indexes = comp.get_indexes
|
141
|
+
self.need_source_columns
|
142
|
+
end
|
143
|
+
|
144
|
+
def apply_row(r)
|
145
|
+
@current_row = r
|
146
|
+
code = @actions[r]
|
147
|
+
if r == 0 && @rc_offset > 0
|
148
|
+
elsif code == "@@"
|
149
|
+
self.apply_header
|
150
|
+
self.apply_action("@@")
|
151
|
+
elsif code == "!"
|
152
|
+
self.apply_meta
|
153
|
+
elsif code == "+++"
|
154
|
+
self.apply_action(code)
|
155
|
+
elsif code == "---"
|
156
|
+
self.apply_action(code)
|
157
|
+
elsif code == "+" || code == ":"
|
158
|
+
self.apply_action(code)
|
159
|
+
elsif (code.index("->",nil || 0) || -1) >= 0
|
160
|
+
self.apply_action("->")
|
161
|
+
else
|
162
|
+
@last_source_row = -1
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def get_datum(c)
|
167
|
+
return @patch.get_cell(c,@current_row)
|
168
|
+
end
|
169
|
+
|
170
|
+
def get_string(c)
|
171
|
+
return @view.to_s(self.get_datum(c))
|
172
|
+
end
|
173
|
+
|
174
|
+
def apply_meta
|
175
|
+
_g1 = @payload_col
|
176
|
+
_g = @payload_top
|
177
|
+
while(_g1 < _g)
|
178
|
+
i = _g1
|
179
|
+
_g1+=1
|
180
|
+
name = self.get_string(i)
|
181
|
+
next if name == ""
|
182
|
+
@modifier[i] = name
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def apply_header
|
187
|
+
begin
|
188
|
+
_g1 = @payload_col
|
189
|
+
_g = @payload_top
|
190
|
+
while(_g1 < _g)
|
191
|
+
i = _g1
|
192
|
+
_g1+=1
|
193
|
+
name = self.get_string(i)
|
194
|
+
if name == "..."
|
195
|
+
@modifier[i] = "..."
|
196
|
+
@have_dropped_columns = true
|
197
|
+
next
|
198
|
+
end
|
199
|
+
mod = @modifier[i]
|
200
|
+
move = false
|
201
|
+
if mod != nil
|
202
|
+
if (mod[0].ord rescue nil) == 58
|
203
|
+
move = true
|
204
|
+
mod = mod[1,mod.length]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
@header[i] = name
|
208
|
+
if mod != nil
|
209
|
+
if (mod[0].ord rescue nil) == 40
|
210
|
+
prev_name = mod[1,mod.length - 2]
|
211
|
+
@header_pre[prev_name] = i
|
212
|
+
@header_post[name] = i
|
213
|
+
@header_rename[prev_name] = name
|
214
|
+
next
|
215
|
+
end
|
216
|
+
end
|
217
|
+
@header_pre[name] = i if mod != "+++"
|
218
|
+
@header_post[name] = i if mod != "---"
|
219
|
+
if move
|
220
|
+
@header_move = {} if @header_move == nil
|
221
|
+
@header_move[name] = 1
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
self.apply_action("+++") if @source.get_height == 0
|
226
|
+
end
|
227
|
+
|
228
|
+
def look_up(del = 0)
|
229
|
+
at = @patch_in_source_row[@current_row + del]
|
230
|
+
return at if at != nil
|
231
|
+
result = -1
|
232
|
+
@current_row += del
|
233
|
+
if @current_row >= 0 && @current_row < @patch.get_height
|
234
|
+
_g = 0
|
235
|
+
_g1 = @indexes
|
236
|
+
while(_g < _g1.length)
|
237
|
+
idx = _g1[_g]
|
238
|
+
_g+=1
|
239
|
+
match = idx.query_by_content(self)
|
240
|
+
next if match.spot_a != 1
|
241
|
+
result = match.item_a.lst[0]
|
242
|
+
break
|
243
|
+
end
|
244
|
+
end
|
245
|
+
begin
|
246
|
+
@patch_in_source_row[@current_row] = result
|
247
|
+
result
|
248
|
+
end
|
249
|
+
@current_row -= del
|
250
|
+
return result
|
251
|
+
end
|
252
|
+
|
253
|
+
def apply_action(code)
|
254
|
+
mod = ::Coopy::HighlightPatchUnit.new
|
255
|
+
mod.code = code
|
256
|
+
mod.add = code == "+++"
|
257
|
+
mod.rem = code == "---"
|
258
|
+
mod.update = code == "->"
|
259
|
+
self.need_source_index
|
260
|
+
@last_source_row = self.look_up(-1) if @last_source_row == -1
|
261
|
+
mod.source_prev_row = @last_source_row
|
262
|
+
next_act = @actions[@current_row + 1]
|
263
|
+
mod.source_next_row = self.look_up(1) if next_act != "+++" && next_act != "..."
|
264
|
+
if mod.add
|
265
|
+
mod.source_prev_row = self.look_up(-1) if @actions[@current_row - 1] != "+++"
|
266
|
+
mod.source_row = mod.source_prev_row
|
267
|
+
mod.source_row_offset = 1 if mod.source_row != -1
|
268
|
+
else
|
269
|
+
mod.source_row = @last_source_row = self.look_up
|
270
|
+
end
|
271
|
+
@last_source_row = mod.source_next_row if @actions[@current_row + 1] == ""
|
272
|
+
mod.patch_row = @current_row
|
273
|
+
mod.source_row = 0 if code == "@@"
|
274
|
+
@mods.push(mod)
|
275
|
+
end
|
276
|
+
|
277
|
+
def check_act
|
278
|
+
act = self.get_string(@rc_offset)
|
279
|
+
::Coopy::DiffRender.examine_cell(0,0,act,"",act,"",@row_info) if @row_info.value != act
|
280
|
+
end
|
281
|
+
|
282
|
+
def get_pre_string(txt)
|
283
|
+
self.check_act
|
284
|
+
return txt if !@row_info.updated
|
285
|
+
::Coopy::DiffRender.examine_cell(0,0,txt,"",@row_info.value,"",@cell_info)
|
286
|
+
return txt if !@cell_info.updated
|
287
|
+
return @cell_info.lvalue
|
288
|
+
end
|
289
|
+
|
290
|
+
public
|
291
|
+
|
292
|
+
def get_row_string(c)
|
293
|
+
at = @source_in_patch_col[c]
|
294
|
+
return "NOT_FOUND" if at == nil
|
295
|
+
return self.get_pre_string(self.get_string(at))
|
296
|
+
end
|
297
|
+
|
298
|
+
protected
|
299
|
+
|
300
|
+
def sort_mods(a,b)
|
301
|
+
return 1 if b.code == "@@" && a.code != "@@"
|
302
|
+
return -1 if a.code == "@@" && b.code != "@@"
|
303
|
+
return 1 if a.source_row == -1 && !a.add && b.source_row != -1
|
304
|
+
return -1 if a.source_row != -1 && !b.add && b.source_row == -1
|
305
|
+
return 1 if a.source_row + a.source_row_offset > b.source_row + b.source_row_offset
|
306
|
+
return -1 if a.source_row + a.source_row_offset < b.source_row + b.source_row_offset
|
307
|
+
return 1 if a.patch_row > b.patch_row
|
308
|
+
return -1 if a.patch_row < b.patch_row
|
309
|
+
return 0
|
310
|
+
end
|
311
|
+
|
312
|
+
def process_mods(rmods,fate,len)
|
313
|
+
rmods.sort{|a,b| self.sort_mods(a,b)}
|
314
|
+
offset = 0
|
315
|
+
last = -1
|
316
|
+
target = 0
|
317
|
+
begin
|
318
|
+
_g = 0
|
319
|
+
while(_g < rmods.length)
|
320
|
+
mod = rmods[_g]
|
321
|
+
_g+=1
|
322
|
+
if last != -1
|
323
|
+
_g2 = last
|
324
|
+
_g1 = mod.source_row + mod.source_row_offset
|
325
|
+
while(_g2 < _g1)
|
326
|
+
i = _g2
|
327
|
+
_g2+=1
|
328
|
+
fate.push(i + offset)
|
329
|
+
target+=1
|
330
|
+
last+=1
|
331
|
+
end
|
332
|
+
end
|
333
|
+
if mod.rem
|
334
|
+
fate.push(-1)
|
335
|
+
offset-=1
|
336
|
+
elsif mod.add
|
337
|
+
mod.dest_row = target
|
338
|
+
target+=1
|
339
|
+
offset+=1
|
340
|
+
else
|
341
|
+
mod.dest_row = target
|
342
|
+
end
|
343
|
+
if mod.source_row >= 0
|
344
|
+
last = mod.source_row + mod.source_row_offset
|
345
|
+
last+=1 if mod.rem
|
346
|
+
else
|
347
|
+
last = -1
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
if last != -1
|
352
|
+
_g3 = last
|
353
|
+
while(_g3 < len)
|
354
|
+
i1 = _g3
|
355
|
+
_g3+=1
|
356
|
+
fate.push(i1 + offset)
|
357
|
+
target+=1
|
358
|
+
last+=1
|
359
|
+
end
|
360
|
+
end
|
361
|
+
return len + offset
|
362
|
+
end
|
363
|
+
|
364
|
+
def compute_ordering(mods,permutation,permutation_rev,dim)
|
365
|
+
to_unit = {}
|
366
|
+
from_unit = {}
|
367
|
+
meta_from_unit = {}
|
368
|
+
ct = 0
|
369
|
+
begin
|
370
|
+
_g = 0
|
371
|
+
while(_g < mods.length)
|
372
|
+
mod = mods[_g]
|
373
|
+
_g+=1
|
374
|
+
next if mod.add || mod.rem
|
375
|
+
next if mod.source_row < 0
|
376
|
+
if mod.source_prev_row >= 0
|
377
|
+
begin
|
378
|
+
v = mod.source_row
|
379
|
+
to_unit[mod.source_prev_row] = v
|
380
|
+
v
|
381
|
+
end
|
382
|
+
begin
|
383
|
+
v1 = mod.source_prev_row
|
384
|
+
from_unit[mod.source_row] = v1
|
385
|
+
v1
|
386
|
+
end
|
387
|
+
ct+=1 if mod.source_prev_row + 1 != mod.source_row
|
388
|
+
end
|
389
|
+
if mod.source_next_row >= 0
|
390
|
+
begin
|
391
|
+
v2 = mod.source_next_row
|
392
|
+
to_unit[mod.source_row] = v2
|
393
|
+
v2
|
394
|
+
end
|
395
|
+
begin
|
396
|
+
v3 = mod.source_row
|
397
|
+
from_unit[mod.source_next_row] = v3
|
398
|
+
v3
|
399
|
+
end
|
400
|
+
ct+=1 if mod.source_row + 1 != mod.source_next_row
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
if ct > 0
|
405
|
+
cursor = nil
|
406
|
+
logical = nil
|
407
|
+
starts = []
|
408
|
+
begin
|
409
|
+
_g1 = 0
|
410
|
+
while(_g1 < dim)
|
411
|
+
i = _g1
|
412
|
+
_g1+=1
|
413
|
+
u = from_unit[i]
|
414
|
+
if u != nil
|
415
|
+
meta_from_unit[u] = i
|
416
|
+
i
|
417
|
+
else
|
418
|
+
starts.push(i)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
used = {}
|
423
|
+
len = 0
|
424
|
+
begin
|
425
|
+
_g2 = 0
|
426
|
+
while(_g2 < dim)
|
427
|
+
i1 = _g2
|
428
|
+
_g2+=1
|
429
|
+
if meta_from_unit.include?(logical)
|
430
|
+
cursor = meta_from_unit[logical]
|
431
|
+
else
|
432
|
+
cursor = nil
|
433
|
+
end
|
434
|
+
if cursor == nil
|
435
|
+
v4 = starts.shift
|
436
|
+
cursor = v4
|
437
|
+
logical = v4
|
438
|
+
end
|
439
|
+
cursor = 0 if cursor == nil
|
440
|
+
while(used.include?(cursor))
|
441
|
+
cursor = ((cursor + 1).remainder(dim) rescue Float::NAN)
|
442
|
+
end
|
443
|
+
logical = cursor
|
444
|
+
permutation_rev.push(cursor)
|
445
|
+
begin
|
446
|
+
used[cursor] = 1
|
447
|
+
1
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
begin
|
452
|
+
_g11 = 0
|
453
|
+
_g3 = permutation_rev.length
|
454
|
+
while(_g11 < _g3)
|
455
|
+
i2 = _g11
|
456
|
+
_g11+=1
|
457
|
+
permutation[i2] = -1
|
458
|
+
end
|
459
|
+
end
|
460
|
+
begin
|
461
|
+
_g12 = 0
|
462
|
+
_g4 = permutation.length
|
463
|
+
while(_g12 < _g4)
|
464
|
+
i3 = _g12
|
465
|
+
_g12+=1
|
466
|
+
permutation[permutation_rev[i3]] = i3
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
472
|
+
def permute_rows
|
473
|
+
@row_permutation = Array.new
|
474
|
+
@row_permutation_rev = Array.new
|
475
|
+
self.compute_ordering(@mods,@row_permutation,@row_permutation_rev,@source.get_height)
|
476
|
+
end
|
477
|
+
|
478
|
+
def finish_rows
|
479
|
+
fate = Array.new
|
480
|
+
self.permute_rows
|
481
|
+
if @row_permutation.length > 0
|
482
|
+
_g = 0
|
483
|
+
_g1 = @mods
|
484
|
+
while(_g < _g1.length)
|
485
|
+
mod = _g1[_g]
|
486
|
+
_g+=1
|
487
|
+
mod.source_row = @row_permutation[mod.source_row] if mod.source_row >= 0
|
488
|
+
end
|
489
|
+
end
|
490
|
+
@source.insert_or_delete_rows(@row_permutation,@row_permutation.length) if @row_permutation.length > 0
|
491
|
+
len = self.process_mods(@mods,fate,@source.get_height)
|
492
|
+
@source.insert_or_delete_rows(fate,len)
|
493
|
+
begin
|
494
|
+
_g2 = 0
|
495
|
+
_g11 = @mods
|
496
|
+
while(_g2 < _g11.length)
|
497
|
+
mod1 = _g11[_g2]
|
498
|
+
_g2+=1
|
499
|
+
if !mod1.rem
|
500
|
+
if mod1.add
|
501
|
+
_it = ::Rb::RubyIterator.new(@header_post.values)
|
502
|
+
while(_it.has_next) do
|
503
|
+
c = _it._next
|
504
|
+
offset = @patch_in_source_col[c]
|
505
|
+
@source.set_cell(offset,mod1.dest_row,@patch.get_cell(c,mod1.patch_row)) if offset != nil && offset >= 0
|
506
|
+
end
|
507
|
+
elsif mod1.update
|
508
|
+
@current_row = mod1.patch_row
|
509
|
+
self.check_act
|
510
|
+
next if !@row_info.updated
|
511
|
+
_it2 = ::Rb::RubyIterator.new(@header_pre.values)
|
512
|
+
while(_it2.has_next) do
|
513
|
+
c1 = _it2._next
|
514
|
+
txt = @view.to_s(@patch.get_cell(c1,mod1.patch_row))
|
515
|
+
::Coopy::DiffRender.examine_cell(0,0,txt,"",@row_info.value,"",@cell_info)
|
516
|
+
next if !@cell_info.updated
|
517
|
+
next if @cell_info.conflicted
|
518
|
+
d = @view.to_datum(@csv.parse_single_cell(@cell_info.rvalue))
|
519
|
+
@source.set_cell(@patch_in_source_col[c1],mod1.dest_row,d)
|
520
|
+
end
|
521
|
+
end
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
def permute_columns
|
528
|
+
return if @header_move == nil
|
529
|
+
@col_permutation = Array.new
|
530
|
+
@col_permutation_rev = Array.new
|
531
|
+
self.compute_ordering(@cmods,@col_permutation,@col_permutation_rev,@source.get_width)
|
532
|
+
return if @col_permutation.length == 0
|
533
|
+
end
|
534
|
+
|
535
|
+
def finish_columns
|
536
|
+
self.need_source_columns
|
537
|
+
begin
|
538
|
+
_g1 = @payload_col
|
539
|
+
_g = @payload_top
|
540
|
+
while(_g1 < _g)
|
541
|
+
i = _g1
|
542
|
+
_g1+=1
|
543
|
+
act = @modifier[i]
|
544
|
+
hdr = @header[i]
|
545
|
+
act = "" if act == nil
|
546
|
+
if act == "---"
|
547
|
+
at = @patch_in_source_col[i]
|
548
|
+
mod = ::Coopy::HighlightPatchUnit.new
|
549
|
+
mod.code = act
|
550
|
+
mod.rem = true
|
551
|
+
mod.source_row = at
|
552
|
+
mod.patch_row = i
|
553
|
+
@cmods.push(mod)
|
554
|
+
elsif act == "+++"
|
555
|
+
mod1 = ::Coopy::HighlightPatchUnit.new
|
556
|
+
mod1.code = act
|
557
|
+
mod1.add = true
|
558
|
+
prev = -1
|
559
|
+
cont = false
|
560
|
+
mod1.source_row = -1
|
561
|
+
mod1.source_row = @cmods[@cmods.length - 1].source_row if @cmods.length > 0
|
562
|
+
mod1.source_row_offset = 1 if mod1.source_row != -1
|
563
|
+
mod1.patch_row = i
|
564
|
+
@cmods.push(mod1)
|
565
|
+
elsif act != "..."
|
566
|
+
mod2 = ::Coopy::HighlightPatchUnit.new
|
567
|
+
mod2.code = act
|
568
|
+
mod2.patch_row = i
|
569
|
+
mod2.source_row = @patch_in_source_col[i]
|
570
|
+
@cmods.push(mod2)
|
571
|
+
end
|
572
|
+
end
|
573
|
+
end
|
574
|
+
at1 = -1
|
575
|
+
rat = -1
|
576
|
+
begin
|
577
|
+
_g11 = 0
|
578
|
+
_g2 = @cmods.length - 1
|
579
|
+
while(_g11 < _g2)
|
580
|
+
i1 = _g11
|
581
|
+
_g11+=1
|
582
|
+
icode = @cmods[i1].code
|
583
|
+
at1 = @cmods[i1].source_row if icode != "+++" && icode != "---"
|
584
|
+
@cmods[i1 + 1].source_prev_row = at1
|
585
|
+
j = @cmods.length - 1 - i1
|
586
|
+
jcode = @cmods[j].code
|
587
|
+
rat = @cmods[j].source_row if jcode != "+++" && jcode != "---"
|
588
|
+
@cmods[j - 1].source_next_row = rat
|
589
|
+
end
|
590
|
+
end
|
591
|
+
fate = Array.new
|
592
|
+
self.permute_columns
|
593
|
+
if @header_move != nil
|
594
|
+
if @col_permutation.length > 0
|
595
|
+
begin
|
596
|
+
_g3 = 0
|
597
|
+
_g12 = @cmods
|
598
|
+
while(_g3 < _g12.length)
|
599
|
+
mod3 = _g12[_g3]
|
600
|
+
_g3+=1
|
601
|
+
mod3.source_row = @col_permutation[mod3.source_row] if mod3.source_row >= 0
|
602
|
+
end
|
603
|
+
end
|
604
|
+
@source.insert_or_delete_columns(@col_permutation,@col_permutation.length)
|
605
|
+
end
|
606
|
+
end
|
607
|
+
len = self.process_mods(@cmods,fate,@source.get_width)
|
608
|
+
@source.insert_or_delete_columns(fate,len)
|
609
|
+
begin
|
610
|
+
_g4 = 0
|
611
|
+
_g13 = @cmods
|
612
|
+
while(_g4 < _g13.length)
|
613
|
+
cmod = _g13[_g4]
|
614
|
+
_g4+=1
|
615
|
+
if !cmod.rem
|
616
|
+
if cmod.add
|
617
|
+
begin
|
618
|
+
_g21 = 0
|
619
|
+
_g31 = @mods
|
620
|
+
while(_g21 < _g31.length)
|
621
|
+
mod4 = _g31[_g21]
|
622
|
+
_g21+=1
|
623
|
+
if mod4.patch_row != -1 && mod4.dest_row != -1
|
624
|
+
d = @patch.get_cell(cmod.patch_row,mod4.patch_row)
|
625
|
+
@source.set_cell(cmod.dest_row,mod4.dest_row,d)
|
626
|
+
end
|
627
|
+
end
|
628
|
+
end
|
629
|
+
hdr1 = @header[cmod.patch_row]
|
630
|
+
@source.set_cell(cmod.dest_row,0,@view.to_datum(hdr1))
|
631
|
+
end
|
632
|
+
end
|
633
|
+
end
|
634
|
+
end
|
635
|
+
begin
|
636
|
+
_g14 = 0
|
637
|
+
_g5 = @source.get_width
|
638
|
+
while(_g14 < _g5)
|
639
|
+
i2 = _g14
|
640
|
+
_g14+=1
|
641
|
+
name = @view.to_s(@source.get_cell(i2,0))
|
642
|
+
next_name = @header_rename[name]
|
643
|
+
next if next_name == nil
|
644
|
+
@source.set_cell(i2,0,@view.to_datum(next_name))
|
645
|
+
end
|
646
|
+
end
|
647
|
+
end
|
648
|
+
|
649
|
+
end
|
650
|
+
|
651
|
+
end
|