James Moger
2011-06-25 22fc5e48cbe050d8485f78f6165b59e4085eaeef
src/com/gitblit/utils/MetricUtils.java
@@ -39,19 +39,22 @@
   private static final Logger LOGGER = LoggerFactory.getLogger(MetricUtils.class);
   public static List<Metric> getDateMetrics(Repository r, boolean includeTotal, String format) {
   public static List<Metric> getDateMetrics(Repository r, String objectId, boolean includeTotal,
         String format) {
      Metric total = new Metric("TOTAL");
      final Map<String, Metric> metricMap = new HashMap<String, Metric>();
      if (StringUtils.isEmpty(objectId)) {
         objectId = Constants.HEAD;
      }
      if (JGitUtils.hasCommits(r)) {
         final List<RefModel> tags = JGitUtils.getTags(r, -1);
         final List<RefModel> tags = JGitUtils.getTags(r, true, -1);
         final Map<ObjectId, RefModel> tagMap = new HashMap<ObjectId, RefModel>();
         for (RefModel tag : tags) {
            tagMap.put(tag.getReferencedObjectId(), tag);
         }
         try {
            RevWalk walk = new RevWalk(r);
            ObjectId object = r.resolve(Constants.HEAD);
            ObjectId object = r.resolve(objectId);
            RevCommit lastCommit = walk.parseCommit(object);
            walk.markStart(lastCommit);
@@ -62,12 +65,9 @@
               int diffDays = (lastCommit.getCommitTime() - firstCommit.getCommitTime())
                     / (60 * 60 * 24);
               total.duration = diffDays;
               if (diffDays <= 90) {
               if (diffDays <= 365) {
                  // Days
                  df = new SimpleDateFormat("yyyy-MM-dd");
               } else if (diffDays > 90 && diffDays < 365) {
                  // Weeks
                  df = new SimpleDateFormat("yyyy-MM (w)");
               } else {
                  // Months
                  df = new SimpleDateFormat("yyyy-MM");
@@ -108,13 +108,15 @@
      return metrics;
   }
   public static List<Metric> getAuthorMetrics(Repository r, boolean byEmail) {
   public static List<Metric> getAuthorMetrics(Repository r, String objectId, boolean byEmail) {
      final Map<String, Metric> metricMap = new HashMap<String, Metric>();
      if (StringUtils.isEmpty(objectId)) {
         objectId = Constants.HEAD;
      }
      if (JGitUtils.hasCommits(r)) {
         try {
            RevWalk walk = new RevWalk(r);
            ObjectId object = r.resolve(Constants.HEAD);
            ObjectId object = r.resolve(objectId);
            RevCommit lastCommit = walk.parseCommit(object);
            walk.markStart(lastCommit);
@@ -122,14 +124,14 @@
            for (RevCommit rev : revlog) {
               String p;
               if (byEmail) {
                  p = rev.getAuthorIdent().getEmailAddress();
                  p = rev.getAuthorIdent().getEmailAddress().toLowerCase();
                  if (StringUtils.isEmpty(p)) {
                     p = rev.getAuthorIdent().getName();
                     p = rev.getAuthorIdent().getName().toLowerCase();
                  }
               } else {
                  p = rev.getAuthorIdent().getName();
                  p = rev.getAuthorIdent().getName().toLowerCase();
                  if (StringUtils.isEmpty(p)) {
                     p = rev.getAuthorIdent().getEmailAddress();
                     p = rev.getAuthorIdent().getEmailAddress().toLowerCase();
                  }
               }
               if (!metricMap.containsKey(p)) {