cache.h: add GITMODULES_FILE macro

Add a macro to be used when specifying the '.gitmodules' file and
convert any existing hard coded '.gitmodules' file strings to use the
new macro.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brandon Williams
2017-08-02 12:49:16 -07:00
committed by Junio C Hamano
parent ba43964d47
commit 4c0eeafe47
3 changed files with 12 additions and 11 deletions

View File

@ -433,6 +433,7 @@ static inline enum object_type object_type(unsigned int mode)
#define GITATTRIBUTES_FILE ".gitattributes" #define GITATTRIBUTES_FILE ".gitattributes"
#define INFOATTRIBUTES_FILE "info/attributes" #define INFOATTRIBUTES_FILE "info/attributes"
#define ATTRIBUTE_MACRO_PREFIX "[attr]" #define ATTRIBUTE_MACRO_PREFIX "[attr]"
#define GITMODULES_FILE ".gitmodules"
#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" #define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" #define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" #define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"

View File

@ -63,7 +63,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
struct strbuf entry = STRBUF_INIT; struct strbuf entry = STRBUF_INIT;
const struct submodule *submodule; const struct submodule *submodule;
if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */ if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
return -1; return -1;
if (gitmodules_is_unmerged) if (gitmodules_is_unmerged)
@ -77,7 +77,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
strbuf_addstr(&entry, "submodule."); strbuf_addstr(&entry, "submodule.");
strbuf_addstr(&entry, submodule->name); strbuf_addstr(&entry, submodule->name);
strbuf_addstr(&entry, ".path"); strbuf_addstr(&entry, ".path");
if (git_config_set_in_file_gently(".gitmodules", entry.buf, newpath) < 0) { if (git_config_set_in_file_gently(GITMODULES_FILE, entry.buf, newpath) < 0) {
/* Maybe the user already did that, don't error out here */ /* Maybe the user already did that, don't error out here */
warning(_("Could not update .gitmodules entry %s"), entry.buf); warning(_("Could not update .gitmodules entry %s"), entry.buf);
strbuf_release(&entry); strbuf_release(&entry);
@ -97,7 +97,7 @@ int remove_path_from_gitmodules(const char *path)
struct strbuf sect = STRBUF_INIT; struct strbuf sect = STRBUF_INIT;
const struct submodule *submodule; const struct submodule *submodule;
if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */ if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
return -1; return -1;
if (gitmodules_is_unmerged) if (gitmodules_is_unmerged)
@ -110,7 +110,7 @@ int remove_path_from_gitmodules(const char *path)
} }
strbuf_addstr(&sect, "submodule."); strbuf_addstr(&sect, "submodule.");
strbuf_addstr(&sect, submodule->name); strbuf_addstr(&sect, submodule->name);
if (git_config_rename_section_in_file(".gitmodules", sect.buf, NULL) < 0) { if (git_config_rename_section_in_file(GITMODULES_FILE, sect.buf, NULL) < 0) {
/* Maybe the user already did that, don't error out here */ /* Maybe the user already did that, don't error out here */
warning(_("Could not remove .gitmodules entry for %s"), path); warning(_("Could not remove .gitmodules entry for %s"), path);
strbuf_release(&sect); strbuf_release(&sect);
@ -122,7 +122,7 @@ int remove_path_from_gitmodules(const char *path)
void stage_updated_gitmodules(void) void stage_updated_gitmodules(void)
{ {
if (add_file_to_cache(".gitmodules", 0)) if (add_file_to_cache(GITMODULES_FILE, 0))
die(_("staging updated .gitmodules failed")); die(_("staging updated .gitmodules failed"));
} }
@ -230,21 +230,21 @@ void gitmodules_config(void)
struct strbuf gitmodules_path = STRBUF_INIT; struct strbuf gitmodules_path = STRBUF_INIT;
int pos; int pos;
strbuf_addstr(&gitmodules_path, work_tree); strbuf_addstr(&gitmodules_path, work_tree);
strbuf_addstr(&gitmodules_path, "/.gitmodules"); strbuf_addstr(&gitmodules_path, "/" GITMODULES_FILE);
if (read_cache() < 0) if (read_cache() < 0)
die("index file corrupt"); die("index file corrupt");
pos = cache_name_pos(".gitmodules", 11); pos = cache_name_pos(GITMODULES_FILE, 11);
if (pos < 0) { /* .gitmodules not found or isn't merged */ if (pos < 0) { /* .gitmodules not found or isn't merged */
pos = -1 - pos; pos = -1 - pos;
if (active_nr > pos) { /* there is a .gitmodules */ if (active_nr > pos) { /* there is a .gitmodules */
const struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = active_cache[pos];
if (ce_namelen(ce) == 11 && if (ce_namelen(ce) == 11 &&
!memcmp(ce->name, ".gitmodules", 11)) !memcmp(ce->name, GITMODULES_FILE, 11))
gitmodules_is_unmerged = 1; gitmodules_is_unmerged = 1;
} }
} else if (pos < active_nr) { } else if (pos < active_nr) {
struct stat st; struct stat st;
if (lstat(".gitmodules", &st) == 0 && if (lstat(GITMODULES_FILE, &st) == 0 &&
ce_match_stat(active_cache[pos], &st, 0) & DATA_CHANGED) ce_match_stat(active_cache[pos], &st, 0) & DATA_CHANGED)
gitmodules_is_modified = 1; gitmodules_is_modified = 1;
} }
@ -264,7 +264,7 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
void repo_read_gitmodules(struct repository *repo) void repo_read_gitmodules(struct repository *repo)
{ {
char *gitmodules_path = repo_worktree_path(repo, ".gitmodules"); char *gitmodules_path = repo_worktree_path(repo, GITMODULES_FILE);
git_config_from_file(gitmodules_cb, gitmodules_path, repo); git_config_from_file(gitmodules_cb, gitmodules_path, repo);
free(gitmodules_path); free(gitmodules_path);

View File

@ -286,7 +286,7 @@ static void reload_gitmodules_file(struct index_state *index,
for (i = 0; i < index->cache_nr; i++) { for (i = 0; i < index->cache_nr; i++) {
struct cache_entry *ce = index->cache[i]; struct cache_entry *ce = index->cache[i];
if (ce->ce_flags & CE_UPDATE) { if (ce->ce_flags & CE_UPDATE) {
int r = strcmp(ce->name, ".gitmodules"); int r = strcmp(ce->name, GITMODULES_FILE);
if (r < 0) if (r < 0)
continue; continue;
else if (r == 0) { else if (r == 0) {