Example #1
0
        public ActionResult ViewCommits(string repo, string @object = null, int page = 1)
        {
            var resourceInfo = this.FileManager.GetResourceInfo(repo);

            if (resourceInfo.Type != ResourceType.Directory || page < 1)
            {
                return(HttpNotFound());
            }

            const int PageSize = 20;
            int       skip     = PageSize * (page - 1);
            var       count    = GitUtilities.CountCommits(resourceInfo.FullPath, @object);

            if (skip >= count)
            {
                return(HttpNotFound());
            }

            AddRepoBreadCrumb(repo);
            this.BreadCrumbs.Append("Browse", "ViewCommits", "Commit Log", new { repo, @object });

            var commits  = GitUtilities.GetLogEntries(resourceInfo.FullPath, PageSize, skip, @object);
            var branches = GitUtilities.GetAllRefs(resourceInfo.FullPath).Where(r => r.RefType == RefType.Branch).ToList();

            ViewBag.PaginationInfo = new PaginationInfo(page, (count + PageSize - 1) / PageSize, "Browse", "ViewCommits", new { repo });
            ViewBag.RepoName       = resourceInfo.Name;
            ViewBag.Object         = @object ?? "HEAD";
            ViewBag.Branches       = branches;

            return(View(commits));
        }
Example #2
0
        public ActionResult ViewCommit(string repo, string @object)
        {
            var resourceInfo = this.FileManager.GetResourceInfo(repo);

            if (resourceInfo.Type != ResourceType.Directory)
            {
                return(HttpNotFound());
            }

            AddRepoBreadCrumb(repo);
            this.BreadCrumbs.Append("Browse", "ViewCommit", @object, new { repo, @object });

            var commit = GitUtilities.GetLogEntries(resourceInfo.FullPath, 1, 0, @object).FirstOrDefault();

            if (commit == null)
            {
                return(HttpNotFound());
            }

            var diffs = GitUtilities.GetDiffInfo(resourceInfo.FullPath, commit.Parents.FirstOrDefault() ?? GitUtilities.EmptyTreeHash, commit.CommitHash);

            ViewBag.RepoName       = resourceInfo.Name;
            ViewBag.CommitLogEntry = commit;

            return(View(diffs));
        }
Example #3
0
        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 LastCommits()
        {
            var directory = this.FileManager.DirectoryInfo;

            var items = from repo in directory.EnumerateDirectories()
                        from entry in GitUtilities.GetLogEntries(repo.FullName, 1)
                        select FormatLogEntry(entry, repo.Name);

            var feed = BuildFeed("Last Commit in All Repos", items);

            return(new AtomActionResult(feed));
        }
        public ActionResult Commits(string repo)
        {
            var resourceInfo = this.FileManager.GetResourceInfo(repo);

            if (resourceInfo.Type != ResourceType.Directory)
            {
                return(HttpNotFound());
            }

            var items = from entry in GitUtilities.GetLogEntries(resourceInfo.FullPath, 20)
                        select FormatLogEntry(entry, repo);

            var feed = BuildFeed(repo + " Commits", items);

            return(new AtomActionResult(feed));
        }
Example #6
0
        public List <GraphEntry> GetLogEntries(string path, int count)
        {
            var nodeColors  = new Dictionary <string, int>();
            var colorNumber = 0;

            var entries = GitUtilities.GetLogEntries(path, count + 1000, allRefs: true);
            var refs    = GitUtilities.GetAllRefs(path);

            var results = new List <GraphEntry>();

            var incoming = new List <string>();

            foreach (var entry in entries.Take(count))
            {
                var color = ColorNode(entry, nodeColors, ref colorNumber);

                results.Add(new GraphEntry
                {
                    LogEntry = entry,
                    Refs     = refs.Where(r => r.ShaId == entry.CommitHash).ToList(),

                    Node = new NodeInfo {
                        Hash = entry.CommitHash, Color = color
                    },
                    IncomingNodes = incoming.Select(i => new NodeInfo {
                        Hash = i, Color = nodeColors[i]
                    }).ToList(),
                    ParentNodes = entry.Parents.Select(i => new NodeInfo {
                        Hash = i, Color = nodeColors[i]
                    }).ToList(),
                });

                incoming = BuildOutgoing(incoming, entry);
            }

            return(results);
        }