evhan committed d3bf2b2

Add glob pattern argument for filtering references-fold

  • Participants
  • Parent commits f8e1f8b

Comments (0)

Files changed (4)

File git-lolevel-exports.scm

+ reference-foreach-glob

File git-lolevel.scm

        repository reference-foreach-name-cb            c-pointer)
        repo       (location reference_foreach_name_cb) callback))))
+(define (reference-foreach-glob repo glob f)
+  (let-handle ((callback f))
+    (guard-errors git_reference_foreach_name
+     ((foreign-safe-lambda int git_reference_foreach_glob
+       repository nonnull-c-string reference-foreach-name-cb            c-pointer)
+       repo       glob             (location reference_foreach_name_cb) callback))))
 ;;; refspec.h
 (define (reference repo name)
   (pointer->reference repo (git-reference-lookup (repository->pointer repo) name)))
-(define (references-fold kons knil repo #!optional (type 'all))
+(define (references-fold kons knil repo #!optional glob)
   (begin0-let ((state knil))
-    (git-reference-foreach-name
-     (repository->pointer repo)
-     (lambda (name)
-       (set! state
-         (kons (pointer->reference
-                repo
-                (git-reference-lookup
-                 (repository->pointer repo)
-                 name))
-               state))))))
-(define (references repo #!optional (type 'all))
-  (references-fold cons '() repo type))
+    (let* ((*repo    (repository->pointer repo))
+           (callback (lambda (name)
+                       (set! state
+                         (kons (pointer->reference
+                                repo
+                                (git-reference-lookup *repo name))
+                               state)))))
+      (cond
+        (glob (git-reference-foreach-glob *repo glob callback))
+        (else (git-reference-foreach-name *repo callback))))))
+(define (references repo #!optional glob)
+  (references-fold cons '() repo glob))
 (define (create-reference repo #!key name target symbolic force)
   (let ((repo* (repository->pointer repo)))
 reference is a {{remote}}, {{branch}}, or {{tag}}-type reference,
-<procedure>(references-fold kons knil repository [type]) => object</procedure>
+<procedure>(references-fold kons knil repository [glob]) => object</procedure>
 Folds over the given {{repository}}'s references in unspecified order.
-An optional {{type}} symbol may be provided to limit the types of
-references returnd, and may be one of the symbols {{oid}},
-{{symbolic}}, or {{all}}. If no {{type}} is given, {{all}} is used.
+An optional {{glob}} pattern string may be used to filter the references
+returned. If given, it will be matched in "glob" style where a {{#\?}}
+matches any letter, a {{#\*}} matches any sequence of letters, and
+square brackets match a range of characters (such as "[0-9]" for
+digits). If no {{glob}} is given, all references will be provided to
 <procedure>(references repository [type]) => (list-of reference)</procedure>