(refs #76)Show the content of the previous commit for removed files.

This commit is contained in:
takezoe
2013-08-15 02:22:11 +09:00
parent dee13542cd
commit 52ab3c625e
9 changed files with 75 additions and 54 deletions

View File

@@ -80,7 +80,6 @@ trait PullRequestsControllerBase extends ControllerBase {
getMilestonesWithIssueCount(owner, name), getMilestonesWithIssueCount(owner, name),
commits, commits,
diffs, diffs,
requestCommitId.getName,
if(issue.closed){ if(issue.closed){
false false
} else { } else {

View File

@@ -130,9 +130,12 @@ trait RepositoryViewerControllerBase extends ControllerBase {
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git => JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id)) val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit), JGitUtil.getDiffs(git, id) match { case (diffs, oldCommitId) =>
JGitUtil.getBranchesOfCommit(git, revCommit.getName), JGitUtil.getTagsOfCommit(git, revCommit.getName), repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
repository, JGitUtil.getDiffs(git, id)) JGitUtil.getBranchesOfCommit(git, revCommit.getName),
JGitUtil.getTagsOfCommit(git, revCommit.getName),
repository, diffs, oldCommitId)
}
} }
}) })

View File

@@ -254,7 +254,7 @@ object JGitUtil {
* @param page the page number (1-) * @param page the page number (1-)
* @param limit the number of commit info per page. 0 (default) means unlimited. * @param limit the number of commit info per page. 0 (default) means unlimited.
* @param path filters by this path. default is no filter. * @param path filters by this path. default is no filter.
* @return a tuple of the commit list and whether has next * @return a tuple of the commit list and whether has next, or the error message
*/ */
def getCommitLog(git: Git, revision: String, page: Int = 1, limit: Int = 0, path: String = ""): Either[String, (List[CommitInfo], Boolean)] = { def getCommitLog(git: Git, revision: String, page: Int = 1, limit: Int = 0, path: String = ""): Either[String, (List[CommitInfo], Boolean)] = {
val fixedPage = if(page <= 0) 1 else page val fixedPage = if(page <= 0) 1 else page
@@ -278,7 +278,7 @@ object JGitUtil {
if(path.nonEmpty){ if(path.nonEmpty){
revWalk.setRevFilter(new RevFilter(){ revWalk.setRevFilter(new RevFilter(){
def include(walk: RevWalk, commit: RevCommit): Boolean = { def include(walk: RevWalk, commit: RevCommit): Boolean = {
getDiffs(git, commit.getName, false).find(_.newPath == path).nonEmpty getDiffs(git, commit.getName, false)._1.find(_.newPath == path).nonEmpty
} }
override def clone(): RevFilter = this override def clone(): RevFilter = this
}) })
@@ -379,8 +379,11 @@ object JGitUtil {
} catch { } catch {
case e: MissingObjectException => None case e: MissingObjectException => None
} }
def getDiffs(git: Git, id: String, fetchContent: Boolean = true): List[DiffInfo] = { /**
* Returns the tuple of diff of the given commit and the previous commit id.
*/
def getDiffs(git: Git, id: String, fetchContent: Boolean = true): (List[DiffInfo], Option[String]) = {
@scala.annotation.tailrec @scala.annotation.tailrec
def getCommitLog(i: java.util.Iterator[RevCommit], logs: List[RevCommit]): List[RevCommit] = def getCommitLog(i: java.util.Iterator[RevCommit], logs: List[RevCommit]): List[RevCommit] =
i.hasNext match { i.hasNext match {
@@ -399,7 +402,7 @@ object JGitUtil {
if(commits.length >= 2){ if(commits.length >= 2){
// not initial commit // not initial commit
val oldCommit = commits(1) val oldCommit = commits(1)
getDiffs(git, oldCommit.getName, id, fetchContent) (getDiffs(git, oldCommit.getName, id, fetchContent), Some(oldCommit.getName))
} else { } else {
// initial commit // initial commit
@@ -415,7 +418,7 @@ object JGitUtil {
})) }))
} }
walk.release walk.release
buffer.toList (buffer.toList, None)
} }
} }

View File

@@ -1,4 +1,7 @@
@(diffs: Seq[util.JGitUtil.DiffInfo], repository: service.RepositoryService.RepositoryInfo, commitId: Option[String])(implicit context: app.Context) @(diffs: Seq[util.JGitUtil.DiffInfo],
repository: service.RepositoryService.RepositoryInfo,
newCommitId: Option[String],
oldCommitId: Option[String])(implicit context: app.Context)
@import context._ @import context._
@import view.helpers._ @import view.helpers._
@import org.eclipse.jgit.diff.DiffEntry.ChangeType @import org.eclipse.jgit.diff.DiffEntry.ChangeType
@@ -9,17 +12,27 @@
<th style="font-weight: normal;" class="box-header"> <th style="font-weight: normal;" class="box-header">
@if(diff.changeType == ChangeType.COPY || diff.changeType == ChangeType.RENAME){ @if(diff.changeType == ChangeType.COPY || diff.changeType == ChangeType.RENAME){
@diff.oldPath -> @diff.newPath @diff.oldPath -> @diff.newPath
@if(newCommitId.isDefined){
<div class="pull-right align-right">
<a href="@url(repository)/blob/@newCommitId.get/@diff.newPath" class="btn btn-small">View file @@ @newCommitId.get.substring(0, 10)</a>
</div>
}
} }
@if(diff.changeType == ChangeType.ADD || diff.changeType == ChangeType.MODIFY){ @if(diff.changeType == ChangeType.ADD || diff.changeType == ChangeType.MODIFY){
@diff.newPath @diff.newPath
@if(newCommitId.isDefined){
<div class="pull-right align-right">
<a href="@url(repository)/blob/@newCommitId.get/@diff.newPath" class="btn btn-small">View file @@ @newCommitId.get.substring(0, 10)</a>
</div>
}
} }
@if(diff.changeType == ChangeType.DELETE){ @if(diff.changeType == ChangeType.DELETE){
@diff.oldPath @diff.oldPath
} @if(oldCommitId.isDefined){
@if(commitId.isDefined){ <div class="pull-right align-right">
<div class="pull-right align-right"> <a href="@url(repository)/blob/@oldCommitId.get/@diff.oldPath" class="btn btn-small">View file @@ @oldCommitId.get.substring(0, 10)</a>
<a href="@url(repository)/blob/@commitId.get/@diff.newPath" class="btn btn-small">View file @@ @commitId.get.substring(0, 10)</a> </div>
</div> }
} }
</th> </th>
</tr> </tr>

View File

@@ -134,7 +134,7 @@
</li> </li>
} }
</ul> </ul>
@helper.html.diff(diffs, repository, Some(commitId)) @helper.html.diff(diffs, repository, Some(commitId), Some(sourceId))
} }
} }
<script> <script>

