Skip to content

Instantly share code, notes, and snippets.

@chobie
Created December 25, 2010 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chobie/754646 to your computer and use it in GitHub Desktop.
Save chobie/754646 to your computer and use it in GitHub Desktop.
git clone https://github.com/libgit2/libgit2.git libgit2
cd libgit2
./waf configure
./waf build-shared
./waf install-shared
# see also
# http://libgit2.github.com/api.html#index
# libgit2を使ったgitのインデックスファイルの捜査でSegmentation Faultが起きちゃう。
cat > git_index.c <<EOF
#include <stdio.h>
#include <git2.h>
#include <string.h>
int main(int argc, char * args[])
{
git_index_entry *entry;
git_index *index;
git_index_open_bare(&index,args[1]);
int ret = git_index_read(index);
printf("%d\n",ret);
int ecount = git_index_entrycount(index);
int offset = git_index_find(index,"README.md");
printf("%d:%d\n",ecount,offset);
entry = git_index_get(index,offset);
if(entry == NULL){
fprintf(stderr, "エントリがみつからないお><\n");
return -1;
}else{
printf("mtime: %d\n", (int)entry->mtime.seconds);
printf("file_size: %d\n", (int)entry->file_size);
//ここでSegmentation Faultが起きちゃう
printf("path: %s\n",entry->path);
}
return 0;
}
EOF
# [shell] gcc -o git_index -Wall -lgit2 git_index.c
# [shell] ./git_index ./.git/index
# mtime: 1293196934
# file_size: 4481
# Segmentation fault
#
# 誰か助けてヘルプミー><
# https://github.com/libgit2/rugged/blob/master/ext/rugged/rugged_index.c
# でruggedのgit_index_getの使い方を見る限りおそらく使い方としては
# 正しいとは思うんだけれどpathをみようとするとSegmentation Faultしちゃう。
# http://libgit2.github.com/api.html#indexが古いのでもしかしたら
# そもそもの使い方が間違っているかもしれない。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment