Commits

evhan  committed 86e31cb

use begin0 idiom for git_*_foreach iterators

  • Participants
  • Parent commits 4552c05

Comments (0)

Files changed (1)

                             (,(s+ 'git- getter) (,->pointer obj)))))))
                   attrs))))))
 
+(define-syntax begin0-let
+  (syntax-rules ()
+    ((_ ((n e) . rest) . body)
+     (let ((n e) . rest) (begin . body) n))))
+
 (define ((git-record-attribute-setter f) r v) (f (object->pointer r) v))
 (define ((set-owner m f) o) (m o (f o)))
 (define ((preserve-owner m f) o) (m (object-owner o) (f o)))
   (pointer->reference repo (git-reference-lookup (repository->pointer repo) name)))
 
 (define (references-fold kons knil repo #!optional (type 'all))
-  (let ((state knil))
+  (begin0-let ((state knil))
     (git-reference-foreach-name
      (repository->pointer repo)
      (lambda (name)
                 (git-reference-lookup
                  (repository->pointer repo)
                  name))
-               state))))
-    state))
+               state))))))
 
 (define (references repo #!optional (type 'all))
   (references-fold cons '() repo type))
   (git-status-should-ignore (repository->pointer repo) path))
 
 (define (file-statuses-fold kons knil repo)
-  (let ((state knil))
+  (begin0-let ((state knil))
     (git-status-foreach
      (lambda (path status)
        (set! state (kons path status state)))
-     (repository->pointer repo))
-    state))
+     (repository->pointer repo))))
 
 (define (file-statuses repo)
   (file-statuses-fold
         ;; If the notes reference doesn't exist, return knil immediately.
         (if (not (reference-exists? repo* (or reference (git-note-default-ref repo*))))
             knil
-            (let ((state knil))
+            (begin0-let ((state knil))
               (git-note-foreach
                repo*
                reference
                (lambda (bid* oid*)
                  (set! state
-                   (kons (pointer->note repo (git-note-read repo* reference oid*)) state))))
-              state))))))
+                   (kons (pointer->note repo (git-note-read repo* reference oid*)) state))))))))))
 
 (define (notes repo #!optional reference)
   (notes-fold cons '() repo reference))
     (->oid->pointer ref))))
 
 (define (tags-fold kons knil repo)
-  (let ((state knil))
+  (begin0-let ((state knil))
     (git-tag-foreach
      (lambda (name oid*)
        (set! state
                  (repository->pointer repo)
                  oid*))
                state)))
-     (repository->pointer repo))
-    state))
+     (repository->pointer repo))))
 
 (define (tags repo)
   (tags-fold cons '() repo))