diff options
author | Russell Belfer <rb@github.com> | 2013-05-16 10:38:27 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-05-16 10:38:27 -0700 |
commit | 58206c9ae79af8ef675e30087e5430065b078bbb (patch) | |
tree | 68fa8a68d13a3d4cccf0551f9515b5578ec63f07 /src/commit.c | |
parent | 54e489c21efc19a14eac0f6f83313e3a753688f8 (diff) | |
download | libgit2-58206c9ae79af8ef675e30087e5430065b078bbb.tar.gz |
Add cat-file example and increase const use in API
This adds an example implementation that emulates git cat-file.
It is a convenient and relatively simple example of getting data
out of a repository.
Implementing this also revealed that there are a number of APIs
that are still not using const pointers to objects that really
ought to be. The main cause of this is that `git_vector_bsearch`
may need to call `git_vector_sort` before doing the search, so a
const pointer to the vector is not allowed. However, for tree
objects, with a little care, we can ensure that the vector of
tree entries is always sorted and allow lookups to take a const
pointer. Also, the missing const in commit objects just looks
like an oversight.
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/commit.c b/src/commit.c index be6e32c76..1ab9b34f7 100644 --- a/src/commit.c +++ b/src/commit.c @@ -266,14 +266,16 @@ int git_commit_tree(git_tree **tree_out, const git_commit *commit) return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_id); } -const git_oid *git_commit_parent_id(git_commit *commit, unsigned int n) +const git_oid *git_commit_parent_id( + const git_commit *commit, unsigned int n) { assert(commit); return git_vector_get(&commit->parent_ids, n); } -int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n) +int git_commit_parent( + git_commit **parent, const git_commit *commit, unsigned int n) { const git_oid *parent_id; assert(commit); |