Skip to content

Commit

Permalink
Merge 80fc8ca into 5b28fdb
Browse files Browse the repository at this point in the history
  • Loading branch information
stoivo committed Oct 11, 2019
2 parents 5b28fdb + 80fc8ca commit bb7c40b
Show file tree
Hide file tree
Showing 50 changed files with 2,496 additions and 570 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist: trusty

sudo: required

env:
Expand All @@ -12,7 +14,7 @@ matrix:
os: linux
dist: trusty
language: python
python: 3.3
python: 3.6
- name: OSX
os: osx
language: generic
Expand All @@ -29,12 +31,11 @@ before_install:
install:
- sh travis.sh bootstrap
- sh travis.sh install_package_control
- pip3 install python-coveralls pycodestyle;
- pip3 install python-coveralls flake8

script:
- sh travis.sh run_tests --coverage
- sh travis.sh run_syntax_tests
- pycodestyle --statistics --count

after_success:
- coveralls
Expand Down
8 changes: 8 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
"caption": "git: graph",
"command": "gs_log_graph"
},
{
"caption": "git: graph current branch",
"command": "gs_log_graph_current_branch"
},
{
"caption": "git: graph current file",
"command": "gs_log_graph",
Expand Down Expand Up @@ -288,6 +292,10 @@
"caption": "git: log",
"command": "gs_log"
},
{
"caption": "git: log current branch",
"command": "gs_log_current_branch"
},
{
"caption": "git: log current file",
"command": "gs_log",
Expand Down
35 changes: 27 additions & 8 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,25 @@
{ "key": "setting.git_savvy.diff_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["+"],
"command": "gs_diff_zoom",
"args": { "amount": 10 },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.diff_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["-"],
"command": "gs_diff_zoom",
"args": { "amount": -10 },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.diff_view", "operator": "equal", "operand": true }
]
},

{
"keys": ["?"],
"command": "gs_interface_toggle_popup_help",
Expand Down Expand Up @@ -1378,7 +1397,7 @@

{
"keys": ["enter"],
"command": "gs_log_graph_action",
"command": "gs_compare_commit_action",
"context": [
{ "key": "setting.git_savvy.compare_commit_view", "operator": "equal", "operand": true }
]
Expand Down Expand Up @@ -1788,7 +1807,7 @@
"args": { "type": "pick" },
"context": [
{ "key": "setting.git_savvy.git-rebase-todo_view", "operator": "equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase.interactive meta.git-savvy.rebase-interactive.line" }
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase-interactive meta.git-savvy.rebase-interactive.line" }
]
},
{
Expand All @@ -1797,7 +1816,7 @@
"args": { "type": "reword" },
"context": [
{ "key": "setting.git_savvy.git-rebase-todo_view", "operator": "equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase.interactive meta.git-savvy.rebase-interactive.line" }
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase-interactive meta.git-savvy.rebase-interactive.line" }
]
},
{
Expand All @@ -1806,7 +1825,7 @@
"args": { "type": "edit" },
"context": [
{ "key": "setting.git_savvy.git-rebase-todo_view", "operator": "equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase.interactive meta.git-savvy.rebase-interactive.line" }
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase-interactive meta.git-savvy.rebase-interactive.line" }
]
},
{
Expand All @@ -1815,7 +1834,7 @@
"args": { "type": "squash" },
"context": [
{ "key": "setting.git_savvy.git-rebase-todo_view", "operator": "equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase.interactive meta.git-savvy.rebase-interactive.line" }
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase-interactive meta.git-savvy.rebase-interactive.line" }
]
},
{
Expand All @@ -1824,7 +1843,7 @@
"args": { "type": "fixup" },
"context": [
{ "key": "setting.git_savvy.git-rebase-todo_view", "operator": "equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase.interactive meta.git-savvy.rebase-interactive.line" }
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase-interactive meta.git-savvy.rebase-interactive.line" }
]
},
{
Expand All @@ -1833,7 +1852,7 @@
"args": { "type": "exec" },
"context": [
{ "key": "setting.git_savvy.git-rebase-todo_view", "operator": "equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase.interactive meta.git-savvy.rebase-interactive.line" }
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase-interactive meta.git-savvy.rebase-interactive.line" }
]
},
{
Expand All @@ -1842,7 +1861,7 @@
"args": { "type": "drop" },
"context": [
{ "key": "setting.git_savvy.git-rebase-todo_view", "operator": "equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase.interactive meta.git-savvy.rebase-interactive.line" }
{ "key": "selector", "operator": "equal", "operand": "git-savvy.rebase-interactive meta.git-savvy.rebase-interactive.line" }
]
},

Expand Down
6 changes: 6 additions & 0 deletions GitSavvy.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
"remove_background": "#A83732",
"remove_foreground_bold": "#F9F9F4",
"remove_background_bold": "#702820"
},
"log_graph": {
"commit_dot_foreground": "#9911",
"commit_dot_background": "#991",
"path_foreground": "#991",
"path_background": "#99991109"
}
},

Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ install:
- ps: .\appveyor.ps1 "install_package_control" -verbose
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- ps: python -m pip install --upgrade pip
- ps: pip install pycodestyle
- ps: pip install flake8

