From df75fa3a0961fc6a539209d5f13788d64b109a34 Mon Sep 17 00:00:00 2001
From: Florian Zschocke <florian.zschocke@cycos.com>
Date: Mon, 26 Aug 2013 06:30:53 -0400
Subject: [PATCH] Add new configuration setting 'git.userRepositoryPrefix'.
---
src/main/java/com/gitblit/GitBlit.java | 33 +++++++++++++++++++++++++++------
1 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index cb5c0c5..9b79e3c 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -125,6 +125,7 @@
import com.gitblit.utils.JGitUtils.LastChange;
import com.gitblit.utils.JsonUtils;
import com.gitblit.utils.MetricUtils;
+import com.gitblit.utils.ModelUtils;
import com.gitblit.utils.ObjectCache;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TimeUtils;
@@ -1243,8 +1244,8 @@
// personal repository
model.addOwner(user.username);
String oldRepositoryName = model.name;
- model.name = "~" + user.username + model.name.substring(model.projectPath.length());
- model.projectPath = "~" + user.username;
+ model.name = user.getPersonalPath() + model.name.substring(model.projectPath.length());
+ model.projectPath = user.getPersonalPath();
updateRepositoryModel(oldRepositoryName, model, false);
} else if (model.isOwner(username)) {
// common/shared repo
@@ -1853,8 +1854,8 @@
ProjectModel project = configs.get(name.toLowerCase());
if (project == null) {
project = new ProjectModel(name);
- if (name.length() > 0 && name.charAt(0) == '~') {
- UserModel user = getUserModel(name.substring(1));
+ if (ModelUtils.isPersonalRepository(name)) {
+ UserModel user = getUserModel(ModelUtils.getUserNameFromRepoPath(name));
if (user != null) {
project.title = user.getDisplayName();
project.description = "personal repositories";
@@ -1985,6 +1986,14 @@
boolean hasOrigin = !StringUtils.isEmpty(config.getString("remote", "origin", "url"));
if (config != null) {
+ // Initialize description from description file
+ if (getConfig(config,"description", null) == null) {
+ File descFile = new File(r.getDirectory(), "description");
+ if (descFile.exists()) {
+ config.setString(Constants.CONFIG_GITBLIT, null, "description",
+ com.gitblit.utils.FileUtils.readContent(descFile, System.getProperty("line.separator")));
+ }
+ }
model.description = getConfig(config, "description", "");
model.originRepository = getConfig(config, "originRepository", null);
model.addOwners(ArrayUtils.fromString(getConfig(config, "owner", "")));
@@ -2118,7 +2127,7 @@
* @return the name of the user's fork, null otherwise
*/
public String getFork(String username, String origin) {
- String userProject = "~" + username.toLowerCase();
+ String userProject = ModelUtils.getPersonalPath(username);
if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
String userPath = userProject + "/";
@@ -2497,6 +2506,15 @@
// update settings
if (r != null) {
updateConfiguration(r, repository);
+ // Update the description file
+ File descFile = new File(r.getDirectory(), "description");
+ if (repository.description != null)
+ {
+ com.gitblit.utils.FileUtils.writeContent(descFile, repository.description);
+ }
+ else if (descFile.exists() && !descFile.isDirectory()) {
+ descFile.delete();
+ }
// only update symbolic head if it changes
String currentRef = JGitUtils.getHEADRef(r);
if (!StringUtils.isEmpty(repository.HEAD) && !repository.HEAD.equals(currentRef)) {
@@ -3422,6 +3440,9 @@
luceneExecutor = new LuceneExecutor(settings, repositoriesFolder);
gcExecutor = new GCExecutor(settings);
+ // initialize utilities
+ ModelUtils.setUserRepoPrefix(settings);
+
// calculate repository list settings checksum for future config changes
repositoryListSettingsChecksum.set(getRepositoryListSettingsChecksum());
@@ -3801,7 +3822,7 @@
* @throws GitBlitException
*/
public RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException {
- String cloneName = MessageFormat.format("~{0}/{1}.git", user.username, StringUtils.stripDotGit(StringUtils.getLastPathElement(repository.name)));
+ String cloneName = MessageFormat.format("{0}/{1}.git", user.getPersonalPath(), StringUtils.stripDotGit(StringUtils.getLastPathElement(repository.name)));
String fromUrl = MessageFormat.format("file://{0}/{1}", repositoriesFolder.getAbsolutePath(), repository.name);
// clone the repository
--
Gitblit v1.9.1