Skip to content
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

feature: log current line #540

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
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
26 changes: 16 additions & 10 deletions git/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)
Expand All @@ -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')]
Expand Down Expand Up @@ -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


Expand Down