1
1
#include "cache.h"
2
+ #include "submodule-config.h"
2
3
#include "submodule.h"
3
4
#include "dir.h"
4
5
#include "diff.h"
12
13
#include "argv-array.h"
13
14
#include "blob.h"
14
15
15
- static struct string_list config_name_for_path ;
16
- static struct string_list config_fetch_recurse_submodules_for_name ;
17
- static struct string_list config_ignore_for_name ;
18
16
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND ;
19
17
static struct string_list changed_submodule_paths ;
20
18
static int initialized_fetch_ref_tips ;
@@ -41,77 +39,6 @@ static int gitmodules_is_unmerged;
41
39
*/
42
40
static int gitmodules_is_modified ;
43
41
44
- static const char * get_name_for_path (const char * path )
45
- {
46
- struct string_list_item * path_option ;
47
- if (path == NULL ) {
48
- if (config_name_for_path .nr > 0 )
49
- return config_name_for_path .items [0 ].util ;
50
- else
51
- return NULL ;
52
- }
53
- path_option = unsorted_string_list_lookup (& config_name_for_path , path );
54
- if (!path_option )
55
- return NULL ;
56
- return path_option -> util ;
57
- }
58
-
59
- static void set_name_for_path (const char * path , const char * name , int namelen )
60
- {
61
- struct string_list_item * config ;
62
- config = unsorted_string_list_lookup (& config_name_for_path , path );
63
- if (config )
64
- free (config -> util );
65
- else
66
- config = string_list_append (& config_name_for_path , xstrdup (path ));
67
- config -> util = xmemdupz (name , namelen );
68
- }
69
-
70
- static const char * get_ignore_for_name (const char * name )
71
- {
72
- struct string_list_item * ignore_option ;
73
- ignore_option = unsorted_string_list_lookup (& config_ignore_for_name , name );
74
- if (!ignore_option )
75
- return NULL ;
76
-
77
- return ignore_option -> util ;
78
- }
79
-
80
- static void set_ignore_for_name (const char * name , int namelen , const char * ignore )
81
- {
82
- struct string_list_item * config ;
83
- char * name_cstr = xmemdupz (name , namelen );
84
- config = unsorted_string_list_lookup (& config_ignore_for_name , name_cstr );
85
- if (config ) {
86
- free (config -> util );
87
- free (name_cstr );
88
- } else
89
- config = string_list_append (& config_ignore_for_name , name_cstr );
90
- config -> util = xstrdup (ignore );
91
- }
92
-
93
- static int get_fetch_recurse_for_name (const char * name )
94
- {
95
- struct string_list_item * fetch_recurse ;
96
- fetch_recurse = unsorted_string_list_lookup (& config_fetch_recurse_submodules_for_name , name );
97
- if (!fetch_recurse )
98
- return RECURSE_SUBMODULES_NONE ;
99
-
100
- return (intptr_t ) fetch_recurse -> util ;
101
- }
102
-
103
- static void set_fetch_recurse_for_name (const char * name , int namelen , int fetch_recurse )
104
- {
105
- struct string_list_item * config ;
106
- char * name_cstr = xmemdupz (name , namelen );
107
- config = unsorted_string_list_lookup (& config_fetch_recurse_submodules_for_name , name_cstr );
108
- if (!config )
109
- config = string_list_append (& config_fetch_recurse_submodules_for_name , name_cstr );
110
- else
111
- free (name_cstr );
112
- config -> util = (void * )(intptr_t ) fetch_recurse ;
113
- }
114
-
115
42
int is_staging_gitmodules_ok (void )
116
43
{
117
44
return !gitmodules_is_modified ;
@@ -125,21 +52,21 @@ int is_staging_gitmodules_ok(void)
125
52
int update_path_in_gitmodules (const char * oldpath , const char * newpath )
126
53
{
127
54
struct strbuf entry = STRBUF_INIT ;
128
- const char * path ;
55
+ const struct submodule * submodule ;
129
56
130
57
if (!file_exists (".gitmodules" )) /* Do nothing without .gitmodules */
131
58
return -1 ;
132
59
133
60
if (gitmodules_is_unmerged )
134
61
die (_ ("Cannot change unmerged .gitmodules, resolve merge conflicts first" ));
135
62
136
- path = get_name_for_path ( oldpath );
137
- if (!path ) {
63
+ submodule = submodule_from_path ( null_sha1 , oldpath );
64
+ if (!submodule || ! submodule -> name ) {
138
65
warning (_ ("Could not find section in .gitmodules where path=%s" ), oldpath );
139
66
return -1 ;
140
67
}
141
68
strbuf_addstr (& entry , "submodule." );
142
- strbuf_addstr (& entry , path );
69
+ strbuf_addstr (& entry , submodule -> name );
143
70
strbuf_addstr (& entry , ".path" );
144
71
if (git_config_set_in_file (".gitmodules" , entry .buf , newpath ) < 0 ) {
145
72
/* Maybe the user already did that, don't error out here */
@@ -159,21 +86,21 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
159
86
int remove_path_from_gitmodules (const char * path )
160
87
{
161
88
struct strbuf sect = STRBUF_INIT ;
162
- const char * path_option ;
89
+ const struct submodule * submodule ;
163
90
164
91
if (!file_exists (".gitmodules" )) /* Do nothing without .gitmodules */
165
92
return -1 ;
166
93
167
94
if (gitmodules_is_unmerged )
168
95
die (_ ("Cannot change unmerged .gitmodules, resolve merge conflicts first" ));
169
96
170
- path_option = get_name_for_path ( path );
171
- if (!path_option ) {
97
+ submodule = submodule_from_path ( null_sha1 , path );
98
+ if (!submodule || ! submodule -> name ) {
172
99
warning (_ ("Could not find section in .gitmodules where path=%s" ), path );
173
100
return -1 ;
174
101
}
175
102
strbuf_addstr (& sect , "submodule." );
176
- strbuf_addstr (& sect , path_option );
103
+ strbuf_addstr (& sect , submodule -> name );
177
104
if (git_config_rename_section_in_file (".gitmodules" , sect .buf , NULL ) < 0 ) {
178
105
/* Maybe the user already did that, don't error out here */
179
106
warning (_ ("Could not remove .gitmodules entry for %s" ), path );
@@ -235,11 +162,10 @@ static int add_submodule_odb(const char *path)
235
162
void set_diffopt_flags_from_submodule_config (struct diff_options * diffopt ,
236
163
const char * path )
237
164
{
238
- const char * name = get_name_for_path (path );
239
- if (name ) {
240
- const char * ignore = get_ignore_for_name (name );
241
- if (ignore )
242
- handle_ignore_submodules_arg (diffopt , ignore );
165
+ const struct submodule * submodule = submodule_from_path (null_sha1 , path );
166
+ if (submodule ) {
167
+ if (submodule -> ignore )
168
+ handle_ignore_submodules_arg (diffopt , submodule -> ignore );
243
169
else if (gitmodules_is_unmerged )
244
170
DIFF_OPT_SET (diffopt , IGNORE_SUBMODULES );
245
171
}
@@ -288,42 +214,6 @@ void gitmodules_config(void)
288
214
}
289
215
}
290
216
291
- int parse_submodule_config_option (const char * var , const char * value )
292
- {
293
- const char * name , * key ;
294
- int namelen ;
295
-
296
- if (parse_config_key (var , "submodule" , & name , & namelen , & key ) < 0 || !name )
297
- return 0 ;
298
-
299
- if (!strcmp (key , "path" )) {
300
- if (!value )
301
- return config_error_nonbool (var );
302
-
303
- set_name_for_path (value , name , namelen );
304
-
305
- } else if (!strcmp (key , "fetchrecursesubmodules" )) {
306
- int fetch_recurse = parse_fetch_recurse_submodules_arg (var , value );
307
-
308
- set_fetch_recurse_for_name (name , namelen , fetch_recurse );
309
-
310
- } else if (!strcmp (key , "ignore" )) {
311
-
312
- if (!value )
313
- return config_error_nonbool (var );
314
-
315
- if (strcmp (value , "untracked" ) && strcmp (value , "dirty" ) &&
316
- strcmp (value , "all" ) && strcmp (value , "none" )) {
317
- warning ("Invalid parameter \"%s\" for config option \"submodule.%s.ignore\"" , value , var );
318
- return 0 ;
319
- }
320
-
321
- set_ignore_for_name (name , namelen , value );
322
- return 0 ;
323
- }
324
- return 0 ;
325
- }
326
-
327
217
void handle_ignore_submodules_arg (struct diff_options * diffopt ,
328
218
const char * arg )
329
219
{
@@ -699,7 +589,7 @@ static void calculate_changed_submodule_paths(void)
699
589
struct argv_array argv = ARGV_ARRAY_INIT ;
700
590
701
591
/* No need to check if there are no submodules configured */
702
- if (!get_name_for_path ( NULL ))
592
+ if (!submodule_from_path ( NULL , NULL ))
703
593
return ;
704
594
705
595
init_revisions (& rev , NULL );
@@ -746,7 +636,6 @@ int fetch_populated_submodules(const struct argv_array *options,
746
636
int i , result = 0 ;
747
637
struct child_process cp = CHILD_PROCESS_INIT ;
748
638
struct argv_array argv = ARGV_ARRAY_INIT ;
749
- const char * name_for_path ;
750
639
const char * work_tree = get_git_work_tree ();
751
640
if (!work_tree )
752
641
goto out ;
@@ -771,23 +660,26 @@ int fetch_populated_submodules(const struct argv_array *options,
771
660
struct strbuf submodule_git_dir = STRBUF_INIT ;
772
661
struct strbuf submodule_prefix = STRBUF_INIT ;
773
662
const struct cache_entry * ce = active_cache [i ];
774
- const char * git_dir , * name , * default_argv ;
663
+ const char * git_dir , * default_argv ;
664
+ const struct submodule * submodule ;
775
665
776
666
if (!S_ISGITLINK (ce -> ce_mode ))
777
667
continue ;
778
668
779
- name = ce -> name ;
780
- name_for_path = get_name_for_path (ce -> name );
781
- if (name_for_path )
782
- name = name_for_path ;
669
+ submodule = submodule_from_path (null_sha1 , ce -> name );
670
+ if (!submodule )
671
+ submodule = submodule_from_name (null_sha1 , ce -> name );
783
672
784
673
default_argv = "yes" ;
785
674
if (command_line_option == RECURSE_SUBMODULES_DEFAULT ) {
786
- int fetch_recurse_option = get_fetch_recurse_for_name (name );
787
- if (fetch_recurse_option != RECURSE_SUBMODULES_NONE ) {
788
- if (fetch_recurse_option == RECURSE_SUBMODULES_OFF )
675
+ if (submodule &&
676
+ submodule -> fetch_recurse !=
677
+ RECURSE_SUBMODULES_NONE ) {
678
+ if (submodule -> fetch_recurse ==
679
+ RECURSE_SUBMODULES_OFF )
789
680
continue ;
790
- if (fetch_recurse_option == RECURSE_SUBMODULES_ON_DEMAND ) {
681
+ if (submodule -> fetch_recurse ==
682
+ RECURSE_SUBMODULES_ON_DEMAND ) {
791
683
if (!unsorted_string_list_lookup (& changed_submodule_paths , ce -> name ))
792
684
continue ;
793
685
default_argv = "on-demand" ;
0 commit comments