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 <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Feb 29, 2016 at 18:07 UTC
ea2fa5a3388281b880ae2aa75c8eac0d4b1a6c69
4 files changed
+52
submodule-config.c
+13
@@ -59,6 +59,7 @@ static void free_one_config(struct submodule_entry *entry)
59
{
60
free((void *) entry->config->path);
61
free((void *) entry->config->name);
62
+ free((void *) entry->config->update_strategy.command);
63
free(entry->config);
64
}
65
@@ -194,6 +195,8 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
195
196
submodule->path = NULL;
197
submodule->url = NULL;
198
+ submodule->update_strategy.type = SM_UPDATE_UNSPECIFIED;
199
+ submodule->update_strategy.command = NULL;
200
submodule->fetch_recurse = RECURSE_SUBMODULES_NONE;
201
submodule->ignore = NULL;
202
@@ -311,6 +314,16 @@ static int parse_config(const char *var, const char *value, void *data)
314
free((void *) submodule->url);
315
submodule->url = xstrdup(value);
316
}
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);
327
}
328
329
strbuf_release(&name);
submodule-config.h
+2
@@ -2,6 +2,7 @@
2
#define SUBMODULE_CONFIG_CACHE_H
3
4
#include "hashmap.h"
5
+#include "submodule.h"
6
#include "strbuf.h"
7
8
/*
@@ -14,6 +15,7 @@ struct submodule {
15
const char *url;
16
int fetch_recurse;
17
const char *ignore;
18
+ struct submodule_update_strategy update_strategy;
19
/* the sha1 blob id of the responsible .gitmodules file */
20
unsigned char gitmodules_sha1[20];
21
};
submodule.c
+21
@@ -210,6 +210,27 @@ void gitmodules_config(void)
210
}
211
}
212
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
+
234
void handle_ignore_submodules_arg(struct diff_options *diffopt,
235
const char *arg)
236
{
submodule.h
+16
@@ -13,6 +13,20 @@ enum {
13
RECURSE_SUBMODULES_ON = 2
14
};
15
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
+
30
int is_staging_gitmodules_ok(void);
31
int update_path_in_gitmodules(const char *oldpath, const char *newpath);
32
int remove_path_from_gitmodules(const char *path);
@@ -21,6 +35,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
35
const char *path);
36
int submodule_config(const char *var, const char *value, void *cb);
37
void gitmodules_config(void);
38
+int parse_submodule_update_strategy(const char *value,
39
+ struct submodule_update_strategy *dst);
40
void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *);
41
void show_submodule_summary(FILE *f, const char *path,
42
const char *line_prefix,