Exemplo n.º 1
0
        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(),
            });
        }
Exemplo n.º 2
0
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;

            var commandResult = GitUtilities.Execute(string.Format(this.commandFormat, this.service), this.workingDir);
            var commandData   = GitUtilities.DefaultEncoding.GetBytes(commandResult);

            response.StatusCode  = 200;
            response.ContentType = "application/x-git-" + this.service + "-advertisement";
            response.BinaryWrite(PacketFormat(string.Format("# service=git-{0}\n", this.service)));
            response.BinaryWrite(PacketFlush());
            response.BinaryWrite(commandData);
        }