def commit(self, msg): commit = Commit(self.repository) commit.parent = self.parent commit.changelog = self.changelog commit.schema = self.schema commit.msg = msg commit.commit_id = hashlib.sha1(json.dumps(commit.toDict())).hexdigest() commit.checkedout = True self.repository.commits[commit.commit_id] = commit.toDict() self.repository.checkouts[commit.commit_id] = commit self.repository.branches[self.name] = commit.commit_id self.parent = commit self.reset()
def checkout_commit(self, commit_id): commit = Commit() try: commit_dict = self.commits[commit_id] except KeyError: raise CommitNotFound("Could not find the commit %s" % commit_id) commit.commit_id = commit_id commit.msg = commit_dict['msg'] commit.changelog = commit_dict['changelog'] if 'parent' in commit_dict: commit.parent = self.checkout_commit(commit_dict['parent']) commit.schema = copy.deepcopy(commit.parent.schema) else: commit.parent = None commit.schema = Schema() for change_id in commit.changelog: change = self.changes[change_id] commit.schema.add(change) return commit