changeset 511:f1fe20ff3c07

Refactor: set closed branch statuses before creating items
author Chris Cannam
date Tue, 18 Oct 2011 11:33:58 +0100
parents c623ce6b3104
children 67d18eaca830
files src/grapher.cpp
diffstat 1 files changed, 30 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/grapher.cpp	Tue Oct 18 11:30:00 2011 +0100
+++ b/src/grapher.cpp	Tue Oct 18 11:33:58 2011 +0100
@@ -419,6 +419,34 @@
             parent->addChild(id);
         }
     }
+    
+    // Ensure the closed branches are all marked as closed
+
+    foreach (QString closedId, m_closedIds) {
+        
+        if (!m_changesets.contains(closedId)) continue;
+        
+        Changeset *cs = m_changesets[closedId];
+        QString branch = cs->branch();
+
+        while (cs) {
+
+            if (cs->children().size() > 1 || !cs->isOnBranch(branch)) {
+                break;
+            }
+
+            cs->setClosed(true);
+
+            if (cs->parents().size() >= 1) {
+                //!!! this is wrong, not adequate for merges in-branch
+                QString pid = cs->parents()[0];
+                if (!m_changesets.contains(pid)) break;
+                cs = m_changesets[pid];
+            } else {
+                cs = 0;
+            }
+        }
+    }
 
     // Create (but don't yet position) the changeset items
 
@@ -432,37 +460,11 @@
         m_scene->addChangesetItem(item);
     }
     
-    // Ensure the closed branches are all marked as closed
+    // Ensure the closing changeset items are appropriately marked
 
     foreach (QString closedId, m_closedIds) {
-        
         if (!m_items.contains(closedId)) continue;
-        
-        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 || !cs->isOnBranch(branch)) {
-                break;
-            }
-
-            cs->setClosed(true);
-
-            int pcount = cs->parents().size();
-            if (pcount >= 1) {
-                QString pid = cs->parents()[0];
-                if (!m_items.contains(pid)) break;
-                cs = m_changesets[pid];
-                item = m_items[pid];
-            } else {
-                item = 0;
-            }
-        }
+        m_items[closedId]->setClosingCommit(true);
     }
 
     // Add the connecting lines