diff --git a/gitbrowse/browser.py b/gitbrowse/browser.py index 00d400c..5a1db3f 100644 --- a/gitbrowse/browser.py +++ b/gitbrowse/browser.py @@ -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 @@ -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): diff --git a/gitbrowse/git.py b/gitbrowse/git.py index 9ff5ad6..7d3302a 100644 --- a/gitbrowse/git.py +++ b/gitbrowse/git.py @@ -1,5 +1,5 @@ import os - +import itertools class GitCommit(object): """ @@ -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