Skip to content

Ability to jump to the commit under the cursor #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions gitbrowse/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ def get_status(self):
'message': self.file_history.current_commit.message,
}

def _move_commit(self, method_name):
def _move_commit(self, method_name, sha = None):
start = self.file_history.current_commit.sha

method = getattr(self.file_history, method_name)
if not method():
if sha != None:
result = method(sha)
else:
result = method()
if not result:
curses.beep()
return

Expand All @@ -93,6 +97,11 @@ def _move_commit(self, method_name):
# not out of range for the newly loaded revision of the file.
self.highlight_line = self.highlight_line

@ModalScrollingInterface.key_bindings('t')
def jump_to_commit(self, times=0):
wants_sha = self.content()[self.highlight_line].sha
self._move_commit('jump', wants_sha)

@ModalScrollingInterface.key_bindings(']')
def next_commit(self, times=1):
for i in range(0,times):
Expand Down
15 changes: 14 additions & 1 deletion gitbrowse/git.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

import itertools

class GitCommit(object):
"""
Expand Down Expand Up @@ -62,6 +62,19 @@ def __init__(self, path, start_commit):
def current_commit(self):
return self.commits[self._index]

def jump(self, sha):
"""
Jump to a specific commit matching a given SHA
"""
commit = itertools.ifilter(lambda x: x.sha == sha, self.commits).next()
try:
indx = self.commits.index(commit)
self._index = indx
self._blame = None
return True
except ValueError:
return False

def next(self):
"""
Moves to the next commit that touched this file, returning False
Expand Down