diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 40798d4..e6cd4f8 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -466,10 +466,10 @@ } }) - get("/:owner/:repository/commit/:id/patch")(referrersOnly { repository => + get("/:owner/:repository/patch/:id")(referrersOnly { repository => try { using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git => - val diff = JGitUtil.getPatch(git, params("id")) + val diff = JGitUtil.getPatch(git, None, params("id")) contentType = formats("txt") diff } @@ -478,6 +478,19 @@ } }) + get("/:owner/:repository/patch/*...*")(referrersOnly { repository => + try { + val Seq(fromId, toId) = multiParams("splat") + using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git => + val diff = JGitUtil.getPatch(git, Some(fromId), toId) + contentType = formats("txt") + diff + } + } catch { + case e: MissingObjectException => NotFound() + } + }) + post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) => val id = params("id") createCommitComment(repository.owner, repository.name, id, context.loginAccount.get.userName, form.content, diff --git a/src/main/scala/gitbucket/core/util/JGitUtil.scala b/src/main/scala/gitbucket/core/util/JGitUtil.scala index e09f73a..fd70e67 100644 --- a/src/main/scala/gitbucket/core/util/JGitUtil.scala +++ b/src/main/scala/gitbucket/core/util/JGitUtil.scala @@ -519,13 +519,13 @@ }.toMap } - def getPatch(git: Git, id: String): String = { + def getPatch(git: Git, from: Option[String], to: String): String = { val out = new ByteArrayOutputStream() val df = new DiffFormatter(out) df.setRepository(git.getRepository) df.setDiffComparator(RawTextComparator.DEFAULT) df.setDetectRenames(true) - df.format(getDiffEntries(git, None, id).head) + df.format(getDiffEntries(git, from, to).head) new String(out.toByteArray, "UTF-8") } diff --git a/src/main/twirl/gitbucket/core/helper/diff.scala.html b/src/main/twirl/gitbucket/core/helper/diff.scala.html index 2cc6f9f..46ccbf6 100644 --- a/src/main/twirl/gitbucket/core/helper/diff.scala.html +++ b/src/main/twirl/gitbucket/core/helper/diff.scala.html @@ -10,9 +10,15 @@ @import org.eclipse.jgit.diff.DiffEntry.ChangeType @if(showIndex){
Showing @diffs.size changed @helpers.plural(diffs.size, "file")