diff options
author | James Moger <james.moger@gitblit.com> | 2012-02-28 17:22:40 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2012-02-28 17:22:40 -0500 |
commit | b938aeea1e892b9c95396ca0745ac2adb79ff78e (patch) | |
tree | 720c80ab898ca8c04c458dd96f6df4bacb8b2fb5 /src/com/gitblit/utils/LuceneUtils.java | |
parent | e31da050c6ab5ece38fb18196948337395ae59e6 (diff) | |
download | gitblit-b938aeea1e892b9c95396ca0745ac2adb79ff78e.tar.gz gitblit-b938aeea1e892b9c95396ca0745ac2adb79ff78e.zip |
Delete branch from index. Queue index update from the PostReceiveHook.
Diffstat (limited to 'src/com/gitblit/utils/LuceneUtils.java')
-rw-r--r-- | src/com/gitblit/utils/LuceneUtils.java | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/com/gitblit/utils/LuceneUtils.java b/src/com/gitblit/utils/LuceneUtils.java index eaf02dfb..d463cdf1 100644 --- a/src/com/gitblit/utils/LuceneUtils.java +++ b/src/com/gitblit/utils/LuceneUtils.java @@ -473,13 +473,24 @@ public class LuceneUtils { tags.get(tag.getReferencedObjectId().getName()).add(tag.displayName);
}
+ // detect branch deletion
+ // first assume all branches are deleted and then remove each
+ // 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);
- // TODO detect branch deletion
-
- // walk through each branch
for (RefModel branch : branches) {
- // determine last commit
String branchName = branch.getName();
+
+ // remove this branch from the deletedBranches set
+ deletedBranches.remove(branchName);
+
+ // determine last commit
String keyName = getBranchKey(branchName);
String lastCommit = config.getString(CONF_BRANCH, null, keyName);
@@ -504,6 +515,16 @@ public class LuceneUtils { 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) {
+ for (String branch : deletedBranches) {
+ IndexWriter writer = getIndexWriter(repository, false);
+ writer.deleteDocuments(new Term(FIELD_BRANCH, branch));
+ writer.commit();
+ }
+ }
success = true;
} catch (Throwable t) {
t.printStackTrace();
|