Unverified Commit 0bcb1d5f by Edward Thomson Committed by GitHub

Merge pull request #4799 from pks-t/pks/config-multivar-quadratic

config_file: fix quadratic behaviour when adding config multivars
parents 695067f7 f2694635
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
typedef struct config_entry_list { typedef struct config_entry_list {
struct config_entry_list *next; struct config_entry_list *next;
struct config_entry_list *last;
git_config_entry *entry; git_config_entry *entry;
} config_entry_list; } config_entry_list;
...@@ -131,15 +132,11 @@ int git_config_file_normalize_section(char *start, char *end) ...@@ -131,15 +132,11 @@ int git_config_file_normalize_section(char *start, char *end)
static void config_entry_list_append(config_entry_list **list, config_entry_list *entry) static void config_entry_list_append(config_entry_list **list, config_entry_list *entry)
{ {
config_entry_list *head = *list; if (*list)
(*list)->last->next = entry;
if (head) { else
while (head->next != NULL)
head = head->next;
head->next = entry;
} else {
*list = entry; *list = entry;
} (*list)->last = entry;
} }
/* Add or append the new config option */ /* Add or append the new config option */
...@@ -155,6 +152,17 @@ static int diskfile_entries_append(diskfile_entries *entries, git_config_entry * ...@@ -155,6 +152,17 @@ static int diskfile_entries_append(diskfile_entries *entries, git_config_entry *
pos = git_strmap_lookup_index(entries->map, entry->name); pos = git_strmap_lookup_index(entries->map, entry->name);
if (!git_strmap_valid_index(entries->map, pos)) { if (!git_strmap_valid_index(entries->map, pos)) {
/*
* We only ever inspect `last` from the first config
* entry in a multivar. In case where this new entry is
* the first one in the entry map, it will also be the
* last one at the time of adding it, which is
* why we set `last` here to itself. Otherwise we
* do not have to set `last` and leave it set to
* `NULL`.
*/
var->last = var;
git_strmap_insert(entries->map, entry->name, var, &error); git_strmap_insert(entries->map, entry->name, var, &error);
if (error > 0) if (error > 0)
...@@ -517,10 +525,7 @@ static int config_get(git_config_backend *cfg, const char *key, git_config_entry ...@@ -517,10 +525,7 @@ static int config_get(git_config_backend *cfg, const char *key, git_config_entry
} }
var = git_strmap_value_at(entry_map, pos); var = git_strmap_value_at(entry_map, pos);
while (var->next) *out = var->last->entry;
var = var->next;
*out = var->entry;
(*out)->free = free_diskfile_entry; (*out)->free = free_diskfile_entry;
(*out)->payload = entries; (*out)->payload = entries;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment