]> source.dussan.org Git - gitblit.git/commitdiff
Implemented support for "default" branch
authorJames Moger <james.moger@gitblit.com>
Tue, 27 Mar 2012 20:51:35 +0000 (16:51 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 27 Mar 2012 20:51:35 +0000 (16:51 -0400)
src/com/gitblit/Constants.java
src/com/gitblit/LuceneExecutor.java
src/com/gitblit/client/RepositoriesPanel.java
src/com/gitblit/wicket/pages/EditRepositoryPage.java

index 879c5a49b7634cff6cfc9cfddffce1b13e6a77ab..929ab64fdeb42d03064224aac5910e4991c90010 100644 (file)
@@ -70,6 +70,8 @@ public class Constants {
        \r
        public static final int LEN_SHORTLOG_REFS = 60;\r
        \r
+       public static final String DEFAULT_BRANCH = "default";\r
+       \r
        public static String getGitBlitVersion() {\r
                return NAME + " v" + VERSION;\r
        }\r
index 25ed9daf69757288ca9ddc943a681f792c6c4bb2..961267b272cd8bc9101064196b940e8ca7121720 100644 (file)
@@ -447,7 +447,7 @@ public class LuceneExecutor implements Runnable {
                        ObjectId defaultBranchId = JGitUtils.getDefaultBranch(repository);\r
                        for (RefModel branch :  branches) {\r
                                if (branch.getObjectId().equals(defaultBranchId)) {\r
-                                       defaultBranch = branch;                                 \r
+                                       defaultBranch = branch;\r
                                        break;\r
                                }\r
                        }\r
@@ -457,8 +457,22 @@ public class LuceneExecutor implements Runnable {
                        // walk through each branch\r
                        for (RefModel branch : branches) {\r
 \r
+                               boolean indexBranch = false;\r
+                               if (model.indexedBranches.contains(com.gitblit.Constants.DEFAULT_BRANCH)\r
+                                               && branch.equals(defaultBranch)) {\r
+                                       // indexing "default" branch\r
+                                       indexBranch = true;\r
+                               } else if (IssueUtils.GB_ISSUES.equals(branch)) {\r
+                                       // skip the GB_ISSUES branch because it is indexed later\r
+                                       // note: this is different than updateIndex\r
+                                       indexBranch = false;\r
+                               } else {\r
+                                       // normal explicit branch check\r
+                                       indexBranch = model.indexedBranches.contains(branch.getName());\r
+                               }\r
+                               \r
                                // if this branch is not specifically indexed then skip\r
-                               if (!model.indexedBranches.contains(branch.getName())) {\r
+                               if (!indexBranch) {\r
                                        continue;\r
                                }\r
 \r
@@ -782,20 +796,55 @@ public class LuceneExecutor implements Runnable {
                                deletedBranches.add(branch);\r
                        }\r
 \r
-                       // walk through each branches\r
+                       // get the local branches\r
                        List<RefModel> branches = JGitUtils.getLocalBranches(repository, true, -1);\r
+                       \r
+                       // sort them by most recently updated\r
+                       Collections.sort(branches, new Comparator<RefModel>() {\r
+                               @Override\r
+                               public int compare(RefModel ref1, RefModel ref2) {\r
+                                       return ref2.getDate().compareTo(ref1.getDate());\r
+                               }\r
+                       });\r
+                                               \r
+                       // reorder default branch to first position\r
+                       RefModel defaultBranch = null;\r
+                       ObjectId defaultBranchId = JGitUtils.getDefaultBranch(repository);\r
+                       for (RefModel branch :  branches) {\r
+                               if (branch.getObjectId().equals(defaultBranchId)) {\r
+                                       defaultBranch = branch;\r
+                                       break;\r
+                               }\r
+                       }\r
+                       branches.remove(defaultBranch);\r
+                       branches.add(0, defaultBranch);\r
+                       \r
+                       // walk through each branches\r
                        for (RefModel branch : branches) {\r
                                String branchName = branch.getName();\r
 \r
-                               // determine if we should skip this branch\r
-                               if (!IssueUtils.GB_ISSUES.equals(branch)\r
-                                               && !model.indexedBranches.contains(branch.getName())) {\r
+                               boolean indexBranch = false;\r
+                               if (model.indexedBranches.contains(com.gitblit.Constants.DEFAULT_BRANCH)\r
+                                               && branch.equals(defaultBranch)) {\r
+                                       // indexing "default" branch\r
+                                       indexBranch = true;\r
+                               } else if (IssueUtils.GB_ISSUES.equals(branch)) {\r
+                                       // update issues modified on the GB_ISSUES branch\r
+                                       // note: this is different than reindex\r
+                                       indexBranch = true;\r
+                               } else {\r
+                                       // normal explicit branch check\r
+                                       indexBranch = model.indexedBranches.contains(branch.getName());\r
+                               }\r
+                               \r
+                               // if this branch is not specifically indexed then skip\r
+                               if (!indexBranch) {\r
                                        continue;\r
                                }\r
                                \r
                                // remove this branch from the deletedBranches set\r
                                deletedBranches.remove(branchName);\r
-\r
+                               \r
                                // determine last commit\r
                                String keyName = getBranchKey(branchName);\r
                                String lastCommit = config.getString(CONF_BRANCH, null, keyName);\r
index 0643b60b9241ee5e4297964216b034384b73f446..685a70a6edf32b0b6ccd5a6ccca96453007c54e1 100644 (file)
@@ -27,6 +27,7 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;\r
 import java.io.IOException;\r
 import java.util.ArrayList;\r
+import java.util.Arrays;\r
 import java.util.List;\r
 \r
 import javax.swing.JButton;\r
@@ -44,6 +45,7 @@ import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.TableCellRenderer;\r
 import javax.swing.table.TableRowSorter;\r
 \r
+import com.gitblit.Constants;\r
 import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.models.FeedModel;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -357,7 +359,7 @@ public abstract class RepositoriesPanel extends JPanel {
                dialog.setTeams(gitblit.getTeamnames(), null);\r
                dialog.setRepositories(gitblit.getRepositories());\r
                dialog.setFederationSets(gitblit.getFederationSets(), null);\r
-               dialog.setIndexedBranches(new ArrayList<String>(), null);\r
+               dialog.setIndexedBranches(new ArrayList<String>(Arrays.asList(Constants.DEFAULT_BRANCH)), null);\r
                dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null),\r
                                gitblit.getPreReceiveScriptsInherited(null), null);\r
                dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null),\r
@@ -420,7 +422,10 @@ public abstract class RepositoriesPanel extends JPanel {
                dialog.setTeams(gitblit.getTeamnames(), gitblit.getPermittedTeamnames(repository));\r
                dialog.setRepositories(gitblit.getRepositories());\r
                dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);\r
-               dialog.setIndexedBranches(repository.getLocalBranches(), repository.indexedBranches);\r
+               List<String> allLocalBranches = new ArrayList<String>();\r
+               allLocalBranches.add(Constants.DEFAULT_BRANCH);\r
+               allLocalBranches.addAll(repository.getLocalBranches());\r
+               dialog.setIndexedBranches(allLocalBranches, repository.indexedBranches);\r
                dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(repository),\r
                                gitblit.getPreReceiveScriptsInherited(repository), repository.preReceiveScripts);\r
                dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(repository),\r
index ded154554dedb3afb6257d9a5bdbe7434b7f473a..c4bacc6972a97cba51aaf2417865ecb8fb5cde13 100644 (file)
@@ -42,6 +42,7 @@ import org.apache.wicket.model.util.ListModel;
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.FederationStrategy;\r
+import com.gitblit.Constants;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.Keys;\r
@@ -116,12 +117,14 @@ public class EditRepositoryPage extends RootSubPage {
                                new StringChoiceRenderer(), 8, false);\r
 \r
                // indexed local branches palette\r
-               List<String> allLocalBranches = repositoryModel.getLocalBranches();\r
+               List<String> allLocalBranches = new ArrayList<String>();\r
+               allLocalBranches.add(Constants.DEFAULT_BRANCH);\r
+               allLocalBranches.addAll(repositoryModel.getLocalBranches());\r
                boolean luceneEnabled = GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true);\r
                final Palette<String> indexedBranchesPalette = new Palette<String>("indexedBranches", new ListModel<String>(\r
                                indexedBranches), new CollectionModel<String>(allLocalBranches),\r
                                new StringChoiceRenderer(), 8, false);\r
-               indexedBranchesPalette.setEnabled(luceneEnabled && (allLocalBranches.size() > 0));\r
+               indexedBranchesPalette.setEnabled(luceneEnabled);\r
                \r
                // federation sets palette\r
                List<String> sets = GitBlit.getStrings(Keys.federation.sets);\r