forked from jisaacks/GitGutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_gutter_compare.py
83 lines (68 loc) · 2.76 KB
/
git_gutter_compare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sublime
import sublime_plugin
ST3 = int(sublime.version()) >= 3000
if ST3:
from .view_collection import ViewCollection
else:
from view_collection import ViewCollection
class GitGutterCompareCommit(sublime_plugin.WindowCommand):
def run(self):
self.view = self.window.active_view()
self.handler = ViewCollection.get_handler(self.view)
self.results = self.commit_list()
if self.results:
self.window.show_quick_panel(self.results, self.on_select)
def commit_list(self):
result = self.handler.git_commits().decode("utf-8")
return [r.split('\a', 2) for r in result.strip().split('\n')]
def item_to_commit(self, item):
return item[1].split(' ')[0]
def on_select(self, selected):
if 0 > selected < len(self.results):
return
item = self.results[selected]
commit = self.item_to_commit(item)
ViewCollection.set_compare(commit)
ViewCollection.clear_git_time(self.view)
ViewCollection.add(self.view)
class GitGutterCompareBranch(GitGutterCompareCommit):
def commit_list(self):
result = self.handler.git_branches().decode("utf-8")
return [self.parse_result(r) for r in result.strip().split('\n')]
def parse_result(self, result):
pieces = result.split('\a')
message = pieces[0]
branch = pieces[1].split("/",2)[2]
commit = pieces[2][0:7]
return [branch, commit + " " + message]
class GitGutterCompareTag(GitGutterCompareCommit):
def commit_list(self):
result = self.handler.git_tags().decode("utf-8")
if result:
return [self.parse_result(r) for r in result.strip().split('\n')]
else:
sublime.message_dialog("No tags found in repository")
def parse_result(self, result):
pieces = result.split(' ')
commit = pieces[0]
tag = pieces[1].replace("refs/tags/", "")
return [tag, commit]
def item_to_commit(self, item):
return item[1]
class GitGutterCompareHead(sublime_plugin.WindowCommand):
def run(self):
self.view = self.window.active_view()
ViewCollection.set_compare("HEAD")
ViewCollection.clear_git_time(self.view)
ViewCollection.add(self.view)
class GitGutterCompareOrigin(sublime_plugin.WindowCommand):
def run(self):
self.view = self.window.active_view()
ViewCollection.set_compare("origin")
ViewCollection.clear_git_time(self.view)
ViewCollection.add(self.view)
class GitGutterShowCompare(sublime_plugin.WindowCommand):
def run(self):
self.view = self.window.active_view()
comparing = ViewCollection.get_compare(self.view)
sublime.message_dialog("GitGutter is comparing against: " + comparing)