<s> from __future__ import absolute_import , unicode_literals , print_function , division <EOL> import sublime <EOL> import sublime_plugin <EOL> import os <EOL> import re <EOL> from . import git_root , GitTextCommand , GitWindowCommand , do_when , goto_xy <EOL> class GitDiff ( object ) : <EOL> def run ( self , edit = None , ignore_whitespace = False ) : <EOL> command = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if ignore_whitespace : <EOL> command . extend ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> command . extend ( ( '<STR_LIT>' , self . get_file_name ( ) ) ) <EOL> self . run_command ( command , self . diff_done ) <EOL> def diff_done ( self , result ) : <EOL> if not result . strip ( ) : <EOL> self . panel ( "<STR_LIT>" ) <EOL> return <EOL> s = sublime . load_settings ( "<STR_LIT>" ) <EOL> syntax = s . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if s . get ( '<STR_LIT>' ) : <EOL> view = self . panel ( result , syntax = syntax ) <EOL> else : <EOL> view = self . scratch ( result , title = "<STR_LIT>" , syntax = syntax ) <EOL> class GitDiffCommit ( object ) : <EOL> def run ( self , edit = None , ignore_whitespace = False ) : <EOL> command = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if ignore_whitespace : <EOL> command . extend ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . run_command ( command , self . diff_done ) <EOL> def diff_done ( self , result ) : <EOL> if not result . strip ( ) : <EOL> self . panel ( "<STR_LIT>" ) <EOL> return <EOL> s = sublime . load_settings ( "<STR_LIT>" ) <EOL> syntax = s . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . scratch ( result , title = "<STR_LIT>" , syntax = syntax ) <EOL> class GitDiffCommand ( GitDiff , GitTextCommand ) : <EOL> pass <EOL> class GitDiffAllCommand ( GitDiff , GitWindowCommand ) : <EOL> pass <EOL> class GitDiffCommitCommand ( GitDiffCommit , GitWindowCommand ) : <EOL> pass <EOL> class GitGotoDiff ( sublime_plugin . TextCommand ) : <EOL> def __init__ ( self , view ) : <EOL> self . view = view <EOL> def run ( self , edit ) : <EOL> v = self . view <EOL> view_scope_name = v . scope_name ( v . sel ( ) [ <NUM_LIT:0> ] . a ) <EOL> scope_markup_inserted = ( "<STR_LIT>" in view_scope_name ) <EOL> scope_markup_deleted = ( "<STR_LIT>" in view_scope_name ) <EOL> if not scope_markup_inserted and not scope_markup_deleted : <EOL> return <EOL> beg = v . sel ( ) [ <NUM_LIT:0> ] . a <EOL> pt = v . line ( beg ) . a <EOL> self . column = beg - pt - <NUM_LIT:1> <EOL> self . file_name = None <EOL> hunk_line = None <EOL> line_offset = <NUM_LIT:0> <EOL> while pt > <NUM_LIT:0> : <EOL> line = v . line ( pt ) <EOL> lineContent = v . substr ( line ) <EOL> if lineContent . startswith ( "<STR_LIT>" ) : <EOL> if not hunk_line : <EOL> hunk_line = lineContent <EOL> elif lineContent . startswith ( "<STR_LIT>" ) : <EOL> self . file_name = v . substr ( sublime . Region ( line . a + <NUM_LIT:6> , line . b ) ) . strip ( ) <EOL> break <EOL> elif not hunk_line and not lineContent . startswith ( "<STR_LIT:->" ) : <EOL> line_offset = line_offset + <NUM_LIT:1> <EOL> pt = v . line ( pt - <NUM_LIT:1> ) . a <EOL> hunk = re . match ( r"<STR_LIT>" , hunk_line ) <EOL> if not hunk : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> hunk_start_line = hunk . group ( <NUM_LIT:3> ) <EOL> self . goto_line = int ( hunk_start_line ) + line_offset - <NUM_LIT:1> <EOL> git_root_dir = v . settings ( ) . get ( "<STR_LIT>" ) <EOL> full_path_file_name = self . file_name <EOL> if git_root_dir : <EOL> full_path_file_name = os . path . join ( git_root_dir , self . file_name ) <EOL> else : <EOL> git_root_dir = "<STR_LIT>" <EOL> if not os . path . isfile ( full_path_file_name ) : <EOL> caption = "<STR_LIT>" % self . file_name <EOL> v . window ( ) . show_input_panel ( caption , <EOL> git_root_dir , <EOL> self . on_path_confirmed , <EOL> None , <EOL> None ) <EOL> else : <EOL> self . on_path_confirmed ( git_root_dir ) <EOL> def on_path_confirmed ( self , git_root_dir ) : <EOL> v = self . view <EOL> old_git_root_dir = v . settings ( ) . get ( "<STR_LIT>" ) <EOL> if old_git_root_dir != git_root_dir : <EOL> v . settings ( ) . set ( "<STR_LIT>" , git_root_dir ) <EOL> full_path_file_name = os . path . join ( git_root_dir , self . file_name ) <EOL> new_view = v . window ( ) . open_file ( full_path_file_name ) <EOL> do_when ( lambda : not new_view . is_loading ( ) , <EOL> lambda : goto_xy ( new_view , self . goto_line , self . column ) ) </s>
