/*
- * Copyright (C) 2012 the libgit2 contributors
+ * Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
#include "common.h"
#include "git2/config.h"
+#include "git2/sys/config.h"
#include "git2/types.h"
#include "git2/repository.h"
#include "git2/index.h"
str, static kh_inline, const char *, void *, 1,
str_hash_no_trailing_slash, str_equal_no_trailing_slash);
-static int load_submodule_config(git_repository *repo, bool force);
+static int load_submodule_config(git_repository *repo);
static git_config_backend *open_gitmodules(git_repository *, bool, const git_oid *);
static int lookup_head_remote(git_buf *url, git_repository *repo);
static int submodule_get(git_submodule **, git_repository *, const char *, const char *);
assert(repo && name);
- if ((error = load_submodule_config(repo, false)) < 0)
+ if ((error = load_submodule_config(repo)) < 0)
return error;
pos = git_strmap_lookup_index(repo->submodules, name);
assert(repo && callback);
- if ((error = load_submodule_config(repo, false)) < 0)
+ if ((error = load_submodule_config(repo)) < 0)
return error;
git_strmap_foreach_value(repo->submodules, sm, {
* and path are not the same.
*/
if (sm->refcount > 1) {
- if (git_vector_bsearch(&seen, sm) != GIT_ENOTFOUND)
+ if (git_vector_bsearch(NULL, &seen, sm) != GIT_ENOTFOUND)
continue;
if ((error = git_vector_insert(&seen, sm)) < 0)
break;
assert(sm);
if ((error = git_repository_index__weakptr(&index, sm->owner)) < 0 ||
- (error = git_index_add_from_workdir(index, GIT_MODULES_FILE)) < 0)
+ (error = git_index_add_bypath(index, GIT_MODULES_FILE)) < 0)
return error;
return git_submodule_add_to_index(sm, true);
git_buf_free(&path);
/* if we have opened the submodule successfully, let's grab the HEAD OID */
- if (!error && !(submodule->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID)) {
+ if (!error) {
if (!git_reference_name_to_id(
&submodule->wd_oid, *subrepo, GIT_HEAD_FILE))
submodule->flags |= GIT_SUBMODULE_STATUS__WD_OID_VALID;
int git_submodule_reload_all(git_repository *repo)
{
assert(repo);
- return load_submodule_config(repo, true);
+ git_submodule_config_free(repo);
+ return load_submodule_config(repo);
}
int git_submodule_reload(git_submodule *submodule)
{
git_repository *repo;
git_index *index;
- int pos, error;
+ int error;
+ size_t pos;
git_tree *head;
git_config_backend *mods;
~(GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS__INDEX_OID_VALID);
- pos = git_index_find(index, submodule->path);
- if (pos >= 0) {
+ if (!git_index_find(&pos, index, submodule->path)) {
const git_index_entry *entry = git_index_get_byindex(index, pos);
if (S_ISGITLINK(entry->mode)) {
return error;
}
+int git_submodule_location(
+ unsigned int *location_status,
+ git_submodule *submodule)
+{
+ assert(location_status && submodule);
+
+ *location_status = submodule->flags &
+ (GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_IN_WD);
+
+ return 0;
+}
+
+
/*
* INTERNAL FUNCTIONS
*/
git_repository *repo, git_oid *gitmodules_oid)
{
int error;
+ git_index *index;
git_iterator *i;
const git_index_entry *entry;
- if ((error = git_iterator_for_repo_index(&i, repo)) < 0)
+ if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
+ (error = git_iterator_for_index(&i, index, 0, NULL, NULL)) < 0)
return error;
- error = git_iterator_current(i, &entry);
+ error = git_iterator_current(&entry, i);
while (!error && entry != NULL) {
git_oid_cpy(gitmodules_oid, &entry->oid);
}
- error = git_iterator_advance(i, &entry);
+ error = git_iterator_advance(&entry, i);
}
git_iterator_free(i);
if ((error = git_repository_head_tree(&head, repo)) < 0)
return error;
- if ((error = git_iterator_for_tree(&i, head)) < 0) {
+ if ((error = git_iterator_for_tree(&i, head, 0, NULL, NULL)) < 0) {
git_tree_free(head);
return error;
}
- error = git_iterator_current(i, &entry);
+ error = git_iterator_current(&entry, i);
while (!error && entry != NULL) {
git_oid_cpy(gitmodules_oid, &entry->oid);
}
- error = git_iterator_advance(i, &entry);
+ error = git_iterator_advance(&entry, i);
}
git_iterator_free(i);
return mods;
}
-static int load_submodule_config(git_repository *repo, bool force)
+static int load_submodule_config(git_repository *repo)
{
int error;
git_oid gitmodules_oid;
git_buf path = GIT_BUF_INIT;
git_config_backend *mods = NULL;
- if (repo->submodules && !force)
+ if (repo->submodules)
return 0;
memset(&gitmodules_oid, 0, sizeof(gitmodules_oid));
goto cleanup;
}
- if ((error = git_branch_tracking(&remote, head)) < 0)
+ if ((error = git_branch_upstream(&remote, head)) < 0)
goto cleanup;
/* remote should refer to something like refs/remotes/ORIGIN/BRANCH */
if (untracked > 0)
*status |= GIT_SUBMODULE_STATUS_WD_UNTRACKED;
- if ((git_diff_num_deltas(diff) - untracked) > 0)
+ if (git_diff_num_deltas(diff) != untracked)
*status |= GIT_SUBMODULE_STATUS_WD_WD_MODIFIED;
git_diff_list_free(diff);