From 3b7663fd5cf869668f7f06ee3ac2db740d51bc6f Mon Sep 17 00:00:00 2001 From: mikedeboer Date: Thu, 14 Oct 2010 18:26:19 +0200 Subject: [PATCH] fixed codesearch to use the correct grep syntax --- lib/DAV/plugins/codesearch.js | 31 +++++++++++++++++++------------ lib/DAV/util.js | 6 ++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/DAV/plugins/codesearch.js b/lib/DAV/plugins/codesearch.js index 16a4d9ba..c9fa4193 100644 --- a/lib/DAV/plugins/codesearch.js +++ b/lib/DAV/plugins/codesearch.js @@ -92,12 +92,15 @@ var exts = []; for (var type in jsDAV_Codesearch_Plugin.MAPPINGS) { exts = exts.concat(jsDAV_Codesearch_Plugin.MAPPINGS[type]); } -jsDAV_Codesearch_Plugin.PATTERN_EXT = "\\." + Util.makeUnique(exts).join("|\\."); +// grep pattern matching for extensions +jsDAV_Codesearch_Plugin.PATTERN_EXT = Util.makeUnique(exts).join(","); var dirs = []; for (type in jsDAV_Codesearch_Plugin.IGNORE_DIRS) { - dirs.push(Util.escapeRegExp(type)); + dirs.push(type); } -jsDAV_Codesearch_Plugin.PATTERN_DIR = Util.makeUnique(dirs).join("|"); +dirs = Util.makeUnique(dirs); +jsDAV_Codesearch_Plugin.PATTERN_DIR = Util.escapeRegExp(dirs.join("|")); +jsDAV_Codesearch_Plugin.PATTERN_EDIR = dirs.join(","); (function() { this.initialize = function() { @@ -141,18 +144,22 @@ jsDAV_Codesearch_Plugin.PATTERN_DIR = Util.makeUnique(dirs).join("|"); }; this.doCodesearch = function(node, options, cbsearch) { - var cmd = "grep -P -s -r --binary-files=without-match", + var cmd = "grep -P -s -r --binary-files=without-match -n", file = this.handler.server.tmpDir + "/" + Util.uuid(), _self = this; - if (Util.isTrue(options.ignorecase)) - cmd += " -i" + if (!Util.isTrue(options.casesensitive)) + cmd += " -i"; + var t, + include = "*.{" + jsDAV_Codesearch_Plugin.PATTERN_EXT + "}"; + if (!Util.empty(options.pattern) && (t = jsDAV_Codesearch_Plugin.MAPPINGS[options.pattern])) { + include = (t.length > 1 ? "*.{" : "*.") + t.join(",") + (t.length > 1 ? "}" : ""); + } if (options.maxresults) cmd += " -m " + options.maxresults; - if (!Util.isFalse(options.showlinenumber)) - cmd += " -n"; - cmd += " --exclude='(" + jsDAV_Codesearch_Plugin.PATTERN_DIR + ")|(" - + jsDAV_Codesearch_Plugin.PATTERN_EXT + ")'" - + " '" + Util.escapeRegExp(options.query) + "' '" + node.path + cmd += " --exclude=*{" + jsDAV_Codesearch_Plugin.PATTERN_EDIR + "}*" + + " --include=" + include + " '" + (Util.isTrue(options.regexp) + ? options.query + : Util.escapeRegExp(options.query)) + "' '" + node.path + "' > '" + file + "'"; if (jsDAV.debugMode) console.log("search command: " + cmd); @@ -189,7 +196,7 @@ jsDAV_Codesearch_Plugin.PATTERN_DIR = Util.makeUnique(dirs).join("|"); this.parseSearchResult = function(res, basePath, options) { var namespace, prefix, lastFile, parts, file, aXml = ['