diff options
author | Ben Straub <bs@github.com> | 2013-10-09 16:16:43 -0700 |
---|---|---|
committer | Ben Straub <bs@github.com> | 2013-10-09 16:16:43 -0700 |
commit | 43a07b860b9c172081e3c9dee18aeead9091f2cf (patch) | |
tree | e0284c0e7a6a8a4582258ff9334a0dc0af53a41a /examples/blame.c | |
parent | 2ccc84d2efaf8adf4886cfc42d8bd16e2ba98188 (diff) | |
download | libgit2-43a07b860b9c172081e3c9dee18aeead9091f2cf.tar.gz |
Simplify loading blob
Diffstat (limited to 'examples/blame.c')
-rw-r--r-- | examples/blame.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/examples/blame.c b/examples/blame.c index 5efb19930..a7d0a12a5 100644 --- a/examples/blame.c +++ b/examples/blame.c @@ -32,13 +32,11 @@ int main(int argc, char *argv[]) int i, line; char *path = NULL, *a; const char *rawdata, *commitspec=NULL; + char spec[1024] = {0}; git_repository *repo = NULL; git_revspec revspec = {0}; git_blame_options opts = GIT_BLAME_OPTIONS_INIT; git_blame *blame = NULL; - git_commit *commit; - git_tree *tree; - git_tree_entry *entry; git_blob *blob; git_threads_init(); @@ -86,16 +84,19 @@ int main(int argc, char *argv[]) check(git_blame_file(&blame, repo, path, &opts), "Blame error"); /* Get the raw data for output */ - if (git_oid_iszero(&opts.newest_commit)) { + if (git_oid_iszero(&opts.newest_commit)) + strcpy(spec, "HEAD"); + else + git_oid_tostr(spec, sizeof(spec), &opts.newest_commit); + strcat(spec, ":"); + strcat(spec, path); + + { git_object *obj; - check(git_revparse_single(&obj, repo, "HEAD"), "Can't find HEAD"); - git_oid_cpy(&opts.newest_commit, git_object_id(obj)); + check(git_revparse_single(&obj, repo, spec), "Object lookup error"); + check(git_blob_lookup(&blob, repo, git_object_id(obj)), "Blob lookup error"); git_object_free(obj); } - check(git_commit_lookup(&commit, repo, &opts.newest_commit), "Commit lookup error"); - check(git_commit_tree(&tree, commit), "Commit tree lookup error"); - check(git_tree_entry_bypath(&entry, tree, path), "Tree entry lookup error"); - check(git_blob_lookup(&blob, repo, git_tree_entry_id(entry)), "Blob lookup error"); rawdata = git_blob_rawcontent(blob); /* Produce the output */ @@ -126,9 +127,6 @@ int main(int argc, char *argv[]) /* Cleanup */ git_blob_free(blob); - git_tree_entry_free(entry); - git_tree_free(tree); - git_commit_free(commit); git_blame_free(blame); git_repository_free(repo); git_threads_shutdown(); |