Skip to content

Commit 4c0eeaf

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ba43964 commit 4c0eeaf

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ static inline enum object_type object_type(unsigned int mode)
433433
#define GITATTRIBUTES_FILE ".gitattributes"
434434
#define INFOATTRIBUTES_FILE "info/attributes"
435435
#define ATTRIBUTE_MACRO_PREFIX "[attr]"
436+
#define GITMODULES_FILE ".gitmodules"
436437
#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
437438
#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
438439
#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"

submodule.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
6363
struct strbuf entry = STRBUF_INIT;
6464
const struct submodule *submodule;
6565

66-
if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */
66+
if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
6767
return -1;
6868

6969
if (gitmodules_is_unmerged)
@@ -77,7 +77,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
7777
strbuf_addstr(&entry, "submodule.");
7878
strbuf_addstr(&entry, submodule->name);
7979
strbuf_addstr(&entry, ".path");
80-
if (git_config_set_in_file_gently(".gitmodules", entry.buf, newpath) < 0) {
80+
if (git_config_set_in_file_gently(GITMODULES_FILE, entry.buf, newpath) < 0) {
8181
/* Maybe the user already did that, don't error out here */
8282
warning(_("Could not update .gitmodules entry %s"), entry.buf);
8383
strbuf_release(&entry);
@@ -97,7 +97,7 @@ int remove_path_from_gitmodules(const char *path)
9797
struct strbuf sect = STRBUF_INIT;
9898
const struct submodule *submodule;
9999

100-
if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */
100+
if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
101101
return -1;
102102

103103
if (gitmodules_is_unmerged)
@@ -110,7 +110,7 @@ int remove_path_from_gitmodules(const char *path)
110110
}
111111
strbuf_addstr(&sect, "submodule.");
112112
strbuf_addstr(&sect, submodule->name);
113-
if (git_config_rename_section_in_file(".gitmodules", sect.buf, NULL) < 0) {
113+
if (git_config_rename_section_in_file(GITMODULES_FILE, sect.buf, NULL) < 0) {
114114
/* Maybe the user already did that, don't error out here */
115115
warning(_("Could not remove .gitmodules entry for %s"), path);
116116
strbuf_release(&sect);
@@ -122,7 +122,7 @@ int remove_path_from_gitmodules(const char *path)
122122

123123
void stage_updated_gitmodules(void)
124124
{
125-
if (add_file_to_cache(".gitmodules", 0))
125+
if (add_file_to_cache(GITMODULES_FILE, 0))
126126
die(_("staging updated .gitmodules failed"));
127127
}
128128

@@ -230,21 +230,21 @@ void gitmodules_config(void)
230230
struct strbuf gitmodules_path = STRBUF_INIT;
231231
int pos;
232232
strbuf_addstr(&gitmodules_path, work_tree);
233-
strbuf_addstr(&gitmodules_path, "/.gitmodules");
233+
strbuf_addstr(&gitmodules_path, "/" GITMODULES_FILE);
234234
if (read_cache() < 0)
235235
die("index file corrupt");
236-
pos = cache_name_pos(".gitmodules", 11);
236+
pos = cache_name_pos(GITMODULES_FILE, 11);
237237
if (pos < 0) { /* .gitmodules not found or isn't merged */
238238
pos = -1 - pos;
239239
if (active_nr > pos) { /* there is a .gitmodules */
240240
const struct cache_entry *ce = active_cache[pos];
241241
if (ce_namelen(ce) == 11 &&
242-
!memcmp(ce->name, ".gitmodules", 11))
242+
!memcmp(ce->name, GITMODULES_FILE, 11))
243243
gitmodules_is_unmerged = 1;
244244
}
245245
} else if (pos < active_nr) {
246246
struct stat st;
247-
if (lstat(".gitmodules", &st) == 0 &&
247+
if (lstat(GITMODULES_FILE, &st) == 0 &&
248248
ce_match_stat(active_cache[pos], &st, 0) & DATA_CHANGED)
249249
gitmodules_is_modified = 1;
250250
}
@@ -264,7 +264,7 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
264264

265265
void repo_read_gitmodules(struct repository *repo)
266266
{
267-
char *gitmodules_path = repo_worktree_path(repo, ".gitmodules");
267+
char *gitmodules_path = repo_worktree_path(repo, GITMODULES_FILE);
268268

269269
git_config_from_file(gitmodules_cb, gitmodules_path, repo);
270270
free(gitmodules_path);

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static void reload_gitmodules_file(struct index_state *index,
286286
for (i = 0; i < index->cache_nr; i++) {
287287
struct cache_entry *ce = index->cache[i];
288288
if (ce->ce_flags & CE_UPDATE) {
289-
int r = strcmp(ce->name, ".gitmodules");
289+
int r = strcmp(ce->name, GITMODULES_FILE);
290290
if (r < 0)
291291
continue;
292292
else if (r == 0) {

0 commit comments

Comments
 (0)