From: James Moger Date: Tue, 27 Mar 2012 20:51:35 +0000 (-0400) Subject: Implemented support for "default" branch X-Git-Tag: v0.9.0~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1aabf0a23f112f06cd7ea5e43a11c11bd177872b;p=gitblit.git Implemented support for "default" branch --- diff --git a/src/com/gitblit/Constants.java b/src/com/gitblit/Constants.java index 879c5a49..929ab64f 100644 --- a/src/com/gitblit/Constants.java +++ b/src/com/gitblit/Constants.java @@ -70,6 +70,8 @@ public class Constants { public static final int LEN_SHORTLOG_REFS = 60; + public static final String DEFAULT_BRANCH = "default"; + public static String getGitBlitVersion() { return NAME + " v" + VERSION; } diff --git a/src/com/gitblit/LuceneExecutor.java b/src/com/gitblit/LuceneExecutor.java index 25ed9daf..961267b2 100644 --- a/src/com/gitblit/LuceneExecutor.java +++ b/src/com/gitblit/LuceneExecutor.java @@ -447,7 +447,7 @@ public class LuceneExecutor implements Runnable { ObjectId defaultBranchId = JGitUtils.getDefaultBranch(repository); for (RefModel branch : branches) { if (branch.getObjectId().equals(defaultBranchId)) { - defaultBranch = branch; + defaultBranch = branch; break; } } @@ -457,8 +457,22 @@ public class LuceneExecutor implements Runnable { // walk through each branch for (RefModel branch : branches) { + boolean indexBranch = false; + if (model.indexedBranches.contains(com.gitblit.Constants.DEFAULT_BRANCH) + && branch.equals(defaultBranch)) { + // indexing "default" branch + indexBranch = true; + } else if (IssueUtils.GB_ISSUES.equals(branch)) { + // skip the GB_ISSUES branch because it is indexed later + // note: this is different than updateIndex + indexBranch = false; + } else { + // normal explicit branch check + indexBranch = model.indexedBranches.contains(branch.getName()); + } + // if this branch is not specifically indexed then skip - if (!model.indexedBranches.contains(branch.getName())) { + if (!indexBranch) { continue; } @@ -782,20 +796,55 @@ public class LuceneExecutor implements Runnable { deletedBranches.add(branch); } - // walk through each branches + // get the local branches List branches = JGitUtils.getLocalBranches(repository, true, -1); + + // sort them by most recently updated + Collections.sort(branches, new Comparator() { + @Override + public int compare(RefModel ref1, RefModel ref2) { + return ref2.getDate().compareTo(ref1.getDate()); + } + }); + + // reorder default branch to first position + RefModel defaultBranch = null; + ObjectId defaultBranchId = JGitUtils.getDefaultBranch(repository); + for (RefModel branch : branches) { + if (branch.getObjectId().equals(defaultBranchId)) { + defaultBranch = branch; + break; + } + } + branches.remove(defaultBranch); + branches.add(0, defaultBranch); + + // walk through each branches for (RefModel branch : branches) { String branchName = branch.getName(); - // determine if we should skip this branch - if (!IssueUtils.GB_ISSUES.equals(branch) - && !model.indexedBranches.contains(branch.getName())) { + boolean indexBranch = false; + if (model.indexedBranches.contains(com.gitblit.Constants.DEFAULT_BRANCH) + && branch.equals(defaultBranch)) { + // indexing "default" branch + indexBranch = true; + } else if (IssueUtils.GB_ISSUES.equals(branch)) { + // update issues modified on the GB_ISSUES branch + // note: this is different than reindex + indexBranch = true; + } else { + // normal explicit branch check + indexBranch = model.indexedBranches.contains(branch.getName()); + } + + // if this branch is not specifically indexed then skip + if (!indexBranch) { continue; } // 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); diff --git a/src/com/gitblit/client/RepositoriesPanel.java b/src/com/gitblit/client/RepositoriesPanel.java index 0643b60b..685a70a6 100644 --- a/src/com/gitblit/client/RepositoriesPanel.java +++ b/src/com/gitblit/client/RepositoriesPanel.java @@ -27,6 +27,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.swing.JButton; @@ -44,6 +45,7 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableRowSorter; +import com.gitblit.Constants; import com.gitblit.Constants.RpcRequest; import com.gitblit.models.FeedModel; import com.gitblit.models.RepositoryModel; @@ -357,7 +359,7 @@ public abstract class RepositoriesPanel extends JPanel { dialog.setTeams(gitblit.getTeamnames(), null); dialog.setRepositories(gitblit.getRepositories()); dialog.setFederationSets(gitblit.getFederationSets(), null); - dialog.setIndexedBranches(new ArrayList(), null); + dialog.setIndexedBranches(new ArrayList(Arrays.asList(Constants.DEFAULT_BRANCH)), null); dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null), gitblit.getPreReceiveScriptsInherited(null), null); dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null), @@ -420,7 +422,10 @@ public abstract class RepositoriesPanel extends JPanel { dialog.setTeams(gitblit.getTeamnames(), gitblit.getPermittedTeamnames(repository)); dialog.setRepositories(gitblit.getRepositories()); dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets); - dialog.setIndexedBranches(repository.getLocalBranches(), repository.indexedBranches); + List allLocalBranches = new ArrayList(); + allLocalBranches.add(Constants.DEFAULT_BRANCH); + allLocalBranches.addAll(repository.getLocalBranches()); + dialog.setIndexedBranches(allLocalBranches, repository.indexedBranches); dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(repository), gitblit.getPreReceiveScriptsInherited(repository), repository.preReceiveScripts); dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(repository), diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java index ded15455..c4bacc69 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -42,6 +42,7 @@ import org.apache.wicket.model.util.ListModel; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Constants.FederationStrategy; +import com.gitblit.Constants; import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; @@ -116,12 +117,14 @@ public class EditRepositoryPage extends RootSubPage { new StringChoiceRenderer(), 8, false); // indexed local branches palette - List allLocalBranches = repositoryModel.getLocalBranches(); + List allLocalBranches = new ArrayList(); + allLocalBranches.add(Constants.DEFAULT_BRANCH); + allLocalBranches.addAll(repositoryModel.getLocalBranches()); boolean luceneEnabled = GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true); final Palette indexedBranchesPalette = new Palette("indexedBranches", new ListModel( indexedBranches), new CollectionModel(allLocalBranches), new StringChoiceRenderer(), 8, false); - indexedBranchesPalette.setEnabled(luceneEnabled && (allLocalBranches.size() > 0)); + indexedBranchesPalette.setEnabled(luceneEnabled); // federation sets palette List sets = GitBlit.getStrings(Keys.federation.sets);