submodule-config: rename commit_sha1 to treeish_name

It is also possible to pass in any treeish name to lookup a submodule config. Make it clear by naming the variables accordingly. Looking up a submodule config by tree hash will come in handy in a later patch. Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Nov 22, 2016 at 12:14 UTC 73c293bb6c15992690b16c90bcac243a76d86400
4 files changed +44 -29
Documentation/technical/api-submodule-config.txt
+5 -4
@@ -47,15 +47,16 @@ Functions
47 Can be passed to the config parsing infrastructure to parse
48 local (worktree) submodule configurations.
49
50 -`const struct submodule *submodule_from_path(const unsigned char *commit_sha1, const char *path)`::
50 +`const struct submodule *submodule_from_path(const unsigned char *treeish_name, const char *path)`::
51
52 - Lookup values for one submodule by its commit_sha1 and path.
52 + Given a tree-ish in the superproject and a path, return the
53 + submodule that is bound at the path in the named tree.
54
54 -`const struct submodule *submodule_from_name(const unsigned char *commit_sha1, const char *name)`::
55 +`const struct submodule *submodule_from_name(const unsigned char *treeish_name, const char *name)`::
56
57 The same as above but lookup by name.
58
58 -If given the null_sha1 as commit_sha1 the local configuration of a
59 +If given the null_sha1 as treeish_name the local configuration of a
60 submodule will be returned (e.g. consolidated values from local git
61 configuration and the .gitmodules file in the worktree).
62
submodule-config.c
+23 -23
@@ -263,12 +263,12 @@ int parse_push_recurse_submodules_arg(const char *opt, const char *arg)
263 return parse_push_recurse(opt, arg, 1);
264 }
265
266 -static void warn_multiple_config(const unsigned char *commit_sha1,
266 +static void warn_multiple_config(const unsigned char *treeish_name,
267 const char *name, const char *option)
268 {
269 const char *commit_string = "WORKTREE";
270 - if (commit_sha1)
271 - commit_string = sha1_to_hex(commit_sha1);
270 + if (treeish_name)
271 + commit_string = sha1_to_hex(treeish_name);
272 warning("%s:.gitmodules, multiple configurations found for "
273 "'submodule.%s.%s'. Skipping second one!",
274 commit_string, name, option);
@@ -276,7 +276,7 @@ static void warn_multiple_config(const unsigned char *commit_sha1,
276
277 struct parse_config_parameter {
278 struct submodule_cache *cache;
279 - const unsigned char *commit_sha1;
279 + const unsigned char *treeish_name;
280 const unsigned char *gitmodules_sha1;
281 int overwrite;
282 };
@@ -300,7 +300,7 @@ static int parse_config(const char *var, const char *value, void *data)
300 if (!value)
301 ret = config_error_nonbool(var);
302 else if (!me->overwrite && submodule->path)
303 - warn_multiple_config(me->commit_sha1, submodule->name,
303 + warn_multiple_config(me->treeish_name, submodule->name,
304 "path");
305 else {
306 if (submodule->path)
@@ -314,7 +314,7 @@ static int parse_config(const char *var, const char *value, void *data)
314 int die_on_error = is_null_sha1(me->gitmodules_sha1);
315 if (!me->overwrite &&
316 submodule->fetch_recurse != RECURSE_SUBMODULES_NONE)
317 - warn_multiple_config(me->commit_sha1, submodule->name,
317 + warn_multiple_config(me->treeish_name, submodule->name,
318 "fetchrecursesubmodules");
319 else
320 submodule->fetch_recurse = parse_fetch_recurse(
@@ -324,7 +324,7 @@ static int parse_config(const char *var, const char *value, void *data)
324 if (!value)
325 ret = config_error_nonbool(var);
326 else if (!me->overwrite && submodule->ignore)
327 - warn_multiple_config(me->commit_sha1, submodule->name,
327 + warn_multiple_config(me->treeish_name, submodule->name,
328 "ignore");
329 else if (strcmp(value, "untracked") &&
330 strcmp(value, "dirty") &&
@@ -340,7 +340,7 @@ static int parse_config(const char *var, const char *value, void *data)
340 if (!value) {
341 ret = config_error_nonbool(var);
342 } else if (!me->overwrite && submodule->url) {
343 - warn_multiple_config(me->commit_sha1, submodule->name,
343 + warn_multiple_config(me->treeish_name, submodule->name,
344 "url");
345 } else {
346 free((void *) submodule->url);
@@ -351,21 +351,21 @@ static int parse_config(const char *var, const char *value, void *data)
351 ret = config_error_nonbool(var);
352 else if (!me->overwrite &&
353 submodule->update_strategy.type != SM_UPDATE_UNSPECIFIED)
354 - warn_multiple_config(me->commit_sha1, submodule->name,
354 + warn_multiple_config(me->treeish_name, submodule->name,
355 "update");
356 else if (parse_submodule_update_strategy(value,
357 &submodule->update_strategy) < 0)
358 die(_("invalid value for %s"), var);
359 } else if (!strcmp(item.buf, "shallow")) {
360 if (!me->overwrite && submodule->recommend_shallow != -1)
361 - warn_multiple_config(me->commit_sha1, submodule->name,
361 + warn_multiple_config(me->treeish_name, submodule->name,
362 "shallow");
363 else
364 submodule->recommend_shallow =
365 git_config_bool(var, value);
366 } else if (!strcmp(item.buf, "branch")) {
367 if (!me->overwrite && submodule->branch)
368 - warn_multiple_config(me->commit_sha1, submodule->name,
368 + warn_multiple_config(me->treeish_name, submodule->name,
369 "branch");
370 else {
371 free((void *)submodule->branch);
@@ -379,18 +379,18 @@ static int parse_config(const char *var, const char *value, void *data)
379 return ret;
380 }
381
382 -static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
382 +static int gitmodule_sha1_from_commit(const unsigned char *treeish_name,
383 unsigned char *gitmodules_sha1,
384 struct strbuf *rev)
385 {
386 int ret = 0;
387
388 - if (is_null_sha1(commit_sha1)) {
388 + if (is_null_sha1(treeish_name)) {
389 hashclr(gitmodules_sha1);
390 return 1;
391 }
392
393 - strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
393 + strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(treeish_name));
394 if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
395 ret = 1;
396
@@ -402,7 +402,7 @@ static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
402 * revisions.
403 */
404 static const struct submodule *config_from(struct submodule_cache *cache,
405 - const unsigned char *commit_sha1, const char *key,
405 + const unsigned char *treeish_name, const char *key,
406 enum lookup_type lookup_type)
407 {
408 struct strbuf rev = STRBUF_INIT;
@@ -418,7 +418,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
418 * return the first submodule. Can be used to check whether
419 * there are any submodules parsed.
420 */
421 - if (!commit_sha1 || !key) {
421 + if (!treeish_name || !key) {
422 struct hashmap_iter iter;
423 struct submodule_entry *entry;
424
@@ -428,7 +428,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
428 return entry->config;
429 }
430
431 - if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev))
431 + if (!gitmodule_sha1_from_commit(treeish_name, sha1, &rev))
432 goto out;
433
434 switch (lookup_type) {
@@ -448,7 +448,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
448
449 /* fill the submodule config into the cache */
450 parameter.cache = cache;
451 - parameter.commit_sha1 = commit_sha1;
451 + parameter.treeish_name = treeish_name;
452 parameter.gitmodules_sha1 = sha1;
453 parameter.overwrite = 0;
454 git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
@@ -484,7 +484,7 @@ int parse_submodule_config_option(const char *var, const char *value)
484 {
485 struct parse_config_parameter parameter;
486 parameter.cache = &the_submodule_cache;
487 - parameter.commit_sha1 = NULL;
487 + parameter.treeish_name = NULL;
488 parameter.gitmodules_sha1 = null_sha1;
489 parameter.overwrite = 1;
490
@@ -492,18 +492,18 @@ int parse_submodule_config_option(const char *var, const char *value)
492 return parse_config(var, value, &parameter);
493 }
494
495 -const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
495 +const struct submodule *submodule_from_name(const unsigned char *treeish_name,
496 const char *name)
497 {
498 ensure_cache_init();
499 - return config_from(&the_submodule_cache, commit_sha1, name, lookup_name);
499 + return config_from(&the_submodule_cache, treeish_name, name, lookup_name);
500 }
501
502 -const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
502 +const struct submodule *submodule_from_path(const unsigned char *treeish_name,
503 const char *path)
504 {
505 ensure_cache_init();
506 - return config_from(&the_submodule_cache, commit_sha1, path, lookup_path);
506 + return config_from(&the_submodule_cache, treeish_name, path, lookup_path);
507 }
508
509 void submodule_free(void)
submodule-config.h
+2 -2
@@ -25,9 +25,9 @@ struct submodule {
25 int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
26 int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
27 int parse_submodule_config_option(const char *var, const char *value);
28 -const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
28 +const struct submodule *submodule_from_name(const unsigned char *commit_or_tree,
29 const char *name);
30 -const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
30 +const struct submodule *submodule_from_path(const unsigned char *commit_or_tree,
31 const char *path);
32 void submodule_free(void);
33
t/t7411-submodule-config.sh
+14
@@ -93,6 +93,20 @@ test_expect_success 'error message contains blob reference' '
93 )
94 '
95
96 +test_expect_success 'using different treeishs works' '
97 + (
98 + cd super &&
99 + git tag new_tag &&
100 + tree=$(git rev-parse HEAD^{tree}) &&
101 + commit=$(git rev-parse HEAD^{commit}) &&
102 + test-submodule-config $commit b >expect &&
103 + test-submodule-config $tree b >actual.1 &&
104 + test-submodule-config new_tag b >actual.2 &&
105 + test_cmp expect actual.1 &&
106 + test_cmp expect actual.2
107 + )
108 +'
109 +
110 cat >super/expect_url <<EOF
111 Submodule url: 'git@somewhere.else.net:a.git' for path 'b'
112 Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'