James Moger
2013-09-17 bb6b148bfc2d4a22b4fd3bdbafebadccaccf6661
Revisions and documentation for personal repository prefix change
11 files modified
216 ■■■■■ changed files
build.moxie 2 ●●● patch | view | raw | blame | history
releases.moxie 13 ●●●● patch | view | raw | blame | history
src/main/distrib/data/gitblit.properties 12 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/Constants.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/GitBlit.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/client/EditTeamDialog.java 21 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/client/EditUserDialog.java 20 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/utils/ModelUtils.java 54 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/pages/RootSubPage.java 4 ●●● patch | view | raw | blame | history
src/test/java/com/gitblit/tests/GitBlitSuite.java 3 ●●●● patch | view | raw | blame | history
src/test/java/com/gitblit/tests/ModelUtilsTest.java 82 ●●●● patch | view | raw | blame | history
build.moxie
@@ -10,7 +10,7 @@
description: pure Java Git solution
groupId: com.gitblit
artifactId: gitblit
version: 1.3.3-SNAPSHOT
version: 1.4.0-SNAPSHOT
inceptionYear: 2011
# Current stable release
releases.moxie
@@ -9,11 +9,18 @@
    html: ~
    text: ~
    security: ~
    fixes: ~
    changes: ~
    fixes:
    - Fix potential NPE on removing uncached repository from cache
    changes:
    - Personal repository prefix (~) is now configurable (issue-265)
    - Updated default binary and Lucene ignore extensions
    additions: ~
    dependencyChanges: ~
    contributors: ~
    contributors:
    - James Moger
    - Robin Rosenberg
    - Klaus Nuber
    - Florian Zschocke
}
#
src/main/distrib/data/gitblit.properties
@@ -164,15 +164,21 @@
git.defaultAuthorizationControl = NAMED
# The prefix for a users personal repository directory.
#
# Personal user repositories are created in this directory, named by the user name
# prefixed with the userRepositoeryPrefix. For eaxmple, a user 'john' would have his
# prefixed with the userRepositoryPrefix. For eaxmple, a user 'john' would have his
# personal repositories in the directory '~john'.
#
# Cannot be an empty string. Also, absolute paths are changed to relative paths by 
# removing the first directory separator.
#
# It is not recommended to change this value AFTER your user's have created
# personal repositories because it will break all permissions, ownership, and
# repository push/pull operations.
#
# RESTART REQUIRED
# SINCE 1.3.2
git.userRepositoryPrefix = "~"
# SINCE 1.4.0
git.userRepositoryPrefix = ~
# The default incremental push tag prefix.  Tag prefix applied to a repository
# that has automatic push tags enabled and does not specify a custom tag prefix.
src/main/java/com/gitblit/Constants.java
@@ -47,6 +47,8 @@
    public static final String EXTERNAL_ACCOUNT = "#externalAccount";
    public static final String PROPERTIES_FILE = "gitblit.properties";
    public static final String DEFAULT_USER_REPOSITORY_PREFIX = "~";
    public static final String GIT_PATH = "/git/";
src/main/java/com/gitblit/GitBlit.java
@@ -3441,7 +3441,8 @@
        gcExecutor = new GCExecutor(settings);
        
        // initialize utilities
        ModelUtils.setUserRepoPrefix(settings);
        String prefix = settings.getString(Keys.git.userRepositoryPrefix, "~");
        ModelUtils.setUserRepoPrefix(prefix);
        // calculate repository list settings checksum for future config changes
        repositoryListSettingsChecksum.set(getRepositoryListSettingsChecksum());
