/* Returns 0 on success, negative on failure. */ static int do_submodule_path(struct strbuf *buf, const char *path, const char *fmt, va_list args) { struct strbuf git_submodule_common_dir = STRBUF_INIT; struct strbuf git_submodule_dir = STRBUF_INIT; int ret; ret = submodule_to_gitdir(&git_submodule_dir, path); if (ret) goto cleanup; strbuf_complete(&git_submodule_dir, '/'); strbuf_addbuf(buf, &git_submodule_dir); strbuf_vaddf(buf, fmt, args); if (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf)) update_common_dir(buf, git_submodule_dir.len, git_submodule_common_dir.buf); strbuf_cleanup_path(buf); cleanup: strbuf_release(&git_submodule_dir); strbuf_release(&git_submodule_common_dir); return ret; }
static void do_submodule_path(struct strbuf *buf, const char *path, const char *fmt, va_list args) { const char *git_dir; struct strbuf git_submodule_common_dir = STRBUF_INIT; struct strbuf git_submodule_dir = STRBUF_INIT; strbuf_addstr(buf, path); strbuf_complete(buf, '/'); strbuf_addstr(buf, ".git"); git_dir = read_gitfile(buf->buf); if (git_dir) { strbuf_reset(buf); strbuf_addstr(buf, git_dir); } strbuf_addch(buf, '/'); strbuf_addstr(&git_submodule_dir, buf->buf); strbuf_vaddf(buf, fmt, args); if (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf)) update_common_dir(buf, git_submodule_dir.len, git_submodule_common_dir.buf); strbuf_cleanup_path(buf); strbuf_release(&git_submodule_dir); strbuf_release(&git_submodule_common_dir); }
int get_common_dir(struct strbuf *sb, const char *gitdir) { const char *git_env_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT); if (git_env_common_dir) { strbuf_addstr(sb, git_env_common_dir); return 1; } else { return get_common_dir_noenv(sb, gitdir); } }
static int find_common_dir(struct strbuf *sb, const char *gitdir, int fromenv) { if (fromenv) { const char *value = getenv(GIT_COMMON_DIR_ENVIRONMENT); if (value) { strbuf_addstr(sb, value); return 1; } } return get_common_dir_noenv(sb, gitdir); }
int submodule_uses_worktrees(const char *path) { char *submodule_gitdir; struct strbuf sb = STRBUF_INIT; DIR *dir; struct dirent *d; int ret = 0; struct repository_format format; submodule_gitdir = git_pathdup_submodule(path, "%s", ""); if (!submodule_gitdir) return 0; /* The env would be set for the superproject. */ get_common_dir_noenv(&sb, submodule_gitdir); free(submodule_gitdir); /* * The check below is only known to be good for repository format * version 0 at the time of writing this code. */ strbuf_addstr(&sb, "/config"); read_repository_format(&format, sb.buf); if (format.version != 0) { strbuf_release(&sb); return 1; } /* Replace config by worktrees. */ strbuf_setlen(&sb, sb.len - strlen("config")); strbuf_addstr(&sb, "worktrees"); /* See if there is any file inside the worktrees directory. */ dir = opendir(sb.buf); strbuf_release(&sb); if (!dir) return 0; while ((d = readdir(dir)) != NULL) { if (is_dot_or_dotdot(d->d_name)) continue; ret = 1; break; } closedir(dir); return ret; }
static void repo_set_commondir(struct repository *repo, const char *commondir) { struct strbuf sb = STRBUF_INIT; free(repo->commondir); if (commondir) { repo->different_commondir = 1; repo->commondir = xstrdup(commondir); return; } repo->different_commondir = get_common_dir_noenv(&sb, repo->gitdir); repo->commondir = strbuf_detach(&sb, NULL); }
static int do_submodule_path(struct strbuf *buf, const char *path, const char *fmt, va_list args) { const char *git_dir; struct strbuf git_submodule_common_dir = STRBUF_INIT; struct strbuf git_submodule_dir = STRBUF_INIT; const struct submodule *sub; int err = 0; strbuf_addstr(buf, path); strbuf_complete(buf, '/'); strbuf_addstr(buf, ".git"); git_dir = read_gitfile(buf->buf); if (git_dir) { strbuf_reset(buf); strbuf_addstr(buf, git_dir); } if (!is_git_directory(buf->buf)) { gitmodules_config(); sub = submodule_from_path(null_sha1, path); if (!sub) { err = SUBMODULE_PATH_ERR_NOT_CONFIGURED; goto cleanup; } strbuf_reset(buf); strbuf_git_path(buf, "%s/%s", "modules", sub->name); } strbuf_addch(buf, '/'); strbuf_addbuf(&git_submodule_dir, buf); strbuf_vaddf(buf, fmt, args); if (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf)) update_common_dir(buf, git_submodule_dir.len, git_submodule_common_dir.buf); strbuf_cleanup_path(buf); cleanup: strbuf_release(&git_submodule_dir); strbuf_release(&git_submodule_common_dir); return err; }