build: off

test_script:
- ps: .\appveyor.ps1 "run_tests" -verbose
- ps: .\appveyor.ps1 "run_syntax_tests" -verbose
- ps: pycodestyle --statistics --count
- ps: flake8 .
13 changes: 7 additions & 6 deletions common/commands/view_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ class GsReplaceViewTextCommand(TextCommand):

def run(self, edit, text, nuke_cursors=False, restore_cursors=False):
cursors_num = len(self.view.sel())

if restore_cursors:
save_cursors = [self.view.rowcol(s.a) for s in self.view.sel()]
self.view.sel().clear()

# Always clear the selection before replacing the view. Otherwise you
# will have a flash where all the text is selected.
self.view.sel().clear()

is_read_only = self.view.is_read_only()
self.view.set_read_only(False)
self.view.replace(edit, sublime.Region(0, self.view.size()), text)
self.view.set_read_only(is_read_only)

if not cursors_num or nuke_cursors:
selections = self.view.sel()
selections.clear()
if cursors_num == 0 or nuke_cursors:
self.view.sel().clear()
pt = sublime.Region(0, 0)
selections.add(pt)
self.view.sel().add(pt)

elif restore_cursors:
self.view.sel().clear()
Expand Down
24 changes: 22 additions & 2 deletions common/theme_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def apply_new_theme(self, name, target_view):

# Sublime expects `/`-delimited paths, even in Windows.
theme_path = os.path.join("Packages", path_in_packages).replace("\\", "/")
target_view.settings().set("color_scheme", theme_path)
try_apply_theme(target_view, theme_path)


class JSONThemeGenerator(ThemeGenerator):
Expand Down Expand Up @@ -149,4 +149,24 @@ def write_new_theme(self, name):

def apply_new_theme(self, name, target_view):
self.write_new_theme(name)
target_view.settings().set("color_scheme", self.get_theme_name(name))
theme_path = self.get_theme_name(name)
try_apply_theme(target_view, theme_path)


def try_apply_theme(view, theme_path, tries=0):
""" Safly apply new theme as color_scheme. """
try:
sublime.load_resource(theme_path)
except Exception:
if tries >= 8:
print(
'GitSavvy: The theme {} is not ready to load. Maybe restart to get colored '
'highlights.'.format(theme_path)
)
return

delay = (pow(2, tries) - 1) * 10
sublime.set_timeout_async(lambda: try_apply_theme(view, theme_path, tries + 1), delay)
return

view.settings().set("color_scheme", theme_path)
20 changes: 16 additions & 4 deletions common/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
EDIT_DEFAULT_HELP_TEXT = "## To finalize your edit, press {super_key}+Enter. To cancel, close the view.\n"


