summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-01-18 15:12:11 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-01-18 15:12:11 -0800
commit55d128ae06b7b82f867961b677984620612a201c (patch)
tree5628d92c5a897c1738ae99b360d303a2ac62409e /submodule.c
parentMerge git://ozlabs.org/~paulus/gitk (diff)
parentgrep: search history of moved submodules (diff)
downloadtgif-55d128ae06b7b82f867961b677984620612a201c.tar.xz
Merge branch 'bw/grep-recurse-submodules'
"git grep" has been taught to optionally recurse into submodules. * bw/grep-recurse-submodules: grep: search history of moved submodules grep: enable recurse-submodules to work on <tree> objects grep: optionally recurse into submodules grep: add submodules as a grep source type submodules: load gitmodules file from commit sha1 submodules: add helper to determine if a submodule is initialized submodules: add helper to determine if a submodule is populated real_path: canonicalize directory separators in root parts real_path: have callers use real_pathdup and strbuf_realpath real_path: create real_pathdup real_path: convert real_path_internal to strbuf_realpath real_path: resolve symlinks by hand
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c58
1 files changed, 54 insertions, 4 deletions
diff --git a/submodule.c b/submodule.c
index 73521cdbb2..f8fee3dfdd 100644
--- a/submodule.c
+++ b/submodule.c
@@ -199,6 +199,56 @@ void gitmodules_config(void)
}
}
+void gitmodules_config_sha1(const unsigned char *commit_sha1)
+{
+ struct strbuf rev = STRBUF_INIT;
+ unsigned char sha1[20];
+
+ if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
+ git_config_from_blob_sha1(submodule_config, rev.buf,
+ sha1, NULL);
+ }
+ strbuf_release(&rev);
+}
+
+/*
+ * Determine if a submodule has been initialized at a given 'path'
+ */
+int is_submodule_initialized(const char *path)
+{
+ int ret = 0;
+ const struct submodule *module = NULL;
+
+ module = submodule_from_path(null_sha1, path);
+
+ if (module) {
+ char *key = xstrfmt("submodule.%s.url", module->name);
+ char *value = NULL;
+
+ ret = !git_config_get_string(key, &value);
+
+ free(value);
+ free(key);
+ }
+
+ return ret;
+}
+
+/*
+ * Determine if a submodule has been populated at a given 'path'
+ */
+int is_submodule_populated(const char *path)
+{
+ int ret = 0;
+ char *gitdir = xstrfmt("%s/.git", path);
+
+ if (resolve_gitdir(gitdir))
+ ret = 1;
+
+ free(gitdir);
+ return ret;
+}
+
int parse_submodule_update_strategy(const char *value,
struct submodule_update_strategy *dst)
{
@@ -1333,7 +1383,7 @@ static void relocate_single_git_dir_into_superproject(const char *prefix,
/* If it is an actual gitfile, it doesn't need migration. */
return;
- real_old_git_dir = xstrdup(real_path(old_git_dir));
+ real_old_git_dir = real_pathdup(old_git_dir);
sub = submodule_from_path(null_sha1, path);
if (!sub)
@@ -1342,7 +1392,7 @@ static void relocate_single_git_dir_into_superproject(const char *prefix,
new_git_dir = git_path("modules/%s", sub->name);
if (safe_create_leading_directories_const(new_git_dir) < 0)
die(_("could not create directory '%s'"), new_git_dir);
- real_new_git_dir = xstrdup(real_path(new_git_dir));
+ real_new_git_dir = real_pathdup(new_git_dir);
if (!prefix)
prefix = get_super_prefix();
@@ -1379,8 +1429,8 @@ void absorb_git_dir_into_superproject(const char *prefix,
goto out;
/* Is it already absorbed into the superprojects git dir? */
- real_sub_git_dir = xstrdup(real_path(sub_git_dir));
- real_common_git_dir = xstrdup(real_path(get_git_common_dir()));
+ real_sub_git_dir = real_pathdup(sub_git_dir);
+ real_common_git_dir = real_pathdup(get_git_common_dir());
if (!skip_prefix(real_sub_git_dir, real_common_git_dir, &v))
relocate_single_git_dir_into_superproject(prefix, path);