Skip to content

Commit 9223b09

Browse files
authored
Merge pull request #9 from frou/show-commit-button
Add button to show the commit in full
2 parents d4a94a6 + e2e173c commit 9223b09

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

git-blame.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
template = '''
3434
<span>
3535
{scheme}
36-
<strong>Git Blame:</strong> ({user})
36+
&nbsp;<strong>Git Blame:</strong> ({user})
3737
Updated: {date} {time} |
38-
<a href="copy-{sha}">[{sha}]</a> |
39-
<a href="close">
40-
<close>&#10006;</close>&nbsp;
41-
</a>
38+
{sha}
39+
<a href="copy-{sha}">[Copy]</a>
40+
<a href="show-{sha}">[Show]</a>
41+
<a href="close"><close>[X]</close></a>&nbsp;
4242
</span>
4343
'''
4444

@@ -82,10 +82,32 @@ def parse_blame(self, blame):
8282

8383
return(sha, user[1:], date, time)
8484

85+
def get_commit(self, sha, path):
86+
try:
87+
return shell(["git", "show", sha],
88+
cwd=os.path.dirname(os.path.realpath(path)),
89+
startupinfo=si)
90+
except Exception as e:
91+
return
92+
8593
def on_phantom_close(self, href):
86-
if href.startswith('copy'):
87-
sha = href.replace('copy-','')
88-
sublime.set_clipboard(sha)
94+
href_parts = href.split('-')
95+
96+
if len(href_parts) > 1:
97+
intent = href_parts[0]
98+
sha = href_parts[1]
99+
# The SHA output by git-blame may have a leading caret to indicate
100+
# that it is a "boundary commit". That useful information has
101+
# already been shown in the phantom, so strip it before going on to
102+
# use the SHA programmatically.
103+
sha = sha.strip('^')
104+
105+
if intent == "copy":
106+
sublime.set_clipboard(sha)
107+
elif intent == "show":
108+
desc = self.get_commit(sha, self.view.file_name()).decode('utf-8')
109+
buf = self.view.window().new_file()
110+
buf.run_command('insert_commit_description', {'desc': desc})
89111

90112
self.view.erase_phantoms('git-blame')
91113

@@ -114,3 +136,13 @@ def run(self, edit):
114136
phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close)
115137
phantoms.append(phantom)
116138
self.phantom_set.update(phantoms)
139+
140+
141+
class InsertCommitDescriptionCommand(sublime_plugin.TextCommand):
142+
143+
def run(self, edit, desc):
144+
view = self.view
145+
view.set_scratch(True)
146+
view.set_syntax_file('Packages/Diff/Diff.sublime-syntax')
147+
view.insert(edit, 0, desc)
148+

0 commit comments

Comments
 (0)