diff --git a/WebGitNet.SharedLib/GitUtilities.cs b/WebGitNet.SharedLib/GitUtilities.cs index b302883..3cf3c76 100644 --- a/WebGitNet.SharedLib/GitUtilities.cs +++ b/WebGitNet.SharedLib/GitUtilities.cs @@ -243,6 +243,42 @@ public static List GetLogEntries(string repoPath, int count, int skip select parseResults(r)).ToList(); } + public static List GetLogEntriesAdvanced(string repoPath, string repoAuthor, int count, int skip = 0, string @object = null, bool allRefs = false) + { + if (count < 0) + { + throw new ArgumentOutOfRangeException("count"); + } + + if (skip < 0) + { + throw new ArgumentOutOfRangeException("skip"); + } + + @object = @object ?? "HEAD"; + var results = Execute(string.Format("log -n {0} --encoding=UTF-8 --author=\"{3}\" -z --date-order --format=\"format:commit %H%ntree %T%nparent %P%nauthor %an%nauthor mail %ae%nauthor date %aD%ncommitter %cn%ncommitter mail %ce%ncommitter date %cD%nsubject %s%%b%n%x00\"{1} {2}", count + skip, allRefs ? " --all" : "", Q(@object), repoAuthor), repoPath, Encoding.UTF8); + + Func parseResults = result => + { + var commit = ParseResultLine("commit ", result, out result); + var tree = ParseResultLine("tree ", result, out result); + var parent = ParseResultLine("parent ", result, out result); + var author = ParseResultLine("author ", result, out result); + var authorEmail = ParseResultLine("author mail ", result, out result); + var authorDate = ParseResultLine("author date ", result, out result); + var committer = ParseResultLine("committer ", result, out result); + var committerEmail = ParseResultLine("committer mail ", result, out result); + var committerDate = ParseResultLine("committer date ", result, out result); + var subject = ParseResultLine("subject ", result, out result); + var body = result; + + return new LogEntry(commit, tree, parent, author, authorEmail, authorDate, committer, committerEmail, committerDate, subject, body); + }; + + return (from r in results.Split(new[] { '\0' }, StringSplitOptions.RemoveEmptyEntries).Skip(skip) + select parseResults(r)).ToList(); + } + public static RepoInfo GetRepoInfo(string repoPath) { var descrPath = Path.Combine(repoPath, "description"); diff --git a/WebGitNet/Controllers/BrowseController.cs b/WebGitNet/Controllers/BrowseController.cs index 0558560..5815fee 100644 --- a/WebGitNet/Controllers/BrowseController.cs +++ b/WebGitNet/Controllers/BrowseController.cs @@ -149,6 +149,37 @@ public ActionResult ViewCommits(string repo, string @object = null, int page = 1 return View(commits); } + public ActionResult ViewCommitsAdvanced(string repo, string @object = null, int page = 1, string author = "", int pagesize = 20) + { + var resourceInfo = this.FileManager.GetResourceInfo(repo); + if (resourceInfo.Type != ResourceType.Directory || page < 1 || author == "") + { + return HttpNotFound(); + } + + int PageSize = pagesize; + int skip = PageSize * (page - 1); + var count = GitUtilities.CountCommits(resourceInfo.FullPath, @object); + + if (skip >= count) + { + return HttpNotFound(); + } + + AddRepoBreadCrumb(repo); + this.BreadCrumbs.Append("Browse", "ViewCommitsAdvanced", "Commit Log", new { repo, @object }); + + var commits = GitUtilities.GetLogEntriesAdvanced(resourceInfo.FullPath, author, 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", "ViewCommitsAdvanced", new { repo }, "page", author); + ViewBag.RepoName = resourceInfo.Name; + ViewBag.Object = @object ?? "HEAD"; + ViewBag.Branches = branches; + + return View(commits); + } + public ActionResult ViewRepo(string repo) { var resourceInfo = this.FileManager.GetResourceInfo(repo); @@ -242,6 +273,11 @@ public void RegisterRoutes(RouteCollection routes) "View Commit Log", "browse/{repo}/commits/{object}", new { controller = "Browse", action = "ViewCommits", routeName = "View Commit Log", routeIcon = "list", @object = UrlParameter.Optional }); + + routes.MapRoute( + "View Commit Log Advanced", + "browse/{repo}/commitsadvanced/{object}", + new { controller = "Browse", action = "ViewCommitsAdvanced", routeName = "View Commit Log Advanced", routeIcon = "list", @object = UrlParameter.Optional }); } } } diff --git a/WebGitNet/Models/PaginationInfo.cs b/WebGitNet/Models/PaginationInfo.cs index 6f9c46a..610e4e3 100644 --- a/WebGitNet/Models/PaginationInfo.cs +++ b/WebGitNet/Models/PaginationInfo.cs @@ -6,10 +6,11 @@ public class PaginationInfo private readonly string controllerName; private readonly int page; private readonly int pageCount; + private readonly string author; private readonly string routeKey; private readonly object routeValues; - public PaginationInfo(int page, int pageCount, string controllerName, string actionName, object routeValues, string routeKey = "page") + public PaginationInfo(int page, int pageCount, string controllerName, string actionName, object routeValues, string routeKey = "page", string author = "") { this.page = page; this.pageCount = pageCount; @@ -17,6 +18,7 @@ public PaginationInfo(int page, int pageCount, string controllerName, string act this.actionName = actionName; this.routeValues = routeValues; this.routeKey = routeKey; + this.author = author; } public string ActionName @@ -44,6 +46,11 @@ public string RouteKey get { return this.routeKey; } } + public string Author + { + get { return this.author; } + } + public object RouteValues { get { return this.routeValues; } diff --git a/WebGitNet/Views/Browse/LogEntry.cshtml b/WebGitNet/Views/Browse/LogEntry.cshtml index 62cd653..a382afc 100644 --- a/WebGitNet/Views/Browse/LogEntry.cshtml +++ b/WebGitNet/Views/Browse/LogEntry.cshtml @@ -14,7 +14,7 @@ { parent:@Html.ActionLink(parent.Substring(0, 16), "ViewCommit", new { @object = parent }) } - author:@Model.Author + author:@Model.Author @if (Model.Author != Model.Committer || Model.AuthorEmail.Trim().ToLowerInvariant() != Model.CommitterEmail.Trim().ToLowerInvariant()) { diff --git a/WebGitNet/Views/Shared/Pagination.cshtml b/WebGitNet/Views/Shared/Pagination.cshtml index 8087009..7027792 100644 --- a/WebGitNet/Views/Shared/Pagination.cshtml +++ b/WebGitNet/Views/Shared/Pagination.cshtml @@ -1,17 +1,22 @@ @model PaginationInfo -@helper Link(string text, int page) { +@helper Link(string text, int page, string author = "") { var r = new RouteValueDictionary((object)Model.RouteValues); if (page != 1) { r[Model.RouteKey ?? "page"] = page; } + + if(author != "") + { + r["author"] = author; + }
  • @Html.ActionLink(text, (string)Model.ActionName, (string)Model.ControllerName, r, null)
  • } \ No newline at end of file diff --git a/WebGitNet/WebGitNet.csproj b/WebGitNet/WebGitNet.csproj index 75f7d23..12d2583 100644 --- a/WebGitNet/WebGitNet.csproj +++ b/WebGitNet/WebGitNet.csproj @@ -235,6 +235,8 @@ + +