        commit-graph->nodes
        distinct-nodes
        nodes->order
-       find-merge-links)
+       find-merge-links
+       nodes->links)
 
   )

    (assoc cg
      :nodes
      (->> new-nodes
           (map (fn [[k v]] [k (rest v)]))
           (into {}))
      :branch-links
      (->> new-nodes
           (map (fn [[k v]] [k (if (nil? (first v))
                                nil
                                (take 2 v))]))
           (into {})))))


(defn find-merge-links [{:keys [causal-order branches] :as cg}]
  (let [branch-heads (into {} (map (fn [[k v]] [v k]) branches))]
    (update-in cg [:merge-links]
      (->> causal-order
           (filter-map [key val] (> (count val) 1))
           (into {})

           (into {})))))


(defn nodes->links [{:keys [nodes] :as cg}]
  (assoc cg
    :links
    (->> nodes
         (map
          (fn [[k v]]
            [k
             (map
              (fn [i]
                [(get v i) (get v (inc i))])
              (range (count v)))])))))

(comment

