Commits

Matthew Watson [Atlassian]  committed 726eb54

Add code to correctly determine if a CS is a branch head, but doesn't work cause no CSdao passed to formatter yet

  • Participants
  • Parent commits 4836b88

Comments (0)

Files changed (2)

File src/main/java/com/atlassian/fisheye/reports/RevSetReportServlet.java

         context.put("webItemKey", "revset-report-tab");
         context.put("errors", new LinkedHashSet<String>());
         context.put("encoder", new XmlEncoder());
-        context.put("formatter", new Formatter());
+        context.put("formatter", new Formatter(getChangesetDao(null))); // TODO Need this to be passed in to determine if a CS is a branch head at render time
         context.put("userMappingService", userMappingService);
         context.put("models", models);
         return context;

File src/main/java/com/atlassian/fisheye/reports/util/Formatter.java

 package com.atlassian.fisheye.reports.util;
 
 import com.cenqua.fisheye.rep.ChangeSet;
+import com.cenqua.fisheye.rep.FileRevision;
+import com.cenqua.fisheye.rep.impl.CommonChangeSetDAO;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
 public class Formatter {
 
+    private final CommonChangeSetDAO<? extends FileRevision, ? extends ChangeSet, ?> csdao;
+
+    public Formatter(CommonChangeSetDAO<? extends FileRevision, ? extends ChangeSet, ?> csdao) {
+        this.csdao = csdao;
+    }
+    
     public String formatDate(Date date, String format) {
         SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US);
         return formatter.format(date);
     }
     
     public String briefCSName(ChangeSet changeSet) {
+        if (changeSet.getTags() != null && changeSet.getTags().size() > 0) {
+            return "<span class=\"tag-lozenge highlight-lozenge\">" + changeSet.getTags().iterator().next() + "</span>";
+        }
         if (changeSet.getChildren() == null || changeSet.getChildren().size() == 0) {
             return "head of <span class=\"icon-branch\">" + changeSet.getBranch() + "</span>";
-        }
-        if (changeSet.getTags() != null && changeSet.getTags().size() > 0) {
-            return "<span class=\"tag-lozenge highlight-lozenge\">" + changeSet.getTags().iterator().next() + "</span>";
+        } else {
+            if (csdao != null) {
+                boolean ishead = true;
+                for (String childId : changeSet.getChildren()) {
+                    ChangeSet child = csdao.getChangeSet(childId);
+                    for (String branch : child.getBranches()) {
+                        if (branch.equals(changeSet.getBranch())) {
+                            ishead = false;
+                        }
+                    }
+                }
+                if (ishead) {
+                    return "head of <span class=\"icon-branch\">" + changeSet.getBranch() + "</span>";
+                }
+                }
         }
         return changeSet.getDisplayId();
     }