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
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.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')
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)
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 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)
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)
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)
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_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
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): 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 on_post_save(self, view): if not self.non_blocking: ViewCollection.add(view)
def clear_git_time(view): key = ViewCollection.get_key(view) ViewCollection.git_times[key] = 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_post_save(self, view): ViewCollection.add(view)
def on_load(self, view): if self.settings_loaded(): if not self.non_blocking and not self.live_mode: ViewCollection.add(view)
def on_activated(self, view): if not self.non_blocking: ViewCollection.add(view)
def on_modified(self, view): if view.settings().get('git_gutter_live_mode', True): ViewCollection.add(view)
def on_clone(self, view): if not self.non_blocking: ViewCollection.add(view)
def on_activated_async(self, view): if self.non_blocking: ViewCollection.add(view)
def on_post_save_async(self, view): if self.non_blocking: ViewCollection.add(view)
def on_clone_async(self, view): if self.non_blocking: ViewCollection.add(view)
def on_modified_async(self, view): if not self.live_mode: return None if self.non_blocking: ViewCollection.add(view)
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)
def get_handler(view): if ViewCollection.has_view(view): key = ViewCollection.get_key(view) return ViewCollection.views[key] else: return ViewCollection.add(view)
def on_post_save(self, view): if self.settings_loaded(): if not self.non_blocking: ViewCollection.add(view)
def diff(view): key = ViewCollection.get_key(view) return ViewCollection.views[key].diff()
def on_activated(self, view): if self.settings_loaded(): if not self.non_blocking and self.focus_change_mode: ViewCollection.add(view)
def untracked(view): key = ViewCollection.get_key(view) return ViewCollection.views[key].untracked()
def on_clone(self, view): ViewCollection.add(view)
def ignored(view): key = ViewCollection.get_key(view) return ViewCollection.views[key].ignored()
def update_git_time(view): key = ViewCollection.get_key(view) ViewCollection.git_times[key] = time.time()
def total_lines(view): key = ViewCollection.get_key(view) return ViewCollection.views[key].total_lines()
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_activated_async(self, view): if self.non_blocking and self.focus_change_mode: ViewCollection.add(view)