/* 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; }
struct ref_store *get_submodule_ref_store(const char *submodule) { struct strbuf submodule_sb = STRBUF_INIT; struct ref_store *refs; int ret; if (!submodule || !*submodule) { /* * FIXME: This case is ideally not allowed. But that * can't happen until we clean up all the callers. */ return get_main_ref_store(); } refs = lookup_submodule_ref_store(submodule); if (refs) return refs; strbuf_addstr(&submodule_sb, submodule); ret = is_nonbare_repository_dir(&submodule_sb); strbuf_release(&submodule_sb); if (!ret) return NULL; ret = submodule_to_gitdir(&submodule_sb, submodule); if (ret) { strbuf_release(&submodule_sb); return NULL; } /* assume that add_submodule_odb() has been called */ refs = ref_store_init(submodule_sb.buf, REF_STORE_READ | REF_STORE_ODB); register_submodule_ref_store(refs, submodule); strbuf_release(&submodule_sb); return refs; }