diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-28 12:00:58 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-28 12:00:58 +0100 |
commit | 146a6fe18da94e12aa46ec74582db640e3bbb3a9 (patch) | |
tree | 8c26d4903de1002acb40ec5cead52e30363a95b5 /lib/git/utils.py | |
parent | 87afd252bd11026b6ba3db8525f949cfb62c90fc (diff) | |
download | gitpython-146a6fe18da94e12aa46ec74582db640e3bbb3a9.tar.gz |
IterableList: added support for prefix allowing remote.refs.master constructs, previously it was remote.refs['%s/master'%remote]
Added first simple test for push support, which shows that much more work is needed on that side to allow just-in-time progress information
Diffstat (limited to 'lib/git/utils.py')
-rw-r--r-- | lib/git/utils.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/git/utils.py b/lib/git/utils.py index 8cdb4804..48427ff2 100644 --- a/lib/git/utils.py +++ b/lib/git/utils.py @@ -260,16 +260,25 @@ class IterableList(list): heads.master heads['master'] heads[0] + + It requires an id_attribute name to be set which will be queried from its + contained items to have a means for comparison. + + A prefix can be specified which is to be used in case the id returned by the + items always contains a prefix that does not matter to the user, so it + can be left out. """ - __slots__ = '_id_attr' + __slots__ = ('_id_attr', '_prefix') - def __new__(cls, id_attr): + def __new__(cls, id_attr, prefix=''): return super(IterableList,cls).__new__(cls) - def __init__(self, id_attr): + def __init__(self, id_attr, prefix=''): self._id_attr = id_attr + self._prefix = prefix def __getattr__(self, attr): + attr = self._prefix + attr for item in self: if getattr(item, self._id_attr) == attr: return item @@ -283,7 +292,7 @@ class IterableList(list): try: return getattr(self, index) except AttributeError: - raise IndexError( "No item found with id %r" % index ) + raise IndexError( "No item found with id %r" % self._prefix + index ) class Iterable(object): """ |