From fc84260e4238fda10842c1bd3b9fb0cb74b95426 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 04 Apr 2011 16:13:11 -0400
Subject: [PATCH] Dropped log links, created new stylesheet, added activity graph.

---
 src/com/gitblit/utils/JGitUtils.java |   36 +++++++++++++++++++++++++++++++-----
 1 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index 673c987..31b5677 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -5,6 +5,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.RandomAccessFile;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -35,9 +37,9 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.gitblit.wicket.models.Metric;
 import com.gitblit.wicket.models.PathModel;
 import com.gitblit.wicket.models.RefModel;
-
 
 public class JGitUtils {
 
@@ -204,7 +206,7 @@
 
 	public static List<PathModel> getFilesInPath(Repository r, String basePath, RevCommit commit) {
 		List<PathModel> list = new ArrayList<PathModel>();
-		final TreeWalk walk = new TreeWalk(r);		
+		final TreeWalk walk = new TreeWalk(r);
 		try {
 			walk.addTree(commit.getTree());
 			if (basePath != null && basePath.length() > 0) {
@@ -214,7 +216,7 @@
 				boolean foundFolder = false;
 				while (walk.next()) {
 					if (!foundFolder && walk.isSubtree()) {
-						walk.enterSubtree();						
+						walk.enterSubtree();
 					}
 					if (walk.getPathString().equals(basePath)) {
 						foundFolder = true;
@@ -264,7 +266,7 @@
 		return list;
 	}
 
-	private static PathModel getPathModel(TreeWalk walk, String basePath, RevCommit commit) {		
+	private static PathModel getPathModel(TreeWalk walk, String basePath, RevCommit commit) {
 		String name;
 		long size = 0;
 		if (basePath == null) {
@@ -310,7 +312,6 @@
 		return FileMode.TREE.equals(mode);
 	}
 
-	
 	public static List<RevCommit> getRevLog(Repository r, int maxCount) {
 		List<RevCommit> list = new ArrayList<RevCommit>();
 		try {
@@ -427,4 +428,29 @@
 		}
 		return null;
 	}
+
+	public static List<Metric> getDateMetrics(Repository r) {
+		final Map<String, Metric> map = new HashMap<String, Metric>();
+		try {
+			DateFormat df = new SimpleDateFormat("yyyy-MM");
+			Git git = new Git(r);
+			Iterable<RevCommit> revlog = git.log().call();
+			for (RevCommit rev : revlog) {
+				Date d = getCommitDate(rev);
+				String p = df.format(d);
+				if (!map.containsKey(p))
+					map.put(p, new Metric(p));
+				map.get(p).count++;
+			}
+		} catch (Throwable t) {
+			LOGGER.error("Failed to mine log history for metrics", t);
+		}
+		List<String> keys = new ArrayList<String>(map.keySet());
+		Collections.sort(keys);
+		List<Metric> metrics = new ArrayList<Metric>();
+		for (String key:keys) {
+			metrics.add(map.get(key));
+		}		
+		return metrics;
+	}
 }

--
Gitblit v1.9.1