Skip to content

Commit

Permalink
Merge b58148c into de9caff
Browse files Browse the repository at this point in the history
  • Loading branch information
asfaltboy committed Feb 5, 2019
2 parents de9caff + b58148c commit cfe2eca
Show file tree
Hide file tree
Showing 64 changed files with 4,663 additions and 323 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Files and directories with the attribute export-ignore won’t be added to
# archive files. See http://git-scm.com/docs/gitattributes for details.

/tests/ export-ignore
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ env:

matrix:
include:
- os: linux
- name: Linux
os: linux
language: python
python: 3.3
- os: osx
- name: OSX
os: osx
language: generic

before_install:
Expand All @@ -26,10 +28,6 @@ before_install:
install:
- sh travis.sh bootstrap
- sh travis.sh install_package_control
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update;
brew install python || brew upgrade python;
fi
- pip3 install python-coveralls pycodestyle;

script:
Expand Down
7 changes: 6 additions & 1 deletion Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@
"caption": "git: clone",
"command": "gs_clone"
},
{
"caption": "git: clone recursively",
"command": "gs_clone",
"args": { "recursive": true }
},
{
"caption": "git: diff",
"command": "gs_diff"
Expand Down Expand Up @@ -333,7 +338,7 @@
"command": "gs_view_git_log"
},
{
"caption": "git: tags",
"caption": "git: tag",
"command": "gs_show_tags"
},
{
Expand Down
27 changes: 27 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,24 @@
{ "key": "setting.git_savvy.diff_view.disable_stage", "operator": "equal", "operand": false }
]
},
{
"keys": ["c"],
"command": "gs_status_commit",
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.diff_view", "operator": "equal", "operand": true },
{ "key": "setting.git_savvy.diff_view.disable_stage", "operator": "equal", "operand": false }
]
},
{
"keys": ["C"],
"command": "gs_status_commit_unstaged",
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.diff_view", "operator": "equal", "operand": true },
{ "key": "setting.git_savvy.diff_view.disable_stage", "operator": "equal", "operand": false }
]
},
{
"keys": ["."],
"command": "gs_diff_navigate",
Expand Down Expand Up @@ -587,6 +605,15 @@
{ "key": "setting.git_savvy.diff_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["tab"],
"command": "gs_diff_toggle_setting",
"args": { "setting": "in_cached_mode" },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.diff_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["s"],
"command": "gs_diff_toggle_setting",
Expand Down
21 changes: 18 additions & 3 deletions GitSavvy.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,27 @@

/*
For each command specified, always include the command line flags
indicated in the global_flags hash.
indicated in the global_flags option AFTER the command.
*/
"global_flags": {
// --no-columns is not supported in Git versions <1.7.11. If Git is configured
// to use columns globally, --no-columns should be added here.
// "branch": ["--no-columns"]
//
// or, configure a GPG key to sign commits with a given key
// "commit": ["-S", "--gpg-sign=<key-id>"]
},

/*
For each command specified, always include the command line flags
indicated in the global_flags option BEFORE the command.
*/
"global_pre_flags": {
// for example, override settings via the "-c" option, e.g
// the following configures a gpg.program no-tty wrapper script
// "commit": ["-c", "gpg.program=./scripts/stgpg.sh"]
// and configure every commit to be signed with your key
// "commit": ["-c", "commit.gpgsign=true"]
},

/*
Expand Down Expand Up @@ -355,15 +370,15 @@
status
branch
rebase
tags
tag
graph
*/
"tab_order": [
"status",
"branch",
"rebase",
"tags",
"tag",
"graph"
],

Expand Down
14 changes: 13 additions & 1 deletion common/commands/view_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ class GsReplaceViewTextCommand(TextCommand):
a single cursor at the start of the file.
"""

def run(self, edit, text, nuke_cursors=False):
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()

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)
Expand All @@ -43,6 +48,12 @@ def run(self, edit, text, nuke_cursors=False):
pt = sublime.Region(0, 0)
selections.add(pt)

elif restore_cursors:
self.view.sel().clear()
for (row, col) in save_cursors:
cursor = self.view.text_point(row, col)
self.view.sel().add(cursor)


class GsReplaceRegionCommand(TextCommand):

Expand All @@ -69,6 +80,7 @@ def run(self, edit):
if savvy_settings.get("vintageous_friendly", False) is True:
self.view.settings().set("git_savvy.vintageous_friendly", True)
if savvy_settings.get("vintageous_enter_insert_mode", False) is True:
self.view.settings().set("vintageous_reset_mode_when_switching_tabs", False)
self.view.run_command("_enter_insert_mode")


Expand Down
33 changes: 20 additions & 13 deletions common/theme_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
from xml.etree import ElementTree
import json
from collections import OrderedDict

import sublime
Expand Down Expand Up @@ -57,6 +56,9 @@ def __init__(self, original_color_scheme):
break
self.color_scheme_string = sublime.load_resource(paths[0])

def get_theme_name(self, name):
return "GitSavvy.{}.{}".format(name, self.hidden_theme_extension)

def get_theme_path(self, name):
"""
Save the transformed theme to disk and return the path to that theme,
Expand All @@ -65,8 +67,7 @@ def get_theme_path(self, name):
if not os.path.exists(os.path.join(sublime.packages_path(), "User", "GitSavvy")):
os.makedirs(os.path.join(sublime.packages_path(), "User", "GitSavvy"))

return os.path.join(
"User", "GitSavvy", "GitSavvy.{}.{}".format(name, self.hidden_theme_extension))
return os.path.join("User", "GitSavvy", self.get_theme_name(name))

def add_scoped_style(self, name, scope, **kwargs):
"""
Expand All @@ -86,14 +87,7 @@ def apply_new_theme(self, name, target_view):
"""
Apply the transformed theme to the specified target view.
"""

self.write_new_theme(name)

path_in_packages = self.get_theme_path(name)

# 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)
pass


class XMLThemeGenerator(ThemeGenerator):
Expand All @@ -120,6 +114,15 @@ def write_new_theme(self, name):
out_f.write(STYLES_HEADER.encode("utf-8"))
out_f.write(ElementTree.tostring(self.plist, encoding="utf-8"))

def apply_new_theme(self, name, target_view):
self.write_new_theme(name)

path_in_packages = self.get_theme_path(name)

# 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)


class JSONThemeGenerator(ThemeGenerator):
"""
Expand All @@ -130,7 +133,7 @@ class JSONThemeGenerator(ThemeGenerator):

def __init__(self, original_color_scheme):
super().__init__(original_color_scheme)
self.dict = json.loads(self.color_scheme_string, object_pairs_hook=OrderedDict)
self.dict = OrderedDict(sublime.decode_value(self.color_scheme_string))

def add_scoped_style(self, name, scope, **kwargs):
new_rule = OrderedDict([("name", name), ("scope", scope)])
Expand All @@ -142,4 +145,8 @@ def write_new_theme(self, name):
full_path = os.path.join(sublime.packages_path(), self.get_theme_path(name))

with util.file.safe_open(full_path, "wb", buffering=0) as out_f:
out_f.write(json.dumps(self.dict, indent=4).encode("utf-8"))
out_f.write(sublime.encode_value(self.dict, pretty=True).encode("utf-8"))

def apply_new_theme(self, name, target_view):
self.write_new_theme(name)
target_view.settings().set("color_scheme", self.get_theme_name(name))
17 changes: 16 additions & 1 deletion common/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def create_view(self, repo_path):
self.view = window.new_file()

self.view.settings().set("git_savvy.repo_path", repo_path)
self.view.set_name(self.title())
self.view.settings().set("git_savvy.{}_view".format(self.interface_type), True)
self.view.settings().set("git_savvy.tabbable", True)
self.view.settings().set("git_savvy.interface", self.interface_type)
Expand All @@ -90,12 +89,25 @@ def create_view(self, repo_path):
self.view.set_scratch(True)
self.view.set_read_only(self.read_only)
util.view.disable_other_plugins(self.view)
self.after_view_creation(self.view)

# Set title as late as possible, otherwise e.g. `result_file_regex` will not apply
# after the initial activate. (It applies after the second activation of the view,
# shall we say a sublime nuance.)
self.view.set_name(self.title())

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

return self.view

def after_view_creation(self, view):
"""
Hook template method called after the view has been created.
Can be used to further manipulate the view and store state on it.
"""
pass

def render(self, nuke_cursors=False):
self.clear_regions()
if hasattr(self, "pre_render"):
Expand Down Expand Up @@ -201,6 +213,9 @@ def get_selection_lines_in_region(self, region):
)

def on_new_dashboard(self):
"""
Hook template method called after the first render.
"""
pass


Expand Down
22 changes: 16 additions & 6 deletions common/util/log.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import sublime


def panel(*msgs):
def panel(*msgs, run_async=True):
msg = "\n".join(str(msg) for msg in msgs)
sublime.set_timeout_async(
lambda: sublime.active_window().active_view().run_command("gs_display_panel", {"msg": msg}))
view = sublime.active_window().active_view()
if run_async:
sublime.set_timeout_async(
lambda: view.run_command("gs_display_panel", {"msg": msg})
)
else:
view.run_command("gs_display_panel", {"msg": msg})


def panel_append(*msgs):
def panel_append(*msgs, run_async=True):
msg = "\n".join(str(msg) for msg in msgs)
sublime.set_timeout_async(
lambda: sublime.active_window().active_view().run_command("gs_append_panel", {"msg": msg}))
view = sublime.active_window().active_view()
if run_async:
sublime.set_timeout_async(
lambda: view.run_command("gs_append_panel", {"msg": msg})
)
else:
view.run_command("gs_append_panel", {"msg": msg})
3 changes: 3 additions & 0 deletions common/util/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def refresh_gitsavvy_interfaces(window,
if view.settings().get("git_savvy.interface") is not None:
view.run_command("gs_interface_refresh", {"nuke_cursors": interface_reset_cursor})

if view.settings().get("git_savvy.log_graph_view", False):
view.run_command("gs_log_graph_refresh")


def refresh_gitsavvy(view, refresh_sidebar=False, refresh_status_bar=True,
interface_reset_cursor=False):
Expand Down
5 changes: 4 additions & 1 deletion core/commands/blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_content(self, ignore_whitespace=False, detect_options=None, commit_hash=
commit_hash, "--", filename_at_commit
)
blame_porcelain = unicodedata.normalize('NFC', blame_porcelain)
blamed_lines, commits = self.parse_blame(blame_porcelain.splitlines())
blamed_lines, commits = self.parse_blame(blame_porcelain.split('\n'))

commit_infos = {
commit_hash: self.short_commit_info(commit)
Expand Down Expand Up @@ -250,6 +250,9 @@ def get_content(self, ignore_whitespace=False, detect_options=None, commit_hash=
return spacer.join(partitions_with_commits_iter)

def parse_blame(self, blame_porcelain):
if blame_porcelain[-1] == '':
blame_porcelain = blame_porcelain[:-1]

lines_iter = iter(blame_porcelain)

blamed_lines = []
Expand Down
4 changes: 2 additions & 2 deletions core/commands/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ def run(self):
if self.file_path:
super().run(file_path=self.file_path)

def on_highlight(self, commit):
def on_highlight(self, commit, file_path=None):
if not self.savvy_settings.get("log_show_more_commit_info", True):
return
if commit:
self.window.run_command('gs_show_file_diff', {
'commit_hash': commit,
'file_path': self.file_path
'file_path': file_path
})

@util.actions.destructive(description="discard uncommitted changes to file")
Expand Down

0 comments on commit cfe2eca

Please sign in to comment.