Commit 96da90ae by Scott Chacon

update examples content to be compilable and up to date

parent 2e6d8ec4
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"input": "include/git2", "input": "include/git2",
"prefix": "git_", "prefix": "git_",
"output": "docs", "output": "docs",
"xbranch": "gh-pages", "branch": "gh-pages",
"examples": "examples", "examples": "examples",
"legacy": { "legacy": {
"input": {"src/git": ["v0.1.0"], "input": {"src/git": ["v0.1.0"],
......
general
showindex
all: general showindex
general : general.c
gcc -lgit2 -o general general.c
showindex : showindex.c
gcc -lgit2 -o showindex showindex.c
clean:
rm general showindex
...@@ -246,7 +246,7 @@ int main (int argc, char** argv) ...@@ -246,7 +246,7 @@ int main (int argc, char** argv)
printf("\n*Tree Parsing*\n"); printf("\n*Tree Parsing*\n");
git_tree *tree; git_tree *tree;
git_tree_entry *entry; const git_tree_entry *entry;
git_object *objt; git_object *objt;
// Create the oid and lookup the tree object just like the other objects. // Create the oid and lookup the tree object just like the other objects.
...@@ -356,7 +356,7 @@ int main (int argc, char** argv) ...@@ -356,7 +356,7 @@ int main (int argc, char** argv)
// You can either open the index from the standard location in an open repository, as we're doing // You can either open the index from the standard location in an open repository, as we're doing
// here, or you can open and manipulate any index file with `git_index_open_bare()`. The index // here, or you can open and manipulate any index file with `git_index_open_bare()`. The index
// for the repository will be located and loaded from disk. // for the repository will be located and loaded from disk.
git_index_open_inrepo(&index, repo); git_repository_index(&index, repo);
// For each entry in the index, you can get a bunch of information including the SHA (oid), path // For each entry in the index, you can get a bunch of information including the SHA (oid), path
// and mode which map to the tree objects that are written out. It also has filesystem properties // and mode which map to the tree objects that are written out. It also has filesystem properties
...@@ -410,6 +410,29 @@ int main (int argc, char** argv) ...@@ -410,6 +410,29 @@ int main (int argc, char** argv)
git_strarray_free(&ref_list); git_strarray_free(&ref_list);
// ### Config Files
//
// The [config API][config] allows you to list and updatee config values in
// any of the accessible config file locations (system, global, local).
//
// [config]: http://libgit2.github.com/libgit2/#HEAD/group/config
printf("\n*Config Listing*\n");
const char *email;
int j;
git_config *cfg;
// Open a config object so we can read global values from it.
git_config_open_global(&cfg);
git_config_get_int(cfg, "help.autocorrect", &j);
printf("Autocorrect: %d\n", j);
git_config_get_string(cfg, "user.email", &email);
printf("Email: %s\n", email);
// Finally, when you're done with the repository, you can free it as well. // Finally, when you're done with the repository, you can free it as well.
git_repository_free(repo); git_repository_free(repo);
} }
......
...@@ -12,9 +12,9 @@ int main (int argc, char** argv) ...@@ -12,9 +12,9 @@ int main (int argc, char** argv)
char out[41]; char out[41];
out[40] = '\0'; out[40] = '\0';
git_repository_open(&repo, "/tmp/gittalk/.git"); git_repository_open(&repo, "/opt/libgit2-test/.git");
git_index_open_inrepo(&index, repo); git_repository_index(&index, repo);
git_index_read(index); git_index_read(index);
ecount = git_index_entrycount(index); ecount = git_index_entrycount(index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment