diff --git a/git-blame.py b/git-blame.py index 6923a76..5e90adf 100644 --- a/git-blame.py +++ b/git-blame.py @@ -33,12 +33,12 @@ template = ''' {scheme} -Git Blame: ({user}) + Git Blame: ({user}) Updated: {date} {time} | -[{sha}] | - -  - +{sha} +[Copy] +[Show] +[X]  ''' @@ -82,10 +82,32 @@ def parse_blame(self, blame): return(sha, user[1:], date, time) + def get_commit(self, sha, path): + try: + return shell(["git", "show", sha], + cwd=os.path.dirname(os.path.realpath(path)), + startupinfo=si) + except Exception as e: + return + def on_phantom_close(self, href): - if href.startswith('copy'): - sha = href.replace('copy-','') - sublime.set_clipboard(sha) + href_parts = href.split('-') + + if len(href_parts) > 1: + intent = href_parts[0] + sha = href_parts[1] + # The SHA output by git-blame may have a leading caret to indicate + # that it is a "boundary commit". That useful information has + # already been shown in the phantom, so strip it before going on to + # use the SHA programmatically. + sha = sha.strip('^') + + if intent == "copy": + sublime.set_clipboard(sha) + elif intent == "show": + desc = self.get_commit(sha, self.view.file_name()).decode('utf-8') + buf = self.view.window().new_file() + buf.run_command('insert_commit_description', {'desc': desc}) self.view.erase_phantoms('git-blame') @@ -114,3 +136,13 @@ def run(self, edit): phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close) phantoms.append(phantom) self.phantom_set.update(phantoms) + + +class InsertCommitDescriptionCommand(sublime_plugin.TextCommand): + + def run(self, edit, desc): + view = self.view + view.set_scratch(True) + view.set_syntax_file('Packages/Diff/Diff.sublime-syntax') + view.insert(edit, 0, desc) +