diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-08-16 12:22:03 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-09-28 11:14:13 +0200 |
commit | b78f4ab082030bc02ee2e1a51eca441bfb6f1e8f (patch) | |
tree | bb345bc7d15583de45c9c3abe071f32ab1b4f51a /src/config_entries.h | |
parent | d49b1365be316b6aa7c6c4c6535ff810853d0c46 (diff) | |
download | libgit2-b78f4ab082030bc02ee2e1a51eca441bfb6f1e8f.tar.gz |
config_entries: refactor entries iterator memory ownership
Right now, the config file code requires us to pass in its backend to
the config entry iterator. This is required with the current code, as
the config file backend will first create a read-only snapshot which is
then passed to the iterator just for that purpose. So after the iterator
is getting free'd, the code needs to make sure that the snapshot gets
free'd, as well.
By now, though, we can easily refactor the code to be more efficient and
remove the reverse dependency from iterator to backend. Instead of
creating a read-only snapshot (which also requires us to re-parse the
complete configuration file), we can simply duplicate the config entries
and pass those to the iterator. Like that, the iterator only needs to
make sure to free the duplicated config entries, which is trivial to do
and clears up memory ownership by a lot.
Diffstat (limited to 'src/config_entries.h')
-rw-r--r-- | src/config_entries.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/config_entries.h b/src/config_entries.h index 02292e27a..6fdbc41ba 100644 --- a/src/config_entries.h +++ b/src/config_entries.h @@ -13,10 +13,11 @@ typedef struct git_config_entries git_config_entries; int git_config_entries_new(git_config_entries **out); +int git_config_entries_dup(git_config_entries **out, git_config_entries *entries); void git_config_entries_incref(git_config_entries *entries); void git_config_entries_free(git_config_entries *entries); /* Add or append the new config option */ int git_config_entries_append(git_config_entries *entries, git_config_entry *entry); int git_config_entries_get(git_config_entry **out, git_config_entries *entries, const char *key); int git_config_entries_get_unique(git_config_entry **out, git_config_entries *entries, const char *key); -int git_config_entries_iterator_new(git_config_iterator **out, git_config_backend *backend, git_config_entries *entries); +int git_config_entries_iterator_new(git_config_iterator **out, git_config_entries *entries); |