gpt4 book ai didi

python - 是否有 git Shortlog 的 python 接口(interface)?

转载 作者:行者123 更新时间:2023-11-30 23:13:26 25 4
gpt4 key购买 nike

我正在尝试将 git 中的日志信息获取到 python 中。我查看了 pygit2 和 gitpython,但似乎都没有提供类似于 git Shortlog 的高级接口(interface)。是否有一个 python 库提供了这样的接口(interface),或者我应该调用 git 可执行文件?

最佳答案

我假设您的意思是 pygit2 是您查看过的库之一。这是一个较低级别的库,可让您在此基础上编写一个较高级别的库(它已经足够高级了,获取基本日志输出的 3 行代码是否太多了?)。做你想做的事并不难 - 阅读relevant documentation你可以想出类似的东西:

>>> from pygit2 import Repository
>>> from pygit2 import GIT_SORT_TIME
>>> from pygit2 import GIT_SORT_REVERSE
>>> repo = Repository('/path/to/repo')
>>> rev = repo.revparse_single('HEAD').hex
>>> iterator = repo.walk(rev, GIT_SORT_TIME | GIT_SORT_REVERSE)
>>> results = [(commit.committer.name, commit.message.splitlines()[0])
... for commit in iterator]
>>> results
[(u'User', u'first commit.'), (u'User', u'demo file.'), ... (u'User', u'okay?')]

如果你想将输出分组为与 git Shortlog 相同,这也不难,你需要的所有数据都已经在迭代器中,所以只需使用它将数据放入您需要的格式。

关于python - 是否有 git Shortlog 的 python 接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29336832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com