Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customizable properties to blame_all command #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Settings/Git blame.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// ["-C", "-C"]
//
"custom_blame_flags": [],
"blame_all_message_max_len": 40,
"blame_all_display_author": true,
"blame_all_display_date": true,
"blame_all_display_time": true,
"inline_blame_enabled": false,
"inline_blame_delay": 300
}
10 changes: 9 additions & 1 deletion src/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@


class BaseBlame(metaclass=ABCMeta):
def __init__(self, *args, **kwargs):
super(BaseBlame, self).__init__(*args, **kwargs)
self.message_map = {}

def run_git(self, view_file_path, cli_args):
if sys.platform == "win32":
startup_info = subprocess.STARTUPINFO()
Expand Down Expand Up @@ -42,8 +46,12 @@ def get_commit_fulltext(self, sha, path):
return self.run_git(path, cli_args)

def get_commit_message_subject(self, sha, path):
if sha == '00000000': return ''
if sha in self.message_map:
return self.message_map[sha]
cli_args = ["show", "--no-color", sha, "--pretty=format:%s", "--no-patch"]
return self.run_git(path, cli_args)
self.message_map[sha] = self.run_git(path, cli_args)
return self.message_map[sha]

@classmethod
def parse_line(cls, line):
Expand Down
30 changes: 26 additions & 4 deletions src/blame_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
from .base import BaseBlame
from .templates import blame_all_phantom_css, blame_all_phantom_html_template

from .settings import pkg_settings
from .settings import PKG_SETTINGS_BLAME_ALL_MESSAGE_MAX_LEN
from .settings import PKG_SETTINGS_BLAME_ALL_DISPLAY_AUTHOR
from .settings import PKG_SETTINGS_BLAME_ALL_DISPLAY_DATE
from .settings import PKG_SETTINGS_BLAME_ALL_DISPLAY_TIME

VIEW_SETTINGS_KEY_PHANTOM_ALL_DISPLAYED = "git-blame-all-displayed"
VIEW_SETTINGS_KEY_RULERS = "rulers" # A stock ST setting
VIEW_SETTINGS_KEY_RULERS_PREV = "rulers_prev" # Made up by us
Expand Down Expand Up @@ -59,14 +65,30 @@ def run(self, edit):
line_number = int(blame["line_number"])
author = blame["author"]

message_len = pkg_settings().get(PKG_SETTINGS_BLAME_ALL_MESSAGE_MAX_LEN)
message = ""
if message_len > 0:
message = self.get_commit_message_subject(blame["sha"].strip('^'), self.view.file_name())
message.strip()
if len(message) > message_len: message = message[0:message_len].strip()
message = message + ' ' * (message_len - len(message))
message = "  " + message

display_author = pkg_settings().get(PKG_SETTINGS_BLAME_ALL_DISPLAY_AUTHOR)
display_date = pkg_settings().get(PKG_SETTINGS_BLAME_ALL_DISPLAY_DATE)
display_time = pkg_settings().get(PKG_SETTINGS_BLAME_ALL_DISPLAY_TIME)
sha = blame["sha"]
if sha == '00000000': sha = " " * 8
else: sha = '<a href="show?sha={sha}">{sha}</a>'.format(sha=sha)
phantom = sublime.Phantom(
self.phantom_region(line_number),
blame_all_phantom_html_template.format(
css=blame_all_phantom_css,
sha=blame["sha"],
author=author + "&nbsp;" * (max_author_len - len(author)),
date=blame["date"],
time=blame["time"],
sha=sha,
message=message,
author="&nbsp;&nbsp;" + author + "&nbsp;" * (max_author_len - len(author)) if display_author else "",
date="&nbsp;&nbsp;" + blame["date"] if display_date else "",
time="&nbsp;&nbsp;" + blame["time"] if display_time else "",
),
sublime.LAYOUT_INLINE,
self.handle_phantom_button,
Expand Down
5 changes: 5 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ def pkg_settings():

PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED = "inline_blame_enabled"
PKG_SETTINGS_KEY_INLINE_BLAME_DELAY = "inline_blame_delay"

PKG_SETTINGS_BLAME_ALL_MESSAGE_MAX_LEN = "blame_all_message_max_len"
PKG_SETTINGS_BLAME_ALL_DISPLAY_AUTHOR = "blame_all_display_author"
PKG_SETTINGS_BLAME_ALL_DISPLAY_DATE = "blame_all_display_date"
PKG_SETTINGS_BLAME_ALL_DISPLAY_TIME = "blame_all_display_time"
2 changes: 1 addition & 1 deletion src/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<style>{css}</style>
<div class="phantom">
<span class="message">
{sha}&nbsp;&nbsp;{author}&nbsp;&nbsp;{date}&nbsp;&nbsp;{time}
{sha}{author}{message}{date}{time}
<a class="close" href="close">\u00D7</a>
</span>
</div>
Expand Down