def focus_view(view):
window = view.window()
if not window:
return

group, _ = window.get_view_index(view)
window.focus_group(group)
window.focus_view(view)


class Interface():

interface_type = ""
Expand All @@ -35,9 +45,11 @@ def __new__(cls, repo_path=None, **kwargs):
window = sublime.active_window()
for view in window.views():
vset = view.settings()
if vset.get("git_savvy.interface") == cls.interface_type and \
vset.get("git_savvy.repo_path") == repo_path:
window.focus_view(view)
if (
vset.get("git_savvy.interface") == cls.interface_type
and vset.get("git_savvy.repo_path") == repo_path
):
focus_view(view)
try:
return interfaces[view.id()]
except KeyError:
Expand Down Expand Up @@ -97,7 +109,7 @@ def create_view(self, repo_path):
self.view.set_name(self.title())

self.render()
window.focus_view(self.view)
focus_view(self.view)

return self.view

Expand Down
2 changes: 1 addition & 1 deletion common/util/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def wrapped_fn(*args, **kwargs):
if not sublime.ok_cancel_dialog(message):
return

fn(*args, **kwargs)
return fn(*args, **kwargs)

return wrapped_fn

Expand Down
23 changes: 19 additions & 4 deletions common/util/debug.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from contextlib import contextmanager
import functools
import json
import pprint as _pprint

from contextlib import contextmanager
import threading

from ...core.settings import GitSavvySettings


# Preserve state of `enabled` during hot-reloads
try:
enabled
except NameError:
enabled = False

_log = []
enabled = False
ENCODING_NOT_UTF8 = "{} was sent as binaries and we dont know the encoding, not utf-8"


Expand All @@ -26,11 +32,12 @@ def stop_logging():
@contextmanager
def disable_logging():
global enabled
previous_state = enabled
enabled = False
try:
yield
finally:
enabled = True
enabled = previous_state


def get_log():
Expand All @@ -54,6 +61,14 @@ def make_log_message(_type, **kwargs):

def log_git(command, stdin, stdout, stderr, seconds):
""" Add git command details to debug log """
global enabled
if enabled:
print(' ({thread}) [{runtime:3.0f}ms] $ {cmd}'.format(
thread=threading.current_thread().name[0],
cmd=' '.join(['git'] + list(filter(None, command))),
runtime=seconds * 1000,
))

message = make_log_message(
'git', command=command, stdin=stdin, stdout=stdout, stderr=stderr,
seconds=seconds
Expand Down
7 changes: 7 additions & 0 deletions common/util/diff_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def get_indices(chunks):


def get_changes(old, new):
# if one of the inputs, either old or new is more then 10 000 characters
# we skip trying to find the words which changed. If a hunk is more than
# 10 000 characters it is most likely a generated change.
# We skip since this calculation take a lot of time then it gets bigger.
if max(len(old), len(new)) > 10000:
return []

old_chunks = tuple(filter(lambda x: x, boundary.split(old)))
new_chunks = tuple(filter(lambda x: x, boundary.split(new)))
old_indices = get_indices(old_chunks)
Expand Down
4 changes: 2 additions & 2 deletions common/util/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _determine_syntax_files():
try:
# Use `sublime.load_resource`, in case Package is `*.sublime-package`.
resource = sublime.load_resource(syntax_file)
for extension in yaml.load(resource)["file_extensions"]:
for extension in yaml.safe_load(resource)["file_extensions"]:
if extension not in syntax_file_map:
syntax_file_map[extension] = []
extension_list = syntax_file_map[extension]
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_file_contents(repo_path, file_path):
binary = get_file_contents_binary(repo_path, file_path)
try:
return binary.decode('utf-8')
except UnicodeDecodeError as unicode_err:
except UnicodeDecodeError:
return binary.decode('latin-1')


Expand Down

0 comments on commit bb7c40b

Please sign in to comment.