View File

@@ -1,7 +1,8 @@
@(issue: model.Issue, @(issue: model.Issue,
pullreq: model.PullRequest, pullreq: model.PullRequest,
diffs: Seq[util.JGitUtil.DiffInfo], diffs: Seq[util.JGitUtil.DiffInfo],
commitId: String, newCommitId: String,
oldCommitId: String,
hasWritePermission: Boolean, hasWritePermission: Boolean,
repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context) repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
@import context._ @import context._
@@ -33,7 +34,7 @@
</li> </li>
} }
</ul> </ul>
@helper.html.diff(diffs, repository, Some(commitId)) @helper.html.diff(diffs, repository, Some(newCommitId), Some(oldCommitId))
<script> <script>
$(function(){ $(function(){
$('#toggle-file-list').click(function(){ $('#toggle-file-list').click(function(){

View File

@@ -3,9 +3,8 @@
comments: List[model.IssueComment], comments: List[model.IssueComment],
collaborators: List[String], collaborators: List[String],
milestones: List[(model.Milestone, Int, Int)], milestones: List[(model.Milestone, Int, Int)],
commits: Seq[Seq[util.JGitUtil.CommitInfo]], dayByDayCommits: Seq[Seq[util.JGitUtil.CommitInfo]],
diffs: Seq[util.JGitUtil.DiffInfo], diffs: Seq[util.JGitUtil.DiffInfo],
commitId: String,
hasConflict: Boolean, hasConflict: Boolean,
hasWritePermission: Boolean, hasWritePermission: Boolean,
repository: service.RepositoryService.RepositoryInfo, repository: service.RepositoryService.RepositoryInfo,
@@ -14,40 +13,42 @@
@import view.helpers._ @import view.helpers._
@html.main("%s - Pull Request #%d - %s/%s".format(issue.title, issue.issueId, repository.owner, repository.name)){ @html.main("%s - Pull Request #%d - %s/%s".format(issue.title, issue.issueId, repository.owner, repository.name)){
@html.header("pulls", repository) @html.header("pulls", repository)
<div class="pullreq-info"> @defining(dayByDayCommits.flatten){ commits =>
@if(issue.closed) { <div class="pullreq-info">
@comments.find(_.action == "merge").map{ comment => @if(issue.closed) {
<span class="label label-info">Merged</span> @comments.find(_.action == "merge").map{ comment =>
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> merged @commits.flatten.size @plural(commits.flatten.size, "commit") <span class="label label-info">Merged</span>
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code> <a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> merged @commits.size @plural(commits.size, "commit")
at @datetime(comment.registeredDate) into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
}.getOrElse { at @datetime(comment.registeredDate)
<span class="label label-important">Closed</span> }.getOrElse {
<a href="@url(issue.openedUserName)" class="username strong">@issue.openedUserName</a> wants to merge @commits.flatten.size @plural(commits.flatten.size, "commit") <span class="label label-important">Closed</span>
<a href="@url(issue.openedUserName)" class="username strong">@issue.openedUserName</a> wants to merge @commits.size @plural(commits.size, "commit")
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
}
} else {
<span class="label label-success">Open</span>
<a href="@url(issue.openedUserName)" class="username strong">@issue.openedUserName</a> wants to merge @commits.size @plural(commits.size, "commit")
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code> into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
} }
} else {
<span class="label label-success">Open</span>
<a href="@url(issue.openedUserName)" class="username strong">@issue.openedUserName</a> wants to merge @commits.flatten.size @plural(commits.flatten.size, "commit")
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
}
</div>
<ul class="nav nav-tabs" id="pullreq-tab">
<li class="active"><a href="#discussion">Discussion</a></li>
<li><a href="#commits">Commits <span class="badge">@commits.flatten.size</span></a></li>
<li><a href="#files">Files Changed <span class="badge">@diffs.size</span></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="discussion">
@pulls.html.discussion(issue, pullreq, comments, collaborators, milestones, hasConflict, hasWritePermission, repository, requestRepositoryUrl)
</div> </div>
<div class="tab-pane" id="commits"> <ul class="nav nav-tabs" id="pullreq-tab">
@pulls.html.commits(issue, pullreq, commits, hasWritePermission, repository) <li class="active"><a href="#discussion">Discussion</a></li>
<li><a href="#commits">Commits <span class="badge">@commits.size</span></a></li>
<li><a href="#files">Files Changed <span class="badge">@diffs.size</span></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="discussion">
@pulls.html.discussion(issue, pullreq, comments, collaborators, milestones, hasConflict, hasWritePermission, repository, requestRepositoryUrl)
</div>
<div class="tab-pane" id="commits">
@pulls.html.commits(issue, pullreq, dayByDayCommits, hasWritePermission, repository)
</div>
<div class="tab-pane" id="files">
@pulls.html.files(issue, pullreq, diffs, commits.head.id, commits.last.id, hasWritePermission, repository)
</div>
</div> </div>
<div class="tab-pane" id="files"> }
@pulls.html.files(issue, pullreq, diffs, commitId, hasWritePermission, repository)
</div>
</div>
} }
<script> <script>
$('#pullreq-tab a').click(function (e) { $('#pullreq-tab a').click(function (e) {

View File

@@ -3,7 +3,8 @@
branches: List[String], branches: List[String],
tags: List[String], tags: List[String],
repository: service.RepositoryService.RepositoryInfo, repository: service.RepositoryService.RepositoryInfo,
diffs: Seq[util.JGitUtil.DiffInfo])(implicit context: app.Context) diffs: Seq[util.JGitUtil.DiffInfo],
oldCommitId: Option[String])(implicit context: app.Context)
@import context._ @import context._
@import view.helpers._ @import view.helpers._
@import util.Implicits._ @import util.Implicits._
@@ -103,7 +104,7 @@
</li> </li>
} }
</ul> </ul>
@helper.html.diff(diffs, repository, Some(commit.id)) @helper.html.diff(diffs, repository, Some(commit.id), oldCommitId)
} }
<script> <script>
$(function(){ $(function(){

View File

@@ -22,5 +22,5 @@
</div> </div>
</li> </li>
</ul> </ul>
@helper.html.diff(diffs, repository, None) @helper.html.diff(diffs, repository, None, None)
} }