int git_submodule_foreach( git_repository *repo, int (*callback)(git_submodule *sm, const char *name, void *payload), void *payload) { int error; git_submodule *sm; git_vector seen = GIT_VECTOR_INIT; git_vector_set_cmp(&seen, submodule_cmp); assert(repo && callback); if ((error = load_submodule_config(repo)) < 0) return error; git_strmap_foreach_value(repo->submodules, sm, { /* Usually the following will not come into play - it just prevents * us from issuing a callback twice for a submodule where the name * and path are not the same. */ if (sm->refcount > 1) { if (git_vector_bsearch(NULL, &seen, sm) != GIT_ENOTFOUND) continue; if ((error = git_vector_insert(&seen, sm)) < 0) break; } if (callback(sm, sm->name, payload)) { giterr_clear(); error = GIT_EUSER; break; } });
int git_attr_file__lookup_one( git_attr_file *file, git_attr_path *path, const char *attr, const char **value) { size_t i; git_attr_name name; git_attr_rule *rule; *value = NULL; name.name = attr; name.name_hash = git_attr_file__name_hash(attr); git_attr_file__foreach_matching_rule(file, path, i, rule) { size_t pos; if (!git_vector_bsearch(&pos, &rule->assigns, &name)) { *value = ((git_attr_assignment *) git_vector_get(&rule->assigns, pos))->value; break; } }
static git_blame__origin* find_origin( git_blame *blame, git_commit *parent, git_blame__origin *origin) { git_blame__origin *porigin = NULL; git_diff *difflist = NULL; git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT; git_tree *otree=NULL, *ptree=NULL; /* Get the trees from this commit and its parent */ if (0 != git_commit_tree(&otree, origin->commit) || 0 != git_commit_tree(&ptree, parent)) goto cleanup; /* Configure the diff */ diffopts.context_lines = 0; diffopts.flags = GIT_DIFF_SKIP_BINARY_CHECK; /* Check to see if files we're interested have changed */ diffopts.pathspec.count = blame->paths.length; diffopts.pathspec.strings = (char**)blame->paths.contents; if (0 != git_diff_tree_to_tree(&difflist, blame->repository, ptree, otree, &diffopts)) goto cleanup; if (!git_diff_num_deltas(difflist)) { /* No changes; copy data */ git_blame__get_origin(&porigin, blame, parent, origin->path); } else { git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT; int i; /* Generate a full diff between the two trees */ git_diff_free(difflist); diffopts.pathspec.count = 0; if (0 != git_diff_tree_to_tree(&difflist, blame->repository, ptree, otree, &diffopts)) goto cleanup; /* Let diff find renames */ findopts.flags = GIT_DIFF_FIND_RENAMES; if (0 != git_diff_find_similar(difflist, &findopts)) goto cleanup; /* Find one that matches */ for (i=0; i<(int)git_diff_num_deltas(difflist); i++) { const git_diff_delta *delta = git_diff_get_delta(difflist, i); if (!git_vector_bsearch(NULL, &blame->paths, delta->new_file.path)) { git_vector_insert_sorted(&blame->paths, (void*)git__strdup(delta->old_file.path), paths_on_dup); make_origin(&porigin, parent, delta->old_file.path); } } } cleanup: git_diff_free(difflist); git_tree_free(otree); git_tree_free(ptree); return porigin; }