changeset 509:6f371814509d

Refactor: sort out changeset structure and parent-child relationships before anything else in grapher. Also stop marking changesets as closed when we reach a change of branch name
author Chris Cannam
date Tue, 18 Oct 2011 11:21:20 +0100
parents c43880dfdb78
children c623ce6b3104
files src/grapher.cpp
diffstat 1 files changed, 37 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/grapher.cpp	Tue Oct 18 11:10:20 2011 +0100
+++ b/src/grapher.cpp	Tue Oct 18 11:21:20 2011 +0100
@@ -391,7 +391,7 @@
 
     if (csets.empty()) return;
 
-    // Create (but don't yet position) the changeset items
+    // Initialise changesets hash
 
     foreach (Changeset *cs, csets) {
 
@@ -407,7 +407,23 @@
         }
 
         m_changesets[id] = cs;
+    }
+    
+    // Set the children for each changeset
 
+    foreach (Changeset *cs, csets) {
+        QString id = cs->id();
+        foreach (QString parentId, cs->parents()) {
+            if (!m_changesets.contains(parentId)) continue;
+            Changeset *parent = m_changesets[parentId];
+            parent->addChild(id);
+        }
+    }
+
+    // Create (but don't yet position) the changeset items
+
+    foreach (Changeset *cs, csets) {
+        QString id = cs->id();
         ChangesetItem *item = new ChangesetItem(cs);
         item->setX(0);
         item->setY(0);
@@ -415,25 +431,6 @@
         m_items[id] = item;
         m_scene->addChangesetItem(item);
     }
-
-    // Add the connecting lines
-
-    foreach (Changeset *cs, csets) {
-        QString id = cs->id();
-        ChangesetItem *item = m_items[id];
-        bool merge = (cs->parents().size() > 1);
-        foreach (QString parentId, cs->parents()) {
-            if (!m_changesets.contains(parentId)) continue;
-            Changeset *parent = m_changesets[parentId];
-            parent->addChild(id);
-            ConnectionItem *conn = new ConnectionItem();
-            if (merge) conn->setConnectionType(ConnectionItem::Merge);
-            conn->setChild(item);
-            conn->setParent(m_items[parentId]);
-            conn->setZValue(-1);
-            m_scene->addItem(conn);
-        }
-    }
     
     // Ensure the closed branches are all marked as closed
 
@@ -444,11 +441,13 @@
         Changeset *cs = m_changesets[closedId];
         ChangesetItem *item = m_items[closedId];
 
+        QString branch = cs->branch();
+
         item->setClosingCommit(true);
 
         while (cs && item) {
 
-            if (cs->children().size() > 1) {
+            if (cs->children().size() > 1 || !cs->isOnBranch(branch)) {
                 break;
             }
 
@@ -466,6 +465,23 @@
         }
     }
 
+    // Add the connecting lines
+
+    foreach (Changeset *cs, csets) {
+        QString id = cs->id();
+        ChangesetItem *item = m_items[id];
+        bool merge = (cs->parents().size() > 1);
+        foreach (QString parentId, cs->parents()) {
+            if (!m_changesets.contains(parentId)) continue;
+            ConnectionItem *conn = new ConnectionItem();
+            if (merge) conn->setConnectionType(ConnectionItem::Merge);
+            conn->setChild(item);
+            conn->setParent(m_items[parentId]);
+            conn->setZValue(-1);
+            m_scene->addItem(conn);
+        }
+    }
+
     // Add uncommitted item and connecting line as necessary
 
     if (!m_uncommittedParents.empty()) {