Skip to content

Commit

Permalink
Merge branch 'feature/return-config-entry-name-from-iter' into featur…
Browse files Browse the repository at this point in the history
…e/return-config-entry-from-iter
  • Loading branch information
thecjharries committed Mar 17, 2018
2 parents 0f64ac4 + f471b6d commit 3d76e44
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pygit2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def _next_entry(self):
err = C.git_config_next(centry, self._iter)
check_error(err)

return centry[0]
return ConfigEntry._from_c(centry[0], True)

def next(self):
return self.__next__()

def __next__(self):
entry = self._next_entry()
return ffi.string(entry.name).decode('utf-8')
return ffi.string(entry._entry.name).decode('utf-8')


class ConfigMultivarIterator(ConfigIterator):
Expand Down Expand Up @@ -291,13 +291,15 @@ class ConfigEntry(object):
"""

@classmethod
def _from_c(cls, ptr):
def _from_c(cls, ptr, from_iterator=False):
entry = cls.__new__(cls)
entry._entry = ptr
entry.from_iterator = from_iterator
return entry

def __del__(self):
C.git_config_entry_free(self._entry)
if not self.from_iterator:
C.git_config_entry_free(self._entry)

@property
def value(self):
Expand Down

0 comments on commit 3d76e44

Please sign in to comment.