Skip to content

Commit 7d834b2

Browse files
committed
Add feature to jump directly to the commit that introduced the current line (#3)
1 parent 5b53715 commit 7d834b2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

gitbrowse/browser.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ def _move_commit(self, method_name):
9696

9797
self._update_mapping(start, finish)
9898

99+
def _jump_to_commit(self, sha):
100+
101+
start = self.file_history.current_commit.sha
102+
103+
if not self.file_history.jump_to_commit(sha):
104+
curses.beep()
105+
return
106+
107+
finish = sha
108+
109+
if start == finish:
110+
curses.beep()
111+
return
112+
113+
self._update_mapping(start, finish)
114+
115+
@ModalScrollingInterface.key_bindings('j')
116+
def info(self, times=1):
117+
blame_line = self.content()[self.highlight_line]
118+
self._jump_to_commit(blame_line.sha)
119+
99120
@ModalScrollingInterface.key_bindings(']')
100121
def next_commit(self, times=1):
101122
for i in range(0,times):

gitbrowse/git.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ def prev(self):
8787
self._blame = None
8888
return True
8989

90+
def jump_to_commit(self, sha):
91+
"""
92+
Moves to the given commit SHA, returning False if it doesn't exist.
93+
"""
94+
found_index = None
95+
for i, commit in enumerate(self.commits):
96+
if commit.sha == sha:
97+
found_index = i
98+
99+
if found_index is None:
100+
return False
101+
102+
self._index = found_index
103+
self._blame = None
104+
return True
105+
90106
def blame(self):
91107
"""
92108
Returns blame information for this file at the current commit as

0 commit comments

Comments
 (0)