Commits

evhan committed e0774d1

remove unnecessary wind in commit-create

Comments (0)

Files changed (1)

 (define commit-parentcount      (foreign-lambda unsigned-int git_commit_parentcount commit))
 (define commit-parent-id        (foreign-lambda oid git_commit_parent_id commit unsigned-int))
 
-(define (pack-commit-pointer-array ptrs)
-  ((foreign-lambda* (c-pointer commit) ((scheme-object ptrs) (int len))
-    "int i;
-     C_word iter;
-     git_commit **out = malloc(sizeof(git_commit *) * len);
-     for(i = 0, iter = ptrs; i < len; i++, iter = C_u_i_cdr(iter))
-       out[i] = (git_commit *) C_pointer_address(C_u_i_car(iter));
-     C_return(out);")
-    ptrs
-    (length ptrs)))
+(define pack-commit-pointer-array
+  (foreign-lambda* (c-pointer commit) ((scheme-object ptrs) (int len))
+   "int i;
+    C_word iter;
+    git_commit **out = malloc(sizeof(git_commit *) * len);
+    for(i = 0, iter = ptrs; i < len; i++, iter = C_u_i_cdr(iter))
+      out[i] = (git_commit *) C_pointer_address(C_u_i_car(iter));
+    C_return(out);"))
 
 (define (commit-create repo ref author commit msg tree parents)
-  (let ((parents* #f))
-    (dynamic-wind
-     (lambda ()
-       (set! parents* (pack-commit-pointer-array parents)))
-     (lambda ()
-       ((foreign-lambda/allocate oid git_commit_create
-         repository c-string signature signature c-string nonnull-c-string tree int              (c-pointer (const commit)))
-         repo       ref      author    commit    #f       msg              tree (length parents) parents*))
-     (lambda ()
-       (free parents*)))))
+  (let* ((parent-count (length parents))
+         (parent-array (pack-commit-pointer-array parents parent-count))
+         (commit-oid
+          ((foreign-lambda/allocate oid git_commit_create
+            repository c-string signature signature c-string nonnull-c-string tree int          (c-pointer (const commit)))
+            repo       ref      author    commit    #f       msg              tree parent-count parent-array)))
+    (free parent-array)
+    commit-oid))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; common.h