Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c97
1 files changed, 71 insertions, 26 deletions
diff --git a/src/status.c b/src/status.c
index 07fdcb5c3..8d7612f72 100644
--- a/src/status.c
+++ b/src/status.c
@@ -38,7 +38,7 @@ static unsigned int index_delta2status(const git_diff_delta *head2idx)
case GIT_DELTA_RENAMED:
st = GIT_STATUS_INDEX_RENAMED;
- if (!git_oid_equal(&head2idx->old_file.oid, &head2idx->new_file.oid))
+ if (!git_oid_equal(&head2idx->old_file.id, &head2idx->new_file.id))
st |= GIT_STATUS_INDEX_MODIFIED;
break;
case GIT_DELTA_TYPECHANGE:
@@ -74,25 +74,25 @@ static unsigned int workdir_delta2status(
case GIT_DELTA_RENAMED:
st = GIT_STATUS_WT_RENAMED;
- if (!git_oid_equal(&idx2wd->old_file.oid, &idx2wd->new_file.oid)) {
+ if (!git_oid_equal(&idx2wd->old_file.id, &idx2wd->new_file.id)) {
/* if OIDs don't match, we might need to calculate them now to
* discern between RENAMED vs RENAMED+MODIFED
*/
- if (git_oid_iszero(&idx2wd->old_file.oid) &&
+ if (git_oid_iszero(&idx2wd->old_file.id) &&
diff->old_src == GIT_ITERATOR_TYPE_WORKDIR &&
!git_diff__oid_for_file(
- diff->repo, idx2wd->old_file.path, idx2wd->old_file.mode,
- idx2wd->old_file.size, &idx2wd->old_file.oid))
- idx2wd->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
+ &idx2wd->old_file.id, diff, idx2wd->old_file.path,
+ idx2wd->old_file.mode, idx2wd->old_file.size))
+ idx2wd->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
- if (git_oid_iszero(&idx2wd->new_file.oid) &&
+ if (git_oid_iszero(&idx2wd->new_file.id) &&
diff->new_src == GIT_ITERATOR_TYPE_WORKDIR &&
!git_diff__oid_for_file(
- diff->repo, idx2wd->new_file.path, idx2wd->new_file.mode,
- idx2wd->new_file.size, &idx2wd->new_file.oid))
- idx2wd->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
+ &idx2wd->new_file.id, diff, idx2wd->new_file.path,
+ idx2wd->new_file.mode, idx2wd->new_file.size))
+ idx2wd->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
- if (!git_oid_equal(&idx2wd->old_file.oid, &idx2wd->new_file.oid))
+ if (!git_oid_equal(&idx2wd->old_file.id, &idx2wd->new_file.id))
st |= GIT_STATUS_WT_MODIFIED;
}
break;
@@ -225,6 +225,28 @@ static git_status_list *git_status_list_alloc(git_index *index)
return status;
}
+static int status_validate_options(const git_status_options *opts)
+{
+ if (!opts)
+ return 0;
+
+ GITERR_CHECK_VERSION(opts, GIT_STATUS_OPTIONS_VERSION, "git_status_options");
+
+ if (opts->show > GIT_STATUS_SHOW_WORKDIR_ONLY) {
+ giterr_set(GITERR_INVALID, "Unknown status 'show' option");
+ return -1;
+ }
+
+ if ((opts->flags & GIT_STATUS_OPT_NO_REFRESH) != 0 &&
+ (opts->flags & GIT_STATUS_OPT_UPDATE_INDEX) != 0) {
+ giterr_set(GITERR_INVALID, "Updating index from status "
+ "is not allowed when index refresh is disabled");
+ return -1;
+ }
+
+ return 0;
+}
+
int git_status_list_new(
git_status_list **out,
git_repository *repo,
@@ -240,11 +262,10 @@ int git_status_list_new(
int error = 0;
unsigned int flags = opts ? opts->flags : GIT_STATUS_OPT_DEFAULTS;
- assert(show <= GIT_STATUS_SHOW_WORKDIR_ONLY);
-
*out = NULL;
- GITERR_CHECK_VERSION(opts, GIT_STATUS_OPTIONS_VERSION, "git_status_options");
+ if (status_validate_options(opts) < 0)
+ return -1;
if ((error = git_repository__ensure_not_bare(repo, "status")) < 0 ||
(error = git_repository_index(&index, repo)) < 0)
@@ -287,6 +308,8 @@ int git_status_list_new(
diffopt.flags = diffopt.flags | GIT_DIFF_RECURSE_IGNORED_DIRS;
if ((flags & GIT_STATUS_OPT_EXCLUDE_SUBMODULES) != 0)
diffopt.flags = diffopt.flags | GIT_DIFF_IGNORE_SUBMODULES;
+ if ((flags & GIT_STATUS_OPT_UPDATE_INDEX) != 0)
+ diffopt.flags = diffopt.flags | GIT_DIFF_UPDATE_INDEX;
if ((flags & GIT_STATUS_OPT_RENAMES_FROM_REWRITES) != 0)
findopt.flags = findopt.flags |
@@ -314,8 +337,9 @@ int git_status_list_new(
goto done;
}
- if ((error = git_diff__paired_foreach(
- status->head2idx, status->idx2wd, status_collect, status)) < 0)
+ error = git_diff__paired_foreach(
+ status->head2idx, status->idx2wd, status_collect, status);
+ if (error < 0)
goto done;
if (flags & GIT_STATUS_OPT_SORT_CASE_SENSITIVELY)
@@ -360,19 +384,13 @@ const git_status_entry *git_status_byindex(git_status_list *status, size_t i)
void git_status_list_free(git_status_list *status)
{
- git_status_entry *status_entry;
- size_t i;
-
if (status == NULL)
return;
git_diff_free(status->head2idx);
git_diff_free(status->idx2wd);
- git_vector_foreach(&status->paired, i, status_entry)
- git__free(status_entry);
-
- git_vector_free(&status->paired);
+ git_vector_free_deep(&status->paired);
git__memzero(status, sizeof(*status));
git__free(status);
@@ -397,9 +415,8 @@ int git_status_foreach_ext(
status_entry->head_to_index->old_file.path :
status_entry->index_to_workdir->old_file.path;
- if (cb(path, status_entry->status, payload) != 0) {
- error = GIT_EUSER;
- giterr_clear();
+ if ((error = cb(path, status_entry->status, payload)) != 0) {
+ giterr_set_after_callback(error);
break;
}
}
@@ -501,3 +518,31 @@ int git_status_should_ignore(
return git_ignore_path_is_ignored(ignored, repo, path);
}
+int git_status_init_options(git_status_options *opts, unsigned int version)
+{
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ opts, version, git_status_options, GIT_STATUS_OPTIONS_INIT);
+ return 0;
+}
+
+int git_status_list_get_perfdata(
+ git_diff_perfdata *out, const git_status_list *status)
+{
+ assert(out);
+ GITERR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata");
+
+ out->stat_calls = 0;
+ out->oid_calculations = 0;
+
+ if (status->head2idx) {
+ out->stat_calls += status->head2idx->perf.stat_calls;
+ out->oid_calculations += status->head2idx->perf.oid_calculations;
+ }
+ if (status->idx2wd) {
+ out->stat_calls += status->idx2wd->perf.stat_calls;
+ out->oid_calculations += status->idx2wd->perf.oid_calculations;
+ }
+
+ return 0;
+}
+