@ -137,62 +137,65 @@ function cleanAndGetIndexes(text) {
return { text : finalText , zones : zones } ;
}
function diffHandler ( req , res , next ) {
// console.log("req: "+JSON.stringify(JSON.decycle(req)));
// console.log("");
// console.log("res: "+JSON.stringify(JSON.decycle(res)));
// console.log("");
// console.log("next: "+JSON.stringify(JSON.decycle(next)));
var before = req . body . before ;
var after = req . body . after ;
if ( before === undefined ) {
console . log ( "Warning : Bad request : wrong \"before\"" ) ;
//return next(new Error("Bad request : wrong \"before\""));
}
if ( after === undefined ) {
console . log ( "Warning : Bad request : wrong \"after\"" ) ;
//return next(new Error("Bad request : wrong \"after\""));
}
//console.log("Before: ");
//console.log(before);
//console.log("After: ");
//console.log(after);
// TODO : make async the two creation of temp files + call to wdiff
var before _temp _file = "/tmp/gcc-explorer-before"
fs . writeFileSync ( before _temp _file , before ) ;
var after _temp _file = "/tmp/gcc-explorer-after"
fs . writeFileSync ( after _temp _file , after ) ;
var wdiff _exe = "/work1/gdevillers/compiler-explorer/external/wdiff-1.2.2/src/wdiff" ;
var maxSize = 100000 ;
var wdiffResult = child _process . spawnSync (
"/work1/gdevillers/compiler-explorer/external/wdiff-1.2.2/src/wdiff" ,
[ "/tmp/gcc-explorer-before" , "/tmp/gcc-explorer-after" ] ,
{ maxBuffer : 100000 } ) ;
res . set ( 'Content-Type' , 'application/json' ) ;
var cleaned = cleanAndGetIndexes ( wdiffResult . stdout . toString ( ) ) ;
if ( cleaned == null ) {
res . end ( JSON . stringify ( {
computedDiff : "Failed to clean the diff" ,
zones : null
} ) ) ;
} else {
res . end ( JSON . stringify ( {
computedDiff : cleaned . text ,
//computedDiff: cleaned.text+
// "\n//// for reference: ////\n"+ // for debug only
// wdiffResult.stdout.toString(),
zones : cleaned . zones
//computedDiff: "aaa\nbbb[-ccc-]\n[-ddd-]eee\n[-fff-]\nsafe"
//computedDiff: "[-aaa-]"
//computedDiff: "aaa"
//computedDiff: "aa[--]a"
//computedDiff: "aa[-b-]"
} ) ) ;
function buildDiffHandler ( config ) {
return function diffHandler ( req , res , next ) {
// console.log("req: "+JSON.stringify(JSON.decycle(req)));
// console.log("");
// console.log("res: "+JSON.stringify(JSON.decycle(res)));
// console.log("");
// console.log("next: "+JSON.stringify(JSON.decycle(next)));
var before = req . body . before ;
var after = req . body . after ;
if ( before === undefined ) {
console . log ( "Warning : Bad request : wrong \"before\"" ) ;
//return next(new Error("Bad request : wrong \"before\""));
}
if ( after === undefined ) {
console . log ( "Warning : Bad request : wrong \"after\"" ) ;
//return next(new Error("Bad request : wrong \"after\""));
}
//console.log("Before: ");
//console.log(before);
//console.log("After: ");
//console.log(after);
// TODO : make async the two creation of temp files + call to wdiff ?
var wdiffExe = config . wdiffExe ;
var tempBeforePath = config . wdiffTmpDir + "/gcc-explorer-wdiff-before" ;
fs . writeFileSync ( tempBeforePath , before ) ;
var tempAfterPath = config . wdiffTmpDir + "/gcc-explorer-wdiff-after" ;
fs . writeFileSync ( tempAfterPath , after ) ;
// TODO : get rid of this buffer or calculate it...
var maxSize = 100000 ;
var wdiffResult = child _process . spawnSync (
wdiffExe ,
[ tempBeforePath , tempAfterPath ] ,
{ maxBuffer : 100000 } ) ;
res . set ( 'Content-Type' , 'application/json' ) ;
var cleaned = cleanAndGetIndexes ( wdiffResult . stdout . toString ( ) ) ;
if ( cleaned == null ) {
res . end ( JSON . stringify ( {
computedDiff : "Failed to clean the diff" ,
zones : null
} ) ) ;
} else {
res . end ( JSON . stringify ( {
computedDiff : cleaned . text ,
// for debug only:
//computedDiff: cleaned.text+
// "\n//// for reference: ////\n"+
// wdiffResult.stdout.toString(),
zones : cleaned . zones
} ) ) ;
}
}
}
module . exports = {
diffHandler: diffHandler,
buil dD iffHandler: buil dD iffHandler,
} ;