Пример #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
 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)