예제 #1
0
    def update_git_file(self):
        # the git repo won't change that often
        # so we can easily wait 5 seconds
        # between updates for performance
        if ViewCollection.git_time(self.view) > 5:
            open(self.git_temp_file.name, 'w').close()

            if self.view.get_status('remote'):
                base_path = self.view.file_name() + '.base'
                if os.path.exists(base_path):
                    shutil.copyfile(base_path, self.git_temp_file.name)
                return

            args = [
                self.git_binary_path,
                '--git-dir=' + self.git_dir,
                '--work-tree=' + self.git_tree,
                'show',
                'HEAD:' + self.git_path,
            ]
            try:
                contents = self.run_command(args)
                contents = contents.replace(b'\r\n', b'\n')
                contents = contents.replace(b'\r', b'\n')
                f = open(self.git_temp_file.name, 'wb')
                f.write(contents)
                f.close()
                ViewCollection.update_git_time(self.view)
            except Exception:
                pass
예제 #2
0
    def update_git_file(self):
        # the git repo won't change that often
        # so we can easily wait 5 seconds
        # between updates for performance
        if ViewCollection.git_time(self.view) > 5:
            open(self.git_temp_file.name, 'w').close()

            if self.view.get_status('remote'):
                base_path = self.view.file_name() + '.base'
                if os.path.exists(base_path):
                    shutil.copyfile(base_path, self.git_temp_file.name)
                return

            args = [
                self.git_binary_path,
                '--git-dir=' + self.git_dir,
                '--work-tree=' + self.git_tree,
                'show',
                'HEAD:' + self.git_path,
            ]
            try:
                contents = self.run_command(args)
                contents = contents.replace(b'\r\n', b'\n')
                contents = contents.replace(b'\r', b'\n')
                f = open(self.git_temp_file.name, 'wb')
                f.write(contents)
                f.close()
                ViewCollection.update_git_time(self.view)
            except Exception:
                pass
예제 #3
0
 def __init__(self, view):
     self.view = view
     self.git_temp_file = ViewCollection.git_tmp_file(self.view)
     self.buf_temp_file = ViewCollection.buf_tmp_file(self.view)
     if self.on_disk():
         self.git_tree = git_helper.git_tree(self.view)
         self.git_dir = git_helper.git_dir(self.git_tree)
         self.git_path = git_helper.git_file_path(self.view, self.git_tree)
예제 #4
0
 def __init__(self, view):
     self.view = view
     self.git_temp_file = ViewCollection.git_tmp_file(self.view)
     self.buf_temp_file = ViewCollection.buf_tmp_file(self.view)
     if self.on_disk():
         self.git_tree = git_helper.git_tree(self.view)
         self.git_dir = git_helper.git_dir(self.git_tree)
         self.git_path = git_helper.git_file_path(self.view, self.git_tree)
예제 #5
0
 def __init__(self, view):
     self.load_settings()
     self.view = view
     self.git_temp_file = ViewCollection.git_tmp_file(self.view)
     self.buf_temp_file = ViewCollection.buf_tmp_file(self.view)
     if self.on_disk():
         self.git_tree = git_helper.git_tree(self.view)
         self.git_dir = git_helper.git_dir(self.git_tree)
         self.git_path = git_helper.git_file_path(self.view, self.git_tree)
         if self.view.get_status('remote'):
             self.git_path = self.view.get_status('remote')
예제 #6
0
 def __init__(self, view):
     self.load_settings()
     self.view = view
     self.git_temp_file = ViewCollection.git_tmp_file(self.view)
     self.buf_temp_file = ViewCollection.buf_tmp_file(self.view)
     if self.on_disk():
         self.git_tree = git_helper.git_tree(self.view)
         self.git_dir = git_helper.git_dir(self.git_tree)
         self.git_path = git_helper.git_file_path(self.view, self.git_tree)
         if self.view.get_status('remote'):
             self.git_path = self.view.get_status('remote')
예제 #7
0
 def on_modified(self, view):
     if not self.live_mode:
         return None
     if not self.non_blocking:
         if not self.live_delay:
             ViewCollection.add(view)
         elif not self.delayed_update_scheduled:
             if self.allow_instant_update:
                 self.allow_instant_update = False
                 sublime.set_timeout(lambda: self.delayed_update(view), 10)
                 sublime.set_timeout(lambda: self.enable_instant_update(), self.live_instant_interval)
             else:
                 self.delayed_update_scheduled = True
                 sublime.set_timeout(lambda: self.delayed_update(view), self.live_continuous_delay)
예제 #8
0
    def run(self):
        self.view = self.window.active_view()
        self.handler = ViewCollection.get_handler(self.view)

        self.results = self.commit_list()
        if self.results:
            self.window.show_quick_panel(self.results, self.on_select)
예제 #9
0
    def run(self):
        self.view = self.window.active_view()
        self.handler = ViewCollection.get_handler(self.view)

        self.results = self.commit_list()
        if self.results:
            self.window.show_quick_panel(self.results, self.on_select)
예제 #10
0
 def update_git_file(self):
     # the git repo won't change that often
     # so we can easily wait 5 seconds
     # between updates for performance
     if ViewCollection.git_time(self.view) > 5:
         open(self.git_temp_file.name, "w").close()
         args = ["git", "--git-dir=" + self.git_dir, "--work-tree=" + self.git_tree, "show", "HEAD:" + self.git_path]
         try:
             contents = self.run_command(args)
             contents = contents.replace(b"\r\n", b"\n")
             contents = contents.replace(b"\r", b"\n")
             f = open(self.git_temp_file.name, "wb")
             f.write(contents)
             f.close()
             ViewCollection.update_git_time(self.view)
         except Exception:
             pass
예제 #11
0
 def run(self):
     self.view = self.window.active_view()
     if not self.view:
         # View is not ready yet, try again later.
         sublime.set_timeout(self.run, 1)
         return
     self.clear_all()
     if ViewCollection.untracked(self.view):
         self.bind_files('untracked')
     elif ViewCollection.ignored(self.view):
         self.bind_files('ignored')
     else:
         # If the file is untracked there is no need to execute the diff update
         inserted, modified, deleted = ViewCollection.diff(self.view)
         self.lines_removed(deleted)
         self.bind_icons('inserted', inserted)
         self.bind_icons('changed', modified)
예제 #12
0
 def run(self):
     self.view = self.window.active_view()
     if not self.view:
         # View is not ready yet, try again later.
         sublime.set_timeout(self.run, 1)
         return
     self.clear_all()
     if ViewCollection.untracked(self.view):
         self.bind_files('untracked')
     elif ViewCollection.ignored(self.view):
         self.bind_files('ignored')
     else:
         # If the file is untracked there is no need to execute the diff update
         inserted, modified, deleted = ViewCollection.diff(self.view)
         self.lines_removed(deleted)
         self.bind_icons('inserted', inserted)
         self.bind_icons('changed', modified)
예제 #13
0
파일: git_gutter.py 프로젝트: 3on/GitGutter
 def bind_files(self, event):
     lines = []
     lineCount = ViewCollection.total_lines(self.view)
     i = 0
     while i < lineCount:
         lines += [i + 1]
         i = i + 1
     self.bind_icons(event, lines)
예제 #14
0
 def bind_files(self, event):
     lines = []
     lineCount = ViewCollection.total_lines(self.view)
     i = 0
     while i < lineCount:
         lines += [i + 1]
         i = i + 1
     self.bind_icons(event, lines)
예제 #15
0
 def add(view):
     key = ViewCollection.get_key(view)
     try:
         from GitGutter.git_gutter_handler import GitGutterHandler
     except ImportError:
         from git_gutter_handler import GitGutterHandler
     handler = ViewCollection.views[key] = GitGutterHandler(view)
     handler.reset()
     return handler
예제 #16
0
 def add(view):
     key = ViewCollection.get_key(view)
     try:
         from GitGutter.git_gutter_handler import GitGutterHandler
     except ImportError:
         from git_gutter_handler import GitGutterHandler
     handler = ViewCollection.views[key] = GitGutterHandler(view)
     handler.reset()
     return handler
 def run(self):
     self.view = self.window.active_view()
     if not self.view:
         # View is not ready yet, try again later.
         sublime.set_timeout(self.run, 1)
         return
     self.clear_all()
     inserted, modified, deleted = ViewCollection.diff(self.view)
     self.lines_removed(deleted)
     self.lines_added(inserted)
     self.lines_modified(modified)
예제 #18
0
 def run(self):
     self.view = self.window.active_view()
     if not self.view:
         # View is not ready yet, try again later.
         sublime.set_timeout(self.run, 1)
         return
     self.clear_all()
     inserted, modified, deleted = ViewCollection.diff(self.view)
     self.lines_removed(deleted)
     self.lines_added(inserted)
     self.lines_modified(modified)
예제 #19
0
 def on_select(self, selected):
     if 0 > selected < len(self.results):
         return
     item = self.results[selected]
     commit = self.item_to_commit(item)
     ViewCollection.set_compare(commit)
     ViewCollection.clear_git_time(self.view)
     ViewCollection.add(self.view)
예제 #20
0
 def on_select(self, selected):
     if 0 > selected < len(self.results):
         return
     item = self.results[selected]
     commit = self.item_to_commit(item)
     ViewCollection.set_compare(commit)
     ViewCollection.clear_git_time(self.view)
     ViewCollection.add(self.view)
