Skip to content

Commit 3172628

Browse files
committed
diff: Handle empty JSON files
1 parent c9425d1 commit 3172628

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

examples/wholegraph.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'added whole graph as .fbp':
2+
from: ""
3+
to: |
4+
INPORT=ledchain.IN:PIXEL
5+
OUTPORT=ledchain.PIXELSET:PIXELSET
6+
ledchain(LedChain) SHOWN -> IN dummy(Forward)
7+
ledchain READY -> IN dummyB(Forward)
8+
diff: |
9+
+ INPORT=ledchain.IN:PIXEL
10+
+ OUTPORT=ledchain.PIXELSET:PIXELSET
11+
+ ledchain(LedChain)
12+
+ dummy(Forward)
13+
+ dummyB(Forward)
14+
+ ledchain SHOWN -> IN dummy
15+
+ ledchain READY -> IN dummyB
16+
17+
'removed whole graph as .fbp':
18+
from: |
19+
INPORT=ledchain.IN:PIXEL
20+
OUTPORT=ledchain.PIXELSET:PIXELSET
21+
ledchain(LedChain) SHOWN -> IN dummy(Forward)
22+
ledchain READY -> IN dummyB(Forward)
23+
to: ""
24+
diff: |
25+
- INPORT=ledchain.IN:PIXEL
26+
- OUTPORT=ledchain.PIXELSET:PIXELSET
27+
- ledchain(LedChain)
28+
- dummy(Forward)
29+
- dummyB(Forward)
30+
- ledchain SHOWN -> IN dummy
31+
- ledchain READY -> IN dummyB
32+
33+
'added whole graph as .json':
34+
format: json
35+
from: ""
36+
to: |
37+
{
38+
"processes": {
39+
"foo": { "component": "Bar" }
40+
},
41+
"connections": [
42+
{ "data": "my iip", "tgt": { "port": "IN", "process": "foo" } }
43+
]
44+
}
45+
diff: |
46+
+ foo(Bar)
47+
+ "my iip" -> IN foo
48+
49+
'removed whole graph as .json':
50+
format: json
51+
from: |
52+
{
53+
"processes": {
54+
"foo": { "component": "Bar" }
55+
},
56+
"connections": [
57+
{ "data": "my iip", "tgt": { "port": "IN", "process": "foo" } }
58+
]
59+
}
60+
to: ""
61+
diff: |
62+
- foo(Bar)
63+
- "my iip" -> IN foo

src/diff.coffee

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,27 @@ readGraph = (contents, type, options) ->
303303
# TODO: support parsing up a diff from the textual output format?
304304
# Mostly useful if/when one can apply diff as a patch
305305

306+
nullGraph = () ->
307+
g =
308+
processes: {}
309+
connections: []
310+
return clone g
311+
312+
306313
# diff two graphs
307314
exports.diff = (from, to, options) ->
308315
options = normalizeOptions options
309316

310-
f = readGraph from, options.fromFormat, options
311-
t = readGraph to, options.toFormat, options
317+
# Handle empty graph when in JSON format
318+
f = if options.fromFormat == 'json' and from == ""
319+
readGraph nullGraph(), 'object', options
320+
else
321+
readGraph from, options.fromFormat, options
322+
323+
t = if options.toFormat == 'json' and to == ""
324+
readGraph nullGraph(), 'object', options
325+
else
326+
readGraph to, options.toFormat, options
312327

313328
diff = calculateDiff f, t
314329
out = formatDiffTextual diff

0 commit comments

Comments
 (0)