From d10fbbe75258cd1c66acebd0aaa71feefdd59f4c Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 07 Aug 2013 14:58:49 -0400
Subject: [PATCH] Update to Moxie 0.8.0
---
src/main/java/com/gitblit/GitBlit.java | 135 ++++++++++++++++++++++++++++++++++----------
1 files changed, 103 insertions(+), 32 deletions(-)
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index 6285733..e47c4c6 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -84,6 +84,7 @@
import com.gitblit.Constants.AccessPermission;
import com.gitblit.Constants.AccessRestrictionType;
+import com.gitblit.Constants.AccountType;
import com.gitblit.Constants.AuthenticationType;
import com.gitblit.Constants.AuthorizationControl;
import com.gitblit.Constants.FederationRequest;
@@ -121,6 +122,7 @@
import com.gitblit.utils.FederationUtils;
import com.gitblit.utils.HttpUtils;
import com.gitblit.utils.JGitUtils;
+import com.gitblit.utils.JGitUtils.LastChange;
import com.gitblit.utils.JsonUtils;
import com.gitblit.utils.MetricUtils;
import com.gitblit.utils.ObjectCache;
@@ -230,6 +232,33 @@
}
return gitblit;
}
+
+ /**
+ * Returns the boot date of the Gitblit server.
+ *
+ * @return the boot date of Gitblit
+ */
+ public static Date getBootDate() {
+ return self().serverStatus.bootDate;
+ }
+
+ /**
+ * Returns the most recent change date of any repository served by Gitblit.
+ *
+ * @return a date
+ */
+ public static Date getLastActivityDate() {
+ Date date = null;
+ for (String name : self().getRepositoryList()) {
+ Repository r = self().getRepository(name);
+ Date lastChange = JGitUtils.getLastChange(r).when;
+ r.close();
+ if (lastChange != null && (date == null || lastChange.after(date))) {
+ date = lastChange;
+ }
+ }
+ return date;
+ }
/**
* Determine if this is the GO variant of Gitblit.
@@ -275,6 +304,15 @@
self().timezone = TimeZone.getTimeZone(tzid);
}
return self().timezone;
+ }
+
+ /**
+ * Returns the active settings.
+ *
+ * @return the active settings
+ */
+ public static IStoredSettings getSettings() {
+ return self().settings;
}
/**
@@ -685,12 +723,12 @@
public boolean supportsCredentialChanges(UserModel user) {
if (user == null) {
return false;
- } else if (!Constants.EXTERNAL_ACCOUNT.equals(user.password)) {
- // credentials likely maintained by Gitblit
- return userService.supportsCredentialChanges();
+ } else if (AccountType.LOCAL.equals(user.accountType)) {
+ // local account, we can change credentials
+ return true;
} else {
- // credentials are externally maintained
- return false;
+ // external account, ask user service
+ return userService.supportsCredentialChanges();
}
}
@@ -722,6 +760,18 @@
*/
public boolean supportsTeamMembershipChanges(UserModel user) {
return (user != null && user.isLocalAccount()) || userService.supportsTeamMembershipChanges();
+ }
+
+ /**
+ * Returns true if the username represents an internal account
+ *
+ * @param username
+ * @return true if the specified username represents an internal account
+ */
+ protected boolean isInternalAccount(String username) {
+ return !StringUtils.isEmpty(username)
+ && (username.equalsIgnoreCase(Constants.FEDERATION_USER)
+ || username.equalsIgnoreCase(UserModel.ANONYMOUS.username));
}
/**
@@ -836,6 +886,7 @@
if (principal != null) {
String username = principal.getName();
if (!StringUtils.isEmpty(username)) {
+ boolean internalAccount = isInternalAccount(username);
UserModel user = getUserModel(username);
if (user != null) {
// existing user
@@ -844,7 +895,7 @@
user.username, httpRequest.getRemoteAddr()));
return user;
} else if (settings.getBoolean(Keys.realm.container.autoCreateAccounts, false)
- && !username.equalsIgnoreCase(Constants.FEDERATION_USER)) {
+ && !internalAccount) {
// auto-create user from an authenticated container principal
user = new UserModel(username.toLowerCase());
user.displayName = username;
@@ -854,7 +905,7 @@
logger.debug(MessageFormat.format("{0} authenticated and created by servlet container principal from {1}",
user.username, httpRequest.getRemoteAddr()));
return user;
- } else {
+ } else if (!internalAccount) {
logger.warn(MessageFormat.format("Failed to find UserModel for {0}, attempted servlet container authentication from {1}",
principal.getName(), httpRequest.getRemoteAddr()));
}
@@ -1506,6 +1557,10 @@
* @return repository or null
*/
public Repository getRepository(String repositoryName, boolean logError) {
+ // Decode url-encoded repository name (issue-278)
+ // http://stackoverflow.com/questions/17183110
+ repositoryName = repositoryName.replace("%7E", "~").replace("%7e", "~");
+
if (isCollectingGarbage(repositoryName)) {
logger.warn(MessageFormat.format("Rejecting request for {0}, busy collecting garbage!", repositoryName));
return null;
@@ -1605,6 +1660,10 @@
* @return repository model or null
*/
public RepositoryModel getRepositoryModel(String repositoryName) {
+ // Decode url-encoded repository name (issue-278)
+ // http://stackoverflow.com/questions/17183110
+ repositoryName = repositoryName.replace("%7E", "~").replace("%7e", "~");
+
if (!repositoryListCache.containsKey(repositoryName)) {
RepositoryModel model = loadRepositoryModel(repositoryName);
if (model == null) {
@@ -1647,7 +1706,9 @@
model.hasCommits = JGitUtils.hasCommits(r);
}
- model.lastChange = JGitUtils.getLastChange(r);
+ LastChange lc = JGitUtils.getLastChange(r);
+ model.lastChange = lc.when;
+ model.lastChangeAuthor = lc.who;
if (!model.skipSizeCalculation) {
ByteFormat byteFormat = new ByteFormat();
model.size = byteFormat.format(calculateSize(model));
@@ -1673,6 +1734,30 @@
}
}
return count;
+ }
+
+ private void reloadProjectMarkdown(ProjectModel project) {
+ // project markdown
+ File pmkd = new File(getRepositoriesFolder(), (project.isRoot ? "" : project.name) + "/project.mkd");
+ if (pmkd.exists()) {
+ Date lm = new Date(pmkd.lastModified());
+ if (!projectMarkdownCache.hasCurrent(project.name, lm)) {
+ String mkd = com.gitblit.utils.FileUtils.readContent(pmkd, "\n");
+ projectMarkdownCache.updateObject(project.name, lm, mkd);
+ }
+ project.projectMarkdown = projectMarkdownCache.getObject(project.name);
+ }
+
+ // project repositories markdown
+ File rmkd = new File(getRepositoriesFolder(), (project.isRoot ? "" : project.name) + "/repositories.mkd");
+ if (rmkd.exists()) {
+ Date lm = new Date(rmkd.lastModified());
+ if (!projectRepositoriesMarkdownCache.hasCurrent(project.name, lm)) {
+ String mkd = com.gitblit.utils.FileUtils.readContent(rmkd, "\n");
+ projectRepositoriesMarkdownCache.updateObject(project.name, lm, mkd);
+ }
+ project.repositoriesMarkdown = projectRepositoriesMarkdownCache.getObject(project.name);
+ }
}
@@ -1709,27 +1794,7 @@
project.title = projectConfigs.getString("project", name, "title");
project.description = projectConfigs.getString("project", name, "description");
- // project markdown
- File pmkd = new File(getRepositoriesFolder(), (project.isRoot ? "" : name) + "/project.mkd");
- if (pmkd.exists()) {
- Date lm = new Date(pmkd.lastModified());
- if (!projectMarkdownCache.hasCurrent(name, lm)) {
- String mkd = com.gitblit.utils.FileUtils.readContent(pmkd, "\n");
- projectMarkdownCache.updateObject(name, lm, mkd);
- }
- project.projectMarkdown = projectMarkdownCache.getObject(name);
- }
-
- // project repositories markdown
- File rmkd = new File(getRepositoriesFolder(), (project.isRoot ? "" : name) + "/repositories.mkd");
- if (rmkd.exists()) {
- Date lm = new Date(rmkd.lastModified());
- if (!projectRepositoriesMarkdownCache.hasCurrent(name, lm)) {
- String mkd = com.gitblit.utils.FileUtils.readContent(rmkd, "\n");
- projectRepositoriesMarkdownCache.updateObject(name, lm, mkd);
- }
- project.repositoriesMarkdown = projectRepositoriesMarkdownCache.getObject(name);
- }
+ reloadProjectMarkdown(project);
configs.put(name.toLowerCase(), project);
}
@@ -1851,6 +1916,8 @@
// no repositories == no project
return null;
}
+
+ reloadProjectMarkdown(project);
return project;
}
@@ -1945,7 +2012,9 @@
model.name = repositoryName;
}
model.hasCommits = JGitUtils.hasCommits(r);
- model.lastChange = JGitUtils.getLastChange(r);
+ LastChange lc = JGitUtils.getLastChange(r);
+ model.lastChange = lc.when;
+ model.lastChangeAuthor = lc.who;
model.projectPath = StringUtils.getFirstPathElement(repositoryName);
StoredConfig config = r.getConfig();
@@ -2019,6 +2088,9 @@
File repoFolder = new File(getRepositoriesFolder(), originRepo);
if (repoFolder.exists()) {
model.originRepository = originRepo.toLowerCase();
+
+ // persist the fork origin
+ updateConfiguration(r, model);
}
}
} catch (URISyntaxException e) {
@@ -2933,8 +3005,7 @@
String cloneUrl = sb.toString();
// Retrieve all available repositories
- UserModel user = new UserModel(Constants.FEDERATION_USER);
- user.canAdmin = true;
+ UserModel user = getFederationUser();
List<RepositoryModel> list = getRepositoryModels(user);
// create the [cloneurl, repositoryModel] map
--
Gitblit v1.9.1