Example #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',
                ViewCollection.get_compare() + ':' + 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
Example #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:
            with open(self.git_temp_file, 'w'):
                pass

            args = [
                self.git_binary_path,
                '--git-dir=' + self.git_dir,
                '--work-tree=' + self.git_tree,
                'show',
                ViewCollection.get_compare(self.view) + ':' + self.git_path,
            ]
            try:
                contents = self.run_command(args)
                contents = contents.replace(b'\r\n', b'\n')
                contents = contents.replace(b'\r', b'\n')
                with open(self.git_temp_file, 'wb') as f:
                    f.write(contents)

                ViewCollection.update_git_time(self.view)
            except Exception:
                pass
Example #3
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',
                ViewCollection.get_compare() + ':' + 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
Example #4
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:
            with open(self.git_temp_file, 'w'):
                pass

            args = [
                self.git_binary_path,
                '--git-dir=' + self.git_dir,
                '--work-tree=' + self.git_tree,
                'show',
                ViewCollection.get_compare(self.view) + ':' + self.git_path,
            ]
            try:
                contents = self.run_command(args)
                contents = contents.replace(b'\r\n', b'\n')
                contents = contents.replace(b'\r', b'\n')
                with open(self.git_temp_file, 'wb') as f:
                    f.write(contents)

                ViewCollection.update_git_time(self.view)
            except Exception:
                pass
Example #5
0
    def update_vcs_file(self):
        # the git repo won't change that often
        # so we can easily wait 5 seconds
        # between updates for performance
        if ViewCollection.vcs_time(self.view) > 5:
            open(self.vcs_temp_file.name, 'w').close()
            status_args = self.get_status_args()
            status = None
            try:
                contents, errors = self.run_command(status_args)
                status = self.process_status_line(contents)
                ViewCollection.update_vcs_status(self.view, status)
            except Exception as e:
                # print e
                pass

            args = self.get_diff_args()
            try:
                if status == 'M':
                    contents, errors = self.run_command(args)
                    contents = VcsGutterHandler._to_unix(contents)
                    VcsGutterHandler._write(self.vcs_temp_file.name, contents)
                    ViewCollection.update_vcs_time(self.view)
            except Exception as e:
                print ("Unable to write file for diff ", e)
Example #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)
     self.git_tree = None
     self.git_dir = None
     self.git_path = None
Example #7
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)
     self.git_tree = None
     self.git_dir = None
     self.git_path = None
 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)
    def __init__(self, view):
        self.view = view
        self.vcs_temp_file = ViewCollection.vcs_tmp_file(self.view)
        self.buf_temp_file = ViewCollection.buf_tmp_file(self.view)

        vcs_helper = self.get_vcs_helper()
        if self.on_disk():
            self.vcs_tree = vcs_helper.vcs_tree(self.view)
            self.vcs_dir = vcs_helper.vcs_dir(self.vcs_tree)
            self.vcs_path = vcs_helper.vcs_file_path(self.view, self.vcs_tree)
Example #10
0
    def run(self, force_refresh=False):
        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
            if force_refresh:
                ViewCollection.clear_git_time(self.view)
            inserted, modified, deleted = ViewCollection.diff(self.view)
            self.lines_removed(deleted)
            self.bind_icons('inserted', inserted)
            self.bind_icons('changed', modified)

            if(ViewCollection.show_status(self.view) != "none"):
                if(ViewCollection.show_status(self.view) == 'all'):
                    branch = ViewCollection.current_branch(
                        self.view).decode("utf-8").strip()
                else:
                    branch = ""

                self.update_status(len(inserted),
                                   len(modified),
                                   len(deleted),
                                   ViewCollection.get_compare(self.view), branch)
            else:
                self.update_status(0, 0, 0, "", "")
Example #11
0
    def run(self, force_refresh=False):
        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
            if force_refresh:
                ViewCollection.clear_git_time(self.view)
            inserted, modified, deleted = ViewCollection.diff(self.view)
            self.lines_removed(deleted)
            self.bind_icons('inserted', inserted)
            self.bind_icons('changed', modified)

            if (ViewCollection.show_status(self.view) != "none"):
                if (ViewCollection.show_status(self.view) == 'all'):
                    branch = ViewCollection.current_branch(
                        self.view).decode("utf-8").strip()
                else:
                    branch = ""

                self.update_status(len(inserted), len(modified), len(deleted),
                                   ViewCollection.get_compare(self.view),
                                   branch)
            else:
                self.update_status(0, 0, 0, "", "")
