<s> import logging <EOL> import os <EOL> import re <EOL> import sys <EOL> from rbtools . clients import PatchResult , SCMClient , RepositoryInfo <EOL> from rbtools . clients . errors import ( AmendError , MergeError , PushError , <EOL> InvalidRevisionSpecError , <EOL> TooManyRevisionsError ) <EOL> from rbtools . clients . perforce import PerforceClient <EOL> from rbtools . clients . svn import SVNClient , SVNRepositoryInfo <EOL> from rbtools . utils . checks import check_install , is_valid_version <EOL> from rbtools . utils . console import edit_text <EOL> from rbtools . utils . diffs import ( normalize_patterns , <EOL> remove_filenames_matching_patterns ) <EOL> from rbtools . utils . process import die , execute <EOL> class GitClient ( SCMClient ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> supports_diff_exclude_patterns = True <EOL> supports_patch_revert = True <EOL> can_amend_commit = True <EOL> can_merge = True <EOL> can_push_upstream = True <EOL> can_delete_branch = True <EOL> can_branch = True <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( GitClient , self ) . __init__ ( ** kwargs ) <EOL> self . git = '<STR_LIT>' <EOL> self . _original_cwd = None <EOL> def _supports_git_config_flag ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _git_version_least_180 = False <EOL> version_str = execute ( [ self . git , '<STR_LIT:version>' ] , ignore_errors = True , <EOL> none_on_ignored_error = True ) <EOL> if version_str : <EOL> m = re . search ( '<STR_LIT>' , version_str ) <EOL> if m : <EOL> git_version = ( int ( m . group ( <NUM_LIT:1> ) ) , <EOL> int ( m . group ( <NUM_LIT:2> ) ) , <EOL> int ( m . group ( <NUM_LIT:3> ) ) ) <EOL> self . _git_version_at_least_180 = git_version >= ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:0> ) <EOL> return self . _git_version_at_least_180 <EOL> def parse_revision_spec ( self , revisions = [ ] ) : <EOL> """<STR_LIT>""" <EOL> n_revs = len ( revisions ) <EOL> result = { } <EOL> if n_revs == <NUM_LIT:0> : <EOL> parent_branch = self . get_parent_branch ( ) <EOL> head_ref = self . _rev_parse ( self . get_head_ref ( ) ) [ <NUM_LIT:0> ] <EOL> merge_base = self . _rev_parse ( <EOL> self . _get_merge_base ( head_ref , self . upstream_branch ) ) [ <NUM_LIT:0> ] <EOL> result = { <EOL> '<STR_LIT>' : head_ref , <EOL> '<STR_LIT>' : head_ref , <EOL> } <EOL> if parent_branch : <EOL> result [ '<STR_LIT>' ] = self . _rev_parse ( parent_branch ) [ <NUM_LIT:0> ] <EOL> result [ '<STR_LIT>' ] = merge_base <EOL> else : <EOL> result [ '<STR_LIT>' ] = merge_base <EOL> if self . has_pending_changes ( ) : <EOL> logging . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif n_revs == <NUM_LIT:1> or n_revs == <NUM_LIT:2> : <EOL> parsed = self . _rev_parse ( revisions ) <EOL> n_parsed_revs = len ( parsed ) <EOL> assert n_parsed_revs <= <NUM_LIT:3> <EOL> if n_parsed_revs == <NUM_LIT:1> : <EOL> parent = self . _rev_parse ( '<STR_LIT>' % parsed [ <NUM_LIT:0> ] ) [ <NUM_LIT:0> ] <EOL> result = { <EOL> '<STR_LIT>' : parent , <EOL> '<STR_LIT>' : parsed [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : parsed [ <NUM_LIT:0> ] , <EOL> } <EOL> elif n_parsed_revs == <NUM_LIT:2> : <EOL> if parsed [ <NUM_LIT:1> ] . startswith ( '<STR_LIT>' ) : <EOL> result = { <EOL> '<STR_LIT>' : parsed [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] , <EOL> '<STR_LIT>' : parsed [ <NUM_LIT:0> ] , <EOL> } <EOL> else : <EOL> result = { <EOL> '<STR_LIT>' : parsed [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : parsed [ <NUM_LIT:1> ] , <EOL> } <EOL> elif n_parsed_revs == <NUM_LIT:3> and parsed [ <NUM_LIT:2> ] . startswith ( '<STR_LIT>' ) : <EOL> merge_base = execute ( [ self . git , '<STR_LIT>' , parsed [ <NUM_LIT:0> ] , <EOL> parsed [ <NUM_LIT:1> ] ] ) . strip ( ) <EOL> result = { <EOL> '<STR_LIT>' : merge_base , <EOL> '<STR_LIT>' : parsed [ <NUM_LIT:0> ] , <EOL> } <EOL> else : <EOL> raise InvalidRevisionSpecError ( <EOL> '<STR_LIT>' ) <EOL> parent_base = self . _get_merge_base ( result [ '<STR_LIT>' ] , <EOL> self . upstream_branch ) <EOL> if parent_base != result [ '<STR_LIT>' ] : <EOL> result [ '<STR_LIT>' ] = parent_base <EOL> else : <EOL> raise TooManyRevisionsError <EOL> return result <EOL> def get_repository_info ( self ) : <EOL> """<STR_LIT>""" <EOL> if not check_install ( [ '<STR_LIT>' , '<STR_LIT>' ] ) : <EOL> if ( sys . platform . startswith ( '<STR_LIT>' ) and <EOL> check_install ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) : <EOL> self . git = '<STR_LIT>' <EOL> else : <EOL> logging . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return None <EOL> git_dir = execute ( [ self . git , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ignore_errors = True ) . rstrip ( "<STR_LIT:\n>" ) <EOL> if git_dir . startswith ( "<STR_LIT>" ) or not os . path . isdir ( git_dir ) : <EOL> return None <EOL> bare = execute ( [ self . git , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ignore_errors = True ) . strip ( ) <EOL> self . bare = bare in ( '<STR_LIT:true>' , '<STR_LIT:1>' ) <EOL> if self . _original_cwd is None : <EOL> self . _original_cwd = os . getcwd ( ) <EOL> if not self . bare : <EOL> git_top = execute ( [ self . git , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ignore_errors = True ) . rstrip ( "<STR_LIT:\n>" ) <EOL> if ( git_top . startswith ( '<STR_LIT>' ) or not os . path . isdir ( git_dir ) <EOL> or git_top . startswith ( '<STR_LIT>' ) ) : <EOL> git_top = git_dir <EOL> os . chdir ( os . path . abspath ( git_top ) ) <EOL> self . head_ref = execute ( [ self . git , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , ignore_errors = True ) . strip ( ) <EOL> git_svn_dir = os . path . join ( git_dir , '<STR_LIT>' ) <EOL> if ( not getattr ( self . options , '<STR_LIT>' , None ) and <EOL> os . path . isdir ( git_svn_dir ) and len ( os . listdir ( git_svn_dir ) ) > <NUM_LIT:0> ) : <EOL> data = execute ( [ self . git , "<STR_LIT>" , "<STR_LIT:info>" ] , ignore_errors = True ) <EOL> m = re . search ( r'<STR_LIT>' , data , re . M ) <EOL> if m : <EOL> path = m . group ( <NUM_LIT:1> ) <EOL> m = re . search ( r'<STR_LIT>' , data , re . M ) <EOL> if m : <EOL> base_path = m . group ( <NUM_LIT:1> ) [ len ( path ) : ] or "<STR_LIT:/>" <EOL> m = re . search ( r'<STR_LIT>' , data , re . M ) <EOL> if m : <EOL> uuid = m . group ( <NUM_LIT:1> ) <EOL> self . type = "<STR_LIT>" <EOL> if getattr ( self . options , '<STR_LIT>' , None ) : <EOL> self . upstream_branch = self . options . tracking <EOL> else : <EOL> data = execute ( [ self . git , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ignore_errors = True ) <EOL> m = re . search ( r'<STR_LIT>' , data , <EOL> re . M ) <EOL> if m : <EOL> self . upstream_branch = m . group ( <NUM_LIT:1> ) <EOL> else : <EOL> sys . stderr . write ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . upstream_branch = '<STR_LIT>' <EOL> return SVNRepositoryInfo ( path = path , <EOL> base_path = base_path , <EOL> uuid = uuid , <EOL> supports_parent_diffs = True ) <EOL> else : <EOL> version = execute ( [ self . git , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ignore_errors = True ) <EOL> version_parts = re . search ( '<STR_LIT>' , <EOL> version ) <EOL> svn_remote = execute ( <EOL> [ self . git , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ignore_errors = True ) <EOL> if ( version_parts and svn_remote and <EOL> not is_valid_version ( ( int ( version_parts . group ( <NUM_LIT:1> ) ) , <EOL> int ( version_parts . group ( <NUM_LIT:2> ) ) , <EOL> int ( version_parts . group ( <NUM_LIT:3> ) ) ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:4> ) ) ) : <EOL> die ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> git_p4_ref = os . path . join ( git_dir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if os . path . exists ( git_p4_ref ) : <EOL> data = execute ( [ self . git , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ignore_errors = True ) <EOL> m = re . search ( r'<STR_LIT>' , data ) <EOL> if m : <EOL> port = m . group ( <NUM_LIT:1> ) <EOL> else : <EOL> port = os . getenv ( '<STR_LIT>' ) <EOL> if port : <EOL> self . type = '<STR_LIT>' <EOL> self . upstream_branch = '<STR_LIT>' <EOL> return RepositoryInfo ( path = port , <EOL> base_path = '<STR_LIT>' , <EOL> supports_parent_diffs = True ) <EOL> self . upstream_branch = '<STR_LIT>' <EOL> if self . head_ref : <EOL> short_head = self . _strip_heads_prefix ( self . head_ref ) <EOL> merge = execute ( [ self . git , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % short_head ] , <EOL> ignore_errors = True ) . strip ( ) <EOL> remote = execute ( [ self . git , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % short_head ] , <EOL> ignore_errors = True ) . strip ( ) <EOL> merge = self . _strip_heads_prefix ( merge ) <EOL> if remote and remote != '<STR_LIT:.>' and merge : <EOL> self . upstream_branch = '<STR_LIT>' % ( remote , merge ) <EOL> url = None <EOL> if getattr ( self . options , '<STR_LIT>' , None ) : <EOL> url = self . options . repository_url <EOL> self . upstream_branch = self . get_origin ( self . upstream_branch , <EOL> True ) [ <NUM_LIT:0> ] <EOL> else : <EOL> self . upstream_branch , origin_url = self . get_origin ( self . upstream_branch , True ) <EOL> if not origin_url or origin_url . startswith ( "<STR_LIT>" ) : <EOL> self . upstream_branch , origin_url = self . get_origin ( ) <EOL> url = origin_url . rstrip ( '<STR_LIT:/>' ) <EOL> if not url : <EOL> url = os . path . abspath ( git_dir ) <EOL> self . upstream_branch = self . upstream_branch . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> if url : <EOL> self . type = "<STR_LIT>" <EOL> return RepositoryInfo ( path = url , base_path = '<STR_LIT>' , <EOL> supports_parent_diffs = True ) <EOL> return None <EOL> def _strip_heads_prefix ( self , ref ) : <EOL> """<STR_LIT>""" <EOL> return re . sub ( r'<STR_LIT>' , '<STR_LIT>' , ref ) <EOL> def get_origin ( self , default_upstream_branch = None , ignore_errors = False ) : <EOL> """<STR_LIT>""" <EOL> upstream_branch = ( getattr ( self . options , '<STR_LIT>' , None ) or <EOL> default_upstream_branch or <EOL> '<STR_LIT>' ) <EOL> upstream_remote = upstream_branch . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> origin_url = execute ( <EOL> [ self . git , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" % upstream_remote ] , <EOL> ignore_errors = True ) . rstrip ( "<STR_LIT:\n>" ) <EOL> return ( upstream_branch , origin_url ) <EOL> def scan_for_server ( self , repository_info ) : <EOL> server_url = super ( GitClient , self ) . scan_for_server ( repository_info ) <EOL> if server_url : <EOL> return server_url <EOL> url = execute ( [ self . git , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ignore_errors = True ) . strip ( ) <EOL> if url : <EOL> return url <EOL> if self . type == "<STR_LIT>" : <EOL> prop = SVNClient ( ) . scan_for_server_property ( repository_info ) <EOL> if prop : <EOL> return prop <EOL> elif self . type == '<STR_LIT>' : <EOL> prop = PerforceClient ( ) . scan_for_server ( repository_info ) <EOL> if prop : <EOL> return prop <EOL> return None <EOL> def get_raw_commit_message ( self , revisions ) : <EOL> """<STR_LIT>""" <EOL> return execute ( <EOL> [ self . git , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % revisions [ '<STR_LIT>' ] , revisions [ '<STR_LIT>' ] ] , <EOL> ignore_errors = True ) . strip ( ) <EOL> def get_parent_branch ( self ) : <EOL> """<STR_LIT>""" <EOL> parent_branch = getattr ( self . options , '<STR_LIT>' , None ) <EOL> if self . type == '<STR_LIT>' : <EOL> parent_branch = parent_branch or '<STR_LIT>' <EOL> return parent_branch <EOL> def get_head_ref ( self ) : <EOL> """<STR_LIT>""" <EOL> head_ref = "<STR_LIT>" <EOL> if self . head_ref : <EOL> head_ref = self . head_ref <EOL> return head_ref <EOL> def _get_merge_base ( self , rev1 , rev2 ) : <EOL> """<STR_LIT>""" <EOL> return execute ( [ self . git , "<STR_LIT>" , rev1 , rev2 ] ) . strip ( ) <EOL> def _rev_parse ( self , revisions ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( revisions , list ) : <EOL> revisions = [ revisions ] <EOL> return execute ( [ self . git , '<STR_LIT>' ] + revisions ) . strip ( ) . split ( '<STR_LIT:\n>' ) <EOL> def diff ( self , revisions , include_files = [ ] , exclude_patterns = [ ] , <EOL> extra_args = [ ] ) : <EOL> """<STR_LIT>""" <EOL> exclude_patterns = normalize_patterns ( exclude_patterns , <EOL> self . _get_root_directory ( ) , <EOL> cwd = self . original_cwd ) <EOL> try : <EOL> merge_base = revisions [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> merge_base = revisions [ '<STR_LIT>' ] <EOL> diff_lines = self . make_diff ( merge_base , <EOL> revisions [ '<STR_LIT>' ] , <EOL> revisions [ '<STR_LIT>' ] , <EOL> include_files , <EOL> exclude_patterns ) <EOL> if '<STR_LIT>' in revisions : <EOL> parent_diff_lines = self . make_diff ( merge_base , <EOL> revisions [ '<STR_LIT>' ] , <EOL> revisions [ '<STR_LIT>' ] , <EOL> include_files , <EOL> exclude_patterns ) <EOL> base_commit_id = revisions [ '<STR_LIT>' ] <EOL> else : <EOL> parent_diff_lines = None <EOL> base_commit_id = revisions [ '<STR_LIT>' ] <EOL> return { <EOL> '<STR_LIT>' : diff_lines , <EOL> '<STR_LIT>' : parent_diff_lines , <EOL> '<STR_LIT>' : revisions . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : base_commit_id , <EOL> } <EOL> def make_diff ( self , merge_base , base , tip , include_files , <EOL> exclude_patterns ) : <EOL> """<STR_LIT>""" <EOL> rev_range = "<STR_LIT>" % ( base , tip ) <EOL> if include_files : <EOL> include_files = [ '<STR_LIT>' ] + include_files <EOL> git_cmd = [ self . git ] <EOL> if self . _supports_git_config_flag ( ) : <EOL> git_cmd . extend ( [ '<STR_LIT:-c>' , '<STR_LIT>' ] ) <EOL> if self . type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> diff_cmd_params = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> elif self . type == '<STR_LIT>' : <EOL> diff_cmd_params = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> if self . _supports_git_config_flag ( ) : <EOL> git_cmd . extend ( [ '<STR_LIT:-c>' , '<STR_LIT>' ] ) <EOL> if ( self . capabilities is not None and <EOL> self . capabilities . has_capability ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> diff_cmd_params . append ( '<STR_LIT>' ) <EOL> else : <EOL> diff_cmd_params . append ( '<STR_LIT>' ) <EOL> else : <EOL> assert False <EOL> if not self . config . get ( '<STR_LIT>' , False ) : <EOL> diff_cmd_params . append ( '<STR_LIT>' ) <EOL> diff_cmd = git_cmd + [ '<STR_LIT>' ] + diff_cmd_params <EOL> if exclude_patterns : <EOL> changed_files_cmd = git_cmd + [ '<STR_LIT>' ] + diff_cmd_params <EOL> if self . type == '<STR_LIT>' : <EOL> changed_files_cmd . append ( '<STR_LIT>' ) <EOL> changed_files = execute ( <EOL> changed_files_cmd + [ rev_range ] + include_files , <EOL> split_lines = True , <EOL> with_errors = False , <EOL> ignore_errors = True , <EOL> none_on_ignored_error = True , <EOL> log_output_on_error = False ) <EOL> changed_files = remove_filenames_matching_patterns ( <EOL> ( filename . split ( ) [ - <NUM_LIT:1> ] for filename in changed_files ) , <EOL> exclude_patterns , base_dir = self . _get_root_directory ( ) ) <EOL> diff_lines = [ ] <EOL> for filename in changed_files : <EOL> lines = execute ( diff_cmd + [ rev_range , '<STR_LIT>' , filename ] , <EOL> split_lines = True , <EOL> with_errors = False , <EOL> ignore_errors = True , <EOL> none_on_ignored_error = True , <EOL> log_output_on_error = False , <EOL> results_unicode = False ) <EOL> if lines is None : <EOL> logging . error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> filename ) <EOL> diff_lines = None <EOL> break <EOL> diff_lines += lines <EOL> else : <EOL> diff_lines = execute ( diff_cmd + [ rev_range ] + include_files , <EOL> split_lines = True , <EOL> with_errors = False , <EOL> ignore_errors = True , <EOL> none_on_ignored_error = True , <EOL> log_output_on_error = False , <EOL> results_unicode = False ) <EOL> if self . type == '<STR_LIT>' : <EOL> return self . make_svn_diff ( merge_base , diff_lines ) <EOL> elif self . type == '<STR_LIT>' : <EOL> return self . make_perforce_diff ( merge_base , diff_lines ) <EOL> else : <EOL> return b'<STR_LIT>' . join ( diff_lines ) <EOL> def make_svn_diff ( self , merge_base , diff_lines ) : <EOL> """<STR_LIT>""" <EOL> rev = execute ( [ self . git , "<STR_LIT>" , "<STR_LIT>" , merge_base ] ) . strip ( ) <EOL> if not rev : <EOL> return None <EOL> diff_data = b'<STR_LIT>' <EOL> original_file = b'<STR_LIT>' <EOL> filename = b'<STR_LIT>' <EOL> newfile = False <EOL> for i , line in enumerate ( diff_lines ) : <EOL> if line . startswith ( b'<STR_LIT>' ) : <EOL> info = line . split ( b'<STR_LIT:U+0020>' ) <EOL> diff_data += b'<STR_LIT>' % info [ <NUM_LIT:2> ] <EOL> diff_data += b'<STR_LIT:=>' * <NUM_LIT> <EOL> diff_data += b'<STR_LIT:\n>' <EOL> elif line . startswith ( b'<STR_LIT>' ) : <EOL> pass <EOL> elif line . strip ( ) == b'<STR_LIT>' : <EOL> newfile = True <EOL> elif ( line . startswith ( b'<STR_LIT>' ) and i + <NUM_LIT:1> < len ( diff_lines ) and <EOL> diff_lines [ i + <NUM_LIT:1> ] . startswith ( b'<STR_LIT>' ) ) : <EOL> newfile = False <EOL> original_file = line [ <NUM_LIT:4> : ] . strip ( ) <EOL> diff_data += b'<STR_LIT>' % ( original_file , rev ) <EOL> elif line . startswith ( b'<STR_LIT>' ) : <EOL> filename = line [ <NUM_LIT:4> : ] . strip ( ) <EOL> if newfile : <EOL> diff_data += b'<STR_LIT>' % filename <EOL> diff_data += b'<STR_LIT>' % filename <EOL> else : <EOL> diff_data += b'<STR_LIT>' % original_file <EOL> elif ( line . startswith ( b'<STR_LIT>' ) or <EOL> line . startswith ( b'<STR_LIT>' ) ) : <EOL> pass <EOL> elif line . startswith ( b'<STR_LIT>' ) : <EOL> diff_data += b'<STR_LIT>' <EOL> diff_data += b'<STR_LIT>' <EOL> else : <EOL> diff_data += line <EOL> return diff_data <EOL> def make_perforce_diff ( self , merge_base , diff_lines ) : <EOL> """<STR_LIT>""" <EOL> diff_data = b'<STR_LIT>' <EOL> filename = b'<STR_LIT>' <EOL> p4rev = b'<STR_LIT>' <EOL> log = execute ( [ self . git , '<STR_LIT>' , merge_base ] , ignore_errors = True ) <EOL> for line in log : <EOL> m = re . search ( br'<STR_LIT>' , <EOL> log , re . M ) <EOL> if m : <EOL> base_path = m . group ( <NUM_LIT:1> ) . strip ( ) <EOL> p4rev = m . group ( <NUM_LIT:2> ) . strip ( ) <EOL> break <EOL> else : <EOL> pass <EOL> for i , line in enumerate ( diff_lines ) : <EOL> if line . startswith ( b'<STR_LIT>' ) : <EOL> filename = line . split ( b'<STR_LIT:U+0020>' ) [ <NUM_LIT:2> ] . strip ( ) <EOL> elif ( line . startswith ( b'<STR_LIT>' ) or <EOL> line . startswith ( b'<STR_LIT>' ) ) : <EOL> pass <EOL> elif ( line . startswith ( b'<STR_LIT>' ) and i + <NUM_LIT:1> < len ( diff_lines ) and <EOL> diff_lines [ i + <NUM_LIT:1> ] . startswith ( b'<STR_LIT>' ) ) : <EOL> data = execute ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , base_path + filename + '<STR_LIT:@>' + p4rev ] , <EOL> ignore_errors = True , results_unicode = False ) <EOL> m = re . search ( br'<STR_LIT>' % ( re . escape ( base_path ) , <EOL> re . escape ( filename ) ) , <EOL> data , re . M ) <EOL> if m : <EOL> file_version = m . group ( <NUM_LIT:1> ) . strip ( ) <EOL> else : <EOL> file_version = <NUM_LIT:1> <EOL> diff_data += b'<STR_LIT>' % ( base_path , filename , <EOL> base_path , filename , <EOL> file_version ) <EOL> elif line . startswith ( b'<STR_LIT>' ) : <EOL> diff_data += b'<STR_LIT>' % ( base_path , filename , <EOL> b'<STR_LIT>' ) <EOL> else : <EOL> diff_data += line <EOL> return diff_data <EOL> def has_pending_changes ( self ) : <EOL> """<STR_LIT>""" <EOL> status = execute ( [ '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> return status != '<STR_LIT>' <EOL> def amend_commit_description ( self , message , revisions ) : <EOL> """<STR_LIT>""" <EOL> if revisions and revisions [ '<STR_LIT>' ] : <EOL> commit_ids = execute ( [ self . git , '<STR_LIT>' , '<STR_LIT>' , <EOL> revisions [ '<STR_LIT>' ] ] , split_lines = True ) <EOL> head_id = commit_ids [ <NUM_LIT:0> ] . strip ( ) <EOL> revision_id = commit_ids [ <NUM_LIT:1> ] . strip ( ) <EOL> if head_id != revision_id : <EOL> raise AmendError ( '<STR_LIT>' <EOL> '<STR_LIT>' % revision_id ) <EOL> execute ( [ self . git , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , message ] ) <EOL> def apply_patch ( self , patch_file , base_path = None , base_dir = None , p = None , <EOL> revert = False ) : <EOL> """<STR_LIT>""" <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if revert : <EOL> cmd . append ( '<STR_LIT>' ) <EOL> if p : <EOL> cmd += [ '<STR_LIT>' , p ] <EOL> cmd . append ( patch_file ) <EOL> rc , data = self . _execute ( cmd , with_errors = True , return_error_code = True ) <EOL> if rc == <NUM_LIT:0> : <EOL> return PatchResult ( applied = True , patch_output = data ) <EOL> elif '<STR_LIT>' in data : <EOL> return PatchResult ( <EOL> applied = True , <EOL> has_conflicts = True , <EOL> conflicting_files = [ <EOL> line . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> for line in data . splitlines ( ) <EOL> if line . startswith ( '<STR_LIT>' ) <EOL> ] , <EOL> patch_output = data ) <EOL> else : <EOL> return PatchResult ( applied = False , patch_output = data ) <EOL> def create_commit ( self , message , author , run_editor , <EOL> files = [ ] , all_files = False ) : <EOL> """<STR_LIT>""" <EOL> if run_editor : <EOL> modified_message = edit_text ( message ) <EOL> else : <EOL> modified_message = message <EOL> if all_files : <EOL> execute ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> elif files : <EOL> execute ( [ '<STR_LIT>' , '<STR_LIT>' ] + files ) <EOL> execute ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , modified_message , <EOL> '<STR_LIT>' % ( author . fullname , author . email ) ] ) <EOL> def delete_branch ( self , branch_name , merged_only = True ) : <EOL> """<STR_LIT>""" <EOL> if merged_only : <EOL> delete_flag = '<STR_LIT>' <EOL> else : <EOL> delete_flag = '<STR_LIT>' <EOL> execute ( [ '<STR_LIT>' , '<STR_LIT>' , delete_flag , branch_name ] ) <EOL> def merge ( self , target , destination , message , author , squash = False , <EOL> run_editor = False ) : <EOL> """<STR_LIT>""" <EOL> rc , output = execute ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , destination ] , <EOL> ignore_errors = True , <EOL> return_error_code = True ) <EOL> if rc : <EOL> raise MergeError ( "<STR_LIT>" % <EOL> ( destination , output ) ) <EOL> if squash : <EOL> method = '<STR_LIT>' <EOL> else : <EOL> method = '<STR_LIT>' <EOL> rc , output = execute ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , target , method , '<STR_LIT>' ] , <EOL> ignore_errors = True , <EOL> return_error_code = True ) <EOL> if rc : <EOL> raise MergeError ( "<STR_LIT>" % <EOL> ( target , destination , output ) ) <EOL> self . create_commit ( message , author , run_editor ) <EOL> def push_upstream ( self , remote_branch ) : <EOL> """<STR_LIT>""" <EOL> origin_url = self . get_origin ( ) [ <NUM_LIT:1> ] <EOL> rc , output = execute ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , origin_url , remote_branch ] , <EOL> ignore_errors = True , <EOL> return_error_code = True ) <EOL> if rc : <EOL> raise PushError ( '<STR_LIT>' ) <EOL> rc , output = execute ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , origin_url , remote_branch ] , <EOL> ignore_errors = True , <EOL> return_error_code = True ) <EOL> if rc : <EOL> raise PushError ( "<STR_LIT>" % <EOL> remote_branch ) <EOL> def get_current_branch ( self ) : <EOL> """<STR_LIT>""" <EOL> return execute ( [ self . git , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ignore_errors = True ) . strip ( ) <EOL> def _get_root_directory ( self ) : <EOL> """<STR_LIT>""" <EOL> git_dir = execute ( [ self . git , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ignore_errors = True ) . rstrip ( "<STR_LIT:\n>" ) <EOL> if git_dir . startswith ( "<STR_LIT>" ) or not os . path . isdir ( git_dir ) : <EOL> logging . error ( "<STR_LIT>" ) <EOL> return None <EOL> return os . path . abspath ( os . path . join ( git_dir , "<STR_LIT:..>" ) ) <EOL> @ property <EOL> def original_cwd ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _original_cwd is None : <EOL> self . _original_cwd = os . getcwd ( ) <EOL> return self . _original_cwd </s>
