Skip to content

Commit 08ea577

Browse files
committed
Add assert to TreeData.__init__()
The mysteriously named `TreeData._x()` staticmethod is replaced with an _iter_entries() method. This allows an assert to be added that ensures that the entry name does not contain '/'. This assert relates to #24 where patches with a '/' in the name cause failures. This assert helps to fail faster, before attempting to commit the tree. Signed-off-by: Peter Grayson <[email protected]>
1 parent 47ef1e2 commit 08ea577

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

stgit/lib/git/objects.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,23 @@ def data(self):
6464
class TreeData(Immutable):
6565
"""Represents the data contents of a git tree object."""
6666

67-
@staticmethod
68-
def _x(po):
69-
if isinstance(po, GitObject):
70-
perm, object = po.default_perm, po
71-
else:
72-
perm, object = po
73-
return perm, object
74-
7567
def __init__(self, entries):
7668
"""Create a new L{TreeData} object from the given mapping from names
7769
(strings) to either (I{permission}, I{object}) tuples or just
7870
objects."""
79-
self.entries = ImmutableDict(
80-
(name, self._x(po)) for (name, po) in entries.items()
81-
)
71+
self.entries = ImmutableDict(self._iter_entries(entries))
72+
73+
@staticmethod
74+
def _iter_entries(entries):
75+
for name, po in entries.items():
76+
assert '/' not in name, (
77+
'tree entry name contains slash: %s' % name
78+
)
79+
if isinstance(po, GitObject):
80+
perm, obj = po.default_perm, po
81+
else:
82+
perm, obj = po
83+
yield name, (perm, obj)
8284

8385
def commit(self, repository):
8486
"""Commit the tree.

0 commit comments

Comments
 (0)