Skip to content

Commit 96da90a

Browse files
committed
update examples content to be compilable and up to date
1 parent 2e6d8ec commit 96da90a

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

api.docurium

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"input": "include/git2",
55
"prefix": "git_",
66
"output": "docs",
7-
"xbranch": "gh-pages",
7+
"branch": "gh-pages",
88
"examples": "examples",
99
"legacy": {
1010
"input": {"src/git": ["v0.1.0"],

examples/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
general
2+
showindex

examples/Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all: general showindex
2+
3+
general : general.c
4+
gcc -lgit2 -o general general.c
5+
6+
showindex : showindex.c
7+
gcc -lgit2 -o showindex showindex.c
8+
9+
clean:
10+
rm general showindex

examples/libgit.c renamed to examples/general.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ int main (int argc, char** argv)
246246
printf("\n*Tree Parsing*\n");
247247

248248
git_tree *tree;
249-
git_tree_entry *entry;
249+
const git_tree_entry *entry;
250250
git_object *objt;
251251

252252
// Create the oid and lookup the tree object just like the other objects.
@@ -356,7 +356,7 @@ int main (int argc, char** argv)
356356
// You can either open the index from the standard location in an open repository, as we're doing
357357
// here, or you can open and manipulate any index file with `git_index_open_bare()`. The index
358358
// for the repository will be located and loaded from disk.
359-
git_index_open_inrepo(&index, repo);
359+
git_repository_index(&index, repo);
360360

361361
// For each entry in the index, you can get a bunch of information including the SHA (oid), path
362362
// 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)
410410

411411
git_strarray_free(&ref_list);
412412

413+
// ### Config Files
414+
//
415+
// The [config API][config] allows you to list and updatee config values in
416+
// any of the accessible config file locations (system, global, local).
417+
//
418+
// [config]: http://libgit2.github.com/libgit2/#HEAD/group/config
419+
420+
printf("\n*Config Listing*\n");
421+
422+
const char *email;
423+
int j;
424+
425+
git_config *cfg;
426+
427+
// Open a config object so we can read global values from it.
428+
git_config_open_global(&cfg);
429+
430+
git_config_get_int(cfg, "help.autocorrect", &j);
431+
printf("Autocorrect: %d\n", j);
432+
433+
git_config_get_string(cfg, "user.email", &email);
434+
printf("Email: %s\n", email);
435+
413436
// Finally, when you're done with the repository, you can free it as well.
414437
git_repository_free(repo);
415438
}

examples/showindex.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ int main (int argc, char** argv)
1212
char out[41];
1313
out[40] = '\0';
1414

15-
git_repository_open(&repo, "/tmp/gittalk/.git");
15+
git_repository_open(&repo, "/opt/libgit2-test/.git");
1616

17-
git_index_open_inrepo(&index, repo);
17+
git_repository_index(&index, repo);
1818
git_index_read(index);
1919

2020
ecount = git_index_entrycount(index);

0 commit comments

Comments
 (0)