Skip to content

Commit ea2fa5a

Browse files
stefanbellergitster
authored andcommitted
submodule-config: keep update strategy around
Currently submodule.<name>.update is only handled by git-submodule.sh. C code will start to need to make use of that value as more of the functionality of git-submodule.sh moves into library code in C. Add the update field to 'struct submodule' and populate it so it can be read as sm->update or from sm->update_command. Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2a73b3d commit ea2fa5a

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

submodule-config.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static void free_one_config(struct submodule_entry *entry)
5959
{
6060
free((void *) entry->config->path);
6161
free((void *) entry->config->name);
62+
free((void *) entry->config->update_strategy.command);
6263
free(entry->config);
6364
}
6465

@@ -194,6 +195,8 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
194195

195196
submodule->path = NULL;
196197
submodule->url = NULL;
198+
submodule->update_strategy.type = SM_UPDATE_UNSPECIFIED;
199+
submodule->update_strategy.command = NULL;
197200
submodule->fetch_recurse = RECURSE_SUBMODULES_NONE;
198201
submodule->ignore = NULL;
199202

@@ -311,6 +314,16 @@ static int parse_config(const char *var, const char *value, void *data)
311314
free((void *) submodule->url);
312315
submodule->url = xstrdup(value);
313316
}
317+
} else if (!strcmp(item.buf, "update")) {
318+
if (!value)
319+
ret = config_error_nonbool(var);
320+
else if (!me->overwrite &&
321+
submodule->update_strategy.type != SM_UPDATE_UNSPECIFIED)
322+
warn_multiple_config(me->commit_sha1, submodule->name,
323+
"update");
324+
else if (parse_submodule_update_strategy(value,
325+
&submodule->update_strategy) < 0)
326+
die(_("invalid value for %s"), var);
314327
}
315328

316329
strbuf_release(&name);

submodule-config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define SUBMODULE_CONFIG_CACHE_H
33

44
#include "hashmap.h"
5+
#include "submodule.h"
56
#include "strbuf.h"
67

78
/*
@@ -14,6 +15,7 @@ struct submodule {
1415
const char *url;
1516
int fetch_recurse;
1617
const char *ignore;
18+
struct submodule_update_strategy update_strategy;
1719
/* the sha1 blob id of the responsible .gitmodules file */
1820
unsigned char gitmodules_sha1[20];
1921
};

submodule.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,27 @@ void gitmodules_config(void)
210210
}
211211
}
212212

213+
int parse_submodule_update_strategy(const char *value,
214+
struct submodule_update_strategy *dst)
215+
{
216+
free((void*)dst->command);
217+
dst->command = NULL;
218+
if (!strcmp(value, "none"))
219+
dst->type = SM_UPDATE_NONE;
220+
else if (!strcmp(value, "checkout"))
221+
dst->type = SM_UPDATE_CHECKOUT;
222+
else if (!strcmp(value, "rebase"))
223+
dst->type = SM_UPDATE_REBASE;
224+
else if (!strcmp(value, "merge"))
225+
dst->type = SM_UPDATE_MERGE;
226+
else if (skip_prefix(value, "!", &value)) {
227+
dst->type = SM_UPDATE_COMMAND;
228+
dst->command = xstrdup(value);
229+
} else
230+
return -1;
231+
return 0;
232+
}
233+
213234
void handle_ignore_submodules_arg(struct diff_options *diffopt,
214235
const char *arg)
215236
{

submodule.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ enum {
1313
RECURSE_SUBMODULES_ON = 2
1414
};
1515

16+
enum submodule_update_type {
17+
SM_UPDATE_UNSPECIFIED = 0,
18+
SM_UPDATE_CHECKOUT,
19+
SM_UPDATE_REBASE,
20+
SM_UPDATE_MERGE,
21+
SM_UPDATE_NONE,
22+
SM_UPDATE_COMMAND
23+
};
24+
25+
struct submodule_update_strategy {
26+
enum submodule_update_type type;
27+
const char *command;
28+
};
29+
1630
int is_staging_gitmodules_ok(void);
1731
int update_path_in_gitmodules(const char *oldpath, const char *newpath);
1832
int remove_path_from_gitmodules(const char *path);
@@ -21,6 +35,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
2135
const char *path);
2236
int submodule_config(const char *var, const char *value, void *cb);
2337
void gitmodules_config(void);
38+
int parse_submodule_update_strategy(const char *value,
39+
struct submodule_update_strategy *dst);
2440
void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *);
2541
void show_submodule_summary(FILE *f, const char *path,
2642
const char *line_prefix,

0 commit comments

Comments
 (0)