From 4ccacdc8ec7524065b0d78a10c9deccd04bcbda7 Mon Sep 17 00:00:00 2001 From: David Catmull Date: Fri, 21 Jul 2017 17:07:10 -0600 Subject: status: Add a baseline field to git_status_options for comparing to trees other than HEAD --- src/status.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/status.c') diff --git a/src/status.c b/src/status.c index 03682bc72..f547bd466 100644 --- a/src/status.c +++ b/src/status.c @@ -280,12 +280,16 @@ int git_status_list_new( if ((error = git_repository__ensure_not_bare(repo, "status")) < 0 || (error = git_repository_index(&index, repo)) < 0) return error; - - /* if there is no HEAD, that's okay - we'll make an empty iterator */ - if ((error = git_repository_head_tree(&head, repo)) < 0) { - if (error != GIT_ENOTFOUND && error != GIT_EUNBORNBRANCH) - goto done; - giterr_clear(); + + if (opts != NULL && opts->baseline != NULL) { + head = opts->baseline; + } else { + /* if there is no HEAD, that's okay - we'll make an empty iterator */ + if ((error = git_repository_head_tree(&head, repo)) < 0) { + if (error != GIT_ENOTFOUND && error != GIT_EUNBORNBRANCH) + goto done; + giterr_clear(); + } } /* refresh index from disk unless prevented */ @@ -377,7 +381,8 @@ done: *out = status; - git_tree_free(head); + if (opts == NULL || opts->baseline != head) + git_tree_free(head); git_index_free(index); return error; -- cgit v1.2.1