# Path: sgit/util.py
# def noop(*args, **kwargs):
#     pass
# 
# class StatusSpinner(object):
# 
#     SIZE = 10  # 10 equal signs
#     TIME = 50  # 50 ms delay
# 
#     def __init__(self, thread, msg):
#         self.counter = 0
#         self.direction = 1
#         self.msg = msg
#         self.thread = thread
# 
#     def progress(self):
#         if not self.thread.is_alive():
#             sublime.status_message('')
#             return
# 
#         left, right = self.counter, (self.SIZE - 1 - self.counter)
#         self.counter += self.direction
#         if self.counter in (0, self.SIZE - 1):
#             self.direction *= -1
# 
#         status = "[%s=%s] %s" % (' ' * left, ' ' * right, self.msg)
# 
#         sublime.status_message(status)
#         sublime.set_timeout(self.progress, self.TIME)
# 
#     def start(self):
#         self.thread.start()
#         sublime.set_timeout(self.progress, 0)
# 
# 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 GitErrorHelper(object):
# 
#     def format_error_message(self, msg):
#         if msg.startswith('error: '):
#             msg = msg[7:]
#         elif msg.lower().startswith('Note: '):
#             msg = msg[6:]
#         if msg.endswith('Aborting\n'):
#             msg = msg.rstrip()[:-8]
#         return msg


import sublime
import shlex
from sublime_plugin import WindowCommand, TextCommand
from .util import noop, StatusSpinner
from .cmd import GitCmd
from .helpers import GitErrorHelper
            def on_done(cmd):
                cmd = cmd.strip()
                if not cmd:
                    return
                self.on_command(repo, cmd, async=async)

            self.window.show_input_panel('git', '', on_done, noop, noop)
        else:
            self.on_command(repo, cmd, async=async)

    def on_command(self, repo, cmd, async):
        if sublime.version() < '3000':
            cmd = cmd.encode('utf-8')
        cmd = shlex.split(cmd)
        self.init_output(repo, cmd)
        if async:
            self.run_async(repo, cmd)
        else:
            self.run_sync(repo, cmd)

    def run_sync(self, repo, cmd):
        exit, stdout, stderr = self.git(cmd, cwd=repo)
        if exit == 0:
            self.on_output(stdout)
        else:
            sublime.error_message(self.format_error_message(stderr))
        self.window.run_command('git_status', {'refresh_only': True})

    def run_async(self, repo, cmd):
        thread = self.git_async(cmd, cwd=repo, on_data=self.on_output)

# Path: sgit/util.py
# def noop(*args, **kwargs):
#     pass
# 
# class StatusSpinner(object):
# 
#     SIZE = 10  # 10 equal signs
#     TIME = 50  # 50 ms delay
# 
#     def __init__(self, thread, msg):
#         self.counter = 0
#         self.direction = 1
#         self.msg = msg
#         self.thread = thread
# 
#     def progress(self):
#         if not self.thread.is_alive():
#             sublime.status_message('')
#             return
# 
#         left, right = self.counter, (self.SIZE - 1 - self.counter)
#         self.counter += self.direction
#         if self.counter in (0, self.SIZE - 1):
#             self.direction *= -1
# 
#         status = "[%s=%s] %s" % (' ' * left, ' ' * right, self.msg)
# 
#         sublime.status_message(status)
#         sublime.set_timeout(self.progress, self.TIME)
# 
#     def start(self):
#         self.thread.start()
#         sublime.set_timeout(self.progress, 0)
# 
# 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 GitErrorHelper(object):
# 
#     def format_error_message(self, msg):
#         if msg.startswith('error: '):
#             msg = msg[7:]
#         elif msg.lower().startswith('Note: '):
#             msg = msg[6:]
#         if msg.endswith('Aborting\n'):
#             msg = msg.rstrip()[:-8]
#         return msg


# Path: sgit/custom.py
import sublime
import shlex
from sublime_plugin import WindowCommand, TextCommand
from .util import noop, StatusSpinner
from .cmd import GitCmd
from .helpers import GitErrorHelper

            def on_done(cmd):
                cmd = cmd.strip()
                if not cmd:
                    return
                self.on_command(repo, cmd, async=async)

            self.window.show_input_panel('git', '', on_done, noop, noop)
        else:
            self.on_command(repo, cmd, async=async)

    def on_command(self, repo, cmd, async):
        if sublime.version() < '3000':
            cmd = cmd.encode('utf-8')
        cmd = shlex.split(cmd)
        self.init_output(repo, cmd)
        if async:
            self.run_async(repo, cmd)
        else:
            self.run_sync(repo, cmd)

    def run_sync(self, repo, cmd):
        exit, stdout, stderr = self.git(cmd, cwd=repo)
        if exit == 0:
            self.on_output(stdout)
        else:
            sublime.error_message(self.format_error_message(stderr))
        self.window.run_command('git_status', {'refresh_only': True})

    def run_async(self, repo, cmd):
        thread = self.git_async(cmd, cwd=repo, on_data=self.on_output)

        runner = StatusSpinner(thread, "Running %s" % " ".join(cmd))