| | |
| | | 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();
|
| | |
| | |
|
| | | // detect branch deletion
|
| | | // first assume all branches are deleted and then remove each
|
| | | // existing branch from deletedBranches during indexing |
| | | // existing branch from deletedBranches during indexing
|
| | | Set<String> deletedBranches = new TreeSet<String>();
|
| | | for (String alias : config.getNames(CONF_ALIAS)) {
|
| | | String branch = config.getString(CONF_ALIAS, null, alias);
|
| | | deletedBranches.add(branch);
|
| | | }
|
| | | |
| | |
|
| | | // walk through each branches
|
| | | List<RefModel> branches = JGitUtils.getLocalBranches(repository, true, -1);
|
| | | for (RefModel branch : branches) {
|
| | |
| | | // remove this branch from the deletedBranches set
|
| | | deletedBranches.remove(branchName);
|
| | |
|
| | | // determine last commit |
| | | // determine last commit
|
| | | String keyName = getBranchKey(branchName);
|
| | | String lastCommit = config.getString(CONF_BRANCH, null, keyName);
|
| | |
|
| | |
| | | Collections.reverse(revs);
|
| | | for (RevCommit commit : revs) {
|
| | | index(repository, branchName, commit);
|
| | | result.commitCount += 1;
|
| | | }
|
| | |
|
| | | // update the config
|
| | |
| | | config.setString(CONF_BRANCH, null, keyName, branch.getObjectId().getName());
|
| | | config.save();
|
| | | }
|
| | | |
| | |
|
| | | // the deletedBranches set will normally be empty by this point
|
| | | // unless a branch really was deleted and no longer exists
|
| | | if (deletedBranches.size() > 0) {
|
| | |
| | | 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;
|
| | | }
|
| | | }
|