}\r
}\r
\r
+ /**\r
+ * Update the Lucene index of a repository.\r
+ * \r
+ * @param repository\r
+ */\r
+ public void updateLuceneIndex(RepositoryModel repository) {\r
+ luceneExecutor.queue(repository);\r
+ }\r
+\r
/**\r
* Returns the descriptions/comments of the Gitblit config settings.\r
* \r
public void contextDestroyed(ServletContextEvent contextEvent) {\r
logger.info("Gitblit context destroyed by servlet container.");\r
scheduledExecutor.shutdownNow();\r
+ luceneExecutor.close();\r
}\r
}\r
public LuceneExecutor(IStoredSettings settings) {\r
this.settings = settings;\r
this.isLuceneEnabled = settings.getBoolean("lucene.enableLucene", false);\r
- this.isPollingMode = settings.getBoolean("lucene.pollingMode", false); \r
+ this.isPollingMode = settings.getBoolean("lucene.pollingMode", false);\r
}\r
\r
/**\r
if (!isLuceneEnabled) {\r
return;\r
}\r
- \r
+\r
if (firstRun.get() || isPollingMode) {\r
- // update all indexes on first run or if polling mode \r
+ // update all indexes on first run or if polling mode\r
firstRun.set(false);\r
queue.addAll(GitBlit.self().getRepositoryList());\r
}\r
"Lucene executor could not find repository {0}. Skipping.",\r
repositoryName));\r
continue;\r
- } \r
+ }\r
index(repositoryName, repository);\r
repository.close();\r
processed.add(repositoryName);\r
logger.error(MessageFormat.format("Lucene indexing failure for {0}", repositoryName), t);\r
}\r
}\r
+\r
+ /**\r
+ * Close all Lucene indexers.\r
+ * \r
+ */\r
+ public void close() {\r
+ LuceneUtils.close();\r
+ }\r
}\r
tags.get(tag.getReferencedObjectId().getName()).add(tag.displayName);\r
}\r
\r
+ // detect branch deletion\r
+ // first assume all branches are deleted and then remove each\r
+ // existing branch from deletedBranches during indexing \r
+ Set<String> deletedBranches = new TreeSet<String>();\r
+ for (String alias : config.getNames(CONF_ALIAS)) {\r
+ String branch = config.getString(CONF_ALIAS, null, alias);\r
+ deletedBranches.add(branch);\r
+ }\r
+ \r
+ // walk through each branches\r
List<RefModel> branches = JGitUtils.getLocalBranches(repository, true, -1);\r
- // TODO detect branch deletion\r
-\r
- // walk through each branch\r
for (RefModel branch : branches) {\r
- // determine last commit\r
String branchName = branch.getName();\r
+\r
+ // remove this branch from the deletedBranches set\r
+ deletedBranches.remove(branchName);\r
+\r
+ // determine last commit \r
String keyName = getBranchKey(branchName);\r
String lastCommit = config.getString(CONF_BRANCH, null, keyName);\r
\r
config.setString(CONF_BRANCH, null, keyName, branch.getObjectId().getName());\r
config.save();\r
}\r
+ \r
+ // the deletedBranches set will normally be empty by this point\r
+ // unless a branch really was deleted and no longer exists\r
+ if (deletedBranches.size() > 0) {\r
+ for (String branch : deletedBranches) {\r
+ IndexWriter writer = getIndexWriter(repository, false);\r
+ writer.deleteDocuments(new Term(FIELD_BRANCH, branch));\r
+ writer.commit();\r
+ }\r
+ }\r
success = true;\r
} catch (Throwable t) {\r
t.printStackTrace();\r