private IEnumerable <SearchResult> Search(SearchQuery query, RepoInfo repo, bool includeRepoName = false) { var allTerms = string.Join(" --or ", query.Terms.Select(t => "-e " + GitUtilities.Q(t))); var commandResult = GitUtilities.Execute("grep --line-number --fixed-strings --ignore-case --context 3 --null --all-match " + allTerms + " HEAD", repo.RepoPath); var repoResults = commandResult.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); return(from m in repoResults where m != "--" where !m.StartsWith("Binary file") let parts = m.Split('\0') let filePath = parts[0].Split(':')[1] let searchLine = new SearchLine { Line = parts[2], LineNumber = int.Parse(parts[1]), } group searchLine by filePath into g select new SearchResult { LinkText = (includeRepoName ? repo.Name + " " : string.Empty) + "/" + g.Key, ActionName = "ViewBlob", ControllerName = "Browse", RouteValues = new { repo = repo.Name, @object = "HEAD", path = g.Key }, Lines = g.ToList(), }); }