I think I may have come across a bug in the git egg.
klm@pisa ~/.c/chicken-install> chicken-status | grep git
git ......................................................... version: 0.1.0
klm@pisa ~/.c/chicken-install> csi -R git -P '(define r (create-repository "/tmp/repo")) (create-blob r #${abba})'
#<unspecified>
Error: bad argument count - received 2 but expected 3: #<procedure>
...
I have managed to put together this patch which seems to fix the problem:
klm@pisa ~/.c/c/git (master)> git diff
diff --git a/git.scm b/git.scm
index b33cd45..c8762d1 100644
--- a/git.scm
+++ b/git.scm
@@ -785,7 +785,7 @@
(git-blob-lookup
repo*
(cond ((chicken-blob? source)
- (git-blob-create-frombuffer repo* source))
+ (git-blob-create-frombuffer repo* source (number-of-bytes source)))
((string? source)
(if (regular-file? source)
(git-blob-create-fromdisk repo* source)
diff --git a/libgit2.scm b/libgit2.scm
index a1e095c..0c724dd 100644
--- a/libgit2.scm
+++ b/libgit2.scm
@@ -295,7 +295,7 @@
(define blob-lookup-prefix (foreign-lambda/allocate blob* git_blob_lookup_prefix repository oid unsigned-int))
(define blob-create-fromdisk (foreign-lambda/allocate oid git_blob_create_fromdisk repository nonnull-c-string))
(define blob-create-fromworkdir (foreign-lambda/allocate oid git_blob_create_fromworkdir repository nonnull-c-string))
-(define blob-create-frombuffer (foreign-lambda/allocate oid git_blob_create_frombuffer repository nonnull-c-string unsigned-int))
+(define blob-create-frombuffer (foreign-lambda/allocate oid git_blob_create_frombuffer repository nonnull-scheme-pointer unsigned-int))
(define blob-id (foreign-lambda/copy oid git_blob_id blob*))
(define blob-free (foreign-lambda void git_blob_free blob*))
(define blob-rawcontent (foreign-lambda c-pointer git_blob_rawcontent blob*))
@@ -303,9 +303,9 @@
(define blob-is-binary (foreign-lambda bool git_blob_is_binary blob*))
(define blob*-lookup blob-lookup)
-(define blob*-create-frombuffer blob-create-fromdisk)
-(define blob*-create-fromdisk blob-create-fromworkdir)
-(define blob*-create-fromworkdir blob-create-frombuffer)
+(define blob*-create-frombuffer blob-create-frombuffer)
+(define blob*-create-fromdisk blob-create-fromdisk)
+(define blob*-create-fromworkdir blob-create-fromworkdir)
(define blob*-free blob-free)
(define blob*-id blob-id)
(define blob*-is-binary blob-is-binary)
The fix has 3 parts:
- adding the missing number-of-bytes to blob-create-frombuffer
- changes blob-create-frombuffer signature to accept nonnull-scheme-pointer instead of nonnull-c-string so that we don't have to blob->string
- rearranges mismatched fromworkdir, frombuffer and fromdisk (although I don't know if that's necessary to fix the problem above)
I don't know if this is sufficient to qualify for a commit upstream, but now my code snippet works:
klm@pisa /t/repo (master)> csi -R git -P '(define r (create-repository "/tmp/repo")) (create-blob r #${abba})'
#<unspecified>
#<blob "79efd60">
klm@pisa /t/repo (master)> git cat-file blob 79efd60 | xxd
00000000: abba ..
I'm hoping this can be looked into.
Thanks,
K.