Example #12
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')
Example #13
0
    def __init__(self, view, exc_path):
        self.view = view
        self.exc_path = exc_path
        self.vcs_temp_file = ViewCollection.vcs_tmp_file(self.view)
        self.buf_temp_file = ViewCollection.buf_tmp_file(self.view)

        vcs_helper = self.get_vcs_helper()
        if self.on_disk():
            self.vcs_tree = vcs_helper.vcs_tree(self.view)
            self.vcs_dir = vcs_helper.vcs_dir(self.vcs_tree)
            self.vcs_path = vcs_helper.vcs_file_path(self.view, self.vcs_tree)
Example #14
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')
Example #15
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:
     self.git_temp_file.truncate()
     args = ['git','--git-dir='+self.git_dir,'--work-tree='+self.git_tree,'show','head:'+self.git_path]
     try:
       subprocess.call(args, stdout=self.git_temp_file)
       ViewCollection.update_git_time(self.view)
     except Exception:
       pass
Example #16
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)
    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)
Example #18
0
 def run(self):
     self.view = self.window.active_view()
     self.clear_all()
     inserted, modified, deleted = ViewCollection.diff(self.view)
     self.lines_removed(deleted)
     self.lines_added(inserted)
     self.lines_modified(modified)
Example #19
0
 def on_modified(self, view):
     if view.settings().get('git_gutter_live_mode', True):
         # Sublime Text is very strict on the amount of time plugin
         # uses in performance-critical events. Sometimes invoking plugin
         # from this event causes Sublime warning to appear, so we need to
         # schedule its run for future.
         sublime.set_timeout(lambda: ViewCollection.add(view), 1)
Example #20
0
 def run(self):
     self.view = self.window.active_view()
     self.clear_all()
     inserted, modified, deleted = ViewCollection.diff(self.view)
     self.lines_removed(deleted)
     self.lines_added(inserted)
     self.lines_modified(modified)
Example #21
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)
Example #22
0
 def update_vcs_file(self):
     # the git repo won't change that often
     # so we can easily wait 5 seconds
     # between updates for performance
     if ViewCollection.vcs_time(self.view) > 5:
         open(self.vcs_temp_file.name, 'w').close()
         args = self.get_diff_args()
         try:
             contents = self.run_command(args)
             contents = contents.replace(b'\r\n', b'\n')
             contents = contents.replace(b'\r', b'\n')
             f = open(self.vcs_temp_file.name, 'wb')
             f.write(contents)
             f.close()
             ViewCollection.update_vcs_time(self.view)
         except Exception as e:
             print("Unable to write file for diff ", e)
 def update_vcs_file(self):
     # the git repo won't change that often
     # so we can easily wait 5 seconds
     # between updates for performance
     if ViewCollection.vcs_time(self.view) > 5:
         open(self.vcs_temp_file.name, 'w').close()
         args = self.get_diff_args()
         try:
             contents = self.run_command(args)
             contents = contents.replace('\r\n', '\n')
             contents = contents.replace('\r', '\n')
             f = open(self.vcs_temp_file.name, 'w')
             f.write(contents)
             f.close()
             ViewCollection.update_vcs_time(self.view)
         except Exception:
             pass
 def update_vcs_file(self):
     # the git repo won't change that often
     # so we can easily wait 5 seconds
     # between updates for performance
     if ViewCollection.vcs_time(self.view) > 5:
         open(self.vcs_temp_file.name, "w").close()
         args = self.get_diff_args()
         try:
             contents = self.run_command(args)
             contents = contents.replace(b"\r\n", b"\n")
             contents = contents.replace(b"\r", b"\n")
             f = open(self.vcs_temp_file.name, "wb")
             f.write(contents)
             f.close()
             ViewCollection.update_vcs_time(self.view)
         except Exception as e:
             print("Unable to write file for diff ", e)
Example #25
0
  def run(self, edit):
    self.clear_all()

    (inserted, modified, deleted) = ViewCollection.diff(self.view)

    self.lines_removed(deleted)
    self.lines_added(inserted)
    self.lines_modified(modified)
Example #26
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)
Example #27
0
 def run(self, force_refresh=False):
     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
         if force_refresh:
             ViewCollection.clear_git_time(self.view)
         inserted, modified, deleted = ViewCollection.diff(self.view)
         self.lines_removed(deleted)
         self.bind_icons('inserted', inserted)
         self.bind_icons('changed', modified)
