|
31 | 31 | [(c) (in-list v)])
|
32 | 32 | (hash-update ht c (lambda (p) (cons k p)) null)))
|
33 | 33 |
|
| 34 | + ;; One particular path that we sync forks to: |
34 | 35 | (define main-line-commits
|
35 | 36 | (let loop ([a head-commit])
|
36 | 37 | (cons a
|
|
43 | 44 | (for/hash ([f (in-list main-line-commits)])
|
44 | 45 | (values f #t)))
|
45 | 46 |
|
46 |
| - (define (advance-to-main commit) |
| 47 | + ;; To find a commit that is on all paths from head to the initial |
| 48 | + ;; commit: |
| 49 | + (define (find-newest-older-cut p) |
| 50 | + (define (can-reach-root-without? without) |
| 51 | + (define seen (make-hash)) |
| 52 | + (let loop ([p head-commit]) |
| 53 | + (cond |
| 54 | + [(hash-ref seen p #f) |
| 55 | + #f] |
| 56 | + [else |
| 57 | + (hash-set! seen p #t) |
| 58 | + (define ps (hash-ref commit->parents p)) |
| 59 | + (or (null? ps) |
| 60 | + (for/or ([p (in-list ps)]) |
| 61 | + (and (not (equal? p without)) |
| 62 | + (loop p))))]))) |
| 63 | + (let loop ([p p]) |
| 64 | + (if (can-reach-root-without? p) |
| 65 | + (loop (car (hash-ref commit->parents p))) |
| 66 | + p))) |
| 67 | + |
| 68 | + (define (advance-to-main/newer commit) |
47 | 69 | (if (hash-ref commit->main? commit #f)
|
48 | 70 | commit
|
49 |
| - (advance-to-main (car (hash-ref commit->children commit))))) |
50 |
| - |
| 71 | + (advance-to-main/newer (car (hash-ref commit->children commit))))) |
| 72 | + |
| 73 | + (define (advance-to-main/older commit) |
| 74 | + (if (hash-ref commit->main? commit #f) |
| 75 | + commit |
| 76 | + (advance-to-main/older (car (hash-ref commit->parents commit))))) |
| 77 | + |
51 | 78 | (define files
|
52 | 79 | (for/list ([f (in-directory subdir)]
|
53 | 80 | #:when (file-exists? f))
|
|
86 | 113 | (when (and in-commit prev-name)
|
87 | 114 | (printf "~a : ~a...~a^\n" prev-name start-commit in-commit)
|
88 | 115 | (hash-set! lifetimes prev-name (cons start-commit in-commit))
|
89 |
| - (find-lifetime! current-name (advance-to-main in-commit)) |
| 116 | + (find-lifetime! current-name (advance-to-main/newer in-commit)) |
90 | 117 | (set! done? #t)))
|
91 | 118 | (void
|
92 | 119 | (filter-input
|
|
165 | 192 | (write (for/hash ([(k v) (in-hash commit->actions)])
|
166 | 193 | (values (string->bytes/utf-8 k) v)))))
|
167 | 194 |
|
168 |
| - (define oldest-relevant |
| 195 | + (define oldest-relevant-commit |
169 | 196 | (let ([advanced-relevants
|
170 | 197 | (for/hash ([c (in-hash-keys relevants)])
|
171 |
| - (values (advance-to-main c) #t))]) |
| 198 | + (values (advance-to-main/older c) #t))]) |
172 | 199 | (let loop ([cs main-line-commits] [c head-commit])
|
173 | 200 | (cond
|
174 | 201 | [(null? cs) c]
|
175 | 202 | [(hash-ref advanced-relevants (car cs) #f)
|
176 | 203 | (loop (cdr cs) (car cs))]
|
177 | 204 | [else (loop (cdr cs) c)]))))
|
| 205 | + (printf "Looking for cut older than ~a...\n" oldest-relevant-commit) |
| 206 | + (define oldest-relevant |
| 207 | + (find-newest-older-cut oldest-relevant-commit)) |
| 208 | + |
178 | 209 | (printf "relevant commits bounded by ~a\n" oldest-relevant)
|
179 | 210 | (hash-set! relevants oldest-relevant #t)
|
180 | 211 |
|
|
0 commit comments