diff options
author | Gabriel Devillers <gdevillers@kalray.eu> | 2016-07-29 10:29:19 +0200 |
---|---|---|
committer | Gabriel Devillers <gdevillers@kalray.eu> | 2016-08-05 11:51:49 +0200 |
commit | 90894e8abc2fdf457170828d3c57e38223bd7ce9 (patch) | |
tree | 8f5452174c3e8ed531171ce89b650a00b18c73c0 /lib/diff.js | |
parent | 4c279d734e06afd0b5096092d3df414b32dbf71a (diff) | |
download | compiler-explorer-90894e8abc2fdf457170828d3c57e38223bd7ce9.tar.gz compiler-explorer-90894e8abc2fdf457170828d3c57e38223bd7ce9.zip |
Added wdiff configuration options.
Configuration is read from gccexplorer config file.
Default values are:
/tmp for temporary directory
/usr/bin/wdiff for the wdiff executable
Also: Cleaned lib/diff.js.
Diffstat (limited to 'lib/diff.js')
-rw-r--r-- | lib/diff.js | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/lib/diff.js b/lib/diff.js index 1f3203245..8d109751d 100644 --- a/lib/diff.js +++ b/lib/diff.js @@ -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, + buildDiffHandler: buildDiffHandler, }; |