Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 1545581

Browse files
committed
[[ Diff ]] Place deletion ops before addition ops in unified diff output
1 parent 51bac3f commit 1545581

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

extensions/script-libraries/diff/diff.livecodescript

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ end detailed_files
215215
-- format conversion --
216216

217217
constant kContent = "content"
218+
constant kAdditions = "additions"
218219
constant kSource = "source"
219220
constant kSourceLength = "sourceLength"
220221
constant kContextLength = "contextLength"
@@ -270,6 +271,8 @@ private command begin_hunk @pHunk, pSource, pSourceLength, pContextLength
270271
end begin_hunk
271272

272273
private command end_hunk @pHunk
274+
flush_additions pHunk
275+
273276
if pHunk[kLastSourceIndex] is not empty then
274277
add_context_before pHunk, pHunk[kLastSourceIndex] + pHunk[kContextLength] + 1
275278
end if
@@ -299,14 +302,22 @@ end add_deletion
299302

300303
private command add_addition @pHunk, pIndex, pContent
301304
add_context_before pHunk, pIndex + 1
302-
put "+" & pContent after pHunk[kContent]
305+
// Defer adding additions to ensure they come after deletions
306+
put "+" & pContent after pHunk[kAdditions]
303307
add 1 to pHunk[kDelta]
304308

305309
if not (pContent ends with return) then
306-
put return & "\ No newline at end of file" & return after pHunk[kContent]
310+
put return & "\ No newline at end of file" & return after pHunk[kAdditions]
307311
end if
308312
end add_addition
309313

314+
private command flush_additions @pHunk
315+
if pHunk[kAdditions] is not empty then
316+
put pHunk[kAdditions] after pHunk[kContent]
317+
put empty into pHunk[kAdditions]
318+
end if
319+
end flush_additions
320+
310321
private command add_context_before @pHunk, pIndex
311322
local tStart, tEnd
312323
if pHunk[kLastSourceIndex] is not empty then
@@ -327,6 +338,8 @@ private command add_context_before @pHunk, pIndex
327338
exit add_context_before
328339
end if
329340

341+
flush_additions pHunk
342+
330343
repeat with i = tStart to tEnd
331344
put space & pHunk[kSource][i] after pHunk[kContent]
332345
end repeat

0 commit comments

Comments
 (0)