示例#1
0
文件: views.py 项目: chyhutu/plugs
 def _create(content1, content2, name):
     content = self._diff(content1, content2)
     fileinfo = '%s <a href="%s">r%d</a> - <a href="%s">r%d</a>' % (name,
         url_for(self.__class__.wiki, pagename=pagename, rev=rev2),
         rev2,
         url_for(self.__class__.wiki, pagename=pagename, rev=rev1),
         rev1,
         )
     return diff2html(pagename, pagename, content, fileinfo=fileinfo)
示例#2
0
def diffs2html(diff):
    '''
    Return a list of dictionary, each of item has the following fields:
    name     - the file name of this diff
    revision - blob SHA1 of this diff
    html     - diff representation in HTML
    '''
    htmls = []
    lines = diff.split('\n')
    diffLineNumbers = []
    currentLine = 0
    while currentLine < len(lines):
        line = lines[currentLine]
        if line.lower().startswith('diff --git'):
            diffLineNumbers.append(currentLine)
        currentLine = currentLine + 1
    if diffLineNumbers:
        diffLineNumbers.append(-1)
        diffLineNumbers.reverse()
        start = diffLineNumbers.pop()
        while len(diffLineNumbers) > 0:
            end = diffLineNumbers.pop()
            diffLine = lines[start]
            name = parseFileName(diffLine)
            # Ignore those ignored files
            if not isIgnore(name):
                diffLines = lines[start:end]
                if diffLines:
                    revision = '<UNKNOWN>'
                    for line in diffLines:
                        if line.startswith('index'):
                            revision = parseRevision(line)
                            break
                    html = diff2html('\n'.join(diffLines))
                    if html:
                        htmls.append({'name':name, 'revision':revision, 'html':html})
            start = end
    return htmls
示例#3
0
def diffs2html(diff):
    '''
    Return a list of dictionary, each of item has the following fields:
    name     - the file name of this diff
    revision - blob SHA1 of this diff
    html     - diff representation in HTML
    '''
    htmls = []
    lines = diff.split('\n')
    diffLineNumbers = []
    currentLine = 0
    while currentLine < len(lines):
        line = lines[currentLine]
        if line.lower().startswith('diff --git'):
            diffLineNumbers.append(currentLine)
        currentLine = currentLine + 1
    if diffLineNumbers:
        diffLineNumbers.append(-1)
        diffLineNumbers.reverse()
        start = diffLineNumbers.pop()
        while len(diffLineNumbers) > 0:
            end = diffLineNumbers.pop()
            diffLine = lines[start]
            name = parseFileName(diffLine)
            # Ignore those ignored files
            if not isIgnore(name):
                diffLines = lines[start:end]
                if diffLines:
                    revision = '<UNKNOWN>'
                    for line in diffLines:
                        if line.startswith('index'):
                            revision = parseRevision(line)
                            break
                    html = diff2html('\n'.join(diffLines))
                    if html:
                        htmls.append({'name':name, 'revision':revision, 'html':html})
            start = end
    return htmls