James Moger
2012-03-27 1aabf0a23f112f06cd7ea5e43a11c11bd177872b
Implemented support for "default" branch
4 files modified
81 ■■■■ changed files
src/com/gitblit/Constants.java 2 ●●●●● patch | view | raw | blame | history
src/com/gitblit/LuceneExecutor.java 63 ●●●● patch | view | raw | blame | history
src/com/gitblit/client/RepositoriesPanel.java 9 ●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/pages/EditRepositoryPage.java 7 ●●●● patch | view | raw | blame | history
src/com/gitblit/Constants.java
@@ -70,6 +70,8 @@
    
    public static final int LEN_SHORTLOG_REFS = 60;
    
    public static final String DEFAULT_BRANCH = "default";
    public static String getGitBlitVersion() {
        return NAME + " v" + VERSION;
    }
src/com/gitblit/LuceneExecutor.java
@@ -447,7 +447,7 @@
            ObjectId defaultBranchId = JGitUtils.getDefaultBranch(repository);
            for (RefModel branch :  branches) {
                if (branch.getObjectId().equals(defaultBranchId)) {
                    defaultBranch = branch;
                    defaultBranch = branch;
                    break;
                }
            }
@@ -457,8 +457,22 @@
            // 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 @@
                deletedBranches.add(branch);
            }
            // walk through each branches
            // get the local branches
            List<RefModel> branches = JGitUtils.getLocalBranches(repository, true, -1);
            // sort them by most recently updated
            Collections.sort(branches, new Comparator<RefModel>() {
                @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);
src/com/gitblit/client/RepositoriesPanel.java
@@ -27,6 +27,7 @@
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.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 @@
        dialog.setTeams(gitblit.getTeamnames(), null);
        dialog.setRepositories(gitblit.getRepositories());
        dialog.setFederationSets(gitblit.getFederationSets(), null);
        dialog.setIndexedBranches(new ArrayList<String>(), null);
        dialog.setIndexedBranches(new ArrayList<String>(Arrays.asList(Constants.DEFAULT_BRANCH)), null);
        dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null),
                gitblit.getPreReceiveScriptsInherited(null), null);
        dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null),
@@ -420,7 +422,10 @@
        dialog.setTeams(gitblit.getTeamnames(), gitblit.getPermittedTeamnames(repository));
        dialog.setRepositories(gitblit.getRepositories());
        dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);
        dialog.setIndexedBranches(repository.getLocalBranches(), repository.indexedBranches);
        List<String> allLocalBranches = new ArrayList<String>();
        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),
src/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -42,6 +42,7 @@
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 @@
                new StringChoiceRenderer(), 8, false);
        // indexed local branches palette
        List<String> allLocalBranches = repositoryModel.getLocalBranches();
        List<String> allLocalBranches = new ArrayList<String>();
        allLocalBranches.add(Constants.DEFAULT_BRANCH);
        allLocalBranches.addAll(repositoryModel.getLocalBranches());
        boolean luceneEnabled = GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true);
        final Palette<String> indexedBranchesPalette = new Palette<String>("indexedBranches", new ListModel<String>(
                indexedBranches), new CollectionModel<String>(allLocalBranches),
                new StringChoiceRenderer(), 8, false);
        indexedBranchesPalette.setEnabled(luceneEnabled && (allLocalBranches.size() > 0));
        indexedBranchesPalette.setEnabled(luceneEnabled);
        
        // federation sets palette
        List<String> sets = GitBlit.getStrings(Keys.federation.sets);