mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-05 04:56:02 +01:00
Add a Patch button to the diff view
This commit is contained in:
@@ -466,10 +466,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
}
|
||||
})
|
||||
|
||||
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 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
}
|
||||
})
|
||||
|
||||
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,
|
||||
|
||||
@@ -519,13 +519,13 @@ object JGitUtil {
|
||||
}.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")
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,15 @@
|
||||
@import org.eclipse.jgit.diff.DiffEntry.ChangeType
|
||||
@if(showIndex){
|
||||
<div class="pull-right" style="margin-bottom: 10px;">
|
||||
@if(oldCommitId.isEmpty && newCommitId.isDefined) {
|
||||
<a href="@helpers.url(repository)/patch/@newCommitId" class="btn btn-default">Patch</a>
|
||||
}
|
||||
@if(oldCommitId.isDefined && newCommitId.isDefined) {
|
||||
<a href="@helpers.url(repository)/patch/@oldCommitId...@newCommitId" class="btn btn-default">Patch</a>
|
||||
}
|
||||
<div class="btn-group" data-toggle="buttons">
|
||||
<input type="button" id="btn-unified" class="btn btn-default btn-small active" value="Unified">
|
||||
<input type="button" id="btn-split" class="btn btn-default btn-small" value="Split">
|
||||
<input type="button" id="btn-unified" class="btn btn-default active" value="Unified">
|
||||
<input type="button" id="btn-split" class="btn btn-default" value="Split">
|
||||
</div>
|
||||
</div>
|
||||
Showing <a href="javascript:void(0);" id="toggle-file-list">@diffs.size changed @helpers.plural(diffs.size, "file")</a>
|
||||
|
||||
Reference in New Issue
Block a user