Skip to content

Commit adf42c1

Browse files
committed
Improve showing full commits from the blame view. #436
Changed the command to work reliably for any file, even ones outside the project. Previous code also failed for files within the project, when project had more than one directory added. Also added new syntax file for commit view with better highlighting. And use this syntax for git_document command and commits opened from git log commands.
1 parent c0965a6 commit adf42c1

File tree

3 files changed

+166
-8
lines changed

3 files changed

+166
-8
lines changed

Default.sublime-keymap

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"context": [{"key": "selector", "operand": "markup.inserted.diff"}]},
44
{"keys": ["enter"], "command": "git_goto_diff",
55
"context": [{"key": "selector", "operand": "markup.deleted.diff"}]},
6-
{"keys": ["enter"], "command": "git_goto_blame",
6+
{"keys": ["enter"], "command": "git_goto_commit",
77
"context": [{"key": "selector", "operand": "text.git-blame"}]}
88
]

history.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ def get_lines(self):
3939
return begin_line + 1, end_line + 1
4040

4141
def blame_done(self, result, position=None):
42-
self.scratch(result, title="Git Blame", position=position,
43-
syntax=plugin_file("syntax/Git Blame.tmLanguage"))
42+
view = self.scratch(result, title="Git Blame", position=position,
43+
syntax=plugin_file("syntax/Git Blame.tmLanguage"))
44+
# store working dir to be potentially used by the GitGotoCommit command
45+
view.settings().set("git_working_dir", self.get_working_dir())
4446

4547

4648
class GitLog(object):
@@ -83,7 +85,8 @@ def log_result(self, ref):
8385
self.details_done)
8486

8587
def details_done(self, result):
86-
self.scratch(result, title="Git Commit Details", syntax=plugin_file("syntax/Git Commit Message.tmLanguage"))
88+
self.scratch(result, title="Git Commit Details",
89+
syntax=plugin_file("syntax/Git Commit View.tmLanguage"))
8790

8891

8992
class GitLogCommand(GitLog, GitTextCommand):
@@ -223,13 +226,23 @@ def show_done(self, result):
223226
commits.sort(reverse=True)
224227
commits = [commit for d, commit in commits]
225228

226-
self.scratch('\n\n'.join(commits), title="Git Commit Documentation")
229+
self.scratch('\n\n'.join(commits), title="Git Commit Documentation",
230+
syntax=plugin_file("syntax/Git Commit View.tmLanguage"))
227231

228232

229-
class GitGotoBlame(sublime_plugin.TextCommand):
233+
class GitGotoCommit(GitTextCommand):
230234
def run(self, edit):
231-
line = self.view.substr(self.view.line(self.view.sel()[0].a))
235+
view = self.view
236+
line = view.substr(view.line(view.sel()[0].a))
232237
commit = line.split(" ")[0]
233238
if not commit or commit == "00000000":
234239
return
235-
self.view.window().run_command("git_raw", {"command": "git show %s" % commit, "show_in": "new_tab", "may_change_files": False})
240+
working_dir = view.settings().get("git_working_dir")
241+
self.run_command(['git', 'show', commit], self.show_done, working_dir=working_dir)
242+
243+
def show_done(self, result):
244+
self.scratch(result, title="Git Commit View",
245+
syntax=plugin_file("syntax/Git Commit View.tmLanguage"))
246+
247+
def is_enabled(self):
248+
return True

