diff --git a/Default.sublime-commands b/Default.sublime-commands index 30f0d7d4..a3cb6e56 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -34,6 +34,10 @@ "caption": "Git: Log Current File", "command": "git_log" } + ,{ + "caption": "Git: Log Current Line", + "command": "git_log_line" + } ,{ "caption": "Git: Log All", "command": "git_log_all" diff --git a/git/__init__.py b/git/__init__.py index 7d49d4b6..8e7034c7 100644 --- a/git/__init__.py +++ b/git/__init__.py @@ -411,6 +411,9 @@ def get_working_dir(self): def get_window(self): return self.window + def get_current_line(self): + return -1 + # A base for all git commands that work with the file in the active view class GitTextCommand(GitCommand, sublime_plugin.TextCommand): @@ -446,3 +449,8 @@ def get_window(self): # the case of the quick panel. # So, this is not necessarily ideal, but it does work. return self.view.window() or sublime.active_window() + + def get_current_line(self): + (current_line, column) = self.view.rowcol(self.view.sel()[0].a) + # line is 1 based + return current_line + 1 diff --git a/git/history.py b/git/history.py index ccb959a9..e619c2bf 100644 --- a/git/history.py +++ b/git/history.py @@ -27,11 +27,6 @@ def run(self, edit): command.append(self.get_file_name()) self.run_command(command, callback) - def get_current_line(self): - (current_line, column) = self.view.rowcol(self.view.sel()[0].a) - # line is 1 based - return current_line + 1 - def get_lines(self, selection): if selection.empty(): return False @@ -54,9 +49,11 @@ def blame_done(self, result, focused_line=1): class GitLog(object): def run(self, edit=None): fn = self.get_file_name() - return self.run_log(fn != '', '--', fn) + ln = self.get_current_line() + return self.run_log(fn, ln, '--', fn) + + def run_log(self, fn, ln, *args): - def run_log(self, follow, *args): # the ASCII bell (\a) is just a convenient character I'm pretty sure # won't ever come up in the subject of the commit (and if it does then # you positively deserve broken output...) @@ -66,12 +63,16 @@ def run_log(self, follow, *args): command = [ 'git', 'log', '--no-color', '--pretty=%s (%h)\a%an <%aE>\a%ad (%ar)', '--date=local', '--max-count=9000', - '--follow' if follow else None + '--follow' if fn != '' and ln == -1 else None, + '-L' + str(ln) + ',+1:' + fn if ln != -1 else None, ] - command.extend(args) + + if(ln == -1): + command.extend(args) + self.run_command( command, - self.log_done) + self.log_done if ln == -1 else self.details_done) def log_done(self, result): self.results = [r.split('\a', 2) for r in result.strip().split('\n')] @@ -99,6 +100,11 @@ def details_done(self, result): class GitLogCommand(GitLog, GitTextCommand): + def get_current_line(self): + return -1 + + +class GitLogLineCommand(GitLog, GitTextCommand): pass