diff options
Diffstat (limited to 'load-git.c')
-rw-r--r-- | load-git.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/load-git.c b/load-git.c index 5d55245db..4040c1677 100644 --- a/load-git.c +++ b/load-git.c @@ -14,6 +14,8 @@ #include "device.h" #include "membuffer.h" +const char *saved_git_id = NULL; + struct keyword_action { const char *keyword; void (*fn)(char *, struct membuffer *, void *); @@ -1198,19 +1200,36 @@ static int load_dives_from_tree(git_repository *repo, git_tree *tree) return 0; } +void clear_git_id(void) +{ + saved_git_id = NULL; +} + +void set_git_id(const struct git_oid * id) +{ + static char git_id_buffer[GIT_OID_HEXSZ+1]; + + git_oid_tostr(git_id_buffer, sizeof(git_id_buffer), id); + saved_git_id = git_id_buffer; +} + static int do_git_load(git_repository *repo, const char *branch) { int ret; - git_reference *ref; - git_object *tree; - - ret = git_branch_lookup(&ref, repo, branch, GIT_BRANCH_LOCAL); - if (ret) - return report_error("Unable to look up branch '%s'", branch); - if (git_reference_peel(&tree, ref, GIT_OBJ_TREE)) - return report_error("Could not look up tree of branch '%s'", branch); - ret = load_dives_from_tree(repo, (git_tree *) tree); - git_object_free(tree); + git_object *object; + git_commit *commit; + git_tree *tree; + + if (git_revparse_single(&object, repo, branch)) + return report_error("Unable to look up revision '%s'", branch); + if (git_object_peel((git_object **)&commit, object, GIT_OBJ_COMMIT)) + return report_error("Revision '%s' is not a valid commit", branch); + if (git_commit_tree(&tree, commit)) + return report_error("Could not look up tree of commit in branch '%s'", branch); + ret = load_dives_from_tree(repo, tree); + if (!ret) + set_git_id(git_commit_id(commit)); + git_object_free((git_object *)tree); return ret; } @@ -1224,7 +1243,11 @@ static int do_git_load(git_repository *repo, const char *branch) */ int git_load_dives(struct git_repository *repo, const char *branch) { - int ret = do_git_load(repo, branch); + int ret; + + if (repo == dummy_git_repository) + return report_error("Unable to open git repository at '%s'", branch); + ret = do_git_load(repo, branch); git_repository_free(repo); free((void *)branch); finish_active_dive(); |