Skip to content

Commit

Permalink
Merge 'hv/submodule-config' to 'sb/submodule-helper'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed Aug 19, 2015
2 parents f932729 + 027771f commit 5a1ba6b
Show file tree
Hide file tree
Showing 12 changed files with 836 additions and 98 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
/test-sha1-array
/test-sigchain
/test-string-list
/test-submodule-config
/test-subprocess
/test-svn-fe
/test-urlmatch-normalization
Expand Down
62 changes: 62 additions & 0 deletions Documentation/technical/api-submodule-config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
submodule config cache API
==========================

The submodule config cache API allows to read submodule
configurations/information from specified revisions. Internally
information is lazily read into a cache that is used to avoid
unnecessary parsing of the same .gitmodule files. Lookups can be done by
submodule path or name.

Usage
-----

To initialize the cache with configurations from the worktree the caller
typically first calls `gitmodules_config()` to read values from the
worktree .gitmodules and then to overlay the local git config values
`parse_submodule_config_option()` from the config parsing
infrastructure.

The caller can look up information about submodules by using the
`submodule_from_path()` or `submodule_from_name()` functions. They return
a `struct submodule` which contains the values. The API automatically
initializes and allocates the needed infrastructure on-demand. If the
caller does only want to lookup values from revisions the initialization
can be skipped.

If the internal cache might grow too big or when the caller is done with
the API, all internally cached values can be freed with submodule_free().

Data Structures
---------------

`struct submodule`::

This structure is used to return the information about one
submodule for a certain revision. It is returned by the lookup
functions.

Functions
---------

`void submodule_free()`::

Use these to free the internally cached values.

`int parse_submodule_config_option(const char *var, const char *value)`::

Can be passed to the config parsing infrastructure to parse
local (worktree) submodule configurations.

`const struct submodule *submodule_from_path(const unsigned char *commit_sha1, const char *path)`::

Lookup values for one submodule by its commit_sha1 and path.

`const struct submodule *submodule_from_name(const unsigned char *commit_sha1, const char *name)`::

The same as above but lookup by name.

If given the null_sha1 as commit_sha1 the local configuration of a
submodule will be returned (e.g. consolidated values from local git
configuration and the .gitmodules file in the worktree).

For an example usage see test-submodule-config.c.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ TEST_PROGRAMS_NEED_X += test-sha1
TEST_PROGRAMS_NEED_X += test-sha1-array
TEST_PROGRAMS_NEED_X += test-sigchain
TEST_PROGRAMS_NEED_X += test-string-list
TEST_PROGRAMS_NEED_X += test-submodule-config
TEST_PROGRAMS_NEED_X += test-subprocess
TEST_PROGRAMS_NEED_X += test-svn-fe
TEST_PROGRAMS_NEED_X += test-urlmatch-normalization
Expand Down Expand Up @@ -785,6 +786,7 @@ LIB_OBJS += strbuf.o
LIB_OBJS += streaming.o
LIB_OBJS += string-list.o
LIB_OBJS += submodule.o
LIB_OBJS += submodule-config.o
LIB_OBJS += symlinks.o
LIB_OBJS += tag.o
LIB_OBJS += trace.o
Expand Down
1 change: 1 addition & 0 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "xdiff-interface.h"
#include "ll-merge.h"
#include "resolve-undo.h"
#include "submodule-config.h"
#include "submodule.h"

static const char * const checkout_usage[] = {
Expand Down
1 change: 1 addition & 0 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "run-command.h"
#include "parse-options.h"
#include "sigchain.h"
#include "submodule-config.h"
#include "submodule.h"
#include "connected.h"
#include "argv-array.h"
Expand Down
1 change: 1 addition & 0 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "utf8.h"
#include "userdiff.h"
#include "sigchain.h"
#include "submodule-config.h"
#include "submodule.h"
#include "ll-merge.h"
#include "string-list.h"
Expand Down
Loading

0 comments on commit 5a1ba6b

Please sign in to comment.