Get all data from the bare repository.

Cloned repositories in backend is not necessary at last.
This commit is contained in:
takezoe
2013-04-30 01:07:31 +09:00
parent 1779d167ea
commit 35f0aa7b03
5 changed files with 47 additions and 126 deletions

View File

@@ -61,9 +61,6 @@ class CreateRepositoryServlet extends ServletBase {
FileUtils.deleteDirectory(tmpdir)
}
// update all branches
updateAllBranches(LoginUser, form.name)
// redirect to the repository
redirect("/%s/%s".format(LoginUser, form.name))
}

View File

@@ -36,22 +36,4 @@ class GitRepositoryServlet extends GitServlet {
});
}
/**
* Override GitServlet#service() to pull pushed changes to cloned repositories for branch exploring.
*/
override def service(request: HttpServletRequest, response: HttpServletResponse): Unit = {
super.service(request, response)
logger.debug(request.getMethod + ": " + request.getRequestURI)
// update branches
if(request.getMethod == "POST" && request.getRequestURI.endsWith("/git-receive-pack")){
request.getRequestURI
.replaceFirst("^" + request.getServletContext.getContextPath + "/git/", "")
.replaceFirst("\\.git/git-receive-pack$", "").split("/") match {
case Array(owner, repository) => Directory.updateAllBranches(owner, repository)
}
}
}
}

View File

@@ -98,57 +98,38 @@ class RepositoryViewerServlet extends ServletBase {
val raw = params.get("raw").getOrElse("false").toBoolean
val path = multiParams("splat").head.replaceFirst("^tree/.+?/", "")
val repositoryInfo = JGitUtil.getRepositoryInfo(owner, repository, servletContext)
if(repositoryInfo.branchList.contains(id)){
// id is branch name
val dir = getBranchDir(owner, repository, id)
val git = Git.open(dir)
val rev = git.log.addPath(path).call.iterator.next
val file = new File(dir, path)
val git = Git.open(getRepositoryDir(owner, repository))
val commitId = git.getRepository.resolve(id)
if(raw){
// Download
contentType = "application/octet-stream"
file
} else {
// Viewer
val viewer = if(FileTypeUtil.isImage(file.getName)) "image" else if(FileTypeUtil.isLarge(file.length)) "large" else "text"
val content = ContentInfo(
viewer, if(viewer == "text") Some(FileUtils.readFileToString(file, "UTF-8")) else None
)
html.blob(id, repositoryInfo, path.split("/").toList, content, new CommitInfo(rev))
}
val revWalk = new RevWalk(git.getRepository)
val revCommit = revWalk.parseCommit(commitId)
revWalk.dispose
@scala.annotation.tailrec
def getPathObjectId(path: String, walk: TreeWalk): ObjectId = walk.next match {
case true if(walk.getPathString == path) => walk.getObjectId(0)
case true => getPathObjectId(path, walk)
}
val treeWalk = new TreeWalk(git.getRepository)
treeWalk.addTree(revCommit.getTree)
treeWalk.setRecursive(true)
val objectId = getPathObjectId(path, treeWalk)
treeWalk.release
if(raw){
// Download
contentType = "application/octet-stream"
JGitUtil.getContent(git, objectId, false)
} else {
// id is commit id
val branch = JGitUtil.getBranchNameFromCommitId(id, repositoryInfo)
val dir = getBranchDir(owner, repository, branch)
val git = Git.open(dir)
val rev = git.log.add(ObjectId.fromString(id)).call.iterator.next
@scala.annotation.tailrec
def getPathObjectId(path: String, walk: TreeWalk): ObjectId = walk.next match {
case true if(walk.getPathString == path) => walk.getObjectId(0)
case true => getPathObjectId(path, walk)
}
val walk = new TreeWalk(git.getRepository)
walk.addTree(rev.getTree)
walk.setRecursive(true)
val objectId = getPathObjectId(path, walk)
if(raw){
// Download
contentType = "application/octet-stream"
JGitUtil.getContent(git, objectId, false)
// Viewer
val large = FileTypeUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)
val viewer = if(FileTypeUtil.isImage(path)) "image" else if(large) "large" else "text"
val content = ContentInfo(viewer, if(viewer == "text") JGitUtil.getContent(git, objectId, false).map(new String(_, "UTF-8")) else None)
} else {
// Viewer
val large = FileTypeUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)
val viewer = if(FileTypeUtil.isImage(path)) "image" else if(large) "large" else "text"
val content = ContentInfo(viewer, if(viewer == "text") JGitUtil.getContent(git, objectId, false).map(new String(_, "UTF-8")) else None)
html.blob(branch, repositoryInfo, path.split("/").toList, content, new CommitInfo(rev))
}
html.blob(id, repositoryInfo, path.split("/").toList, content, new CommitInfo(revCommit))
}
}
@@ -162,18 +143,23 @@ class RepositoryViewerServlet extends ServletBase {
val repositoryInfo = JGitUtil.getRepositoryInfo(owner, repository, servletContext)
// get branch by commit id
// TODO this does not work correctly...
val branch = repositoryInfo.branchList.find { branch =>
val git = Git.open(getBranchDir(owner, repository, branch))
git.log.add(ObjectId.fromString(id)).call.iterator.hasNext
}.get
val git = Git.open(getRepositoryDir(owner, repository))
val dir = getBranchDir(owner, repository, branch)
val git = Git.open(dir)
val ite = git.log.add(ObjectId.fromString(id)).call.iterator
val rev = ite.next
val old = ite.next
@scala.annotation.tailrec
def getCommitLog(i: java.util.Iterator[RevCommit], logs: List[RevCommit]): List[RevCommit] =
i.hasNext match {
case true if(logs.size < 2) => getCommitLog(i, logs :+ i.next)
case _ => logs
}
val revWalk = new RevWalk(git.getRepository)
revWalk.markStart(revWalk.parseCommit(git.getRepository.resolve(id)))
val commits = getCommitLog(revWalk.iterator, Nil)
revWalk.release
val rev = commits(0)
val old = commits(1)
val diffs = if(old != null){
// get diff between specified commit and its previous commit
@@ -204,7 +190,7 @@ class RepositoryViewerServlet extends ServletBase {
buffer.toList
}
html.commit(branch,
html.commit(id,
CommitInfo(rev.getName, rev.getCommitterIdent.getWhen, rev.getCommitterIdent.getName, rev.getFullMessage),
repositoryInfo, diffs)
}
@@ -231,6 +217,7 @@ class RepositoryViewerServlet extends ServletBase {
val revWalk = new RevWalk(git.getRepository)
val objectId = git.getRepository.resolve(revision)
val revCommit = revWalk.parseCommit(objectId)
revWalk.dispose
val files = JGitUtil.getFileList(owner, repository, revision, path)