From: James Moger Date: Mon, 11 Jul 2011 20:29:20 +0000 (-0400) Subject: Optionally display repository on-disk size on repositories page. X-Git-Tag: v0.5.2~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5c284113a1a458db0d3440de351034503b3d52b3;p=gitblit.git Optionally display repository on-disk size on repositories page. --- diff --git a/distrib/gitblit.properties b/distrib/gitblit.properties index 953baa1c..2ae3d011 100644 --- a/distrib/gitblit.properties +++ b/distrib/gitblit.properties @@ -97,6 +97,13 @@ web.allowZipDownloads = true # SINCE 0.5.0 web.syndicationEntries = 25 +# Show the size of each repository on the repositories page. +# This requires recursive traversal of each repository folder. This may be +# non-performant on some operating systems and/or filesystems. +# +# SINCE 0.5.2 +web.showRepositorySizes = true + # This is the message display above the repositories table. # This can point to a file with Markdown content. # Specifying "gitblit" uses the internal welcome message. diff --git a/docs/00_index.mkd b/docs/00_index.mkd index d6457938..edb058d8 100644 --- a/docs/00_index.mkd +++ b/docs/00_index.mkd @@ -21,11 +21,10 @@ Gitblit requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit ### Current Release -%VERSION% ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* +**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* -- clarified SSL certificate generation and configuration for both server-side and client-side -- added some more troubleshooting information to documentation -- replaced JavaService with Apache Commons Daemon +- optionally display repository on-disk size on repositories page
**New:** *web.showRepositorySizes = true* +- tone-down repository group header color issues & binaries @ [Google Code][googlecode]
sources @ [Github][gitbltsrc] diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index debab789..94aaa1a1 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -1,13 +1,20 @@ ## Release History ### Current Release -%VERSION% ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* +**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* + +- optionally display repository on-disk size on repositories page
**New:** *web.showRepositorySizes = true* +- tone-down repository group header color + +### Older Releases +**0.5.1** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.1.zip)|[war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.1.war)) based on [JGit 1.0.0 (201106090707-r)][jgit]   *released 2006-06-28* - clarified SSL certificate generation and configuration for both server-side and client-side - added some more troubleshooting information to documentation - replaced JavaService with Apache Commons Daemon -### Older Releases -0.5.0 ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.0.zip)|[war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.0.war)) based on [JGit 1.0.0 (201106090707-r)][jgit]   *released 2006-06-26* +**0.5.0** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.0.zip)|[war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.0.war)) based on [JGit 1.0.0 (201106090707-r)][jgit]   *released 2006-06-26* + +- initial release [jgit]: http://eclipse.org/jgit "Eclipse JGit Site" \ No newline at end of file diff --git a/src/com/gitblit/Constants.java b/src/com/gitblit/Constants.java index 08ffb9ba..766f7c20 100644 --- a/src/com/gitblit/Constants.java +++ b/src/com/gitblit/Constants.java @@ -29,11 +29,11 @@ public class Constants { // The build script extracts this exact line so be careful editing it // and only use A-Z a-z 0-9 .-_ in the string. - public static final String VERSION = "0.5.1"; + public static final String VERSION = "0.5.2-SNAPSHOT"; // The build script extracts this exact line so be careful editing it // and only use A-Z a-z 0-9 .-_ in the string. - public static final String VERSION_DATE = "2011-06-28"; + public static final String VERSION_DATE = "PENDING"; // The build script extracts this exact line so be careful editing it // and only use A-Z a-z 0-9 .-_ in the string. diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 9fe6d201..968034de 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -32,11 +32,13 @@ import javax.servlet.http.Cookie; import org.apache.wicket.protocol.http.WebResponse; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.RepositoryCache.FileKey; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.transport.resolver.FileResolver; import org.eclipse.jgit.transport.resolver.RepositoryResolver; import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; +import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -450,6 +452,17 @@ public class GitBlit implements ServletContextListener { return model; } + /** + * Returns the size in bytes of the repository. + * + * @param model + * @return size in bytes + */ + public long calculateSize(RepositoryModel model) { + File gitDir = FileKey.resolve(new File(repositoriesFolder, model.name), FS.DETECTED); + return com.gitblit.utils.FileUtils.folderSize(gitDir); + } + /** * Returns the gitblit string vlaue for the specified key. If key is not * set, returns defaultValue. diff --git a/src/com/gitblit/utils/FileUtils.java b/src/com/gitblit/utils/FileUtils.java index 468b2a80..ce8cdf94 100644 --- a/src/com/gitblit/utils/FileUtils.java +++ b/src/com/gitblit/utils/FileUtils.java @@ -56,4 +56,28 @@ public class FileUtils { } return sb.toString(); } + + /** + * Recursively traverses a folder and its subfolders to calculate the total + * size in bytes. + * + * @param directory + * @return folder size in bytes + */ + public static long folderSize(File directory) { + if (directory == null || !directory.exists()) { + return -1; + } + if (directory.isFile()) { + return directory.length(); + } + long length = 0; + for (File file : directory.listFiles()) { + if (file.isFile()) + length += file.length(); + else + length += folderSize(file); + } + return length; + } } diff --git a/src/com/gitblit/wicket/panels/RepositoriesPanel.html b/src/com/gitblit/wicket/panels/RepositoriesPanel.html index 7e090e80..a4f5d12e 100644 --- a/src/com/gitblit/wicket/panels/RepositoriesPanel.html +++ b/src/com/gitblit/wicket/panels/RepositoriesPanel.html @@ -57,6 +57,7 @@ Repository Description + Owner Last Change @@ -65,12 +66,13 @@ - [group name] + [group name]
[repository name]
[repository description]
+ [repository size] [repository owner] [last change] diff --git a/src/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/com/gitblit/wicket/panels/RepositoriesPanel.java index c7441487..fa6c661d 100644 --- a/src/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -47,6 +47,7 @@ import com.gitblit.Keys; import com.gitblit.SyndicationServlet; import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; +import com.gitblit.utils.ByteFormat; import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils; import com.gitblit.wicket.GitBlitWebSession; @@ -71,19 +72,30 @@ public class RepositoriesPanel extends BasePanel { add(adminLinks.setVisible(showAdmin)); if (GitBlit.getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) { + List rootRepositories = new ArrayList(); Map> groups = new HashMap>(); for (RepositoryModel model : models) { String rootPath = StringUtils.getRootPath(model.name); - if (StringUtils.isEmpty(rootPath)) { - rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " "); - } - if (!groups.containsKey(rootPath)) { - groups.put(rootPath, new ArrayList()); + if (StringUtils.isEmpty(rootPath)) { + // root repository + rootRepositories.add(model); + } else { + // non-root, grouped repository + if (!groups.containsKey(rootPath)) { + groups.put(rootPath, new ArrayList()); + } + groups.get(rootPath).add(model); } - groups.get(rootPath).add(model); } List roots = new ArrayList(groups.keySet()); Collections.sort(roots); + + if (rootRepositories.size() > 0) { + // inject the root repositories at the top of the page + String rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " "); + roots.add(0, rootPath); + groups.put(rootPath, rootRepositories); + } List groupedModels = new ArrayList(); for (String root : roots) { List subModels = groups.get(root); @@ -95,6 +107,8 @@ public class RepositoriesPanel extends BasePanel { dp = new SortableRepositoriesProvider(models); } + final boolean showSize = GitBlit.getBoolean(Keys.web.showRepositorySizes, true); + final ByteFormat byteFormat = new ByteFormat(); DataView dataView = new DataView("row", dp) { private static final long serialVersionUID = 1L; int counter; @@ -123,11 +137,16 @@ public class RepositoriesPanel extends BasePanel { pp)); row.add(new LinkPanel("repositoryDescription", "list", entry.description, SummaryPage.class, pp)); + if (showSize) { + row.add(new Label("repositorySize", byteFormat.format(GitBlit.self().calculateSize(entry)))); + } else { + row.add(new Label("repositorySize").setVisible(false)); + } } else { // New repository - row.add(new Label("repositoryName", entry.name - + "(empty)").setEscapeModelStrings(false)); + row.add(new Label("repositoryName", entry.name)); row.add(new Label("repositoryDescription", entry.description)); + row.add(new Label("repositorySize", "(empty)").setEscapeModelStrings(false)); } if (entry.useTickets) {