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>
Brandon Williams committed
Aug 2, 2017 at 12:49 UTC
4c0eeafe4755345b0f4636bf09904cf689703e11
3 files changed
+12
-11
cache.h
+1
@@ -433,6 +433,7 @@ static inline enum object_type object_type(unsigned int mode)
433
#define GITATTRIBUTES_FILE ".gitattributes"
434
#define INFOATTRIBUTES_FILE "info/attributes"
435
#define ATTRIBUTE_MACRO_PREFIX "[attr]"
436
+#define GITMODULES_FILE ".gitmodules"
437
#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
438
#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
439
#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"
submodule.c
+10
-10
@@ -63,7 +63,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
63
struct strbuf entry = STRBUF_INIT;
64
const struct submodule *submodule;
65
66
- if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */
66
+ if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
67
return -1;
68
69
if (gitmodules_is_unmerged)
@@ -77,7 +77,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
77
strbuf_addstr(&entry, "submodule.");
78
strbuf_addstr(&entry, submodule->name);
79
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) {
81
/* Maybe the user already did that, don't error out here */
82
warning(_("Could not update .gitmodules entry %s"), entry.buf);
83
strbuf_release(&entry);
@@ -97,7 +97,7 @@ int remove_path_from_gitmodules(const char *path)
97
struct strbuf sect = STRBUF_INIT;
98
const struct submodule *submodule;
99
100
- if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */
100
+ if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
101
return -1;
102
103
if (gitmodules_is_unmerged)
@@ -110,7 +110,7 @@ int remove_path_from_gitmodules(const char *path)
110
}
111
strbuf_addstr(§, "submodule.");
112
strbuf_addstr(§, 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) {
114
/* Maybe the user already did that, don't error out here */
115
warning(_("Could not remove .gitmodules entry for %s"), path);
116
strbuf_release(§);
@@ -122,7 +122,7 @@ int remove_path_from_gitmodules(const char *path)
122
123
void stage_updated_gitmodules(void)
124
{
125
- if (add_file_to_cache(".gitmodules", 0))
125
+ if (add_file_to_cache(GITMODULES_FILE, 0))
126
die(_("staging updated .gitmodules failed"));
127
}
128
@@ -230,21 +230,21 @@ void gitmodules_config(void)
230
struct strbuf gitmodules_path = STRBUF_INIT;
231
int pos;
232
strbuf_addstr(&gitmodules_path, work_tree);
233
- strbuf_addstr(&gitmodules_path, "/.gitmodules");
233
+ strbuf_addstr(&gitmodules_path, "/" GITMODULES_FILE);
234
if (read_cache() < 0)
235
die("index file corrupt");
236
- pos = cache_name_pos(".gitmodules", 11);
236
+ pos = cache_name_pos(GITMODULES_FILE, 11);
237
if (pos < 0) { /* .gitmodules not found or isn't merged */
238
pos = -1 - pos;
239
if (active_nr > pos) { /* there is a .gitmodules */
240
const struct cache_entry *ce = active_cache[pos];
241
if (ce_namelen(ce) == 11 &&
242
- !memcmp(ce->name, ".gitmodules", 11))
242
+ !memcmp(ce->name, GITMODULES_FILE, 11))
243
gitmodules_is_unmerged = 1;
244
}
245
} else if (pos < active_nr) {
246
struct stat st;
247
- if (lstat(".gitmodules", &st) == 0 &&
247
+ if (lstat(GITMODULES_FILE, &st) == 0 &&
248
ce_match_stat(active_cache[pos], &st, 0) & DATA_CHANGED)
249
gitmodules_is_modified = 1;
250
}
@@ -264,7 +264,7 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
264
265
void repo_read_gitmodules(struct repository *repo)
266
{
267
- char *gitmodules_path = repo_worktree_path(repo, ".gitmodules");
267
+ char *gitmodules_path = repo_worktree_path(repo, GITMODULES_FILE);
268
269
git_config_from_file(gitmodules_cb, gitmodules_path, repo);
270
free(gitmodules_path);
unpack-trees.c
+1
-1
@@ -286,7 +286,7 @@ static void reload_gitmodules_file(struct index_state *index,
286
for (i = 0; i < index->cache_nr; i++) {
287
struct cache_entry *ce = index->cache[i];
288
if (ce->ce_flags & CE_UPDATE) {
289
- int r = strcmp(ce->name, ".gitmodules");
289
+ int r = strcmp(ce->name, GITMODULES_FILE);
290
if (r < 0)
291
continue;
292
else if (r == 0) {