diff --git a/src/main/scala/app/PullRequestsController.scala b/src/main/scala/app/PullRequestsController.scala index e0a56f4..0cd143f 100644 --- a/src/main/scala/app/PullRequestsController.scala +++ b/src/main/scala/app/PullRequestsController.scala @@ -80,7 +80,6 @@ getMilestonesWithIssueCount(owner, name), commits, diffs, - requestCommitId.getName, if(issue.closed){ false } else { diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index 7c0a1bb..834e133 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -130,9 +130,12 @@ 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) + } } }) diff --git a/src/main/scala/util/JGitUtil.scala b/src/main/scala/util/JGitUtil.scala index 128d640..0b042ca 100644 --- a/src/main/scala/util/JGitUtil.scala +++ b/src/main/scala/util/JGitUtil.scala @@ -254,7 +254,7 @@ * @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 @@ 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 }) @@ -379,8 +379,11 @@ } catch { 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 @@ 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 @@ })) } walk.release - buffer.toList + (buffer.toList, None) } } diff --git a/src/main/twirl/helper/diff.scala.html b/src/main/twirl/helper/diff.scala.html index 0360230..43928bc 100644 --- a/src/main/twirl/helper/diff.scala.html +++ b/src/main/twirl/helper/diff.scala.html @@ -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 @@ @if(diff.changeType == ChangeType.COPY || diff.changeType == ChangeType.RENAME){ @diff.oldPath -> @diff.newPath + @if(newCommitId.isDefined){ +
+ View file @@ @newCommitId.get.substring(0, 10) +
+ } } @if(diff.changeType == ChangeType.ADD || diff.changeType == ChangeType.MODIFY){ @diff.newPath + @if(newCommitId.isDefined){ +
+ View file @@ @newCommitId.get.substring(0, 10) +
+ } } @if(diff.changeType == ChangeType.DELETE){ @diff.oldPath - } - @if(commitId.isDefined){ -
- View file @@ @commitId.get.substring(0, 10) -
+ @if(oldCommitId.isDefined){ +
+ View file @@ @oldCommitId.get.substring(0, 10) +
+ } } diff --git a/src/main/twirl/pulls/compare.scala.html b/src/main/twirl/pulls/compare.scala.html index cb3a2a8..780bd3b 100644 --- a/src/main/twirl/pulls/compare.scala.html +++ b/src/main/twirl/pulls/compare.scala.html @@ -134,7 +134,7 @@ } - @helper.html.diff(diffs, repository, Some(commitId)) + @helper.html.diff(diffs, repository, Some(commitId), Some(sourceId)) } }