(refs #50)Fix search logic in empty repository

This commit is contained in:
Tomofumi Tanaka
2013-07-24 16:46:46 +09:00
parent cb94447290
commit 62a6d74393
2 changed files with 18 additions and 12 deletions

View File

@@ -29,11 +29,14 @@ trait RepositorySearchService { self: IssuesService =>
def countFiles(owner: String, repository: String, query: String): Int =
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
searchRepositoryFiles(git, query).length
if(JGitUtil.isEmpty(git)) 0 else searchRepositoryFiles(git, query).length
}
def searchFiles(owner: String, repository: String, query: String): List[FileSearchResult] =
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
if(JGitUtil.isEmpty(git)){
Nil
} else {
val files = searchRepositoryFiles(git, query)
val commits = JGitUtil.getLatestCommitFromPaths(git, files.toList.map(_._1), "HEAD")
files.map { case (path, text) =>
@@ -45,6 +48,7 @@ trait RepositorySearchService { self: IssuesService =>
lineNumber)
}
}
}
private def searchRepositoryFiles(git: Git, query: String): List[(String, String)] = {
val revWalk = new RevWalk(git.getRepository)

View File

@@ -524,6 +524,8 @@ object JGitUtil {
}
}
def isEmpty(git: Git): Boolean = git.getRepository.resolve(Constants.HEAD) == null
private def setReceivePack(repository: org.eclipse.jgit.lib.Repository): Unit = {
val config = repository.getConfig
config.setBoolean("http", null, "receivepack", true)