def parse_graftpoints(graftpoints): """Convert a list of graftpoints into a dict :param graftpoints: Iterator of graftpoint lines Each line is formatted as: <commit sha1> <parent sha1> [<parent sha1>]* Resulting dictionary is: <commit sha1>: [<parent sha1>*] https://git.wiki.kernel.org/index.php/GraftPoint """ grafts = {} for l in graftpoints: raw_graft = l.split(None, 1) commit = raw_graft[0] if len(raw_graft) == 2: parents = raw_graft[1].split() else: parents = [] for sha in [commit] + parents: check_hexsha(sha, 'Invalid graftpoint') grafts[commit] = parents return grafts
def test_check_hexsha(self): check_hexsha(a_sha, "failed to check good sha") self.assertRaises(ObjectFormatException, check_hexsha, '1' * 39, 'sha too short') self.assertRaises(ObjectFormatException, check_hexsha, '1' * 41, 'sha too long') self.assertRaises(ObjectFormatException, check_hexsha, 'x' * 40, 'invalid characters')
def _add_graftpoints(self, updated_graftpoints): """Add or modify graftpoints :param updated_graftpoints: Dict of commit shas to list of parent shas """ # Simple validation for commit, parents in updated_graftpoints.items(): for sha in [commit] + parents: check_hexsha(sha, 'Invalid graftpoint') self._graftpoints.update(updated_graftpoints)
def test_check_hexsha(self): check_hexsha(a_sha, "failed to check good sha") self.assertRaises(ObjectFormatException, check_hexsha, "1" * 39, "sha too short") self.assertRaises(ObjectFormatException, check_hexsha, "1" * 41, "sha too long") self.assertRaises(ObjectFormatException, check_hexsha, "x" * 40, "invalid characters")