mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-03 03:55:58 +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),
|
getMilestonesWithIssueCount(owner, name),
|
||||||
commits,
|
commits,
|
||||||
diffs,
|
diffs,
|
||||||
requestCommitId.getName,
|
|
||||||
if(issue.closed){
|
if(issue.closed){
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|
||||||
|
JGitUtil.getDiffs(git, id) match { case (diffs, oldCommitId) =>
|
||||||
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
|
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
|
||||||
JGitUtil.getBranchesOfCommit(git, revCommit.getName), JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
||||||
repository, JGitUtil.getDiffs(git, id))
|
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
||||||
|
repository, diffs, oldCommitId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
})
|
})
|
||||||
@@ -380,7 +380,10 @@ object JGitUtil {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,18 +12,28 @@
|
|||||||
<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/@commitId.get/@diff.newPath" class="btn btn-small">View file @@ @commitId.get.substring(0, 10)</a>
|
<a href="@url(repository)/blob/@oldCommitId.get/@diff.oldPath" class="btn btn-small">View file @@ @oldCommitId.get.substring(0, 10)</a>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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(){
|
||||||
|
|||||||
@@ -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,27 +13,28 @@
|
|||||||
@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)
|
||||||
|
@defining(dayByDayCommits.flatten){ commits =>
|
||||||
<div class="pullreq-info">
|
<div class="pullreq-info">
|
||||||
@if(issue.closed) {
|
@if(issue.closed) {
|
||||||
@comments.find(_.action == "merge").map{ comment =>
|
@comments.find(_.action == "merge").map{ comment =>
|
||||||
<span class="label label-info">Merged</span>
|
<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")
|
<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>
|
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
|
||||||
at @datetime(comment.registeredDate)
|
at @datetime(comment.registeredDate)
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
<span class="label label-important">Closed</span>
|
<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")
|
<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 {
|
} else {
|
||||||
<span class="label label-success">Open</span>
|
<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")
|
<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>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<ul class="nav nav-tabs" id="pullreq-tab">
|
<ul class="nav nav-tabs" id="pullreq-tab">
|
||||||
<li class="active"><a href="#discussion">Discussion</a></li>
|
<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="#commits">Commits <span class="badge">@commits.size</span></a></li>
|
||||||
<li><a href="#files">Files Changed <span class="badge">@diffs.size</span></a></li>
|
<li><a href="#files">Files Changed <span class="badge">@diffs.size</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
@@ -42,12 +42,13 @@
|
|||||||
@pulls.html.discussion(issue, pullreq, comments, collaborators, milestones, hasConflict, hasWritePermission, repository, requestRepositoryUrl)
|
@pulls.html.discussion(issue, pullreq, comments, collaborators, milestones, hasConflict, hasWritePermission, repository, requestRepositoryUrl)
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" id="commits">
|
<div class="tab-pane" id="commits">
|
||||||
@pulls.html.commits(issue, pullreq, commits, hasWritePermission, repository)
|
@pulls.html.commits(issue, pullreq, dayByDayCommits, hasWritePermission, repository)
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" id="files">
|
<div class="tab-pane" id="files">
|
||||||
@pulls.html.files(issue, pullreq, diffs, commitId, hasWritePermission, repository)
|
@pulls.html.files(issue, pullreq, diffs, commits.head.id, commits.last.id, hasWritePermission, repository)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
<script>
|
<script>
|
||||||
$('#pullreq-tab a').click(function (e) {
|
$('#pullreq-tab a').click(function (e) {
|
||||||
|
|||||||
@@ -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(){
|
||||||
|
|||||||
@@ -22,5 +22,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@helper.html.diff(diffs, repository, None)
|
@helper.html.diff(diffs, repository, None, None)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user