From ab07d0d86d8b64b4f7c88b45bc81f1eec22105db Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 10 Apr 2014 19:00:05 -0400
Subject: [PATCH] Preserve key index when re-adding an existing key

---
 src/main/java/com/gitblit/utils/ActivityUtils.java |   47 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/src/main/java/com/gitblit/utils/ActivityUtils.java b/src/main/java/com/gitblit/utils/ActivityUtils.java
index fa74350..3a54d33 100644
--- a/src/main/java/com/gitblit/utils/ActivityUtils.java
+++ b/src/main/java/com/gitblit/utils/ActivityUtils.java
@@ -34,8 +34,9 @@
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.Repository;
 
-import com.gitblit.GitBlit;
+import com.gitblit.IStoredSettings;
 import com.gitblit.Keys;
+import com.gitblit.manager.IRepositoryManager;
 import com.gitblit.models.Activity;
 import com.gitblit.models.GravatarProfile;
 import com.gitblit.models.RefModel;
@@ -45,16 +46,20 @@
 
 /**
  * Utility class for building activity information from repositories.
- * 
+ *
  * @author James Moger
- * 
+ *
  */
 public class ActivityUtils {
 
 	/**
 	 * Gets the recent activity from the repositories for the last daysBack days
 	 * on the specified branch.
-	 * 
+	 *
+	 * @param settings
+	 *            the runtime settings
+	 * @param repositoryManager
+	 *            the repository manager
 	 * @param models
 	 *            the list of repositories to query
 	 * @param daysBack
@@ -66,8 +71,13 @@
 	 *            the timezone for aggregating commits
 	 * @return
 	 */
-	public static List<Activity> getRecentActivity(List<RepositoryModel> models, int daysBack,
-			String objectId, TimeZone timezone) {
+	public static List<Activity> getRecentActivity(
+					IStoredSettings settings,
+					IRepositoryManager repositoryManager,
+					List<RepositoryModel> models,
+					int daysBack,
+					String objectId,
+					TimeZone timezone) {
 
 		// Activity panel shows last daysBack of activity across all
 		// repositories.
@@ -79,10 +89,10 @@
 		df.setTimeZone(timezone);
 		Calendar cal = Calendar.getInstance();
 		cal.setTimeZone(timezone);
-		
+
 		// aggregate author exclusions
 		Set<String> authorExclusions = new TreeSet<String>();
-		authorExclusions.addAll(GitBlit.getStrings(Keys.web.metricAuthorExclusions));
+		authorExclusions.addAll(settings.getStrings(Keys.web.metricAuthorExclusions));
 		for (RepositoryModel model : models) {
 			if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
 				authorExclusions.addAll(model.metricAuthorExclusions);
@@ -99,12 +109,15 @@
 				if (model.isCollectingGarbage) {
 					continue;
 				}
-				Repository repository = GitBlit.self()
-						.getRepository(model.name);
+				Repository repository = repositoryManager.getRepository(model.name);
 				List<String> branches = new ArrayList<String>();
 				if (StringUtils.isEmpty(objectId)) {
 					for (RefModel local : JGitUtils.getLocalBranches(
 							repository, true, -1)) {
+			        	if (!local.getDate().after(thresholdDate)) {
+							// branch not recently updated
+			        		continue;
+			        	}
 						branches.add(local.getName());
 					}
 				} else {
@@ -121,7 +134,7 @@
 						// trim commits to maximum count
 						commits = commits.subList(0,  model.maxActivityCommits);
 					}
-					for (RepositoryCommit commit : commits) {						
+					for (RepositoryCommit commit : commits) {
 						Date date = commit.getCommitDate();
 						String dateStr = df.format(date);
 						if (!activity.containsKey(dateStr)) {
@@ -138,7 +151,7 @@
 						activity.get(dateStr).addCommit(commit);
 					}
 				}
-				
+
 				// close the repository
 				repository.close();
 			}
@@ -151,7 +164,7 @@
 	/**
 	 * Returns the Gravatar profile, if available, for the specified email
 	 * address.
-	 * 
+	 *
 	 * @param emailaddress
 	 * @return a Gravatar Profile
 	 * @throws IOException
@@ -163,7 +176,7 @@
 
 	/**
 	 * Creates a Gravatar thumbnail url from the specified email address.
-	 * 
+	 *
 	 * @param email
 	 *            address to query Gravatar
 	 * @param width
@@ -179,10 +192,10 @@
 				"https://www.gravatar.com/avatar/{0}?s={1,number,0}&d=identicon", emailHash, width);
 		return url;
 	}
-	
+
 	/**
 	 * Creates a Gravatar thumbnail url from the specified email address.
-	 * 
+	 *
 	 * @param email
 	 *            address to query Gravatar
 	 * @param width
@@ -202,7 +215,7 @@
 	/**
 	 * Returns the Gravatar profile, if available, for the specified hashcode.
 	 * address.
-	 * 
+	 *
 	 * @param hash
 	 *            the hash of the email address
 	 * @return a Gravatar Profile

--
Gitblit v1.9.1