| | |
| | | import org.eclipse.jgit.treewalk.TreeWalk;
|
| | | import org.eclipse.jgit.util.FS;
|
| | |
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.models.IssueModel;
|
| | | import com.gitblit.models.IssueModel.Attachment;
|
| | | import com.gitblit.models.PathModel.PathChangeModel;
|
| | |
| | | * @return the repository name
|
| | | */
|
| | | private static String getName(Repository repository) {
|
| | | String rootPath = GitBlit.getRepositoriesFolder().getAbsolutePath();
|
| | | if (repository.isBare()) {
|
| | | return repository.getDirectory().getName();
|
| | | return StringUtils.getRelativePath(rootPath, repository.getDirectory()
|
| | | .getAbsolutePath());
|
| | | } else {
|
| | | return repository.getDirectory().getParentFile().getName();
|
| | | return StringUtils.getRelativePath(rootPath, repository.getDirectory().getParentFile()
|
| | | .getAbsolutePath());
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | * index.
|
| | | *
|
| | | * @param repository
|
| | | * @return true if the indexing has succeeded
|
| | | * @return IndexResult
|
| | | */
|
| | | public static boolean reindex(Repository repository) {
|
| | | public static IndexResult reindex(Repository repository) {
|
| | | IndexResult result = new IndexResult();
|
| | | if (!LuceneUtils.deleteIndex(repository)) {
|
| | | return false;
|
| | | return result;
|
| | | }
|
| | | try {
|
| | | String repositoryName = getName(repository);
|
| | |
| | | Index.NOT_ANALYZED));
|
| | | doc.add(new Field(FIELD_BRANCH, branchName, Store.YES, Index.NOT_ANALYZED));
|
| | | writer.addDocument(doc);
|
| | | result.commitCount += 1;
|
| | | }
|
| | |
|
| | | // traverse the log and index the previous commit objects
|
| | |
| | | Index.NOT_ANALYZED));
|
| | | doc.add(new Field(FIELD_BRANCH, branchName, Store.YES, Index.NOT_ANALYZED));
|
| | | writer.addDocument(doc);
|
| | | result.commitCount += 1;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | config.save();
|
| | | resetIndexSearcher(repository);
|
| | | writer.commit();
|
| | | return true;
|
| | | result.success = true;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return false;
|
| | | return result;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * Updates a repository index incrementally from the last indexed commits.
|
| | | *
|
| | | * @param repository
|
| | | * @return IndexResult
|
| | | */
|
| | | public static boolean updateIndex(Repository repository) {
|
| | | boolean success = false;
|
| | | public static IndexResult updateIndex(Repository repository) {
|
| | | IndexResult result = new IndexResult();
|
| | | try {
|
| | | FileBasedConfig config = getConfig(repository);
|
| | | config.load();
|
| | |
| | | Collections.reverse(revs);
|
| | | for (RevCommit commit : revs) {
|
| | | index(repository, branchName, commit);
|
| | | result.commitCount += 1;
|
| | | }
|
| | |
|
| | | // update the config
|
| | |
| | | writer.commit();
|
| | | }
|
| | | }
|
| | | success = true;
|
| | | result.success = true;
|
| | | } catch (Throwable t) {
|
| | | t.printStackTrace();
|
| | | }
|
| | | return success;
|
| | | return result;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | | SEARCHERS.clear();
|
| | | }
|
| | |
|
| | | public static class IndexResult {
|
| | | public boolean success;
|
| | | public int commitCount;
|
| | | }
|
| | | }
|