git.fiddlerwoaroof.com
Browse code

fix: deduplicate rev-list

Edward Langley authored on 22/10/2023 09:36:53
Showing 1 changed files
... ...
@@ -156,15 +156,20 @@
156 156
   "Return the commits reachable from the ref."
157 157
   (when limit-p
158 158
     (rotatef ref-id limit))
159
-  (labels ((iterate (queue accum &optional (count 0))
160
-             (if (or (when limit-p
161
-                       (= limit count))
162
-                     (null queue))
163
-                 accum
164
-                 (destructuring-bind (next . rest) queue
165
-                   (iterate (append rest
166
-                                    (co.fwoar.git::parents next))
167
-                     (cons next accum)
168
-                     (1+ count))))))
169
-    (iterate (list (ensure-ref ref-id))
170
-      ())))
159
+  (let ((seen (make-hash-table)))
160
+    (labels ((iterate (queue accum &optional (count 0))
161
+               (if (or (when limit-p
162
+                         (= limit count))
163
+                       (null queue))
164
+                   accum
165
+                   (destructuring-bind (next . rest) queue
166
+                     (let ((parents (co.fwoar.git::parents next)))
167
+                       (iterate (append rest parents)
168
+                         (if (gethash next seen)
169
+                             accum
170
+                             (progn
171
+                               (setf (gethash next seen) t)
172
+                               (cons next accum)))
173
+                         (1+ count)))))))
174
+      (iterate (list (ensure-ref ref-id))
175
+        ()))))