src/main/java/com/gitblit/client/EditTeamDialog.java
@@ -44,14 +44,15 @@
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import com.gitblit.Constants;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.AuthorizationControl;
import com.gitblit.Constants.RegistrantType;
import com.gitblit.Keys;
import com.gitblit.models.RegistrantAccessPermission;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.ServerSettings;
import com.gitblit.models.TeamModel;
import com.gitblit.utils.ModelUtils;
import com.gitblit.utils.StringUtils;
public class EditTeamDialog extends JDialog {
@@ -323,8 +324,22 @@
        List<String> list = new ArrayList<String>();
        // repositories
        list.add(".*");
        // all repositories excluding personal repositories
        if (ModelUtils.getUserRepoPrefix().length() == 1) list.add("[^" + ModelUtils.getUserRepoPrefix() +"].*");
        String prefix;
        if (settings.hasKey(Keys.git.userRepositoryPrefix)) {
            prefix = settings.get(Keys.git.userRepositoryPrefix).currentValue;
            if (StringUtils.isEmpty(prefix)) {
                prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
            }
        } else {
            prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
        }
        if (prefix.length() == 1) {
            // all repositories excluding personal repositories
            list.add("[^" + prefix + "].*");
        }
        String lastProject = null;
        for (String repo : restricted) {
            String projectPath = StringUtils.getFirstPathElement(repo);
src/main/java/com/gitblit/client/EditUserDialog.java
@@ -47,6 +47,7 @@
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import com.gitblit.Constants;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.AuthorizationControl;
import com.gitblit.Constants.PermissionType;
@@ -57,7 +58,6 @@
import com.gitblit.models.ServerSettings;
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.ModelUtils;
import com.gitblit.utils.StringUtils;
public class EditUserDialog extends JDialog {
@@ -403,8 +403,22 @@
        List<String> list = new ArrayList<String>();
        // repositories
        list.add(".*");
        // all repositories excluding personal repositories
        if (ModelUtils.getUserRepoPrefix().length() == 1) list.add("[^" + ModelUtils.getUserRepoPrefix() +"].*");
        String prefix;
        if (settings.hasKey(Keys.git.userRepositoryPrefix)) {
            prefix = settings.get(Keys.git.userRepositoryPrefix).currentValue;
            if (StringUtils.isEmpty(prefix)) {
                prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
            }
        } else {
            prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
        }
        if (prefix.length() == 1) {
            // all repositories excluding personal repositories
            list.add("[^" + prefix + "].*");
        }
        String lastProject = null;
        for (String repo : restricted) {
            String projectPath = StringUtils.getFirstPathElement(repo).toLowerCase();
src/main/java/com/gitblit/utils/ModelUtils.java
@@ -1,7 +1,23 @@
/*
 * Copyright 2013 gitblit.com
 * Copyright 2013 Florian Zschocke
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitblit.utils;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.Constants;
/**
 * Utility functions for model classes that do not fit in any other category.
@@ -10,28 +26,22 @@
 */
public class ModelUtils
{
    /**
     * Default value for the prefix for user repository directories.
     */
    private static final String DEFAULT_USER_REPO_PREFIX = "~";
    private static String userRepoPrefix = DEFAULT_USER_REPO_PREFIX;
    private static String userRepoPrefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
    /**
     * Set the user repository prefix from configuration settings.
     * @param settings
     * Set the user repository prefix.
     * @param prefix
     */
    public static void setUserRepoPrefix(IStoredSettings settings)
    public static void setUserRepoPrefix(String prefix)
    {
        String newPrefix = DEFAULT_USER_REPO_PREFIX;
        if (settings != null) {
            String prefix = settings.getString(Keys.git.userRepositoryPrefix, DEFAULT_USER_REPO_PREFIX);
            if (prefix != null && !prefix.trim().isEmpty()) {
                if (prefix.charAt(0) == '/') prefix = prefix.substring(1);
                newPrefix = prefix;
            }
        if (StringUtils.isEmpty(prefix)) {
            userRepoPrefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
            return;
        }
        String newPrefix = prefix.replace('\\', '/');
        if (prefix.charAt(0) == '/') {
            newPrefix = prefix.substring(1);
        }
        userRepoPrefix = newPrefix;
@@ -68,7 +78,7 @@
     */
    public static boolean isPersonalRepository(String name)
    {
        if ( name.startsWith(getUserRepoPrefix()) ) return true;
        if ( name.startsWith(userRepoPrefix) ) return true;
        return false;
    }
@@ -101,7 +111,7 @@
    {
        if ( !isPersonalRepository(path) ) return "";
        return path.substring(getUserRepoPrefix().length());
        return path.substring(userRepoPrefix.length());
    }
}
src/main/java/com/gitblit/wicket/pages/RootSubPage.java
@@ -81,7 +81,9 @@
            // all repositories
            repos.add(".*");
            // all repositories excluding personal repositories
            if (ModelUtils.getUserRepoPrefix().length() == 1) repos.add("[^" + ModelUtils.getUserRepoPrefix() +"].*");
            if (ModelUtils.getUserRepoPrefix().length() == 1) {
                repos.add("[^" + ModelUtils.getUserRepoPrefix() + "].*");
            }
        }
        
        for (String repo : GitBlit.self().getRepositoryList()) {
src/test/java/com/gitblit/tests/GitBlitSuite.java
@@ -60,7 +60,8 @@
        DiffUtilsTest.class, MetricUtilsTest.class, TicgitUtilsTest.class, X509UtilsTest.class,
        GitBlitTest.class, FederationTests.class, RpcTests.class, GitServletTest.class, GitDaemonTest.class,
        GroovyScriptTest.class, LuceneExecutorTest.class, IssuesTest.class, RepositoryModelTest.class,
        FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class, HtpasswdUserServiceTest.class })
        FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class, HtpasswdUserServiceTest.class,
        ModelUtilsTest.class })
public class GitBlitSuite {
    public static final File REPOSITORIES = new File("data/git");
src/test/java/com/gitblit/tests/ModelUtilsTest.java
@@ -4,48 +4,25 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
import org.junit.Test;
import com.gitblit.Keys;
import com.gitblit.tests.mock.MemorySettings;
import com.gitblit.Constants;
import com.gitblit.utils.ModelUtils;
public class ModelUtilsTest {
    private static final String DEFAULT_USER_REPO_PREFIX = "~";
    private static final Map<String, Object> backingMap = new HashMap<String, Object>();
    private static final MemorySettings ms = new MemorySettings(backingMap);
    private static void setPrefix(String prefix)
    {
        backingMap.put(Keys.git.userRepositoryPrefix, prefix);
    }
    private static void setRepoPrefix(String prefix)
    {
        backingMap.put(Keys.git.userRepositoryPrefix, prefix);
        ModelUtils.setUserRepoPrefix(ms);
    }
    @After
    public void resetPrefix()
    {
        setRepoPrefix(DEFAULT_USER_REPO_PREFIX);
        ModelUtils.setUserRepoPrefix(null);
    }
    @Test
    public void testGetUserRepoPrefix()
    {
        assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix());
        assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX, ModelUtils.getUserRepoPrefix());
    }
@@ -53,38 +30,25 @@
    public void testSetUserRepoPrefix()
    {
        assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix());
        assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX, ModelUtils.getUserRepoPrefix());
        setPrefix("@");
        ModelUtils.setUserRepoPrefix(ms);
        ModelUtils.setUserRepoPrefix("@");
        assertEquals("@", ModelUtils.getUserRepoPrefix());
        backingMap.remove(Keys.git.userRepositoryPrefix);
        ModelUtils.setUserRepoPrefix(ms);
        assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix());
        ModelUtils.setUserRepoPrefix("");
        assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX, ModelUtils.getUserRepoPrefix());
        setPrefix("user/");
        ModelUtils.setUserRepoPrefix(ms);
        ModelUtils.setUserRepoPrefix("user/");
        assertEquals("user/", ModelUtils.getUserRepoPrefix());
        setPrefix("");
        ModelUtils.setUserRepoPrefix(ms);
        assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix());
        setPrefix("u_");
        ModelUtils.setUserRepoPrefix(ms);
        ModelUtils.setUserRepoPrefix("u_");
        assertEquals("u_", ModelUtils.getUserRepoPrefix());
        ModelUtils.setUserRepoPrefix(null);
        assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix());
        assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX, ModelUtils.getUserRepoPrefix());
        setPrefix("/somedir/otherdir/");
        ModelUtils.setUserRepoPrefix(ms);
        ModelUtils.setUserRepoPrefix("/somedir/otherdir/");
        assertEquals("somedir/otherdir/", ModelUtils.getUserRepoPrefix());
        setPrefix(DEFAULT_USER_REPO_PREFIX);
        ModelUtils.setUserRepoPrefix(ms);
        assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix());
    }
