Ejemplo n.º 1
0
 def commit(self, branch_name, changes, msg):
     """Commit the given changes to the given branch_name"""
     old_commit = self.checkout_branch(branch_name)
     for change in changes:
         old_commit.schema.verify(change)
     
     new_commit = Commit()
     new_commit.msg = msg
     new_commit.parent = old_commit
     new_commit.schema = copy.deepcopy(old_commit.schema)
     for change in changes:
         change = new_commit.schema.make_change_reversible(change)
         change_id = hashlib.sha1(json.dumps(change)).hexdigest()
         self.changes[change_id] = change
         new_commit.schema.add(change)
         new_commit.changelog.append(change_id)
         
     new_commit_dict = new_commit.to_dict()
     new_commit_id = hashlib.sha1(json.dumps(new_commit_dict)).hexdigest()
     self.commits[new_commit_id] = new_commit_dict
     self.branches[branch_name] = new_commit_id