(git_dir, log_count=1)
return return_dict
Given a git dir and log count, return a json formatted representation
Given a git dir and log count, return a json formatted representation
Given a git dir and log count return a json formatted representation
def sub_git_info(git_dir, log_count=1):
    """
    Given a git dir and log count, return a json formatted representation
    """
    return_dict = {}
    kv_line_format = {
        'sha': '%H',
        'author': '%an <%ae>',
        'date': '%ai',
        'subject': '%s',
        'message': '%b'
    }

    KV_DELIMITER = ':~@#$~:'
    LINE_DELIMITER = '@#\n#@'

    # construct an output of git log that is essentially a:
    # key=value
    # key=value, etc
    # but a sing a custom Key=Value delimiter, and a custom Line delimiter since
    # there might be newlines in messages and subjects
    # the git log -z format delimits the entire log by null, but we need separation of each property

    line_by_line_format = LINE_DELIMITER.join(['%s%s%s' % (k, KV_DELIMITER, v) for k, v in kv_line_format.items()])

    args = ['log',
            '-%s' % log_count,
            '-z',
            '--pretty=format:%s' % line_by_line_format
    ]
    with sub_git_cmd(git_dir, args) as p:
        gitout = p.stdout.read().decode('utf-8').strip()
    url = sub_git_remote_url(git_dir)
    all_raw_revs = gitout.split('\0')

    def parse_rev_block(block_text):
        ret = {}
        for prop in block_text.split(LINE_DELIMITER):
            if len(prop) == 0:
                continue
            try:
                k, v = prop.split(KV_DELIMITER)
            except ValueError:
                k = "GitParseError"
                v = prop
            ret[k] = v
        return ret
    commit_list = [parse_rev_block(s) for s in all_raw_revs]

    for commit in commit_list:
        commit['commit_url'] = get_commit_url(url, commit['sha'])
        commit['compare_master'] = get_compare_url(url, commit['sha'], 'master')

    return_dict['commits'] = commit_list
    return return_dict
def sub_git_info ( git_dir , log_count = 1 ) : return_dict = { } kv_line_format = { 'sha' : '%H' , 'author' : '%an <%ae>' , 'date' : '%ai' , 'subject' : '%s' , 'message' : '%b' } KV_DELIMITER = ':~@#$~:' LINE_DELIMITER = '@#\n#@' # construct an output of git log that is essentially a: # key=value # key=value, etc # but a sing a custom Key=Value delimiter, and a custom Line delimiter since # there might be newlines in messages and subjects # the git log -z format delimits the entire log by null, but we need separation of each property line_by_line_format = LINE_DELIMITER . join ( [ '%s%s%s' % ( k , KV_DELIMITER , v ) for k , v in kv_line_format . items ( ) ] ) args = [ 'log' , '-%s' % log_count , '-z' , '--pretty=format:%s' % line_by_line_format ] with sub_git_cmd ( git_dir , args ) as p : gitout = p . stdout . read ( ) . decode ( 'utf-8' ) . strip ( ) url = sub_git_remote_url ( git_dir ) all_raw_revs = gitout . split ( '\0' ) def parse_rev_block ( block_text ) : ret = { } for prop in block_text . split ( LINE_DELIMITER ) : if len ( prop ) == 0 : continue try : k , v = prop . split ( KV_DELIMITER ) except ValueError : k = "GitParseError" v = prop ret [ k ] = v return ret commit_list = [ parse_rev_block ( s ) for s in all_raw_revs ] for commit in commit_list : commit [ 'commit_url' ] = get_commit_url ( url , commit [ 'sha' ] ) commit [ 'compare_master' ] = get_compare_url ( url , commit [ 'sha' ] , 'master' ) return_dict [ 'commits' ] = commit_list return return_dict