Beispiel #1
0
    def history(self, commit, path=None, max_commits=None, skip=0):
        """
        Returns a list of all commits that infected `path`, starting at branch
        or commit `commit`. `skip` can be used for pagination, `max_commits`
        to limit the number of commits returned.

        Similar to `git log [branch/commit] [--skip skip] [-n max_commits]`.
        """
        # XXX The pure-Python/dulwich code is very slow compared to `git log`
        #     at the time of this writing (mid-2012).
        #     For instance, `git log .tx` in the Django root directory takes
        #     about 0.15s on my machine whereas the history() method needs 5s.
        #     Therefore we use `git log` here until dulwich gets faster.
        #     For the pure-Python implementation, see the 'purepy-hist' branch.

        cmd = ['git', 'log', '--format=%H']
        if skip:
            cmd.append('--skip=%d' % skip)
        if max_commits:
            cmd.append('--max-count=%d' % max_commits)
        cmd.append(commit)
        if path:
            cmd.extend(['--', path])

        sha1_sums = check_output(cmd, cwd=os.path.abspath(self.path))
        return [self[sha1] for sha1 in sha1_sums.strip().split('\n')]
Beispiel #2
0
    def history(self, commit, git_bin, path=None, max_commits=None, skip=0):
        """
        Returns a list of all commits that infected `path`, starting at branch
        or commit `commit`. `skip` can be used for pagination, `max_commits`
        to limit the number of commits returned.

        Similar to `git log [branch/commit] [--skip skip] [-n max_commits]`.
        """
        # XXX The pure-Python/dulwich code is very slow compared to `git log`
        #     at the time of this writing (mid-2012).
        #     For instance, `git log .tx` in the Django root directory takes
        #     about 0.15s on my machine whereas the history() method needs 5s.
        #     Therefore we use `git log` here until dulwich gets faster.
        #     For the pure-Python implementation, see the 'purepy-hist' branch.

        cmd = [git_bin, 'log', '--format=%H']
        if skip:
            cmd.append('--skip=%d' % skip)
        if max_commits:
            cmd.append('--max-count=%d' % max_commits)
        cmd.append(commit)
        if path:
            cmd.extend(['--', path])

        sha1_sums = check_output(cmd, cwd=os.path.abspath(self.path))
        return [self[sha1] for sha1 in sha1_sums.strip().split('\n')]
Beispiel #3
0
def check_have_exuberant_ctags():
    """Check that the 'ctags' binary is *Exuberant* ctags (not etags etc)"""
    try:
        return b"Exuberant" in check_output(["ctags", "--version"],
                                            stderr=subprocess.PIPE)
    except subprocess.CalledProcessError:
        return False
Beispiel #4
0
 def blame(self, commit, path):
     """"""
     cmd = ['git', 'blame', '-ls', '--root', commit.id, '--', path]
     sha1_sums = check_output(cmd, cwd=os.path.abspath(self.path))
     for line in sha1_sums.split("\n"):
         if line:
             yield self.get_commit(line.split(" ", 1)[0].lstrip("^"))
Beispiel #5
0
def guess_git_revision():
    git_dir = os.path.join(os.path.dirname(__file__), '..', '.git')
    if os.path.exists(git_dir):
        return check_output(
            ['git', 'log', '--format=%h', '-n', '1'],
            cwd=git_dir
        ).strip()
Beispiel #6
0
 def blame(self, commit, path):
     """Return a 'git blame' list for the file at `path`: For each line in
     the file, the list contains the commit that last changed that line.
     """
     # XXX see comment in `.history()`
     cmd = ['git', 'blame', '-ls', '--root', commit.id, '--', path]
     output = check_output(cmd, cwd=os.path.abspath(self.path))
     sha1_sums = [line[:40] for line in output.strip().split(b'\n')]
     return [self[sha1] for sha1 in sha1_sums]
Beispiel #7
0
 def blame(self, commit, path):
     """Return a 'git blame' list for the file at `path`: For each line in
     the file, the list contains the commit that last changed that line.
     """
     # XXX see comment in `.history()`
     cmd = ['git', 'blame', '-ls', '--root', commit.id, '--', path]
     output = check_output(cmd, cwd=os.path.abspath(self.path))
     sha1_sums = [line[:40] for line in output.strip().split(b'\n')]
     return [self[sha1] for sha1 in sha1_sums]
