Browse code
Move branch-manipulation to its own place
Ed Langley authored on 06/05/2019 06:53:53
Showing 3 changed files
Showing 3 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,40 @@ |
1 |
+(in-package :fwoar.cl-git) |
|
2 |
+ |
|
3 |
+(defun get-local-unpacked-branches (root) |
|
4 |
+ (mapcar (data-lens:juxt #'pathname-name |
|
5 |
+ (alexandria:compose #'serapeum:trim-whitespace |
|
6 |
+ #'alexandria:read-file-into-string)) |
|
7 |
+ (uiop:directory* |
|
8 |
+ (merge-pathnames ".git/refs/heads/*" |
|
9 |
+ root)))) |
|
10 |
+ |
|
11 |
+(defun get-local-packed-branches (root) |
|
12 |
+ (let* ((packed-ref-file-name (merge-pathnames ".git/packed-refs" |
|
13 |
+ root))) |
|
14 |
+ (when (probe-file packed-ref-file-name) |
|
15 |
+ (with-open-file (s packed-ref-file-name) |
|
16 |
+ (loop for line = (read-line s nil) |
|
17 |
+ for parts = (partition #\space line) |
|
18 |
+ for branch-name = (second parts) |
|
19 |
+ while line |
|
20 |
+ unless (alexandria:starts-with-subseq "#" line) |
|
21 |
+ when (alexandria:starts-with-subseq "refs/heads" branch-name) |
|
22 |
+ collect (list (subseq branch-name |
|
23 |
+ (1+ (position #\/ branch-name |
|
24 |
+ :from-end t))) |
|
25 |
+ (first parts))))))) |
|
26 |
+ |
|
27 |
+(defun get-local-branches (root) |
|
28 |
+ (append (get-local-unpacked-branches root) |
|
29 |
+ (get-local-packed-branches root))) |
|
30 |
+ |
|
31 |
+(defgeneric branches (repository) |
|
32 |
+ (:method ((repository repository)) |
|
33 |
+ (get-local-branches (root repository)))) |
|
34 |
+ |
|
35 |
+(defgeneric branch (repository name) |
|
36 |
+ (:method ((repository repository) name) |
|
37 |
+ (second |
|
38 |
+ (find name (get-local-branches (root repository)) |
|
39 |
+ :test 'equal |
|
40 |
+ :key 'car)))) |
... | ... |
@@ -16,17 +16,6 @@ |
16 | 16 |
(defun turn-read-object-to-string (object) |
17 | 17 |
(data-lens.lenses:over *object-data-lens* 'babel:octets-to-string object)) |
18 | 18 |
|
19 |
-(defgeneric branches (repository) |
|
20 |
- (:method ((repository repository)) |
|
21 |
- (get-local-branches (root repository)))) |
|
22 |
- |
|
23 |
-(defgeneric branch (repository name) |
|
24 |
- (:method ((repository repository) name) |
|
25 |
- (second |
|
26 |
- (find name (get-local-branches (root repository)) |
|
27 |
- :test 'equal |
|
28 |
- :key 'car)))) |
|
29 |
- |
|
30 | 19 |
(defgeneric object (repository id) |
31 | 20 |
(:method ((repository repository) id) |
32 | 21 |
(car |
... | ... |
@@ -28,30 +28,6 @@ |
28 | 28 |
(defun repository (root) |
29 | 29 |
(fw.lu:new 'repository root)) |
30 | 30 |
|
31 |
-(defun get-local-unpacked-branches (root) |
|
32 |
- (mapcar (data-lens:juxt #'pathname-name |
|
33 |
- (alexandria:compose #'serapeum:trim-whitespace |
|
34 |
- #'alexandria:read-file-into-string)) |
|
35 |
- (uiop:directory* |
|
36 |
- (merge-pathnames ".git/refs/heads/*" |
|
37 |
- root)))) |
|
38 |
- |
|
39 |
-(defun get-local-packed-branches (root) |
|
40 |
- (let* ((packed-ref-file-name (merge-pathnames ".git/packed-refs" |
|
41 |
- root))) |
|
42 |
- (when (probe-file packed-ref-file-name) |
|
43 |
- (with-open-file (s packed-ref-file-name) |
|
44 |
- (loop for line = (read-line s nil) |
|
45 |
- for parts = (partition #\space line) |
|
46 |
- for branch-name = (second parts) |
|
47 |
- while line |
|
48 |
- unless (alexandria:starts-with-subseq "#" line) |
|
49 |
- when (alexandria:starts-with-subseq "refs/heads" branch-name) |
|
50 |
- collect (list (subseq branch-name |
|
51 |
- (1+ (position #\/ branch-name |
|
52 |
- :from-end t))) |
|
53 |
- (first parts))))))) |
|
54 |
- |
|
55 | 31 |
(defun get-local-branches (root) |
56 | 32 |
(append (get-local-unpacked-branches root) |
57 | 33 |
(get-local-packed-branches root))) |