mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 11:36:05 +01:00
(refs #76)Show the content of the previous commit for removed files.
This commit is contained in:
@@ -80,7 +80,6 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
getMilestonesWithIssueCount(owner, name),
|
||||
commits,
|
||||
diffs,
|
||||
requestCommitId.getName,
|
||||
if(issue.closed){
|
||||
false
|
||||
} else {
|
||||
|
||||
@@ -130,9 +130,12 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||
|
||||
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
|
||||
JGitUtil.getBranchesOfCommit(git, revCommit.getName), JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
||||
repository, JGitUtil.getDiffs(git, id))
|
||||
JGitUtil.getDiffs(git, id) match { case (diffs, oldCommitId) =>
|
||||
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
|
||||
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
||||
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
||||
repository, diffs, oldCommitId)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -254,7 +254,7 @@ object JGitUtil {
|
||||
* @param page the page number (1-)
|
||||
* @param limit the number of commit info per page. 0 (default) means unlimited.
|
||||
* @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)] = {
|
||||
val fixedPage = if(page <= 0) 1 else page
|
||||
@@ -278,7 +278,7 @@ object JGitUtil {
|
||||
if(path.nonEmpty){
|
||||
revWalk.setRevFilter(new RevFilter(){
|
||||
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
|
||||
})
|
||||
@@ -380,7 +380,10 @@ object JGitUtil {
|
||||
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
|
||||
def getCommitLog(i: java.util.Iterator[RevCommit], logs: List[RevCommit]): List[RevCommit] =
|
||||
i.hasNext match {
|
||||
@@ -399,7 +402,7 @@ object JGitUtil {
|
||||
if(commits.length >= 2){
|
||||
// not initial commit
|
||||
val oldCommit = commits(1)
|
||||
getDiffs(git, oldCommit.getName, id, fetchContent)
|
||||
(getDiffs(git, oldCommit.getName, id, fetchContent), Some(oldCommit.getName))
|
||||
|
||||
} else {
|
||||
// initial commit
|
||||
@@ -415,7 +418,7 @@ object JGitUtil {
|
||||
}))
|
||||
}
|
||||
walk.release
|
||||
buffer.toList
|
||||
(buffer.toList, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 view.helpers._
|
||||
@import org.eclipse.jgit.diff.DiffEntry.ChangeType
|
||||
@@ -9,17 +12,27 @@
|
||||
<th style="font-weight: normal;" class="box-header">
|
||||
@if(diff.changeType == ChangeType.COPY || diff.changeType == ChangeType.RENAME){
|
||||
@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){
|
||||
@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){
|
||||
@diff.oldPath
|
||||
}
|
||||
@if(commitId.isDefined){
|
||||
<div class="pull-right align-right">
|
||||
<a href="@url(repository)/blob/@commitId.get/@diff.newPath" class="btn btn-small">View file @@ @commitId.get.substring(0, 10)</a>
|
||||
</div>
|
||||
@if(oldCommitId.isDefined){
|
||||
<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>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@helper.html.diff(diffs, repository, Some(commitId))
|
||||
@helper.html.diff(diffs, repository, Some(commitId), Some(sourceId))
|
||||
}
|
||||
}
|
||||
<script>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
@(issue: model.Issue,
|
||||
pullreq: model.PullRequest,
|
||||
diffs: Seq[util.JGitUtil.DiffInfo],
|
||||
commitId: String,
|
||||
newCommitId: String,
|
||||
oldCommitId: String,
|
||||
hasWritePermission: Boolean,
|
||||
repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
||||
@import context._
|
||||
@@ -33,7 +34,7 @@
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@helper.html.diff(diffs, repository, Some(commitId))
|
||||
@helper.html.diff(diffs, repository, Some(newCommitId), Some(oldCommitId))
|
||||
<script>
|
||||
$(function(){
|
||||
$('#toggle-file-list').click(function(){
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
comments: List[model.IssueComment],
|
||||
collaborators: List[String],
|
||||
milestones: List[(model.Milestone, Int, Int)],
|
||||
commits: Seq[Seq[util.JGitUtil.CommitInfo]],
|
||||
dayByDayCommits: Seq[Seq[util.JGitUtil.CommitInfo]],
|
||||
diffs: Seq[util.JGitUtil.DiffInfo],
|
||||
commitId: String,
|
||||
hasConflict: Boolean,
|
||||
hasWritePermission: Boolean,
|
||||
repository: service.RepositoryService.RepositoryInfo,
|
||||
@@ -14,40 +13,42 @@
|
||||
@import view.helpers._
|
||||
@html.main("%s - Pull Request #%d - %s/%s".format(issue.title, issue.issueId, repository.owner, repository.name)){
|
||||
@html.header("pulls", repository)
|
||||
<div class="pullreq-info">
|
||||
@if(issue.closed) {
|
||||
@comments.find(_.action == "merge").map{ comment =>
|
||||
<span class="label label-info">Merged</span>
|
||||
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> merged @commits.flatten.size @plural(commits.flatten.size, "commit")
|
||||
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
|
||||
at @datetime(comment.registeredDate)
|
||||
}.getOrElse {
|
||||
<span class="label label-important">Closed</span>
|
||||
<a href="@url(issue.openedUserName)" class="username strong">@issue.openedUserName</a> wants to merge @commits.flatten.size @plural(commits.flatten.size, "commit")
|
||||
@defining(dayByDayCommits.flatten){ commits =>
|
||||
<div class="pullreq-info">
|
||||
@if(issue.closed) {
|
||||
@comments.find(_.action == "merge").map{ comment =>
|
||||
<span class="label label-info">Merged</span>
|
||||
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> merged @commits.size @plural(commits.size, "commit")
|
||||
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
|
||||
at @datetime(comment.registeredDate)
|
||||
}.getOrElse {
|
||||
<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>
|
||||
}
|
||||
} 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 class="tab-pane" id="commits">
|
||||
@pulls.html.commits(issue, pullreq, commits, hasWritePermission, repository)
|
||||
<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.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 class="tab-pane" id="files">
|
||||
@pulls.html.files(issue, pullreq, diffs, commitId, hasWritePermission, repository)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<script>
|
||||
$('#pullreq-tab a').click(function (e) {
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
branches: List[String],
|
||||
tags: List[String],
|
||||
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 view.helpers._
|
||||
@import util.Implicits._
|
||||
@@ -103,7 +104,7 @@
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@helper.html.diff(diffs, repository, Some(commit.id))
|
||||
@helper.html.diff(diffs, repository, Some(commit.id), oldCommitId)
|
||||
}
|
||||
<script>
|
||||
$(function(){
|
||||
|
||||
@@ -22,5 +22,5 @@
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@helper.html.diff(diffs, repository, None)
|
||||
@helper.html.diff(diffs, repository, None, None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user