<s> from pygit2 import GIT_FILEMODE_BLOB_EXECUTABLE <EOL> from pygit2 import GIT_FILEMODE_BLOB <EOL> from pygit2 import Signature <EOL> from ellen . utils import JagareError <EOL> from ellen . utils . tree_node import init_root <EOL> def create_commit ( repository , branch , parent , <EOL> author_name , author_email , <EOL> message , reflog , data ) : <EOL> """<STR_LIT>""" <EOL> if repository . is_empty : <EOL> if branch != "<STR_LIT>" or parent != "<STR_LIT>" : <EOL> raise JagareError ( "<STR_LIT>" ) <EOL> parents_sha = [ ] <EOL> parent_commit = None <EOL> if not repository . is_empty : <EOL> parent_commit = repository . revparse_single ( parent ) <EOL> parents_sha . append ( str ( parent_commit . id ) ) <EOL> ret = [ ] <EOL> flag = False <EOL> root = init_root ( ) <EOL> for filepath , content , action in data : <EOL> content = unicode_to_utf8 ( content ) <EOL> content = content . replace ( "<STR_LIT:\r\n>" , "<STR_LIT:\n>" ) <EOL> if action == "<STR_LIT>" : <EOL> root . add_file ( filepath , content ) <EOL> elif action == "<STR_LIT>" : <EOL> root . del_file ( filepath ) <EOL> else : <EOL> root . add_file ( filepath , content ) <EOL> flag = True <EOL> if flag : <EOL> for entry in root . walk ( ) : <EOL> entry . write ( repository , parent_commit if parent_commit else None ) <EOL> tree_oid = root . id <EOL> signature = Signature ( author_name , author_email ) <EOL> commit_oid = repository . create_commit ( "<STR_LIT>" % branch , <EOL> signature , signature , message , <EOL> tree_oid , parents_sha ) <EOL> master = repository . lookup_reference ( "<STR_LIT>" % branch ) <EOL> master . target = str ( commit_oid ) <EOL> master . log_append ( str ( commit_oid ) , signature , reflog ) <EOL> return ret <EOL> return [ ] <EOL> def _get_pygit2_mode ( mode ) : <EOL> if mode == "<STR_LIT>" : <EOL> return GIT_FILEMODE_BLOB_EXECUTABLE <EOL> return GIT_FILEMODE_BLOB <EOL> def unicode_to_utf8 ( c ) : <EOL> if isinstance ( c , unicode ) : <EOL> c = c . encode ( '<STR_LIT:utf8>' ) <EOL> return c </s>
