Skip to content

Commit 5a1ba6b

Browse files
committed
Merge 'hv/submodule-config' to 'sb/submodule-helper'
* hv/submodule-config: submodule: allow erroneous values for the fetchRecurseSubmodules option submodule: use new config API for worktree configurations submodule: extract functions for config set and lookup submodule: implement a config API for lookup of .gitmodules values
2 parents f932729 + 027771f commit 5a1ba6b

File tree

12 files changed

+836
-98
lines changed

12 files changed

+836
-98
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
/test-sha1-array
206206
/test-sigchain
207207
/test-string-list
208+
/test-submodule-config
208209
/test-subprocess
209210
/test-svn-fe
210211
/test-urlmatch-normalization
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
submodule config cache API
2+
==========================
3+
4+
The submodule config cache API allows to read submodule
5+
configurations/information from specified revisions. Internally
6+
information is lazily read into a cache that is used to avoid
7+
unnecessary parsing of the same .gitmodule files. Lookups can be done by
8+
submodule path or name.
9+
10+
Usage
11+
-----
12+
13+
To initialize the cache with configurations from the worktree the caller
14+
typically first calls `gitmodules_config()` to read values from the
15+
worktree .gitmodules and then to overlay the local git config values
16+
`parse_submodule_config_option()` from the config parsing
17+
infrastructure.
18+
19+
The caller can look up information about submodules by using the
20+
`submodule_from_path()` or `submodule_from_name()` functions. They return
21+
a `struct submodule` which contains the values. The API automatically
22+
initializes and allocates the needed infrastructure on-demand. If the
23+
caller does only want to lookup values from revisions the initialization
24+
can be skipped.
25+
26+
If the internal cache might grow too big or when the caller is done with
27+
the API, all internally cached values can be freed with submodule_free().
28+
29+
Data Structures
30+
---------------
31+
32+
`struct submodule`::
33+
34+
This structure is used to return the information about one
35+
submodule for a certain revision. It is returned by the lookup
36+
functions.
37+
38+
Functions
39+
---------
40+
41+
`void submodule_free()`::
42+
43+
Use these to free the internally cached values.
44+
45+
`int parse_submodule_config_option(const char *var, const char *value)`::
46+
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)`::
51+
52+
Lookup values for one submodule by its commit_sha1 and path.
53+
54+
`const struct submodule *submodule_from_name(const unsigned char *commit_sha1, const char *name)`::
55+
56+
The same as above but lookup by name.
57+
58+
If given the null_sha1 as commit_sha1 the local configuration of a
59+
submodule will be returned (e.g. consolidated values from local git
60+
configuration and the .gitmodules file in the worktree).
61+
62+
For an example usage see test-submodule-config.c.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ TEST_PROGRAMS_NEED_X += test-sha1
594594
TEST_PROGRAMS_NEED_X += test-sha1-array
595595
TEST_PROGRAMS_NEED_X += test-sigchain
596596
TEST_PROGRAMS_NEED_X += test-string-list
597+
TEST_PROGRAMS_NEED_X += test-submodule-config
597598
TEST_PROGRAMS_NEED_X += test-subprocess
598599
TEST_PROGRAMS_NEED_X += test-svn-fe
599600
TEST_PROGRAMS_NEED_X += test-urlmatch-normalization
@@ -785,6 +786,7 @@ LIB_OBJS += strbuf.o
785786
LIB_OBJS += streaming.o
786787
LIB_OBJS += string-list.o
787788
LIB_OBJS += submodule.o
789+
LIB_OBJS += submodule-config.o
788790
LIB_OBJS += symlinks.o
789791
LIB_OBJS += tag.o
790792
LIB_OBJS += trace.o

builtin/checkout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "xdiff-interface.h"
1919
#include "ll-merge.h"
2020
#include "resolve-undo.h"
21+
#include "submodule-config.h"
2122
#include "submodule.h"
2223

2324
static const char * const checkout_usage[] = {

builtin/fetch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "run-command.h"
1212
#include "parse-options.h"
1313
#include "sigchain.h"
14+
#include "submodule-config.h"
1415
#include "submodule.h"
1516
#include "connected.h"
1617
#include "argv-array.h"

diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "utf8.h"
1414
#include "userdiff.h"
1515
#include "sigchain.h"
16+
#include "submodule-config.h"
1617
#include "submodule.h"
1718
#include "ll-merge.h"
1819
#include "string-list.h"

0 commit comments

Comments
 (0)