This Aha belongs in #501: create outline-oriented git diff 
<https://github.com/leo-editor/leo-editor/issues/501>, but I want to talk 
about this here so that a wider audience will be sure to see it.

The Aha:  *don't use git to do the diff!*  Instead, use git to "deliver" 
the files to be diffed.

We will usually want to diff files in an open outline to some older version 
of those files.

*For external files created by @file*

1. Use git diff --patch to generate a patch, and then *apply the patch* to 
generate the *old* file.

Alternatively, use git show <https://stackoverflow.com/questions/888414/> 
to copy the old file into a temp file.

2. Create a "helper outline" (a hidden commander) as is done by Leo's 
existing file-compare-leo-files command. *Once we read the old file into an 
outline, node-by-node comparisons are quick and easy.* The code in 
EditFileCommandsClass.compareAnyTwoFiles shows how. In particular, 
detecting inserted, deleted or moved nodes is a snap.

*For external files generated by @clean*

The process is much the same. We use git to deliver the old external file 
(*without 
*sentinels).  Using the open outline, a variant of the Mulder-Ream update 
algorithm will generate the old file *with* sentinels. Now we can proceed 
as with external files generated from @file.

*Note*: all diffs between files generated from @clean are "relative" to the 
presently open outline.  That is, lines from such external files can only 
be assigned to nodes using a particular, given, outline. I speculate that 
using the presently open outline will suffice in just about all cases.

*Summary*

The Aha: use git diff or git checkout *only *to deliver the *complete *old 
files.

The git-diff command will read old files into a hidden helper outline. 
Thereafter, node by node comparisons will be quick and easy. As with 
file-compare-leo-files, the new code will use difflib only to diff changed 
nodes* one node at at time*.  This will be extremely fast

I expect the new diff commands can be completed in a matter of days.

Edward
<https://github.com/leo-editor/leo-editor/issues/501>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to