vendor/libgit2/src/diff_generate.c in rugged-1.1.1 vs vendor/libgit2/src/diff_generate.c in rugged-1.2.0

- old
+ new

@@ -126,11 +126,11 @@ const git_index_entry *entry = nitem; bool has_old = false; git_diff_delta *delta; const char *matched_pathspec; - assert((oitem != NULL) ^ (nitem != NULL)); + GIT_ASSERT_ARG((oitem != NULL) ^ (nitem != NULL)); if (oitem) { entry = oitem; has_old = true; } @@ -158,11 +158,11 @@ delta = diff_delta__alloc(diff, status, entry->path); GIT_ERROR_CHECK_ALLOC(delta); /* This fn is just for single-sided diffs */ - assert(status != GIT_DELTA_MODIFIED); + GIT_ASSERT(status != GIT_DELTA_MODIFIED); delta->nfiles = 1; if (has_old) { delta->old_file.mode = entry->mode; delta->old_file.size = entry->file_size; @@ -406,11 +406,13 @@ git_iterator *new_iter) { git_diff_generated *diff; git_diff_options dflt = GIT_DIFF_OPTIONS_INIT; - assert(repo && old_iter && new_iter); + GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL); + GIT_ASSERT_ARG_WITH_RETVAL(old_iter, NULL); + GIT_ASSERT_ARG_WITH_RETVAL(new_iter, NULL); if ((diff = git__calloc(1, sizeof(git_diff_generated))) == NULL) return NULL; GIT_REFCOUNT_INC(&diff->base); @@ -587,17 +589,16 @@ git_buf full_path = GIT_BUF_INIT; git_index_entry entry = *src; git_filter_list *fl = NULL; int error = 0; - assert(d->type == GIT_DIFF_TYPE_GENERATED); + GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED); diff = (git_diff_generated *)d; memset(out, 0, sizeof(*out)); - if (git_buf_joinpath(&full_path, - git_repository_workdir(diff->base.repo), entry.path) < 0) + if (git_repository_workdir_path(&full_path, diff->base.repo, entry.path) < 0) return -1; if (!mode) { struct stat st; @@ -676,10 +677,12 @@ git_repository *repo; git_iterator *old_iter; git_iterator *new_iter; const git_index_entry *oitem; const git_index_entry *nitem; + git_strmap *submodule_cache; + bool submodule_cache_initialized; } diff_in_progress; #define MODE_BITS_MASK 0000777 static int maybe_modified_submodule( @@ -690,20 +693,36 @@ { int error = 0; git_submodule *sub; unsigned int sm_status = 0; git_submodule_ignore_t ign = diff->base.opts.ignore_submodules; + git_strmap *submodule_cache = NULL; *status = GIT_DELTA_UNMODIFIED; if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_SUBMODULES) || ign == GIT_SUBMODULE_IGNORE_ALL) return 0; - if ((error = git_submodule_lookup( - &sub, diff->base.repo, info->nitem->path)) < 0) { + if (diff->base.repo->submodule_cache != NULL) { + submodule_cache = diff->base.repo->submodule_cache; + } else { + if (!info->submodule_cache_initialized) { + info->submodule_cache_initialized = true; + /* + * Try to cache the submodule information to avoid having to parse it for + * every submodule. It is okay if it fails, the cache will still be NULL + * and the submodules will be attempted to be looked up individually. + */ + git_submodule_cache_init(&info->submodule_cache, diff->base.repo); + } + submodule_cache = info->submodule_cache; + } + if ((error = git_submodule__lookup_with_cache( + &sub, diff->base.repo, info->nitem->path, submodule_cache)) < 0) { + /* GIT_EEXISTS means dir with .git in it was found - ignore it */ if (error == GIT_EEXISTS) { git_error_clear(); error = 0; } @@ -1188,11 +1207,11 @@ git_iterator *old_iter, git_iterator *new_iter, const git_diff_options *opts) { git_diff_generated *diff; - diff_in_progress info; + diff_in_progress info = {0}; int error = 0; *out = NULL; diff = diff_generated_alloc(repo, old_iter, new_iter); @@ -1202,12 +1221,13 @@ info.old_iter = old_iter; info.new_iter = new_iter; /* make iterators have matching icase behavior */ if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE)) { - git_iterator_set_ignore_case(old_iter, true); - git_iterator_set_ignore_case(new_iter, true); + if ((error = git_iterator_set_ignore_case(old_iter, true)) < 0 || + (error = git_iterator_set_ignore_case(new_iter, true)) < 0) + goto cleanup; } /* finish initialization */ if ((error = diff_generated_apply_options(diff, opts)) < 0) goto cleanup; @@ -1255,10 +1275,12 @@ cleanup: if (!error) *out = &diff->base; else git_diff_free(&diff->base); + if (info.submodule_cache) + git_submodule_cache_free(info.submodule_cache); return error; } static int diff_prepare_iterator_opts(char **prefix, git_iterator_options *a, int aflags, @@ -1300,11 +1322,12 @@ git_iterator *a = NULL, *b = NULL; git_diff *diff = NULL; char *prefix = NULL; int error = 0; - assert(out && repo); + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(repo); *out = NULL; /* for tree to tree diff, be case sensitive even if the index is * currently case insensitive, unless the user explicitly asked @@ -1356,11 +1379,12 @@ git_diff *diff = NULL; char *prefix = NULL; bool index_ignore_case = false; int error = 0; - assert(out && repo); + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(repo); *out = NULL; if (!index && (error = diff_load_index(&index, repo)) < 0) return error; @@ -1399,11 +1423,12 @@ git_iterator *a = NULL, *b = NULL; git_diff *diff = NULL; char *prefix = NULL; int error = 0; - assert(out && repo); + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(repo); *out = NULL; if (!index && (error = diff_load_index(&index, repo)) < 0) return error; @@ -1442,11 +1467,12 @@ git_diff *diff = NULL; char *prefix = NULL; git_index *index; int error; - assert(out && repo); + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(repo); *out = NULL; if ((error = diff_prepare_iterator_opts(&prefix, &a_opts, 0, &b_opts, GIT_ITERATOR_DONT_AUTOEXPAND, opts) < 0) || @@ -1475,11 +1501,12 @@ { git_diff *d1 = NULL, *d2 = NULL; git_index *index = NULL; int error = 0; - assert(out && repo); + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(repo); *out = NULL; if ((error = diff_load_index(&index, repo)) < 0) return error; @@ -1511,10 +1538,12 @@ git_iterator *a = NULL, *b = NULL; git_diff *diff = NULL; char *prefix = NULL; int error; - assert(out && old_index && new_index); + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(old_index); + GIT_ASSERT_ARG(new_index); *out = NULL; if ((error = diff_prepare_iterator_opts(&prefix, &a_opts, GIT_ITERATOR_DONT_IGNORE_CASE, &b_opts, GIT_ITERATOR_DONT_IGNORE_CASE, opts) < 0) ||