# Path: ellen/utils/git.py
# PYGIT2_OBJ_TYPE = {
#     GIT_OBJ_COMMIT: 'commit',
#     GIT_OBJ_BLOB: 'blob',
#     GIT_OBJ_TREE: 'tree',
#     GIT_OBJ_TAG: 'tag',
# }
# 
# Path: ellen/utils/text.py
# def trunc_utf8(string, num, etc="..."):
#     """truncate a utf-8 string, show as num chars.
#     arg: string, a utf-8 encoding string; num, look like num chars
#     return: a utf-8 string
#     """
#     try:
#         gb = string.decode("utf8", "ignore")
#     except UnicodeEncodeError:  # Already decoded
#         gb = string
#     gb = gb.encode("gb18030", "ignore")
#     if num >= len(gb):
#         return string
#     if etc:
#         etc_len = len(etc.decode("utf8", "ignore").encode("gb18030", "ignore"))
#         trunc_idx = num - etc_len
#     else:
#         trunc_idx = num
#     ret = gb[:trunc_idx].decode("gb18030", "ignore").encode("utf8")
#     if etc:
#         ret += etc
#     return ret


import re
import sys
import mime
import magic
from datetime import datetime
from ellen.utils.git import PYGIT2_OBJ_TYPE
from ellen.utils.text import trunc_utf8
    from pygit2 import GIT_MERGE_ANALYSIS_FASTFORWARD, GIT_MERGE_ANALYSIS_UP_TO_DATE
    rev_data = {}
    new_block = True
    for line in res:
        if new_block:
            sha, old_no, line_no = line.split()[:3]
            if sha not in rev_data:
                rev_data[sha] = {}
            rev_data[sha]['line_no'] = line_no
            rev_data[sha]['old_no'] = old_no
            new_block = False
        elif line.startswith('author '):
            _, _, author = line.partition(' ')
            rev_data[sha]['author'] = author.strip()
        elif line.startswith('author-time '):
            _, _, time = line.partition(' ')
            time = datetime.fromtimestamp(float(time)).strftime('%Y-%m-%d')
            rev_data[sha]['time'] = time
        elif line.startswith('author-mail '):
            _, _, email = line.partition(' ')
            email = RE_EMAIL.match(email).group('email')
            rev_data[sha]['email'] = email
        elif line.startswith('summary '):
            _, _, summary = line.partition(' ')
            rev_data[sha]['summary'] = summary.strip()
            disp_summary = trunc_utf8(
                summary.encode('utf-8'), 20).decode('utf-8', 'ignore')
            rev_data[sha]['disp_summary'] = disp_summary
        elif line.startswith('filename'):
            _, _, filename = line.partition(' ')
            rev_data[sha]['filename'] = filename

# Path: ellen/utils/git.py
# PYGIT2_OBJ_TYPE = {
#     GIT_OBJ_COMMIT: 'commit',
#     GIT_OBJ_BLOB: 'blob',
#     GIT_OBJ_TREE: 'tree',
#     GIT_OBJ_TAG: 'tag',
# }
# 
# Path: ellen/utils/text.py
# def trunc_utf8(string, num, etc="..."):
#     """truncate a utf-8 string, show as num chars.
#     arg: string, a utf-8 encoding string; num, look like num chars
#     return: a utf-8 string
#     """
#     try:
#         gb = string.decode("utf8", "ignore")
#     except UnicodeEncodeError:  # Already decoded
#         gb = string
#     gb = gb.encode("gb18030", "ignore")
#     if num >= len(gb):
#         return string
#     if etc:
#         etc_len = len(etc.decode("utf8", "ignore").encode("gb18030", "ignore"))
#         trunc_idx = num - etc_len
#     else:
#         trunc_idx = num
#     ret = gb[:trunc_idx].decode("gb18030", "ignore").encode("utf8")
#     if etc:
#         ret += etc
#     return ret


# Path: ellen/utils/format.py
import re
import sys
import mime
import magic
from datetime import datetime
from ellen.utils.git import PYGIT2_OBJ_TYPE
from ellen.utils.text import trunc_utf8
    from pygit2 import GIT_MERGE_ANALYSIS_FASTFORWARD, GIT_MERGE_ANALYSIS_UP_TO_DATE

    rev_data = {}
    new_block = True
    for line in res:
        if new_block:
            sha, old_no, line_no = line.split()[:3]
            if sha not in rev_data:
                rev_data[sha] = {}
            rev_data[sha]['line_no'] = line_no
            rev_data[sha]['old_no'] = old_no
            new_block = False
        elif line.startswith('author '):
            _, _, author = line.partition(' ')
            rev_data[sha]['author'] = author.strip()
        elif line.startswith('author-time '):
            _, _, time = line.partition(' ')
            time = datetime.fromtimestamp(float(time)).strftime('%Y-%m-%d')
            rev_data[sha]['time'] = time
        elif line.startswith('author-mail '):
            _, _, email = line.partition(' ')
            email = RE_EMAIL.match(email).group('email')
            rev_data[sha]['email'] = email
        elif line.startswith('summary '):
            _, _, summary = line.partition(' ')
            rev_data[sha]['summary'] = summary.strip()
            disp_summary = trunc_utf8(
                summary.encode('utf-8'), 20).decode('utf-8', 'ignore')
            rev_data[sha]['disp_summary'] = disp_summary
        elif line.startswith('filename'):
            _, _, filename = line.partition(' ')
            rev_data[sha]['filename'] = filename

            filename = trunc_utf8(