Example #28
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.bind_icons('inserted', inserted)
     self.bind_icons('changed', modified)
 def run(self, force_refresh=False):
     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
         if force_refresh:
             ViewCollection.clear_git_time(self.view)
         inserted, modified, deleted = ViewCollection.diff(self.view)
         self.lines_removed(deleted)
         self.bind_icons('inserted', inserted)
         self.bind_icons('changed', modified)
 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)
Example #31
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)
 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('\r\n', '\n')
             contents = contents.replace('\r', '\n')
             f = open(self.git_temp_file.name, 'w')
             f.write(contents)
             f.close()
             ViewCollection.update_git_time(self.view)
         except Exception:
             pass
Example #33
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})
Example #34
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})
Example #35
0
 def process_diff(self, diff_str):
     inserted = []
     modified = []
     deleted = []
     pattern = re.compile(b'(\d+),?(\d*)(.)(\d+),?(\d*)')
     lines = diff_str.splitlines()
     for line in lines:
         m = pattern.match(line)
         if not m:
             continue
         kind = m.group(3)
         line_start = int(m.group(4))
         if len(m.group(5)) > 0:
             line_end = int(m.group(5))
         else:
             line_end = line_start
         if kind == b'c':
             modified += range(line_start, line_end + 1)
         elif kind == b'a':
             inserted += range(line_start, line_end + 1)
         elif kind == b'd':
             if line == 1:
                 deleted.append(line_start)
             else:
                 deleted.append(line_start + 1)
     if inserted == self.total_lines():
         # All lines are "inserted"
         # this means this file is either:
         # - New and not being tracked *yet*
         # - Or it is a *gitignored* file
         status = ViewCollection.vcs_status(self.view)
         if status == 'U':
             # use special region 'unknown'
             return ([], [], [], inserted, [])
         elif status == 'I':
             # use special region 'ignored'
             return ([], [], [], [], inserted)
         return (inserted, modified, deleted, [], [])
     else:
         return (inserted, modified, deleted, [], [])
Example #36
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 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)
Example #38
0
 def on_clone_async(self, view):
     if _non_blocking:
         ViewCollection.add(view)
Example #39
0
 def on_load(self, view):
     if self.settings_loaded():
         if not self.non_blocking and not self.live_mode:
             ViewCollection.add(view)
Example #40
0
 def on_activated(self, view):
     if self.settings_loaded():
         if not self.non_blocking and self.focus_change_mode:
             ViewCollection.add(view)
Example #41
0
 def on_post_save_async(self, view):
     if _non_blocking:
         ViewCollection.add(view)
Example #42
0
 def on_post_save(self, view):
     if self.settings_loaded():
         if not self.non_blocking:
             ViewCollection.add(view)
Example #43
0
 def on_clone(self, view):
     if not _non_blocking:
         ViewCollection.add(view)
 def on_modified(self, view):
     if view.settings().get('git_gutter_live_mode', True):
         ViewCollection.add(view)
Example #45
0
    def on_activated_async(self, view):
        if not _live_mode:
            return None

        if _non_blocking:
            ViewCollection.add(view)
Example #46
0
 def run(self):
     self.view = self.window.active_view()
     ViewCollection.set_compare("HEAD")
     ViewCollection.clear_git_time(self.view)
     ViewCollection.add(self.view)
 def on_post_save(self, view):
     ViewCollection.add(view)
 def on_clone(self, view):
     ViewCollection.add(view)
 def on_activated(self, view):
     ViewCollection.add(view)
 def run(self):
     comparing = ViewCollection.get_compare()
     sublime.message_dialog("GitGutter is comparing against: " + comparing)
 def run(self):
     self.view = self.window.active_view()
     ViewCollection.set_compare("HEAD")
     ViewCollection.clear_git_time(self.view)
     ViewCollection.add(self.view)
Example #52
0
    def on_activated(self, view):
        if not _live_mode:
            return None

        ViewCollection.add(view)
Example #53
0
 def run(self):
     comparing = ViewCollection.get_compare()
     sublime.message_dialog("GitGutter is comparing against: " + comparing)
Example #54
0
 def on_post_save(self, view):
     if not _non_blocking:
         ViewCollection.add(view)
Example #55
0
 def on_load_async(self, view):
     if _non_blocking and not _live_mode:
         ViewCollection.add(view)
Example #56
0
 def on_load(self, view):
   ViewCollection.add(view)
Example #57
0
 def on_modified(self, view):
   if view.settings().get('git_gutter_live_mode', True):
     ViewCollection.add(view)