예제 #21
0
 def update_git_file(self):
     # the git repo won't change that often
     # so we can easily wait 5 seconds
     # between updates for performance
     if ViewCollection.git_time(self.view) > 5:
         open(self.git_temp_file.name, 'w').close()
         args = [
             git_helper.git_command(self.view),
             '--git-dir=' + self.git_dir,
             '--work-tree=' + self.git_tree,
             'show',
             'HEAD:' + self.git_path,
         ]
         try:
             contents = self.run_command(args)
             contents = contents.replace(b'\r\n', b'\n')
             contents = contents.replace(b'\r', b'\n')
             f = open(self.git_temp_file.name, 'wb')
             f.write(contents)
             f.close()
             ViewCollection.update_git_time(self.view)
         except Exception:
             pass
예제 #22
0
 def update_git_file(self):
     # the git repo won't change that often
     # so we can easily wait 5 seconds
     # between updates for performance
     if ViewCollection.git_time(self.view) > 5:
         open(self.git_temp_file.name, 'w').close()
         args = [
             'git',
             '--git-dir=' + self.git_dir,
             '--work-tree=' + self.git_tree,
             'show',
             'HEAD:' + self.git_path,
         ]
         try:
             contents = self.run_command(args)
             contents = contents.replace(b'\r\n', b'\n')
             contents = contents.replace(b'\r', b'\n')
             f = open(self.git_temp_file.name, 'wb')
             f.write(contents)
             f.close()
             ViewCollection.update_git_time(self.view)
         except Exception:
             pass
예제 #23
0
    def run(self):
        view = self.window.active_view()

        inserted, modified, deleted = ViewCollection.diff(view)
        inserted = self.lines_to_blocks(inserted)
        modified = self.lines_to_blocks(modified)
        all_changes = sorted(inserted + modified + deleted)
        if all_changes:
            row, col = view.rowcol(view.sel()[0].begin())

            current_row = row + 1

            line = self.jump(all_changes, current_row)

            self.window.active_view().run_command("goto_line", {"line": line})
예제 #24
0
    def run(self):
        view = self.window.active_view()

        inserted, modified, deleted = ViewCollection.diff(view)
        inserted = self.lines_to_blocks(inserted)
        modified = self.lines_to_blocks(modified)
        all_changes = sorted(inserted + modified + deleted)
        if all_changes:
            row, col = view.rowcol(view.sel()[0].begin())

            current_row = row + 1

            line = self.jump(all_changes, current_row)

            self.window.active_view().run_command("goto_line", {"line": line})
예제 #25
0
 def run(self):
     self.view = self.window.active_view()
     if not self.view:
         # Sometimes GitGutter tries to run when there is no active window
         # and it throws an error because self.view is None.
         # I have only been able to reproduce this in the following scenario:
         # you clicked on FileA in the sidebar (FileA is not previously open)
         # not to open it but to preview it. While previewing it you press
         # ctrl+` to open a console. With the console selected and the
         # unopened FileA preview showing in the window you click on another
         # unopened file, FileB to preview that file. There will be no active
         # window at this time and GitGutter will throw an error. So we can
         # just skip running this time because immediately after selecting
         # FileB, focus will shift from the console to its preview. This will
         # cause GitGutter to run again on the FileB preview.
         # Wow that was a really long explanation.
         return
     self.clear_all()
     inserted, modified, deleted = ViewCollection.diff(self.view)
     self.lines_removed(deleted)
     self.lines_added(inserted)
     self.lines_modified(modified)
예제 #26
0
 def run(self):
     self.view = self.window.active_view()
     if not self.view:
         # Sometimes GitGutter tries to run when there is no active window
         # and it throws an error because self.view is None.
         # I have only been able to reproduce this in the following scenario:
         # you clicked on FileA in the sidebar (FileA is not previously open)
         # not to open it but to preview it. While previewing it you press
         # ctrl+` to open a console. With the console selected and the
         # unopened FileA preview showing in the window you click on another
         # unopened file, FileB to preview that file. There will be no active
         # window at this time and GitGutter will throw an error. So we can
         # just skip running this time because immediately after selecting
         # FileB, focus will shift from the console to its preview. This will
         # cause GitGutter to run again on the FileB preview.
         # Wow that was a really long explanation.
         return
     self.clear_all()
     inserted, modified, deleted = ViewCollection.diff(self.view)
     self.lines_removed(deleted)
     self.lines_added(inserted)
     self.lines_modified(modified)
 def on_post_save(self, view):
     if not self.non_blocking:
         ViewCollection.add(view)
