]> source.dussan.org Git - gitblit.git/commitdiff
Activity page now considers all local branches (issue 65)
authorJames Moger <james.moger@gitblit.com>
Fri, 24 Feb 2012 22:34:31 +0000 (17:34 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 24 Feb 2012 22:34:31 +0000 (17:34 -0500)
docs/04_releases.mkd
src/com/gitblit/models/Activity.java
src/com/gitblit/utils/ActivityUtils.java
src/com/gitblit/wicket/pages/ActivityPage.java
src/com/gitblit/wicket/panels/ActivityPanel.java

index 3f5eb39dc4fbbdbf2da087c4911b42b2963434f1..da886334af103872b135619d0f453c1daf72c604 100644 (file)
@@ -30,10 +30,11 @@ Push requests to these repositories will be rejected.
 \r
 #### fixes \r
 \r
+- Activity page now displays all local branches (issue 65)\r
 - Fixed (harmless) nullpointer on pushing to an empty repository (issue 69)\r
 - Fixed possible nullpointer from the servlet container on startup (issue 67)\r
 - Fixed UTF-8 encoding bug on diff page (issue 66)\r
-- Fixed timezone bug on the activity page (issue 54)\r
+- Fixed timezone bugs on the activity page (issue 54)\r
 - Prevent add/edit team with no selected repositories (issue 56) \r
 - Disallow browser autocomplete on add/edit user/team/repository pages\r
 - Fixed username case-sensitivity issues (issue 43)\r
index f24a5abef993558c393fe392e0ec918caab1f084..9d58ef07b7d6c40f7e9bd4e42a5737effd5cc8c8 100644 (file)
@@ -17,10 +17,13 @@ package com.gitblit.models;
 \r
 import java.io.Serializable;\r
 import java.util.ArrayList;\r
+import java.util.Collections;\r
 import java.util.Date;\r
 import java.util.HashMap;\r
+import java.util.LinkedHashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
+import java.util.Set;\r
 \r
 import org.eclipse.jgit.lib.PersonIdent;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
@@ -41,7 +44,7 @@ public class Activity implements Serializable, Comparable<Activity> {
 \r
        public final Date endDate;\r
 \r
-       public final List<RepositoryCommit> commits;\r
+       private final Set<RepositoryCommit> commits;\r
 \r
        private final Map<String, Metric> authorMetrics;\r
 \r
@@ -67,26 +70,48 @@ public class Activity implements Serializable, Comparable<Activity> {
        public Activity(Date date, long duration) {\r
                startDate = date;\r
                endDate = new Date(date.getTime() + duration);\r
-               commits = new ArrayList<RepositoryCommit>();\r
+               commits = new LinkedHashSet<RepositoryCommit>();\r
                authorMetrics = new HashMap<String, Metric>();\r
                repositoryMetrics = new HashMap<String, Metric>();\r
        }\r
 \r
+       /**\r
+        * Adds a commit to the activity object as long as the commit is not a\r
+        * duplicate.\r
+        * \r
+        * @param repository\r
+        * @param branch\r
+        * @param commit\r
+        * @return a RepositoryCommit, if one was added. Null if this is duplicate\r
+        *         commit\r
+        */\r
        public RepositoryCommit addCommit(String repository, String branch, RevCommit commit) {\r
                RepositoryCommit commitModel = new RepositoryCommit(repository, branch, commit);\r
-               commits.add(commitModel);\r
-\r
-               if (!repositoryMetrics.containsKey(repository)) {\r
-                       repositoryMetrics.put(repository, new Metric(repository));\r
-               }\r
-               repositoryMetrics.get(repository).count++;\r
+               if (commits.add(commitModel)) {\r
+                       if (!repositoryMetrics.containsKey(repository)) {\r
+                               repositoryMetrics.put(repository, new Metric(repository));\r
+                       }\r
+                       repositoryMetrics.get(repository).count++;\r
 \r
-               String author = commit.getAuthorIdent().getEmailAddress().toLowerCase();\r
-               if (!authorMetrics.containsKey(author)) {\r
-                       authorMetrics.put(author, new Metric(author));\r
+                       String author = commit.getAuthorIdent().getEmailAddress()\r
+                                       .toLowerCase();\r
+                       if (!authorMetrics.containsKey(author)) {\r
+                               authorMetrics.put(author, new Metric(author));\r
+                       }\r
+                       authorMetrics.get(author).count++;\r
+                       return commitModel;\r
                }\r
-               authorMetrics.get(author).count++;\r
-               return commitModel;\r
+               return null;\r
+       }\r
+       \r
+       public int getCommitCount() {\r
+               return commits.size();\r
+       }\r
+       \r
+       public List<RepositoryCommit> getCommits() {\r
+               List<RepositoryCommit> list = new ArrayList<RepositoryCommit>(commits);\r
+               Collections.sort(list);\r
+               return list;\r
        }\r
 \r
        public Map<String, Metric> getAuthorMetrics() {\r
@@ -154,6 +179,20 @@ public class Activity implements Serializable, Comparable<Activity> {
                public PersonIdent getAuthorIdent() {\r
                        return commit.getAuthorIdent();\r
                }\r
+               \r
+               @Override\r
+               public boolean equals(Object o) {\r
+                       if (o instanceof RepositoryCommit) {\r
+                               RepositoryCommit commit = (RepositoryCommit) o;\r
+                               return repository.equals(commit.repository) && getName().equals(commit.getName());\r
+                       }\r
+                       return false;\r
+               }\r
+               \r
+               @Override\r
+               public int hashCode() {\r
+                       return (repository + commit).hashCode();\r
+               }\r
 \r
                @Override\r
                public int compareTo(RepositoryCommit o) {\r
index d6afd93c90c0eb9fcd331f6bb8712fd7bb18dd39..61b6242aa60badc5457865115e8c3a1e068fcf7e 100644 (file)
@@ -23,7 +23,6 @@ import java.text.MessageFormat;
 import java.text.SimpleDateFormat;\r
 import java.util.ArrayList;\r
 import java.util.Calendar;\r
-import java.util.Collections;\r
 import java.util.Date;\r
 import java.util.HashMap;\r
 import java.util.List;\r
@@ -59,8 +58,8 @@ public class ActivityUtils {
         * @param daysBack\r
         *            the number of days back from Now to collect\r
         * @param objectId\r
-        *            the branch to retrieve. If this value is null the default\r
-        *            branch of the repository is used.\r
+        *            the branch to retrieve. If this value is null or empty all\r
+        *            branches are queried.\r
         * @return\r
         */\r
        public static List<Activity> getRecentActivity(List<RepositoryModel> models, int daysBack,\r
@@ -73,64 +72,60 @@ public class ActivityUtils {
                // Build a map of DailyActivity from the available repositories for the\r
                // specified threshold date.\r
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd");\r
+               df.setTimeZone(GitBlit.getTimezone());\r
                Calendar cal = Calendar.getInstance();\r
+               cal.setTimeZone(GitBlit.getTimezone());\r
 \r
                Map<String, Activity> activity = new HashMap<String, Activity>();\r
                for (RepositoryModel model : models) {\r
                        if (model.hasCommits && model.lastChange.after(thresholdDate)) {\r
-                               Repository repository = GitBlit.self().getRepository(model.name);\r
-                               List<RevCommit> commits = JGitUtils.getRevLog(repository, objectId, thresholdDate);\r
-                               Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository);\r
-                               repository.close();\r
-\r
-                               // determine commit branch\r
-                               String branch = objectId;\r
-                               if (StringUtils.isEmpty(branch) && !commits.isEmpty()) {\r
-                                       List<RefModel> headRefs = allRefs.get(commits.get(0).getId());\r
-                                       List<String> localBranches = new ArrayList<String>();\r
-                                       for (RefModel ref : headRefs) {\r
-                                               if (ref.getName().startsWith(Constants.R_HEADS)) {\r
-                                                       localBranches.add(ref.getName().substring(Constants.R_HEADS.length()));\r
-                                               }\r
-                                       }\r
-                                       // determine branch\r
-                                       if (localBranches.size() == 1) {\r
-                                               // only one branch, choose it\r
-                                               branch = localBranches.get(0);\r
-                                       } else if (localBranches.size() > 1) {\r
-                                               if (localBranches.contains("master")) {\r
-                                                       // choose master\r
-                                                       branch = "master";\r
-                                               } else {\r
-                                                       // choose first branch\r
-                                                       branch = localBranches.get(0);\r
-                                               }\r
+                               Repository repository = GitBlit.self()\r
+                                               .getRepository(model.name);\r
+                               List<String> branches = new ArrayList<String>();\r
+                               if (StringUtils.isEmpty(objectId)) {\r
+                                       for (RefModel local : JGitUtils.getLocalBranches(\r
+                                                       repository, true, -1)) {\r
+                                               branches.add(local.getName());\r
                                        }\r
+                               } else {\r
+                                       branches.add(objectId);\r
                                }\r
+                               Map<ObjectId, List<RefModel>> allRefs = JGitUtils\r
+                                               .getAllRefs(repository);\r
 \r
-                               for (RevCommit commit : commits) {\r
-                                       Date date = JGitUtils.getCommitDate(commit);\r
-                                       String dateStr = df.format(date);\r
-                                       if (!activity.containsKey(dateStr)) {\r
-                                               // Normalize the date to midnight\r
-                                               cal.setTime(date);\r
-                                               cal.set(Calendar.HOUR_OF_DAY, 0);\r
-                                               cal.set(Calendar.MINUTE, 0);\r
-                                               cal.set(Calendar.SECOND, 0);\r
-                                               cal.set(Calendar.MILLISECOND, 0);\r
-                                               activity.put(dateStr, new Activity(cal.getTime()));\r
+                               for (String branch : branches) {\r
+                                       String shortName = branch;\r
+                                       if (shortName.startsWith(Constants.R_HEADS)) {\r
+                                               shortName = shortName.substring(Constants.R_HEADS.length());\r
+                                       }\r
+                                       List<RevCommit> commits = JGitUtils.getRevLog(repository,\r
+                                                       branch, thresholdDate);\r
+                                       for (RevCommit commit : commits) {\r
+                                               Date date = JGitUtils.getCommitDate(commit);\r
+                                               String dateStr = df.format(date);\r
+                                               if (!activity.containsKey(dateStr)) {\r
+                                                       // Normalize the date to midnight\r
+                                                       cal.setTime(date);\r
+                                                       cal.set(Calendar.HOUR_OF_DAY, 0);\r
+                                                       cal.set(Calendar.MINUTE, 0);\r
+                                                       cal.set(Calendar.SECOND, 0);\r
+                                                       cal.set(Calendar.MILLISECOND, 0);\r
+                                                       activity.put(dateStr, new Activity(cal.getTime()));\r
+                                               }\r
+                                               RepositoryCommit commitModel = activity.get(dateStr)\r
+                                                               .addCommit(model.name, shortName, commit);\r
+                                               if (commitModel != null) {\r
+                                                       commitModel.setRefs(allRefs.get(commit.getId()));\r
+                                               }\r
                                        }\r
-                                       RepositoryCommit commitModel = activity.get(dateStr).addCommit(model.name,\r
-                                                       branch, commit);\r
-                                       commitModel.setRefs(allRefs.get(commit.getId()));\r
                                }\r
+                               \r
+                               // close the repository\r
+                               repository.close();\r
                        }\r
                }\r
 \r
                List<Activity> recentActivity = new ArrayList<Activity>(activity.values());\r
-               for (Activity daily : recentActivity) {\r
-                       Collections.sort(daily.commits);\r
-               }\r
                return recentActivity;\r
        }\r
 \r
index 634b29855f2487b058521451bdc45dc5ec8abd35..e59e68ee85b61bc5297bb6a42fb072821695fc21 100644 (file)
@@ -79,7 +79,7 @@ public class ActivityPage extends RootPage {
                        int totalCommits = 0;\r
                        Set<String> uniqueAuthors = new HashSet<String>();\r
                        for (Activity activity : recentActivity) {\r
-                               totalCommits += activity.commits.size();\r
+                               totalCommits += activity.getCommitCount();\r
                                uniqueAuthors.addAll(activity.getAuthorMetrics().keySet());\r
                        }\r
                        int totalAuthors = uniqueAuthors.size();\r
@@ -174,7 +174,7 @@ public class ActivityPage extends RootPage {
                                getString("gb.commits"));\r
                SimpleDateFormat df = new SimpleDateFormat("MMM dd");\r
                for (Activity metric : recentActivity) {\r
-                       chart.addValue(df.format(metric.startDate), metric.commits.size());\r
+                       chart.addValue(df.format(metric.startDate), metric.getCommitCount());\r
                }\r
                chart.setWidth(w);\r
                chart.setHeight(h);\r
index 45486195fa2a4de4cb1289163b5d07be5177af1e..34a281fbafb32f6e782e0881ec94374141843760 100644 (file)
@@ -28,7 +28,6 @@ import com.gitblit.Constants;
 import com.gitblit.models.Activity;\r
 import com.gitblit.models.Activity.RepositoryCommit;\r
 import com.gitblit.utils.StringUtils;\r
-import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.pages.CommitDiffPage;\r
 import com.gitblit.wicket.pages.CommitPage;\r
@@ -62,7 +61,7 @@ public class ActivityPanel extends BasePanel {
 \r
                                // display the commits in chronological order\r
                                DataView<RepositoryCommit> commits = new DataView<RepositoryCommit>("commits",\r
-                                               new ListDataProvider<RepositoryCommit>(entry.commits)) {\r
+                                               new ListDataProvider<RepositoryCommit>(entry.getCommits())) {\r
                                        private static final long serialVersionUID = 1L;\r
 \r
                                        public void populateItem(final Item<RepositoryCommit> item) {\r