from git import *
    
    from django.conf import settings
    from django.template import Library, Node
    register = Library()
    
    class LatestCommitsNode(Node):
        def __init__(self, num, varname):
            self.num, self.varname = num, varname
    
        def render(self, context):
            repo = Repo(settings.REPO)
            context[self.varname] = repo.commits()[-self.num:]
            return ''
    
    @register.tag        
    def get_recent_commits(parser, token):
        bits = token.contents.split()
        if len(bits) != 4:
            raise TemplateSyntaxError, "get_recent_commits tag takes exactly three arguments"
        if bits[2] != 'as':
            raise TemplateSyntaxError, "second argument to get_recent_commits tag must be 'as'"
        return LatestCommitsNode(int(bits[1]), bits[3])