git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/3] config: add hashtable for config parsing & retrieval

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 25, 2014, 18:13 UTC
Message-ID
<xmqq61joamcc.fsf@gitster.dls.corp.google.com>
In-Reply-To
<53A99FEB.5040808@ramsay1.demon.co.uk>
Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:
Show 16 quoted lines
> On 24/06/14 00:25, Junio C Hamano wrote:
> ...
>> Yup, that is a very good point.  There needs an infrastructure to
>> tie a set of files (i.e. the standard one being the chain of
>> system-global /etc/gitconfig to repo-specific .git/config, and any
>> custom one that can be specified by the caller like submodule code)
>> to a separate hashmap; a future built-in submodule code would use
>> two hashmaps aka "config-caches", one to manage the usual
>> "configuration" and the other to manage the contents of the
>> .gitmodules file.
>> 
>
> I had expected to see one hash table per file/blob, with the three
> standard config hash tables linked together to implement the scope/
> priority rules. (Well, these could be merged into one, as the current
> code does, since that makes handling "multi" keys slightly easier).

Again, good point. I think a rough outline of a design that take both

 (1) we may have to read two or more separate sets of "config like
     things" (e.g. the contents from the normal config system and
     the contents from the .gitmodules file) and
 (2) we may have to read two or more files that make up a logically
     single set of "config-like things" (e.g. the "normal config
     system" reads from three separate files)
into account may look like this:
 * Each instance of in-core "config-like things" is expressed as a
   struct "config-set".
 * A "config-set" points at an ordered set of struct "config-file",
   each of which represents what was read and cached in-core from a
   file.
 * When we know or notice that a single file on the filesystem was
   modified, we do not have to invalidate the whole "config-set"
   that depends on the file; the "config-file" that corresponds to
   the file on the filesystem is invalidated instead.
 * The most generic API to read the values for a given key or
   enumerate the keys in a set of "config-like things" takes
   "config-set" as an argument, and reads from the ordered set of
   "config-file" to keep the established illusion that we read them
   all and accumulate, leading to "the last one wins" for single
   valued variables.
 * Because reading from the normal config system happens everywhere
   in the existing code, we will have one struct "config-set"
   instance, called "the_config_set", and have a parallel API of the
   most generic API above, that do not take the "config-set" as an
   explicit argument.  They operate on the_config_set singleton
   instance.

The implementation of the API function "git-config-get-string" may look like this:

	int git_config_get_string(const char *key, const char **value)
	{
        	return git_configset_get_string(&the_config_set, key, value);
	}

which is the "thin-wrapper" for the more generic API to allow you read from an arbitrary config_set, which may even look like this:

	#define git_config_get_string(k, v) \
        	git_configset_get_string(&the_config_set, (k), (v))

When the submodule script that uses "git config -f .gitmodules" is converted into C, if the updated config API is ready, it may be able to do something like these in a single program:

	const char *url;
	struct config_set *gm_config;
        /* read from $GIT_DIR/config */
        url = git_config_get_string("remote.origin.url");
        /*
         * allow us to read from .gitmodules; the parameters are
         * list of files that make up the configset, perhaps.
         */
	gm_config = git_configset_new(".gitmodules", NULL);
        if (!git_configset_get_bool(gm_config, "submodule.frotz.ignore")) {
		/* do a lot of stuff for the submodule */
                ...
	}
        /* when we are done with the configset */
        git_configset_clear(gm_config);
Previous: Ramsay JonesNext: Karsten Blees
Message 18 of 35 in “git config cache & special querying api utilizing the cache”
  1. 0/3 git config cache & special querying api utilizing the cacheTanay Abhra, Jun 23, 2014
  2. 1/3 string-list: add string_list initialiser helper functionsTanay Abhra, Jun 23, 2014
  3. Torsten BögershausenJun 23, 2014
  4. Tanay AbhraJun 23, 2014
  5. 2/3 config: add hashtable for config parsing & retrievalTanay Abhra, Jun 23, 2014
  6. Matthieu MoyJun 23, 2014
  7. Tanay AbhraJun 24, 2014
  8. Karsten BleesJun 25, 2014
  9. Ramsay JonesJun 23, 2014
  10. Tanay AbhraJun 23, 2014
  11. Ramsay JonesJun 24, 2014
  12. Matthieu MoyJun 26, 2014
  13. Junio C HamanoJun 23, 2014
  14. Tanay AbhraJun 24, 2014
  15. Junio C HamanoJun 25, 2014
  16. Tanay AbhraJun 24, 2014
  17. Ramsay JonesJun 24, 2014
  18. Junio C HamanoJun 25, 2014
  19. Karsten BleesJun 25, 2014
  20. Junio C HamanoJun 25, 2014
  21. Matthieu MoyJun 26, 2014
  22. Junio C HamanoJun 26, 2014
  23. Karsten BleesJun 26, 2014
  24. Junio C HamanoJun 26, 2014
  25. Karsten BleesJun 27, 2014
  26. Matthieu MoyJun 27, 2014
  27. Junio C HamanoJun 27, 2014
  28. Junio C HamanoJun 23, 2014
  29. Tanay AbhraJun 24, 2014
  30. Matthieu MoyJun 26, 2014
  31. Karsten BleesJun 25, 2014
  32. Matthieu MoyJun 26, 2014
  33. 3/3 test-config: add usage examples for non-callback query functionsTanay Abhra, Jun 23, 2014
  34. Eric SunshineJun 25, 2014
  35. Tanay AbhraJun 26, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.