Skip to content

Commit

Permalink
fixed codesearch to use the correct grep syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedeboer committed Oct 14, 2010
1 parent e93eaa1 commit 3b7663f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/DAV/plugins/codesearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = ['<?xml version="1.0" encoding="utf-8"?><d:multistatus'],
aLines = res.split(/([\n\r]+)/g),
aLines = (typeof res == "string" ? res : "").split(/([\n\r]+)/g),
i = 0,
count = 0,
l = aLines.length;
Expand Down
6 changes: 6 additions & 0 deletions lib/DAV/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ exports.rtrim = function(str, charlist) {
return (str+"").replace(re, "");
};

exports.splitSafe = function(s, separator, limit, bLowerCase) {
return (bLowerCase && s.toLowerCase() || s)
.replace(/(?:^\s+|\n|\s+$)/g, "")
.split(new RegExp("[\\s ]*" + separator + "[\\s ]*", "g"), limit || 999);
};

/**
* Extends an object with one or more other objects by copying all their
* properties.
Expand Down

0 comments on commit 3b7663f

Please sign in to comment.