Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 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')
Esempio n. 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')
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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
 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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})
Esempio n. 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})
 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 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)
Esempio n. 28
0
 def clear_git_time(view):
     key = ViewCollection.get_key(view)
     ViewCollection.git_times[key] = 0
Esempio n. 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]
Esempio n. 30
0
 def on_post_save(self, view):
     ViewCollection.add(view)
Esempio n. 31
0
 def on_load(self, view):
     if self.settings_loaded():
         if not self.non_blocking and not self.live_mode:
             ViewCollection.add(view)
Esempio n. 32
0
 def on_activated(self, view):
     if not self.non_blocking:
         ViewCollection.add(view)
Esempio n. 33
0
 def on_modified(self, view):
     if view.settings().get('git_gutter_live_mode', True):
         ViewCollection.add(view)
Esempio n. 34
0
 def on_clone(self, view):
     if not self.non_blocking:
         ViewCollection.add(view)
Esempio n. 35
0
 def on_activated_async(self, view):
     if self.non_blocking:
         ViewCollection.add(view)
Esempio n. 36
0
 def on_post_save_async(self, view):
     if self.non_blocking:
         ViewCollection.add(view)
Esempio n. 37
0
 def on_clone_async(self, view):
     if self.non_blocking:
         ViewCollection.add(view)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 43
0
 def on_post_save(self, view):
     if self.settings_loaded():
         if not self.non_blocking:
             ViewCollection.add(view)
Esempio n. 44
0
 def diff(view):
     key = ViewCollection.get_key(view)
     return ViewCollection.views[key].diff()
Esempio n. 45
0
 def on_activated(self, view):
     if self.settings_loaded():
         if not self.non_blocking and self.focus_change_mode:
             ViewCollection.add(view)
Esempio n. 46
0
 def untracked(view):
     key = ViewCollection.get_key(view)
     return ViewCollection.views[key].untracked()
Esempio n. 47
0
 def on_clone(self, view):
     ViewCollection.add(view)
Esempio n. 48
0
 def ignored(view):
     key = ViewCollection.get_key(view)
     return ViewCollection.views[key].ignored()
Esempio n. 49
0
 def update_git_time(view):
     key = ViewCollection.get_key(view)
     ViewCollection.git_times[key] = time.time()
Esempio n. 50
0
 def total_lines(view):
     key = ViewCollection.get_key(view)
     return ViewCollection.views[key].total_lines()
Esempio n. 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]
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 60
0
 def on_post_save(self, view):
     if not self.non_blocking:
         ViewCollection.add(view)