# Path: sgit/util.py
# def noop(*args, **kwargs):
#     pass
# 
# Path: sgit/cmd.py
# class GitCmd(GitRepoHelper, Cmd):
#     executable = 'git'
#     bin = ['git']
#     opts = [
#         '--no-pager',
#         '-c', 'color.diff=false',
#         '-c', 'color.status=false',
#         '-c', 'color.branch=false',
#         '-c', 'status.displayCommentPrefix=true',
#         '-c', 'core.commentchar=#',
#     ]
# 
#     def git(self, cmd, *args, **kwargs):
#         return self.cmd(cmd, *args, **kwargs)
# 
#     def git_string(self, cmd, *args, **kwargs):
#         return self._string(cmd, *args, **kwargs)
# 
#     def git_lines(self, cmd, *args, **kwargs):
#         return self._lines(cmd, *args, **kwargs)
# 
#     def git_exit_code(self, cmd, *args, **kwargs):
#         return self._exit_code(cmd, *args, **kwargs)
# 
#     def git_async(self, cmd, *args, **kwargs):
#         return self.cmd_async(cmd, *args, **kwargs)
# 
# Path: sgit/helpers.py
# class GitLogHelper(object):
# 
#     GIT_QUICK_LOG_FORMAT = ('%s%x03'   # subject
#                             '%H%x03'   # sha1
#                             '%an%x03'  # author name
#                             '%aE%x03'  # author email
#                             '%ad%x03'  # auth date
#                             '%ar'    # auth date relative
#                             '%x04')
# 
#     def get_quick_log(self, repo, path=None, follow=False):
#         cmd = ['log', '--no-color', '--date=local', '--format=%s' % self.GIT_QUICK_LOG_FORMAT]
#         if follow:
#             cmd.append('--follow')
#         if path:
#             cmd.extend(['--', path])
#         out = self.git_string(cmd, cwd=repo, strip=False)
# 
#         lines = []
#         for line in out.split(u'\u0004'):
#             line = line.strip()
#             if line:
#                 parts = line.split(u'\u0003')
#                 if len(parts) != 6:
#                     raise Exception("The line %s splits to %s", line, parts)
#                 lines.append(parts)
#         return lines
# 
#     def format_quick_log(self, log):
#         hashes = [l[1] for l in log]
#         choices = []
#         for subject, sha, name, email, dt, reldt in log:
#             choices.append([subject, '%s by %s <%s>' % (sha[0:8], name, email), '%s (%s)' % (reldt, dt)])
#         return hashes, choices


from sublime_plugin import WindowCommand, TextCommand
from .util import noop
from .cmd import GitCmd
from .helpers import GitLogHelper
class GitQuickLogCommand(WindowCommand, GitCmd, GitLogHelper):
    """
    Documentation coming soon.
    """

    def run(self):
        repo = self.get_repo()
        if not repo:
            return

        log = self.get_quick_log(repo)
        hashes, choices = self.format_quick_log(log)

        def on_done(idx):
            if idx == -1:
                return
            commit = hashes[idx]
            self.window.run_command('git_show', {'obj': commit, 'repo': repo})

        self.window.show_quick_panel(choices, on_done)


class GitQuickLogCurrentFileCommand(TextCommand, GitCmd, GitLogHelper):
    """
    Documentation coming soon.
    """

    def run(self, edit):
        filename = self.view.file_name()
        if not filename:

# Path: sgit/util.py
# def noop(*args, **kwargs):
#     pass
# 
# Path: sgit/cmd.py
# class GitCmd(GitRepoHelper, Cmd):
#     executable = 'git'
#     bin = ['git']
#     opts = [
#         '--no-pager',
#         '-c', 'color.diff=false',
#         '-c', 'color.status=false',
#         '-c', 'color.branch=false',
#         '-c', 'status.displayCommentPrefix=true',
#         '-c', 'core.commentchar=#',
#     ]
# 
#     def git(self, cmd, *args, **kwargs):
#         return self.cmd(cmd, *args, **kwargs)
# 
#     def git_string(self, cmd, *args, **kwargs):
#         return self._string(cmd, *args, **kwargs)
# 
#     def git_lines(self, cmd, *args, **kwargs):
#         return self._lines(cmd, *args, **kwargs)
# 
#     def git_exit_code(self, cmd, *args, **kwargs):
#         return self._exit_code(cmd, *args, **kwargs)
# 
#     def git_async(self, cmd, *args, **kwargs):
#         return self.cmd_async(cmd, *args, **kwargs)
# 
# Path: sgit/helpers.py
# class GitLogHelper(object):
# 
#     GIT_QUICK_LOG_FORMAT = ('%s%x03'   # subject
#                             '%H%x03'   # sha1
#                             '%an%x03'  # author name
#                             '%aE%x03'  # author email
#                             '%ad%x03'  # auth date
#                             '%ar'    # auth date relative
#                             '%x04')
# 
#     def get_quick_log(self, repo, path=None, follow=False):
#         cmd = ['log', '--no-color', '--date=local', '--format=%s' % self.GIT_QUICK_LOG_FORMAT]
#         if follow:
#             cmd.append('--follow')
#         if path:
#             cmd.extend(['--', path])
#         out = self.git_string(cmd, cwd=repo, strip=False)
# 
#         lines = []
#         for line in out.split(u'\u0004'):
#             line = line.strip()
#             if line:
#                 parts = line.split(u'\u0003')
#                 if len(parts) != 6:
#                     raise Exception("The line %s splits to %s", line, parts)
#                 lines.append(parts)
#         return lines
# 
#     def format_quick_log(self, log):
#         hashes = [l[1] for l in log]
#         choices = []
#         for subject, sha, name, email, dt, reldt in log:
#             choices.append([subject, '%s by %s <%s>' % (sha[0:8], name, email), '%s (%s)' % (reldt, dt)])
#         return hashes, choices


# Path: sgit/log.py
from sublime_plugin import WindowCommand, TextCommand
from .util import noop
from .cmd import GitCmd
from .helpers import GitLogHelper

class GitQuickLogCommand(WindowCommand, GitCmd, GitLogHelper):
    """
    Documentation coming soon.
    """

    def run(self):
        repo = self.get_repo()
        if not repo:
            return

        log = self.get_quick_log(repo)
        hashes, choices = self.format_quick_log(log)

        def on_done(idx):
            if idx == -1:
                return
            commit = hashes[idx]
            self.window.run_command('git_show', {'obj': commit, 'repo': repo})

        self.window.show_quick_panel(choices, on_done)


class GitQuickLogCurrentFileCommand(TextCommand, GitCmd, GitLogHelper):
    """
    Documentation coming soon.
    """

    def run(self, edit):
        filename = self.view.file_name()
        if not filename:

            self.window.show_quick_panel(['No log for file'], noop)