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