Skip to content

Filter commit by Author #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions WebGitNet.SharedLib/GitUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,42 @@ public static List<LogEntry> GetLogEntries(string repoPath, int count, int skip
select parseResults(r)).ToList();
}

public static List<LogEntry> 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<string, LogEntry> 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");
Expand Down
36 changes: 36 additions & 0 deletions WebGitNet/Controllers/BrowseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 });
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion WebGitNet/Models/PaginationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ 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;
this.controllerName = controllerName;
this.actionName = actionName;
this.routeValues = routeValues;
this.routeKey = routeKey;
this.author = author;
}

public string ActionName
Expand Down Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion WebGitNet/Views/Browse/LogEntry.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
<tr><td>parent:</td><td>@Html.ActionLink(parent.Substring(0, 16), "ViewCommit", new { @object = parent })</td></tr>
}
<tr><td>author:</td><td><a href="mailto:@Model.AuthorEmail">@Model.Author</a></td></tr>
<tr><td>author:</td><td><a href="commitsadvanced?author=@Model.Author">@Model.Author</a></td></tr>
@if (Model.Author != Model.Committer ||
Model.AuthorEmail.Trim().ToLowerInvariant() != Model.CommitterEmail.Trim().ToLowerInvariant())
{
Expand Down
17 changes: 11 additions & 6 deletions WebGitNet/Views/Shared/Pagination.cshtml
Original file line number Diff line number Diff line change
@@ -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;
}

<li class="@(page == Model.Page ? "active" : string.Empty)">@Html.ActionLink(text, (string)Model.ActionName, (string)Model.ControllerName, r, null)</li>
}
<div class="pagination pagination-centered">
<ul>
@Link("Newest", 1)
@Link("Newer", Math.Max(Model.Page - 1, 1))
@Link("Newest", 1, Model.Author)
@Link("Newer", Math.Max(Model.Page - 1, 1), Model.Author)

@{
int left = Math.Min(Model.Page - 1, 2);
Expand All @@ -20,11 +25,11 @@
int endPage = Math.Min(Model.PageCount, Model.Page + right + (2 - left));
for (int p = startPage; p <= endPage; p++)
{
@Link(p.ToString(), p);
@Link(p.ToString(), p, Model.Author);
}
}

@Link("Older", Math.Min(Model.Page + 1, Model.PageCount))
@Link("Oldest", Model.PageCount)
@Link("Older", Math.Min(Model.Page + 1, Model.PageCount), Model.Author)
@Link("Oldest", Model.PageCount, Model.Author)
</ul>
</div>
2 changes: 2 additions & 0 deletions WebGitNet/WebGitNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@
<None Include="Scripts\jquery.validate.unobtrusive.js" />
<None Include="Scripts\jquery.validate-vsdoc.js" />
<None Include="Scripts\jquery-2.1.0.intellisense.js" />
<Content Include="Views\Browse\ShortLogEntry.cshtml" />
<Content Include="Views\Browse\ViewCommitsAdvanced.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebGitNet.SearchProviders\WebGitNet.SearchProviders.csproj">
Expand Down