public ActionResult ViewRepo(string repo) { var resourceInfo = this.FileManager.GetResourceInfo(repo); if (resourceInfo.Type != ResourceType.Directory) { return(HttpNotFound()); } var repoInfo = GitUtilities.GetRepoInfo(resourceInfo.FullPath); if (!repoInfo.IsGitRepo) { return(HttpNotFound()); } AddRepoBreadCrumb(repo); var lastCommit = GitUtilities.GetLogEntries(resourceInfo.FullPath, 1).FirstOrDefault(); ViewBag.RepoInfo = GitUtilities.GetRepoInfo(resourceInfo.FullPath); ViewBag.LastCommit = lastCommit; ViewBag.CurrentTree = lastCommit != null?GitUtilities.GetTreeInfo(resourceInfo.FullPath, "HEAD") : null; ViewBag.Refs = GitUtilities.GetAllRefs(resourceInfo.FullPath); return(View()); }
public ActionResult ViewTree(string repo, string @object, string path) { var resourceInfo = this.FileManager.GetResourceInfo(repo); if (resourceInfo.Type != ResourceType.Directory) { return(HttpNotFound()); } TreeView items; try { items = GitUtilities.GetTreeInfo(resourceInfo.FullPath, @object, path); } catch (GitErrorException) { return(HttpNotFound()); } AddRepoBreadCrumb(repo); this.BreadCrumbs.Append("Browse", "ViewTree", @object, new { repo, @object, path = string.Empty }); this.BreadCrumbs.Append("Browse", "ViewTree", BreadCrumbTrail.EnumeratePath(path), p => p.Key, p => new { repo, @object, path = p.Value }); ViewBag.RepoName = resourceInfo.Name; ViewBag.Tree = @object; ViewBag.Path = path ?? string.Empty; return(View(items)); }
private IEnumerable <SearchResult> Search(SearchQuery query, RepoInfo repo, bool includeRepoName = false) { TreeView tree; try { tree = GitUtilities.GetTreeInfo(repo.RepoPath, "HEAD", recurse: true); } catch (GitErrorException) { yield break; } foreach (var item in tree.Objects) { var name = item.Name.Substring(item.Name.LastIndexOf('/') + 1); if (query.Terms.All(t => name.IndexOf(t, StringComparison.OrdinalIgnoreCase) != -1)) { var linkText = (includeRepoName ? repo.Name + " " : string.Empty) + "/" + item.Name; switch (item.ObjectType) { case ObjectType.Tree: yield return(new SearchResult { LinkText = linkText + "/", ActionName = "ViewTree", ControllerName = "Browse", RouteValues = new { repo = repo.Name, @object = tree.Tree, path = tree.Path + item.Name + "/" }, Lines = new List <SearchLine>(), }); break; case ObjectType.Blob: yield return(new SearchResult { LinkText = linkText, ActionName = "ViewBlob", ControllerName = "Browse", RouteValues = new { repo = repo.Name, @object = tree.Tree, path = tree.Path + item.Name }, Lines = new List <SearchLine>(), }); break; case ObjectType.Commit: yield return(new SearchResult { LinkText = linkText + "/", ActionName = "ViewTree", ControllerName = "Browse", RouteValues = new { repo = repo.Name, @object = tree.Tree, path = tree.Path + item.Name + "/" }, Lines = new List <SearchLine>(), }); break; } } } }
public ActionResult ViewBlob(string repo, string @object, string path, bool raw = false) { var resourceInfo = this.FileManager.GetResourceInfo(repo); if (resourceInfo.Type != ResourceType.Directory || string.IsNullOrEmpty(path)) { return(HttpNotFound()); } var fileName = Path.GetFileName(path); var containingPath = path.Substring(0, path.Length - fileName.Length); TreeView items; try { items = GitUtilities.GetTreeInfo(resourceInfo.FullPath, @object, containingPath); } catch (GitErrorException) { return(HttpNotFound()); } if (!items.Objects.Any(o => o.Name == fileName)) { return(HttpNotFound()); } var contentType = MimeUtilities.GetMimeType(fileName); if (raw) { return(new GitFileResult(resourceInfo.FullPath, @object, path, contentType)); } AddRepoBreadCrumb(repo); this.BreadCrumbs.Append("Browse", "ViewTree", @object, new { repo, @object, path = string.Empty }); var paths = BreadCrumbTrail.EnumeratePath(path, TrailingSlashBehavior.LeaveOffLastTrailingSlash).ToList(); this.BreadCrumbs.Append("Browse", "ViewTree", paths.Take(paths.Count() - 1), p => p.Key, p => new { repo, @object, path = p.Value }); this.BreadCrumbs.Append("Browse", "ViewBlob", paths.Last().Key, new { repo, @object, path = paths.Last().Value }); ViewBag.RepoName = resourceInfo.Name; ViewBag.Tree = @object; ViewBag.Path = path; ViewBag.FileName = fileName; ViewBag.ContentType = contentType; string model = null; if (contentType.StartsWith("text/") || contentType == "application/xml" || Regex.IsMatch(contentType, @"^application/.*\+xml$")) { using (var blob = GitUtilities.GetBlob(resourceInfo.FullPath, @object, path)) { using (var reader = new StreamReader(blob, detectEncodingFromByteOrderMarks: true)) { model = reader.ReadToEnd(); } } } return(View((object)model)); }