examples: general: extract function demonstrating index walking
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
diff --git a/examples/general.c b/examples/general.c
index ea00015..2ea40d3 100644
--- a/examples/general.c
+++ b/examples/general.c
@@ -43,6 +43,7 @@
#include <stdio.h>
#include <string.h>
+static void index_walking(git_repository *repo);
static void reference_listing(git_repository *repo);
static void config_files(const char *repo_path);
@@ -426,30 +427,46 @@ int main (int argc, char** argv)
// result in undefined behavior
git_revwalk_free(walk);
- // ### Index File Manipulation
+ index_walking(repo);
+ reference_listing(repo);
+ config_files(repo_path);
- // The [index file API][gi] allows you to read, traverse, update and write
- // the Git index file (sometimes thought of as the staging area).
- //
- // [gi]: http://libgit2.github.com/libgit2/#HEAD/group/index
+ // Finally, when you're done with the repository, you can free it as well.
+ git_repository_free(repo);
- printf("\n*Index Walking*\n");
+ return 0;
+}
+/**
+ * ### Index File Manipulation *
+ * The [index file API][gi] allows you to read, traverse, update and write
+ * the Git index file (sometimes thought of as the staging area).
+ *
+ * [gi]: http://libgit2.github.com/libgit2/#HEAD/group/index
+ */
+static void index_walking(git_repository *repo)
+{
git_index *index;
unsigned int i, ecount;
- // 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 for the repository
- // will be located and loaded from disk.
+ printf("\n*Index Walking*\n");
+
+ /**
+ * 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 for the repository
+ * will be located and loaded from disk.
+ */
git_repository_index(&index, repo);
- // 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 to help
- // determine what to inspect for changes (ctime, mtime, dev, ino, uid,
- // gid, file_size and flags) All these properties are exported publicly in
- // the `git_index_entry` struct
+ /**
+ * 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 to help
+ * determine what to inspect for changes (ctime, mtime, dev, ino, uid,
+ * gid, file_size and flags) All these properties are exported publicly in
+ * the `git_index_entry` struct
+ */
ecount = git_index_entrycount(index);
for (i = 0; i < ecount; ++i) {
const git_index_entry *e = git_index_get_byindex(index, i);
@@ -460,14 +477,6 @@ int main (int argc, char** argv)
}
git_index_free(index);
-
- reference_listing(repo);
- config_files(repo_path);
-
- // Finally, when you're done with the repository, you can free it as well.
- git_repository_free(repo);
-
- return 0;
}
/**