我正在编写一个包(Python>;=3.5),它使用git blame
来检索有关文件的信息。我正在努力用自定义代码替换GitPython依赖项,这些代码只支持我们实际需要的功能的一小部分(并以我们实际需要的形式提供数据)
我发现git blame -lts
最接近我需要的,即检索文件中每一行的提交SHA和行内容。这给了我类似的输出
82a3e5021b7131e31fc5b110194a77ebee907955 books/main/docs/index.md 5) Softwareplattform [ILIAS](https://www.ilias.de/), die an zahlreichen
我已经处理过了
line_pattern = re.compile('(.*?)\s.*\s*\d\)(\s*.*)')
for line in cmd.stdout():
m = line_pattern.match(line)
if m:
sha = m.group(1)
content = m.group(2).strip()
这很有效。然而,该软件包的维护人员正确地警告说,“这可能会为非常特定的用户组引入难以调试的错误。可能需要跨多个OS和GIT版本进行大量的单元测试。”
我之所以采用这种方法,是因为我发现git blame --porcelain
的输出解析起来有些乏味
30ed8daf1c48e4a7302de23b6ed262ab13122d31 1 1 1
author XY
author-mail <XY>
author-time 1580742131
author-tz +0100
committer XY
committer-mail <XY>
committer-time 1580742131
committer-tz +0100
summary Stub-Outline-Dateien
filename home/docs/README.md
hero: abcdefghijklmnopqrstuvwxyz
82a3e5021b7131e31fc5b110194a77ebee907955 18 18
82a3e5021b7131e31fc5b110194a77ebee907955 19 19
---
82a3e5021b7131e31fc5b110194a77ebee907955 20 20
...
我不喜欢那种在字符串列表上进行迭代的方式
我的问题是:
1)我是否应该更好地使用--porcelain
输出,因为它明确用于机器消费?
2) 我能期望这种格式在Git版本和操作系统上具有健壮性吗?我是否可以假设以制表符字符开头的行是内容行,这是源行输出的最后一行,并且制表符之后的任何内容都是原始行内容
不知道这是否是最好的解决方案,我在这里不等待答案就尝试了一下。我假设我的两个问题的答案是“是”
在这里的上下文中可以看到以下代码:https://github.com/uliska/mkdocs-git-authors-plugin/blob/6f5822c641452cea3edb82c2bbb9ed63bd254d2e/mkdocs_git_authors_plugin/repo.py#L466-L565
相关问题 更多 >
编程相关推荐