changes to diff algo

This commit is contained in:
Adam Brown 2016-05-24 10:56:13 -04:00
parent 3326eaccb7
commit ab1229e8da
2 changed files with 202 additions and 13 deletions

View File

@ -127,7 +127,39 @@
"file": "server/components/wdiff/index.js", "file": "server/components/wdiff/index.js",
"settings": "settings":
{ {
"buffer_size": 8038, "buffer_size": 8966,
"line_ending": "Unix"
}
},
{
"file": "/C/Users/Adam/Desktop/code/courses/git-status-all",
"settings":
{
"buffer_size": 113,
"line_ending": "Unix"
}
},
{
"file": "/C/Users/Adam/Downloads/JavaScript Refactoring - Course Notes.md",
"settings":
{
"buffer_size": 2388,
"line_ending": "Unix"
}
},
{
"file": "/C/Users/Adam/Dropbox (Envato)/Course Content/Code/ready/Create a New JavaScript Framework - How We Built the Daily Mail CMS/notes - QA.md",
"settings":
{
"buffer_size": 3928,
"line_ending": "Unix"
}
},
{
"file": "/C/Users/Adam/Dropbox (Envato)/Course Content/Code/ready/Create a New JavaScript Framework - Challenges of Rolling Your Own/notes - QA.md",
"settings":
{
"buffer_size": 4420,
"line_ending": "Unix" "line_ending": "Unix"
} }
} }
@ -194,6 +226,8 @@
], ],
"file_history": "file_history":
[ [
"/C/Users/Adam/Dropbox (Envato)/Course Content/Code/incoming/Create a New JavaScript Framework - Full Stack Reactivity with Milo/notes - edit.md",
"/C/Users/Adam/Desktop/code/courses/create-a-new-javascript-framework-full-stack-reactivity-with-milo/README.md",
"/C/Users/Adam/Desktop/code/projects/dubdiff/client/app/main/main.js", "/C/Users/Adam/Desktop/code/projects/dubdiff/client/app/main/main.js",
"/C/Users/Adam/Desktop/code/projects/dubdiff/bin/markdown-format-wdiff", "/C/Users/Adam/Desktop/code/projects/dubdiff/bin/markdown-format-wdiff",
"/C/Users/Adam/Desktop/code/projects/dubdiff/client/app/wdiff/wdiff.scss", "/C/Users/Adam/Desktop/code/projects/dubdiff/client/app/wdiff/wdiff.scss",
@ -319,9 +353,7 @@
"/C/Users/adam/Desktop/vagrant/node/learning-mean-hello/server/views/404.jade", "/C/Users/adam/Desktop/vagrant/node/learning-mean-hello/server/views/404.jade",
"/C/Users/adam/Desktop/vagrant/node/learning-mean-holmes/Gruntfile.js", "/C/Users/adam/Desktop/vagrant/node/learning-mean-holmes/Gruntfile.js",
"/C/Users/adam/Desktop/vagrant/node/scripttest/Gruntfile.js", "/C/Users/adam/Desktop/vagrant/node/scripttest/Gruntfile.js",
"/C/Users/adam/Desktop/vagrant/node/scripttest/package.json", "/C/Users/adam/Desktop/vagrant/node/scripttest/package.json"
"/C/Users/adam/Desktop/vagrant/node/angular-phonecat/app/index.html",
"/C/Users/adam/Desktop/vagrant/node/learning-mean-holmes/package.json"
], ],
"find": "find":
{ {
@ -495,7 +527,7 @@
"groups": "groups":
[ [
{ {
"selected": 3, "selected": 5,
"sheets": "sheets":
[ [
{ {
@ -525,7 +557,7 @@
"translation.y": 516.0, "translation.y": 516.0,
"zoom_level": 1.0 "zoom_level": 1.0
}, },
"stack_index": 2, "stack_index": 6,
"type": "text" "type": "text"
}, },
{ {
@ -555,7 +587,7 @@
"translation.y": 0.0, "translation.y": 0.0,
"zoom_level": 1.0 "zoom_level": 1.0
}, },
"stack_index": 3, "stack_index": 7,
"type": "text" "type": "text"
}, },
{ {
@ -585,7 +617,7 @@
"translation.y": 0.0, "translation.y": 0.0,
"zoom_level": 1.0 "zoom_level": 1.0
}, },
"stack_index": 1, "stack_index": 5,
"type": "text" "type": "text"
}, },
{ {
@ -594,15 +626,15 @@
"semi_transient": false, "semi_transient": false,
"settings": "settings":
{ {
"buffer_size": 8038, "buffer_size": 8966,
"regions": "regions":
{ {
}, },
"selection": "selection":
[ [
[ [
1952, 590,
1952 590
] ]
], ],
"settings": "settings":
@ -612,11 +644,127 @@
"translate_tabs_to_spaces": true "translate_tabs_to_spaces": true
}, },
"translation.x": 0.0, "translation.x": 0.0,
"translation.y": 264.0, "translation.y": 168.0,
"zoom_level": 1.0
},
"stack_index": 4,
"type": "text"
},
{
"buffer": 4,
"file": "/C/Users/Adam/Desktop/code/courses/git-status-all",
"semi_transient": false,
"settings":
{
"buffer_size": 113,
"regions":
{
},
"selection":
[
[
113,
113
]
],
"settings":
{
"syntax": "Packages/Text/Plain text.tmLanguage"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 1,
"type": "text"
},
{
"buffer": 5,
"file": "/C/Users/Adam/Downloads/JavaScript Refactoring - Course Notes.md",
"semi_transient": false,
"settings":
{
"buffer_size": 2388,
"regions":
{
},
"selection":
[
[
0,
0
]
],
"settings":
{
"syntax": "Packages/Markdown/MultiMarkdown.sublime-syntax"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0 "zoom_level": 1.0
}, },
"stack_index": 0, "stack_index": 0,
"type": "text" "type": "text"
},
{
"buffer": 6,
"file": "/C/Users/Adam/Dropbox (Envato)/Course Content/Code/ready/Create a New JavaScript Framework - How We Built the Daily Mail CMS/notes - QA.md",
"semi_transient": false,
"settings":
{
"buffer_size": 3928,
"regions":
{
},
"selection":
[
[
3928,
3928
]
],
"settings":
{
"syntax": "Packages/Markdown/MultiMarkdown.sublime-syntax",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 1786.0,
"zoom_level": 1.0
},
"stack_index": 2,
"type": "text"
},
{
"buffer": 7,
"file": "/C/Users/Adam/Dropbox (Envato)/Course Content/Code/ready/Create a New JavaScript Framework - Challenges of Rolling Your Own/notes - QA.md",
"semi_transient": false,
"settings":
{
"buffer_size": 4420,
"regions":
{
},
"selection":
[
[
1014,
1272
]
],
"settings":
{
"syntax": "Packages/Markdown/MultiMarkdown.sublime-syntax",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 379.0,
"zoom_level": 1.0
},
"stack_index": 3,
"type": "text"
} }
] ]
} }
@ -704,7 +852,7 @@
}, },
"show_minimap": false, "show_minimap": false,
"show_open_files": true, "show_open_files": true,
"show_tabs": false, "show_tabs": true,
"side_bar_visible": true, "side_bar_visible": true,
"side_bar_width": 321.0, "side_bar_width": 321.0,
"status_bar_visible": true, "status_bar_visible": true,