@@ -92,12 +56,12 @@
    public void testGetPersonalPath()
    {
        String username = "rob";
        assertEquals(DEFAULT_USER_REPO_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username));
        assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username));
        username = "James";
        assertEquals(DEFAULT_USER_REPO_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username));
        assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username));
        
        setRepoPrefix("usr/");
        ModelUtils.setUserRepoPrefix("usr/");
        username = "noMan";
        assertEquals("usr/"+username.toLowerCase(), ModelUtils.getPersonalPath(username));        
    }
@@ -106,17 +70,17 @@
    @Test
    public void testIsPersonalRepository()
    {
        String reponame = DEFAULT_USER_REPO_PREFIX + "one";
        String reponame = Constants.DEFAULT_USER_REPOSITORY_PREFIX + "one";
        assertTrue(ModelUtils.isPersonalRepository(reponame));
        reponame = "none";
        assertFalse(ModelUtils.isPersonalRepository(reponame));
        setRepoPrefix("@@");
        ModelUtils.setUserRepoPrefix("@@");
        reponame = "@@two";
        assertTrue(ModelUtils.isPersonalRepository(reponame));
        setRepoPrefix("users/");
        ModelUtils.setUserRepoPrefix("users/");
        reponame = "users/three";
        assertTrue(ModelUtils.isPersonalRepository(reponame));
@@ -128,18 +92,18 @@
    @Test
    public void testIsUsersPersonalRepository()
    {
        String reponame = DEFAULT_USER_REPO_PREFIX + "lynn";
        String reponame = Constants.DEFAULT_USER_REPOSITORY_PREFIX + "lynn";
        assertTrue(ModelUtils.isUsersPersonalRepository("lynn", reponame));
        reponame = "prjB";
        assertFalse(ModelUtils.isUsersPersonalRepository("lynn", reponame));
        setRepoPrefix("@@");
        ModelUtils.setUserRepoPrefix("@@");
        reponame = "@@newton";
        assertTrue(ModelUtils.isUsersPersonalRepository("newton", reponame));
        assertFalse(ModelUtils.isUsersPersonalRepository("hertz", reponame));
        setRepoPrefix("users/");
        ModelUtils.setUserRepoPrefix("users/");
        reponame = "users/fee";
        assertTrue(ModelUtils.isUsersPersonalRepository("fee", reponame));
        assertFalse(ModelUtils.isUsersPersonalRepository("gnome", reponame));
@@ -152,14 +116,14 @@
    @Test
    public void testGetUserNameFromRepoPath()
    {
        String reponame = DEFAULT_USER_REPO_PREFIX + "lynn";
        String reponame = Constants.DEFAULT_USER_REPOSITORY_PREFIX + "lynn";
        assertEquals("lynn", ModelUtils.getUserNameFromRepoPath(reponame));
        setRepoPrefix("@@");
        ModelUtils.setUserRepoPrefix("@@");
        reponame = "@@newton";
        assertEquals("newton", ModelUtils.getUserNameFromRepoPath(reponame));
        setRepoPrefix("users/");
        ModelUtils.setUserRepoPrefix("users/");
        reponame = "users/fee";
        assertEquals("fee", ModelUtils.getUserNameFromRepoPath(reponame));
    }