libgit2 / libgit2-backends

Standalone ODB backends for the libgit2 library
191 stars 54 forks source link

mysql backend question: should oid = sha1(data) ? #9

Closed quantjin closed 9 years ago

quantjin commented 9 years ago

Hello, libgit2 team

First, great project!

I have a question regarding the mysql backend: This is the code to create a blob from buffer, it's a string.

const char str[] = "Hello, World!";
git_blob_create_frombuffer(&oid, mysql_odb_backend->repo, str, strlen(str));

The blob successfully inserted to the odb table, the uncompress(data) is the string content

But I don't understand the oid column value, as according to git concept, it's sha1 value of the data content, please correct me if I'm wrong.

So I did a validation

select  lower(hex(oid)),
        type, 
        size, 
        convert(uncompress(data),char(100)),
        sha1(uncompress(data))
from git2_odb

result:

lower(hex(oid)) type size convert(uncompress(data),char(100)) sha1(uncompress(data))
b45ef6fec89518d314f546fd6c3025367b721684 3 13 Hello, World! 0a0a9f2a6772942557ab5355d76af442f8f65e01

I found that the hex oid value is not the same as sha1 data, is this correct? or I'm doing it in the wrong way?

Thank you!

Best Regards, Jerry