예제 #28
0
 def clear_git_time(view):
     key = ViewCollection.get_key(view)
     ViewCollection.git_times[key] = 0
예제 #29
0
 def buf_tmp_file(view):
     key = ViewCollection.get_key(view)
     if not key in ViewCollection.buf_files:
         ViewCollection.buf_files[key] = tempfile.NamedTemporaryFile()
         ViewCollection.buf_files[key].close()
     return ViewCollection.buf_files[key]
예제 #30
0
 def on_post_save(self, view):
     ViewCollection.add(view)
예제 #31
0
 def on_load(self, view):
     if self.settings_loaded():
         if not self.non_blocking and not self.live_mode:
             ViewCollection.add(view)
예제 #32
0
 def on_activated(self, view):
     if not self.non_blocking:
         ViewCollection.add(view)
예제 #33
0
 def on_modified(self, view):
     if view.settings().get('git_gutter_live_mode', True):
         ViewCollection.add(view)
예제 #34
0
 def on_clone(self, view):
     if not self.non_blocking:
         ViewCollection.add(view)
예제 #35
0
 def on_activated_async(self, view):
     if self.non_blocking:
         ViewCollection.add(view)
예제 #36
0
 def on_post_save_async(self, view):
     if self.non_blocking:
         ViewCollection.add(view)
예제 #37
0
 def on_clone_async(self, view):
     if self.non_blocking:
         ViewCollection.add(view)
예제 #38
0
 def on_modified_async(self, view):
     if not self.live_mode:
         return None
     if self.non_blocking:
         ViewCollection.add(view)
 def on_clone_async(self, view):
     if self.non_blocking:
         ViewCollection.add(view)
예제 #40
0
 def on_activated(self, view):
     ViewCollection.add(view)
 def on_load_async(self, view):
     if self.non_blocking and not self.live_mode:
         ViewCollection.add(view)
예제 #42
0
 def get_handler(view):
     if ViewCollection.has_view(view):
         key = ViewCollection.get_key(view)
         return ViewCollection.views[key]
     else:
         return ViewCollection.add(view)
예제 #43
0
 def on_post_save(self, view):
     if self.settings_loaded():
         if not self.non_blocking:
             ViewCollection.add(view)
예제 #44
0
 def diff(view):
     key = ViewCollection.get_key(view)
     return ViewCollection.views[key].diff()
예제 #45
0
 def on_activated(self, view):
     if self.settings_loaded():
         if not self.non_blocking and self.focus_change_mode:
             ViewCollection.add(view)
예제 #46
0
 def untracked(view):
     key = ViewCollection.get_key(view)
     return ViewCollection.views[key].untracked()
예제 #47
0
 def on_clone(self, view):
     ViewCollection.add(view)
예제 #48
0
 def ignored(view):
     key = ViewCollection.get_key(view)
     return ViewCollection.views[key].ignored()
예제 #49
0
 def update_git_time(view):
     key = ViewCollection.get_key(view)
     ViewCollection.git_times[key] = time.time()
예제 #50
0
 def total_lines(view):
     key = ViewCollection.get_key(view)
     return ViewCollection.views[key].total_lines()
예제 #51
0
 def git_time(view):
     key = ViewCollection.get_key(view)
     if not key in ViewCollection.git_times:
         ViewCollection.git_times[key] = 0
     return time.time() - ViewCollection.git_times[key]
예제 #52
0
 def git_time(view):
     key = ViewCollection.get_key(view)
     if not key in ViewCollection.git_times:
         ViewCollection.git_times[key] = 0
     return time.time() - ViewCollection.git_times[key]
 def on_clone(self, view):
     if not self.non_blocking:
         ViewCollection.add(view)
예제 #54
0
 def clear_git_time(view):
     key = ViewCollection.get_key(view)
     ViewCollection.git_times[key] = 0
 def on_modified_async(self, view):
     if not self.live_mode:
         return None
     if self.non_blocking:
         ViewCollection.add(view)
예제 #56
0
 def update_git_time(view):
     key = ViewCollection.get_key(view)
     ViewCollection.git_times[key] = time.time()
 def on_post_save_async(self, view):
     if self.non_blocking:
         ViewCollection.add(view)
예제 #58
0
 def buf_tmp_file(view):
     key = ViewCollection.get_key(view)
     if not key in ViewCollection.buf_files:
         ViewCollection.buf_files[key] = tempfile.NamedTemporaryFile()
         ViewCollection.buf_files[key].close()
     return ViewCollection.buf_files[key]
 def on_activated_async(self, view):
     if self.non_blocking and self.focus_change_mode:
         ViewCollection.add(view)
예제 #60
0
 def on_post_save(self, view):
     if not self.non_blocking:
         ViewCollection.add(view)