-
-
Notifications
You must be signed in to change notification settings - Fork 399
Refactor Config.__iter__ to iterate over ConfigEntry objects #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Config.__iter__ to iterate over ConfigEntry objects #778
Conversation
Thanks. Could you please squash the commits to simplify reviewing. Also I think |
5a4203b
to
e0e89bc
Compare
I had the same thought when writing it. The raw value is used a couple of times in
|
It looks like I squashed too much. I'll have that fixed in a few minutes. Sorry about that. |
commit f618e30b21401aca34f77c7b7e05c710528697ae Author: CJ Harries <[email protected]> Date: Sun Mar 18 08:23:37 2018 -0500 Pass decoded value via valua and raw value via raw_value commit 5a4203b Merge: 8ca94fc 0c1f2d8 Author: CJ Harries <[email protected]> Date: Fri Mar 16 21:08:12 2018 -0500 Merge branch 'feature/update-docs' into feature/return-config-entry-from-iter commit 0c1f2d8 Author: CJ Harries <[email protected]> Date: Fri Mar 16 21:06:51 2018 -0500 Add ConfigEntry docs commit 67701ed Author: CJ Harries <[email protected]> Date: Fri Mar 16 21:05:59 2018 -0500 Update __iter__ docs commit cdd9566 Author: CJ Harries <[email protected]> Date: Fri Mar 16 21:04:24 2018 -0500 Document properties commit 8f74752 Author: CJ Harries <[email protected]> Date: Fri Mar 16 21:02:51 2018 -0500 Document decode_as_string commit f938b49 Author: CJ Harries <[email protected]> Date: Fri Mar 16 21:01:59 2018 -0500 Document _from_c commit 8ca94fc Merge: 835e711 52de16a Author: CJ Harries <[email protected]> Date: Fri Mar 16 20:15:49 2018 -0500 Merge branch 'feature/iterate-over-config-entries' into feature/return-config-entry-from-iter commit 52de16a Author: CJ Harries <[email protected]> Date: Fri Mar 16 20:15:08 2018 -0500 Update test_iterator to consume ConfigEntr[ies] commit e7798bb Author: CJ Harries <[email protected]> Date: Fri Mar 16 20:03:39 2018 -0500 Return entry, a ConfigEntry from ConfigIterator.__next__ commit 835e711 Merge: bbcb464 55604ca Author: CJ Harries <[email protected]> Date: Fri Mar 16 20:02:45 2018 -0500 Merge branch 'feature/decode-name' into feature/return-config-entry-from-iter commit 55604ca Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:57:25 2018 -0500 Return properly decoded entry.name commit 44326fa Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:57:06 2018 -0500 Decode ConfigEntry name without prompting commit bbcb464 Merge: 74544d6 1c47ece Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:56:29 2018 -0500 Merge branch 'feature/decode-value' into feature/return-config-entry-from-iter commit 1c47ece Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:54:45 2018 -0500 Return entry.value_string from __getitem__ commit cb873be Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:52:14 2018 -0500 Return entry.value_string from ConfigMultivarIterator commit 2e14065 Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:51:53 2018 -0500 Add value_string property, decode_as_string(entry.value) commit 9d10675 Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:51:13 2018 -0500 Add decode_as_string method commit 74544d6 Merge: 3d76e44 ae6eead Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:28:08 2018 -0500 Merge branch 'feature/expose-entry-properties' into feature/return-config-entry-from-iter commit ae6eead Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:26:07 2018 -0500 Return simplified name from __next__ commit 6ca5789 Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:25:11 2018 -0500 Add name property commit c9fdd27 Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:24:47 2018 -0500 Add level property commit 3d76e44 Merge: 0f64ac4 f471b6d Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:23:54 2018 -0500 Merge branch 'feature/return-config-entry-name-from-iter' into feature/return-config-entry-from-iter commit f471b6d Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:20:30 2018 -0500 Expose the proper name (entry._entry.name) commit 6ef0abb Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:20:17 2018 -0500 Return a ConfigEntry from _next_entry commit f48d0d8 Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:19:27 2018 -0500 Only free the entry if it did not come from an iterator commit df0e8b6 Author: CJ Harries <[email protected]> Date: Fri Mar 16 19:19:00 2018 -0500 Add from_iterator creation flag
e0e89bc
to
5026f9c
Compare
Good job, thanks! |
This PR supersedes #776.
Summary
Config.__iter__
iterates over a list ofConfigEntry
objects instead of a list of names, matching the behavior ofgit_config_iterator
.Changes
ConfigEntry
staticmethod
,decode_as_string
, to simplify all theffi.string(value).decode('utf-8')
calls._from_c
,from_iterator=False
, to track the origin of the entry.__del__
behavior to onlygit_config_entry_free
ConfigEntry
s created fromgit_config_get_entry
. Attempting to free entries while iterating results in a seg fault. (If anyone can explain that to me, I'm curious. My C is pretty weak.)level
, thegit_config_level_t
value. (It looks likepygit2
has a shortened list; I didn't play with this too much because that's a different feature.)name
, the name of the entry, as a string (usingdecode_as_string
).value_string
, a convenience accessor fordecode_as_string(self.value)
.All of these changes make it possible to create a
ConfigEntry
both fromgit_config_next
and fromgit_config_get_entry
. They expose some useful properties (level
,name
) which make it easier to track what an entry is and where it came from.value
is the raw value that must be interpreted;value_string
is conveniently a string that can be used immediately.ConfigIterator
_next_entry
returns aConfigEntry
instead of a pointer to agit_config_entry
.__next__
returns aConfigEntry
instead of the entry's name (see Update Config.__iter__ to match the documentation #776 for more info about that).ConfigMultivarIterator
__next__
returnsentry.value_string
instead of callingffi.string(entry.value).decode('utf-8')
Config
__getitem__
returnsentry.value_string
instead of callingffi.string(entry.value).decode('utf-8')
Tests
test_iterator
was refactored to check that each entry'slevel > -1
(again,pygit2
seems to have a reduced set of items; this seemed like a safe check). It still checks thatcore.bare
is in the list of entries and that it is set, which is what the original tests did.ConfigEntry
didn't gain any tests. My knowledge ofcffi
is pretty limited so I'm not quite sure how to set up mocks for that.Docs
Config.__iter__
descriptionConfigEntry
sectionExample