summaryrefslogtreecommitdiff
path: root/src/status.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-04-13 10:33:14 -0700
committerRussell Belfer <rb@github.com>2012-04-17 10:44:50 -0700
commitf201d613a80f7ad6f54d90eb7a7a0d8b8c72676b (patch)
treec3cd8f0eee145f40b640519e06ae628cdb942eb3 /src/status.c
parent1a6e8f8a54eea1159a950cd8a49cedae3699ff9a (diff)
downloadlibgit2-f201d613a80f7ad6f54d90eb7a7a0d8b8c72676b.tar.gz
Add git_reference_lookup_oid and lookup_resolved
Adds a new public reference function `git_reference_lookup_oid` that directly resolved a reference name to an OID without returning the intermediate `git_reference` object (hence, no free needed). Internally, this adds a `git_reference_lookup_resolved` function that combines looking up and resolving a reference. This allows us to be more efficient with memory reallocation. The existing `git_reference_lookup` and `git_reference_resolve` are reimplmented on top of the new utility and a few places in the code are changed to use one of the two new functions.
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/status.c b/src/status.c
index 8d2c7de14..d4f59e355 100644
--- a/src/status.c
+++ b/src/status.c
@@ -20,31 +20,19 @@
static int resolve_head_to_tree(git_tree **tree, git_repository *repo)
{
- git_reference *head = NULL;
+ git_oid head_oid;
git_object *obj = NULL;
- if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0)
- return -1;
-
- if (git_reference_oid(head) == NULL) {
- git_reference *resolved;
-
- if (git_reference_resolve(&resolved, head) < 0) {
- /* cannot resolve HEAD - probably brand new repo */
- giterr_clear();
- git_reference_free(head);
- return GIT_ENOTFOUND;
- }
-
- git_reference_free(head);
- head = resolved;
+ if (git_reference_lookup_oid(&head_oid, repo, GIT_HEAD_FILE) < 0) {
+ /* cannot resolve HEAD - probably brand new repo */
+ giterr_clear();
+ *tree = NULL;
+ return 0;
}
- if (git_object_lookup(&obj, repo, git_reference_oid(head), GIT_OBJ_ANY) < 0)
+ if (git_object_lookup(&obj, repo, &head_oid, GIT_OBJ_ANY) < 0)
goto fail;
- git_reference_free(head);
-
switch (git_object_type(obj)) {
case GIT_OBJ_TREE:
*tree = (git_tree *)obj;
@@ -62,7 +50,6 @@ static int resolve_head_to_tree(git_tree **tree, git_repository *repo)
fail:
git_object_free(obj);
- git_reference_free(head);
return -1;
}
@@ -152,7 +139,7 @@ int git_status_foreach_ext(
diffopt.flags = diffopt.flags | GIT_DIFF_RECURSE_UNTRACKED_DIRS;
/* TODO: support EXCLUDE_SUBMODULES flag */
- if (show != GIT_STATUS_SHOW_WORKDIR_ONLY &&
+ if (show != GIT_STATUS_SHOW_WORKDIR_ONLY && head != NULL &&
(err = git_diff_index_to_tree(repo, &diffopt, head, &idx2head)) < 0)
goto cleanup;