core.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:bock 作者: afreeorange 项目源码 文件源码
def get_diff(self, article_path, a, b):
        """Return a diff string between two revisions of a given
        article title.
        """
        revision_a = self.get_revision(article_path, a)
        revision_b = self.get_revision(article_path, b)

        unified_diff = '\n'.join(
            list(
                difflib.unified_diff(
                    revision_a['raw'].splitlines(),
                    revision_b['raw'].splitlines(),
                    fromfile='{}/{}'.format('a', article_path),
                    tofile='{}/{}'.format('b', article_path),
                    lineterm='',
                )
            )
        )

        diff_template = """diff --git a/{title} b/{title}
index {sha_a}..{sha_b} {file_mode}
{diff}
"""

        unified_diff = diff_template.format(
            title=article_path,
            diff=unified_diff,
            sha_a=a[0:7],
            sha_b=b[0:7],
            file_mode=oct(
                os.stat(self.full_article_path(article_path)).st_mode
            )[2:]
        )

        # Escape HTML and "non-breaking space"
        return self.escape_html(unified_diff)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号