|
33 | 33 | template = ''' |
34 | 34 | <span> |
35 | 35 | {scheme} |
36 | | -<strong>Git Blame:</strong> ({user}) |
| 36 | + <strong>Git Blame:</strong> ({user}) |
37 | 37 | Updated: {date} {time} | |
38 | | -<a href="copy-{sha}">[{sha}]</a> | |
39 | | -<a href="close"> |
40 | | -<close>✖</close> |
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> |
42 | 42 | </span> |
43 | 43 | ''' |
44 | 44 |
|
@@ -82,10 +82,32 @@ def parse_blame(self, blame): |
82 | 82 |
|
83 | 83 | return(sha, user[1:], date, time) |
84 | 84 |
|
| 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 | + |
85 | 93 | 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}) |
89 | 111 |
|
90 | 112 | self.view.erase_phantoms('git-blame') |
91 | 113 |
|
@@ -114,3 +136,13 @@ def run(self, edit): |
114 | 136 | phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close) |
115 | 137 | phantoms.append(phantom) |
116 | 138 | 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