View File

@ -6,13 +6,52 @@ var _ = require('lodash'),
exec = require('child_process').exec, exec = require('child_process').exec,
Lexer = require('lex'); Lexer = require('lex');
var diff = require('diff');
// Automatically track and cleanup files at exit // Automatically track and cleanup files at exit
temp.track(); temp.track();
// Perform a comparison between a and b // Perform a comparison between a and b
// the callback should have parameters (err, result) // the callback should have parameters (err, result)
module.exports = function(a, b, asMarkdown, callback) { module.exports = function(a, b, asMarkdown, callback) {
//a few strings have to be escaped: "[-", "-]", "{+", and "+}"
a = escapeString(a)
b = escapeString(b)
var diffRes = diff.diffWordsWithSpace(a,b, {ignoreWhitespace:true})
var diffStr = diffRes.map (part => {
if (part.added) return "{+"+part.value+"+}";
else if (part.removed) return "[-"+part.value+"-]";
else return part.value;
}).join("");
//if no difference was found by wdiff, err.code will be 0
var wdiffSame;
wdiffSame = false; //???
console.log(diffStr)
var resData = {wdiffNoMarkdown:unescapeString(diffStr), same: wdiffSame};
if (asMarkdown) {
//!!! this needs more sophisticated parsing
//console.log(stdout)
var markdown = unescapeString(rewriteWdiffMarkdown(diffStr))
resData.wdiff=markdown;
}
return callback(null, resData);
}
var oldversion = function(a, b, asMarkdown, callback) {
//!!! this nested file-open is not a good pattern //!!! this nested file-open is not a good pattern
// better would be to use promises and write the two files asynchronously // better would be to use promises and write the two files asynchronously
@ -62,6 +101,8 @@ module.exports = function(a, b, asMarkdown, callback) {
var wdiffSame; var wdiffSame;
wdiffSame = (err && err.code == 0) ? true:false; wdiffSame = (err && err.code == 0) ? true:false;
console.log(stdout)
var resData = {wdiffNoMarkdown:unescapeString(stdout), same: wdiffSame}; var resData = {wdiffNoMarkdown:unescapeString(stdout), same: wdiffSame};
if (asMarkdown) { if (asMarkdown) {