@@ -34,6 +34,8 @@ Changelog
|
|||||||
- Make pygit work in a frozen environment
|
- Make pygit work in a frozen environment
|
||||||
`#453 <https://github.com/libgit2/pygit2/pull/453>`_
|
`#453 <https://github.com/libgit2/pygit2/pull/453>`_
|
||||||
|
|
||||||
|
- New ``iter(pygit2.Blame)``
|
||||||
|
|
||||||
- New ``pygit2.DiffDelta`` and ``pygit2.DiffFile``
|
- New ``pygit2.DiffDelta`` and ``pygit2.DiffFile``
|
||||||
|
|
||||||
- Rename ``pygit2.Hunk`` to ``pygit2.DiffHunk``
|
- Rename ``pygit2.Hunk`` to ``pygit2.DiffHunk``
|
||||||
|
@@ -32,8 +32,10 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
from .errors import check_error
|
from .errors import check_error
|
||||||
from .ffi import ffi, C
|
from .ffi import ffi, C
|
||||||
from .utils import to_bytes, is_string, to_str
|
from .utils import to_bytes, is_string, to_str
|
||||||
|
from .utils import GenericIterator
|
||||||
from _pygit2 import Signature, Oid
|
from _pygit2 import Signature, Oid
|
||||||
|
|
||||||
|
|
||||||
def wrap_signature(csig):
|
def wrap_signature(csig):
|
||||||
if not csig:
|
if not csig:
|
||||||
return None
|
return None
|
||||||
@@ -142,21 +144,5 @@ class Blame(object):
|
|||||||
|
|
||||||
return BlameHunk._from_c(self, chunk)
|
return BlameHunk._from_c(self, chunk)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
class BlameIterator(object):
|
return GenericIterator(self)
|
||||||
def __init__(self, blame):
|
|
||||||
self._count = len(blame)
|
|
||||||
self._index = 0
|
|
||||||
self._blame = blame
|
|
||||||
|
|
||||||
def __next__(self):
|
|
||||||
if self._index >= self._count:
|
|
||||||
raise StopIteration
|
|
||||||
|
|
||||||
hunk = self._blame[self._blame]
|
|
||||||
self._index += 1
|
|
||||||
|
|
||||||
return hunk
|
|
||||||
|
|
||||||
def next(self):
|
|
||||||
return self.__next__()
|
|
||||||
|
@@ -63,15 +63,12 @@ class ConfigIterator(object):
|
|||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
entry = self._next_entry()
|
entry = self._next_entry()
|
||||||
name = ffi.string(entry.name).decode('utf-8')
|
return ffi.string(entry.name).decode('utf-8')
|
||||||
|
|
||||||
return name
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigMultivarIterator(ConfigIterator):
|
class ConfigMultivarIterator(ConfigIterator):
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
entry = self._next_entry()
|
entry = self._next_entry()
|
||||||
|
|
||||||
return ffi.string(entry.value).decode('utf-8')
|
return ffi.string(entry.value).decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
|
@@ -32,7 +32,8 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
from _pygit2 import Oid, Tree, Diff
|
from _pygit2 import Oid, Tree, Diff
|
||||||
from .errors import check_error
|
from .errors import check_error
|
||||||
from .ffi import ffi, C
|
from .ffi import ffi, C
|
||||||
from .utils import is_string, to_bytes, to_str, StrArray
|
from .utils import is_string, to_bytes, to_str
|
||||||
|
from .utils import GenericIterator, StrArray
|
||||||
|
|
||||||
|
|
||||||
class Index(object):
|
class Index(object):
|
||||||
@@ -92,7 +93,7 @@ class Index(object):
|
|||||||
return IndexEntry._from_c(centry)
|
return IndexEntry._from_c(centry)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return IndexIterator(self)
|
return GenericIterator(self)
|
||||||
|
|
||||||
def read(self, force=True):
|
def read(self, force=True):
|
||||||
"""Update the contents the Index
|
"""Update the contents the Index
|
||||||
@@ -369,26 +370,6 @@ class IndexEntry(object):
|
|||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
||||||
class IndexIterator(object):
|
|
||||||
|
|
||||||
def __init__(self, index):
|
|
||||||
self.index = index
|
|
||||||
self.n = 0
|
|
||||||
self.max = len(index)
|
|
||||||
|
|
||||||
def next(self):
|
|
||||||
return self.__next__()
|
|
||||||
|
|
||||||
def __next__(self):
|
|
||||||
if self.n >= self.max:
|
|
||||||
raise StopIteration
|
|
||||||
|
|
||||||
entry = self.index[self.n]
|
|
||||||
self.n += 1
|
|
||||||
|
|
||||||
return entry
|
|
||||||
|
|
||||||
|
|
||||||
class ConflictCollection(object):
|
class ConflictCollection(object):
|
||||||
|
|
||||||
def __init__(self, index):
|
def __init__(self, index):
|
||||||
|
@@ -81,3 +81,27 @@ class StrArray(object):
|
|||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class GenericIterator(object):
|
||||||
|
"""Helper to easily implement an iterator.
|
||||||
|
|
||||||
|
The constructor gets a container which must implement __len__ and
|
||||||
|
__getitem__
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, container):
|
||||||
|
self.container = container
|
||||||
|
self.length = len(container)
|
||||||
|
self.idx = 0
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
return self.__next__()
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
idx = self.idx
|
||||||
|
if idx >= self.length:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
self.idx += 1
|
||||||
|
return self.container[idx]
|
||||||
|
@@ -156,12 +156,6 @@ typedef struct {
|
|||||||
git_index_entry entry;
|
git_index_entry entry;
|
||||||
} IndexEntry;
|
} IndexEntry;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
Index *owner;
|
|
||||||
int i;
|
|
||||||
} IndexIter;
|
|
||||||
|
|
||||||
|
|
||||||
/* git_reference, git_reflog */
|
/* git_reference, git_reflog */
|
||||||
SIMPLE_TYPE(Walker, git_revwalk, walk)
|
SIMPLE_TYPE(Walker, git_revwalk, walk)
|
||||||
|
Reference in New Issue
Block a user