Skip to content

Commit 702f54a

Browse files
committed
diff: Complete/fix exported port rename diffing
1 parent c7e4ebd commit 702f54a

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

examples/exported-ports.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
'default' -> IN read(ReadSomething)
1717
diff: "- INPORT=read.in:filename" #FIXME casing
1818
'renamed inport':
19-
skip: true
2019
format: 'fbp'
2120
from: |
2221
INPORT=read.IN:FILENAME
2322
'default' -> IN read(ReadSomething)
2423
to: |
2524
INPORT=read.IN:NEWFILENAME
2625
'default' -> IN read(ReadSomething)
27-
diff: "- INPORT=read.IN:FILENAME"
26+
diff: ".rename INPORT=read.in:newfilename was INPORT=read.in:filename"

spec/examples.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ chai = require 'chai'
55
testExample = (testcase) ->
66
options =
77
format: testcase.format or 'fbp'
8+
diff = ''
89
it 'should produce a diff', ->
910
diff = fbpDiff.diff testcase.from, testcase.to, options
1011
chai.expect(diff).to.be.a 'string'
1112
it 'diff should equal expected', ->
12-
diff = fbpDiff.diff testcase.from, testcase.to, options
1313
chai.expect(diff).to.equal testcase.diff
1414

1515
loadTestCases = () ->

src/diff.coffee

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ portChanges = (from, to, kind) ->
128128

129129
fromNames = Object.keys from
130130
toNames = Object.keys to
131+
131132
for name, target of from
132133
existsNow = name in toNames
133134
if not existsNow
@@ -177,10 +178,10 @@ removeByPredicate = (array, predicate) ->
177178
return removed
178179

179180
findRenamedExports = (changes, kind) ->
180-
rewritten = clone changes
181+
rewritten = changes
181182

182183
findTargets = (type) ->
183-
c = changes.filter (c) -> c.type == type and kind == kind
184+
c = changes.filter (c) -> c.type == type and c.kind == kind
184185
t = c.map (c) -> return "#{c.process}.#{c.port}"
185186
res =
186187
changes: c
@@ -192,35 +193,36 @@ findRenamedExports = (changes, kind) ->
192193
removed = findTargets 'exported-port-removed'
193194

194195
for target, targetIdx in removed.targets
195-
addedIdx = added.targets.find target
196+
addedIdx = added.targets.indexOf target
196197
if addedIdx != -1
197198
# both added and removed exported port, targeting the same node+port was -> a rename
198199
a = added.changes[addedIdx]
199-
r = added.changes[removedIdx]
200-
201-
console.log a, '\n', r
200+
r = removed.changes[targetIdx]
202201

203-
if not connEquals(a.data.target, b.data.target)
202+
if not connEquals(a.data.target, r.data.target)
204203
throw new Error "Sanity check failed, rename match did not have same target"
205204

206205
# rewrite changes
207206
rewritten = removeByPredicate rewritten, (item) ->
208207
exportedPort = (item.type == 'exported-port-added' or item.type == 'exported-port-removed')
209-
targetEquals = connEquals a.data.target, item.target
208+
targetEquals = connEquals a.data.target, item.data.target
210209
return item.kind == kind and exportedPort and targetEquals
211210

212211
rewritten.push
213212
type: 'exported-port-renamed'
214213
kind: kind
215-
data:
216-
target: a.target
214+
data: a.data
215+
previous:
216+
name: r.data.name
217217

218218
return rewritten
219219

220220
applyHeuristics = (changes) ->
221-
withHeuristics = findRenamedExports changes
221+
rewritten = clone changes
222+
rewritten = findRenamedExports(rewritten, 'inport')
223+
rewritten = findRenamedExports(rewritten, 'outport')
222224

223-
return withHeuristics
225+
return rewritten
224226

225227
# calculate a list of changes between @from and @to
226228
calculateDiff = (from, to) ->
@@ -243,7 +245,7 @@ calculateDiff = (from, to) ->
243245

244246
diff =
245247
raw: changes
246-
changes: changes # FIXME: apply heuristics
248+
changes: applyHeuristics changes
247249
return diff
248250

249251
formatEdge = (e) ->
@@ -272,6 +274,7 @@ formatChangeTextual = (change) ->
272274
when 'exported-port-added' then "+ #{formatExport(change.kind, d.target, d.name)}"
273275
when 'exported-port-removed' then "- #{formatExport(change.kind, d.target, d.name)}"
274276
when 'exported-port-target-changed' then ". #{formatExport(change.kind, d.target, d.name)} was #{formatExport(change.kind, old.target, d.name)}"
277+
when 'exported-port-renamed' then ".rename #{formatExport(change.kind, d.target, d.name)} was #{formatExport(change.kind, d.target, old.name)}"
275278
else
276279
throw new Error "Cannot format unsupported change type: #{change.type}"
277280

0 commit comments

Comments
 (0)