submodule: convert submodule config lookup to use object_id
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jul 13, 2017 at 23:49 UTC
cd73de47148c16760a62fa3f75cafe015ca764b2
10 files changed
+62
-62
builtin/grep.c
+2
-2
@@ -653,7 +653,7 @@ static int grep_submodule(struct grep_opt *opt, const struct object_id *oid,
653
*/
654
if (oid) {
655
const struct submodule *sub =
656
- submodule_from_path(null_sha1, path);
656
+ submodule_from_path(&null_oid, path);
657
if (sub)
658
path = git_path("modules/%s", sub->name);
659
@@ -862,7 +862,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
862
/* load the gitmodules file for this rev */
863
if (recurse_submodules) {
864
submodule_free();
865
- gitmodules_config_sha1(real_obj->oid.hash);
865
+ gitmodules_config_oid(&real_obj->oid);
866
}
867
if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path)) {
868
hit = 1;
builtin/submodule--helper.c
+4
-4
@@ -350,7 +350,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
350
} else
351
displaypath = xstrdup(path);
352
353
- sub = submodule_from_path(null_sha1, path);
353
+ sub = submodule_from_path(&null_oid, path);
354
355
if (!sub)
356
die(_("No url found for submodule path '%s' in .gitmodules"),
@@ -476,7 +476,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
476
usage(_("git submodule--helper name <path>"));
477
478
gitmodules_config();
479
- sub = submodule_from_path(null_sha1, argv[1]);
479
+ sub = submodule_from_path(&null_oid, argv[1]);
480
481
if (!sub)
482
die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -795,7 +795,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
795
goto cleanup;
796
}
797
798
- sub = submodule_from_path(null_sha1, ce->name);
798
+ sub = submodule_from_path(&null_oid, ce->name);
799
800
if (suc->recursive_prefix)
801
displaypath = relative_path(suc->recursive_prefix,
@@ -1060,7 +1060,7 @@ static const char *remote_submodule_branch(const char *path)
1060
gitmodules_config();
1061
git_config(submodule_config, NULL);
1062
1063
- sub = submodule_from_path(null_sha1, path);
1063
+ sub = submodule_from_path(&null_oid, path);
1064
if (!sub)
1065
return NULL;
1066
config.c
+6
-6
@@ -1460,9 +1460,9 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
1460
return do_config_from(&top, fn, data);
1461
}
1462
1463
-int git_config_from_blob_sha1(config_fn_t fn,
1463
+int git_config_from_blob_oid(config_fn_t fn,
1464
const char *name,
1465
- const unsigned char *sha1,
1465
+ const struct object_id *oid,
1466
void *data)
1467
{
1468
enum object_type type;
@@ -1470,7 +1470,7 @@ int git_config_from_blob_sha1(config_fn_t fn,
1470
unsigned long size;
1471
int ret;
1472
1473
- buf = read_sha1_file(sha1, &type, &size);
1473
+ buf = read_sha1_file(oid->hash, &type, &size);
1474
if (!buf)
1475
return error("unable to load config blob object '%s'", name);
1476
if (type != OBJ_BLOB) {
@@ -1488,11 +1488,11 @@ static int git_config_from_blob_ref(config_fn_t fn,
1488
const char *name,
1489
void *data)
1490
{
1491
- unsigned char sha1[20];
1491
+ struct object_id oid;
1492
1493
- if (get_sha1(name, sha1) < 0)
1493
+ if (get_oid(name, &oid) < 0)
1494
return error("unable to resolve config blob '%s'", name);
1495
- return git_config_from_blob_sha1(fn, name, sha1, data);
1495
+ return git_config_from_blob_oid(fn, name, &oid, data);
1496
}
1497
1498
const char *git_etc_gitconfig(void)
config.h
+2
-2
@@ -39,8 +39,8 @@ extern int git_default_config(const char *, const char *, void *);
39
extern int git_config_from_file(config_fn_t fn, const char *, void *);
40
extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
41
const char *name, const char *buf, size_t len, void *data);
42
-extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
43
- const unsigned char *sha1, void *data);
42
+extern int git_config_from_blob_oid(config_fn_t fn, const char *name,
43
+ const struct object_id *oid, void *data);
44
extern void git_config_push_parameter(const char *text);
45
extern int git_config_from_parameters(config_fn_t fn, void *data);
46
extern void read_early_config(config_fn_t cb, void *data);
repository.c
+1
-1
@@ -158,7 +158,7 @@ int repo_submodule_init(struct repository *submodule,
158
struct strbuf worktree = STRBUF_INIT;
159
int ret = 0;
160
161
- sub = submodule_from_cache(superproject, null_sha1, path);
161
+ sub = submodule_from_cache(superproject, &null_oid, path);
162
if (!sub) {
163
ret = -1;
164
goto out;
submodule-config.c
+19
-19
@@ -417,19 +417,19 @@ static int parse_config(const char *var, const char *value, void *data)
417
return ret;
418
}
419
420
-int gitmodule_sha1_from_commit(const unsigned char *treeish_name,
421
- unsigned char *gitmodules_sha1,
420
+int gitmodule_oid_from_commit(const struct object_id *treeish_name,
421
+ struct object_id *gitmodules_oid,
422
struct strbuf *rev)
423
{
424
int ret = 0;
425
426
- if (is_null_sha1(treeish_name)) {
427
- hashclr(gitmodules_sha1);
426
+ if (is_null_oid(treeish_name)) {
427
+ oidclr(gitmodules_oid);
428
return 1;
429
}
430
431
- strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(treeish_name));
432
- if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
431
+ strbuf_addf(rev, "%s:.gitmodules", oid_to_hex(treeish_name));
432
+ if (get_oid(rev->buf, gitmodules_oid) >= 0)
433
ret = 1;
434
435
return ret;
@@ -440,13 +440,13 @@ int gitmodule_sha1_from_commit(const unsigned char *treeish_name,
440
* revisions.
441
*/
442
static const struct submodule *config_from(struct submodule_cache *cache,
443
- const unsigned char *treeish_name, const char *key,
443
+ const struct object_id *treeish_name, const char *key,
444
enum lookup_type lookup_type)
445
{
446
struct strbuf rev = STRBUF_INIT;
447
unsigned long config_size;
448
char *config = NULL;
449
- unsigned char sha1[20];
449
+ struct object_id oid;
450
enum object_type type;
451
const struct submodule *submodule = NULL;
452
struct parse_config_parameter parameter;
@@ -466,28 +466,28 @@ static const struct submodule *config_from(struct submodule_cache *cache,
466
return entry->config;
467
}
468
469
- if (!gitmodule_sha1_from_commit(treeish_name, sha1, &rev))
469
+ if (!gitmodule_oid_from_commit(treeish_name, &oid, &rev))
470
goto out;
471
472
switch (lookup_type) {
473
case lookup_name:
474
- submodule = cache_lookup_name(cache, sha1, key);
474
+ submodule = cache_lookup_name(cache, oid.hash, key);
475
break;
476
case lookup_path:
477
- submodule = cache_lookup_path(cache, sha1, key);
477
+ submodule = cache_lookup_path(cache, oid.hash, key);
478
break;
479
}
480
if (submodule)
481
goto out;
482
483
- config = read_sha1_file(sha1, &type, &config_size);
483
+ config = read_sha1_file(oid.hash, &type, &config_size);
484
if (!config || type != OBJ_BLOB)
485
goto out;
486
487
/* fill the submodule config into the cache */
488
parameter.cache = cache;
489
- parameter.treeish_name = treeish_name;
490
- parameter.gitmodules_sha1 = sha1;
489
+ parameter.treeish_name = treeish_name->hash;
490
+ parameter.gitmodules_sha1 = oid.hash;
491
parameter.overwrite = 0;
492
git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
493
config, config_size, ¶meter);
@@ -496,9 +496,9 @@ static const struct submodule *config_from(struct submodule_cache *cache,
496
497
switch (lookup_type) {
498
case lookup_name:
499
- return cache_lookup_name(cache, sha1, key);
499
+ return cache_lookup_name(cache, oid.hash, key);
500
case lookup_path:
501
- return cache_lookup_path(cache, sha1, key);
501
+ return cache_lookup_path(cache, oid.hash, key);
502
default:
503
return NULL;
504
}
@@ -540,14 +540,14 @@ int parse_submodule_config_option(const char *var, const char *value)
540
return submodule_config_option(the_repository, var, value);
541
}
542
543
-const struct submodule *submodule_from_name(const unsigned char *treeish_name,
543
+const struct submodule *submodule_from_name(const struct object_id *treeish_name,
544
const char *name)
545
{
546
submodule_cache_check_init(the_repository);
547
return config_from(the_repository->submodule_cache, treeish_name, name, lookup_name);
548
}
549
550
-const struct submodule *submodule_from_path(const unsigned char *treeish_name,
550
+const struct submodule *submodule_from_path(const struct object_id *treeish_name,
551
const char *path)
552
{
553
submodule_cache_check_init(the_repository);
@@ -555,7 +555,7 @@ const struct submodule *submodule_from_path(const unsigned char *treeish_name,
555
}
556
557
const struct submodule *submodule_from_cache(struct repository *repo,
558
- const unsigned char *treeish_name,
558
+ const struct object_id *treeish_name,
559
const char *key)
560
{
561
submodule_cache_check_init(repo);
submodule-config.h
+6
-6
@@ -34,15 +34,15 @@ extern int parse_submodule_config_option(const char *var, const char *value);
34
extern int submodule_config_option(struct repository *repo,
35
const char *var, const char *value);
36
extern const struct submodule *submodule_from_name(
37
- const unsigned char *commit_or_tree, const char *name);
37
+ const struct object_id *commit_or_tree, const char *name);
38
extern const struct submodule *submodule_from_path(
39
- const unsigned char *commit_or_tree, const char *path);
39
+ const struct object_id *commit_or_tree, const char *path);
40
extern const struct submodule *submodule_from_cache(struct repository *repo,
41
- const unsigned char *treeish_name,
41
+ const struct object_id *treeish_name,
42
const char *key);
43
-extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
44
- unsigned char *gitmodules_sha1,
45
- struct strbuf *rev);
43
+extern int gitmodule_oid_from_commit(const struct object_id *commit_oid,
44
+ struct object_id *gitmodules_oid,
45
+ struct strbuf *rev);
46
extern void submodule_free(void);
47
48
#endif /* SUBMODULE_CONFIG_H */
submodule.c
+16
-16
@@ -69,7 +69,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
69
if (gitmodules_is_unmerged)
70
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
71
72
- submodule = submodule_from_path(null_sha1, oldpath);
72
+ submodule = submodule_from_path(&null_oid, oldpath);
73
if (!submodule || !submodule->name) {
74
warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
75
return -1;
@@ -103,7 +103,7 @@ int remove_path_from_gitmodules(const char *path)
103
if (gitmodules_is_unmerged)
104
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
105
106
- submodule = submodule_from_path(null_sha1, path);
106
+ submodule = submodule_from_path(&null_oid, path);
107
if (!submodule || !submodule->name) {
108
warning(_("Could not find section in .gitmodules where path=%s"), path);
109
return -1;
@@ -147,7 +147,7 @@ done:
147
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
148
const char *path)
149
{
150
- const struct submodule *submodule = submodule_from_path(null_sha1, path);
150
+ const struct submodule *submodule = submodule_from_path(&null_oid, path);
151
if (submodule) {
152
if (submodule->ignore)
153
handle_ignore_submodules_arg(diffopt, submodule->ignore);
@@ -270,14 +270,14 @@ void repo_read_gitmodules(struct repository *repo)
270
free(gitmodules_path);
271
}
272
273
-void gitmodules_config_sha1(const unsigned char *commit_sha1)
273
+void gitmodules_config_oid(const struct object_id *commit_oid)
274
{
275
struct strbuf rev = STRBUF_INIT;
276
- unsigned char sha1[20];
276
+ struct object_id oid;
277
278
- if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
279
- git_config_from_blob_sha1(git_modules_config, rev.buf,
280
- sha1, NULL);
278
+ if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
279
+ git_config_from_blob_oid(submodule_config, rev.buf,
280
+ &oid, NULL);
281
}
282
strbuf_release(&rev);
283
}
@@ -293,7 +293,7 @@ int is_submodule_active(struct repository *repo, const char *path)
293
const struct string_list *sl;
294
const struct submodule *module;
295
296
- module = submodule_from_cache(repo, null_sha1, path);
296
+ module = submodule_from_cache(repo, &null_oid, path);
297
298
/* early return if there isn't a path->module mapping */
299
if (!module)
@@ -738,7 +738,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
738
if (!should_update_submodules())
739
return NULL;
740
741
- return submodule_from_path(null_sha1, ce->name);
741
+ return submodule_from_path(&null_oid, ce->name);
742
}
743
744
static struct oid_array *submodule_commits(struct string_list *submodules,
@@ -1166,9 +1166,9 @@ static int get_next_submodule(struct child_process *cp,
1166
if (!S_ISGITLINK(ce->ce_mode))
1167
continue;
1168
1169
- submodule = submodule_from_path(null_sha1, ce->name);
1169
+ submodule = submodule_from_path(&null_oid, ce->name);
1170
if (!submodule)
1171
- submodule = submodule_from_name(null_sha1, ce->name);
1171
+ submodule = submodule_from_name(&null_oid, ce->name);
1172
1173
default_argv = "yes";
1174
if (spf->command_line_option == RECURSE_SUBMODULES_DEFAULT) {
@@ -1544,7 +1544,7 @@ int submodule_move_head(const char *path,
1544
if (old && !is_submodule_populated_gently(path, error_code_ptr))
1545
return 0;
1546
1547
- sub = submodule_from_path(null_sha1, path);
1547
+ sub = submodule_from_path(&null_oid, path);
1548
1549
if (!sub)
1550
die("BUG: could not get submodule information for '%s'", path);
@@ -1826,7 +1826,7 @@ static void relocate_single_git_dir_into_superproject(const char *prefix,
1826
1827
real_old_git_dir = real_pathdup(old_git_dir, 1);
1828
1829
- sub = submodule_from_path(null_sha1, path);
1829
+ sub = submodule_from_path(&null_oid, path);
1830
if (!sub)
1831
die(_("could not lookup name for submodule '%s'"), path);
1832
@@ -1882,7 +1882,7 @@ void absorb_git_dir_into_superproject(const char *prefix,
1882
* superproject did not rewrite the git file links yet,
1883
* fix it now.
1884
*/
1885
- sub = submodule_from_path(null_sha1, path);
1885
+ sub = submodule_from_path(&null_oid, path);
1886
if (!sub)
1887
die(_("could not lookup name for submodule '%s'"), path);
1888
connect_work_tree_and_git_dir(path,
@@ -2025,7 +2025,7 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
2025
}
2026
if (!is_git_directory(buf->buf)) {
2027
gitmodules_config();
2028
- sub = submodule_from_path(null_sha1, submodule);
2028
+ sub = submodule_from_path(&null_oid, submodule);
2029
if (!sub) {
2030
ret = -1;
2031
goto cleanup;
submodule.h
+1
-1
@@ -48,7 +48,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
48
void load_submodule_cache(void);
49
extern void gitmodules_config(void);
50
extern void repo_read_gitmodules(struct repository *repo);
51
-extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
51
+extern void gitmodules_config_oid(const struct object_id *commit_oid);
52
extern int is_submodule_active(struct repository *repo, const char *path);
53
/*
54
* Determine if a submodule has been populated at a given 'path' by checking if
t/helper/test-submodule-config.c
+5
-5
@@ -41,7 +41,7 @@ int cmd_main(int argc, const char **argv)
41
git_config(git_test_config, NULL);
42
43
while (*arg) {
44
- unsigned char commit_sha1[20];
44
+ struct object_id commit_oid;
45
const struct submodule *submodule;
46
const char *commit;
47
const char *path_or_name;
@@ -50,14 +50,14 @@ int cmd_main(int argc, const char **argv)
50
path_or_name = arg[1];
51
52
if (commit[0] == '\0')
53
- hashclr(commit_sha1);
54
- else if (get_sha1(commit, commit_sha1) < 0)
53
+ oidclr(&commit_oid);
54
+ else if (get_oid(commit, &commit_oid) < 0)
55
die_usage(argc, argv, "Commit not found.");
56
57
if (lookup_name) {
58
- submodule = submodule_from_name(commit_sha1, path_or_name);
58
+ submodule = submodule_from_name(&commit_oid, path_or_name);
59
} else
60
- submodule = submodule_from_path(commit_sha1, path_or_name);
60
+ submodule = submodule_from_path(&commit_oid, path_or_name);
61
if (!submodule)
62
die_usage(argc, argv, "Submodule not found.");
63