<s> import datetime <EOL> import errno <EOL> from vcs . backends . base import BaseInMemoryChangeset <EOL> from vcs . exceptions import RepositoryError <EOL> from vcs . utils . hgcompat import memfilectx , memctx , hex , tolocal <EOL> class MercurialInMemoryChangeset ( BaseInMemoryChangeset ) : <EOL> def commit ( self , message , author , parents = None , branch = None , date = None , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . check_integrity ( parents ) <EOL> from . repository import MercurialRepository <EOL> if not isinstance ( message , unicode ) or not isinstance ( author , unicode ) : <EOL> raise RepositoryError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( type ( message ) , type ( author ) ) ) <EOL> if branch is None : <EOL> branch = MercurialRepository . DEFAULT_BRANCH_NAME <EOL> kwargs [ '<STR_LIT>' ] = branch <EOL> def filectxfn ( _repo , memctx , path ) : <EOL> """<STR_LIT>""" <EOL> if path in ( node . path for node in self . removed ) : <EOL> raise IOError ( errno . ENOENT , '<STR_LIT>' % path ) <EOL> for node in self . added : <EOL> if node . path == path : <EOL> return memfilectx ( path = node . path , <EOL> data = ( node . content . encode ( '<STR_LIT:utf8>' ) <EOL> if not node . is_binary else node . content ) , <EOL> islink = False , <EOL> isexec = node . is_executable , <EOL> copied = False ) <EOL> for node in self . changed : <EOL> if node . path == path : <EOL> return memfilectx ( path = node . path , <EOL> data = ( node . content . encode ( '<STR_LIT:utf8>' ) <EOL> if not node . is_binary else node . content ) , <EOL> islink = False , <EOL> isexec = node . is_executable , <EOL> copied = False ) <EOL> raise RepositoryError ( "<STR_LIT>" <EOL> "<STR_LIT>" % path ) <EOL> parents = [ None , None ] <EOL> for i , parent in enumerate ( self . parents ) : <EOL> if parent is not None : <EOL> parents [ i ] = parent . _ctx . node ( ) <EOL> if date and isinstance ( date , datetime . datetime ) : <EOL> date = date . ctime ( ) <EOL> commit_ctx = memctx ( repo = self . repository . _repo , <EOL> parents = parents , <EOL> text = '<STR_LIT>' , <EOL> files = self . get_paths ( ) , <EOL> filectxfn = filectxfn , <EOL> user = author , <EOL> date = date , <EOL> extra = kwargs ) <EOL> loc = lambda u : tolocal ( u . encode ( '<STR_LIT:utf-8>' ) ) <EOL> commit_ctx . _text = loc ( message ) <EOL> commit_ctx . _user = loc ( author ) <EOL> commit_ctx . _date = date <EOL> n = self . repository . _repo . commitctx ( commit_ctx ) <EOL> self . _commit_ctx = commit_ctx <EOL> new_id = hex ( n ) <EOL> self . repository . revisions . append ( new_id ) <EOL> self . _repo = self . repository . _get_repo ( create = False ) <EOL> self . repository . branches = self . repository . _get_branches ( ) <EOL> tip = self . repository . get_changeset ( ) <EOL> self . reset ( ) <EOL> return tip </s>