Beispiel #8
0
def test_covers_all_cli_options():
    manpage = check_output(["man", "./klaus.1"])

    def assert_in_manpage(s):
        clean = lambda x: re.sub('(.\\x08)|\s', '', x)
        assert clean(s) in clean(manpage), "%r not found in manpage" % s

    mock_parser = mock.Mock()
    with mock.patch('argparse.ArgumentParser') as mock_cls:
        mock_cls.return_value = mock_parser
        klaus_cli.make_parser()

    for args, kwargs in mock_parser.add_argument.call_args_list:
        if kwargs.get('metavar') == 'DIR':
            continue
        for string in args:
            assert_in_manpage(string)
        if 'help' in kwargs:
            assert_in_manpage(kwargs['help'])
        if 'choices' in kwargs:
            for choice in kwargs['choices']:
                assert_in_manpage(choice)
Beispiel #9
0
def test_covers_all_cli_options():
    manpage = force_unicode(check_output(["man", "./klaus.1"]))

    def assert_in_manpage(s):
        clean = lambda x: re.sub('(.\\x08)|\s', '', x)
        assert clean(s) in clean(manpage), "%r not found in manpage" % s

    mock_parser = mock.Mock()
    with mock.patch('argparse.ArgumentParser') as mock_cls:
        mock_cls.return_value = mock_parser
        klaus_cli.make_parser()

    for args, kwargs in mock_parser.add_argument.call_args_list:
        if kwargs.get('metavar') == 'DIR':
            continue
        for string in args:
            assert_in_manpage(string)
        if 'help' in kwargs:
            assert_in_manpage(kwargs['help'])
        if 'choices' in kwargs:
            for choice in kwargs['choices']:
                assert_in_manpage(choice)
Beispiel #10
0
def check_have_exuberant_ctags():
    """Check that the 'ctags' binary is *Exuberant* ctags (not etags etc)"""
    try:
        return "Exuberant" in check_output(["ctags", "--version"], stderr=subprocess.PIPE)
    except subprocess.CalledProcessError:
        return False
Beispiel #11
0
import os
import subprocess
import jinja2
import flask
import httpauth
import dulwich.web
from klaus import views, utils
from klaus.repo import FancyRepo

KLAUS_ROOT = os.path.dirname(__file__)

try:
    KLAUS_VERSION = utils.check_output(
        ['git', 'log', '--format=%h', '-n', '1']).strip()
except subprocess.CalledProcessError:
    KLAUS_VERSION = '0.2'


class Klaus(flask.Flask):
    jinja_options = {
        'extensions': ['jinja2.ext.autoescape'],
        'undefined': jinja2.StrictUndefined
    }

    def __init__(self, repo_paths, sitename, use_smarthttp):
        self.repos = map(FancyRepo, repo_paths)
        self.repo_map = dict((repo.name, repo) for repo in self.repos)
        self.sitename = sitename
        self.use_smarthttp = use_smarthttp

        flask.Flask.__init__(self, __name__)
Beispiel #12
0
def guess_git_revision():
    git_dir = os.path.join(os.path.dirname(__file__), '..', '.git')
    if os.path.exists(git_dir):
        return check_output(['git', 'log', '--format=%h', '-n', '1'],
                            cwd=git_dir).strip()
Beispiel #13
0
import os
import subprocess
import jinja2
import flask
import httpauth
import dulwich.web
from klaus import views, utils
from klaus.repo import FancyRepo


KLAUS_ROOT = os.path.dirname(__file__)

try:
    KLAUS_VERSION = utils.check_output(['git', 'log', '--format=%h', '-n', '1']).strip()
except subprocess.CalledProcessError:
    KLAUS_VERSION = '0.2'


class Klaus(flask.Flask):
    jinja_options = {
        'extensions': ['jinja2.ext.autoescape'],
        'undefined': jinja2.StrictUndefined
    }

    def __init__(self, repo_paths, sitename, use_smarthttp):
        self.repos = map(FancyRepo, repo_paths)
        self.repo_map = dict((repo.name, repo) for repo in self.repos)
        self.sitename = sitename
        self.use_smarthttp = use_smarthttp

        flask.Flask.__init__(self, __name__)