syntax/Git Commit View.tmLanguage

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>fileTypes</key>
6+
<array>
7+
<string>git-commit-view</string>
8+
</array>
9+
<key>name</key>
10+
<string>Git Commit View</string>
11+
<key>patterns</key>
12+
<array>
13+
<dict>
14+
<key>name</key>
15+
<string>string.sha.git-blame</string>
16+
<key>match</key>
17+
<string>^commit [a-f0-9]+$</string>
18+
</dict>
19+
<dict>
20+
<key>name</key>
21+
<string>support.function.author.git-blame</string>
22+
<key>match</key>
23+
<string>^Author: .+$</string>
24+
</dict>
25+
<dict>
26+
<key>name</key>
27+
<string>constant.numeric.date.git-blame</string>
28+
<key>match</key>
29+
<string>^Date: .+$</string>
30+
</dict>
31+
<dict>
32+
<key>match</key>
33+
<string>(^diff --.+$)</string>
34+
<key>name</key>
35+
<string>string.path.git-diff</string>
36+
</dict>
37+
<dict>
38+
<key>match</key>
39+
<string>(^(((-{3}) .+)|((\*{3}) .+))$\n?|^(={4}) .+(?= - ))</string>
40+
<key>name</key>
41+
<string>meta.diff.header.from-file</string>
42+
</dict>
43+
<dict>
44+
<key>match</key>
45+
<string>(^(\+{3}) .+$\n?| (-) .* (={4})$\n?)</string>
46+
<key>name</key>
47+
<string>meta.diff.header.to-file</string>
48+
</dict>
49+
<dict>
50+
<key>captures</key>
51+
<dict>
52+
<key>1</key>
53+
<dict>
54+
<key>name</key>
55+
<string>punctuation.definition.range.diff</string>
56+
</dict>
57+
<key>2</key>
58+
<dict>
59+
<key>name</key>
60+
<string>meta.toc-list.line-number.diff</string>
61+
</dict>
62+
<key>3</key>
63+
<dict>
64+
<key>name</key>
65+
<string>punctuation.definition.range.diff</string>
66+
</dict>
67+
</dict>
68+
<key>match</key>
69+
<string>^(@@)\s*(.+?)\s*(@@)($\n?)?</string>
70+
<key>name</key>
71+
<string>meta.diff.range.unified</string>
72+
</dict>
73+
<dict>
74+
<key>captures</key>
75+
<dict>
76+
<key>3</key>
77+
<dict>
78+
<key>name</key>
79+
<string>punctuation.definition.inserted.diff</string>
80+
</dict>
81+
<key>6</key>
82+
<dict>
83+
<key>name</key>
84+
<string>punctuation.definition.inserted.diff</string>
85+
</dict>
86+
</dict>
87+
<key>match</key>
88+
<string>^(((&gt;)( .*)?)|((\+).*))$\n?</string>
89+
<key>name</key>
90+
<string>markup.inserted.diff</string>
91+
</dict>
92+
<dict>
93+
<key>captures</key>
94+
<dict>
95+
<key>1</key>
96+
<dict>
97+
<key>name</key>
98+
<string>punctuation.definition.inserted.diff</string>
99+
</dict>
100+
</dict>
101+
<key>match</key>
102+
<string>^(!).*$\n?</string>
103+
<key>name</key>
104+
<string>markup.changed.diff</string>
105+
</dict>
106+
<dict>
107+
<key>captures</key>
108+
<dict>
109+
<key>3</key>
110+
<dict>
111+
<key>name</key>
112+
<string>punctuation.definition.inserted.diff</string>
113+
</dict>
114+
<key>6</key>
115+
<dict>
116+
<key>name</key>
117+
<string>punctuation.definition.inserted.diff</string>
118+
</dict>
119+
</dict>
120+
<key>match</key>
121+
<string>^(((&lt;)( .*)?)|((-).*))$\n?</string>
122+
<key>name</key>
123+
<string>markup.deleted.diff</string>
124+
</dict>
125+
<dict>
126+
<key>captures</key>
127+
<dict>
128+
<key>1</key>
129+
<dict>
130+
<key>name</key>
131+
<string>meta.toc-list.file-name.diff</string>
132+
</dict>
133+
</dict>
134+
<key>match</key>
135+
<string>^index (.+)$\n?</string>
136+
<key>name</key>
137+
<string>meta.diff.index</string>
138+
</dict>
139+
</array>
140+
<key>scopeName</key>
141+
<string>text.git-commit-view</string>
142+
<key>uuid</key>
143+
<string>5d37add9-1219-4174-b232-4bd423b84c0a</string>
144+
</dict>
145+
</plist>

0 commit comments

Comments
 (0)