【问题标题】:Is it possible to get the files changed information from commit ids using mercurial python library?是否可以使用 mercurial python 库从提交 id 获取文件更改信息?
【发布时间】:2019-04-17 16:12:08
【问题描述】:

我在 Rhodecode CI 中实现了一个自定义钩子,它在每次推送时向 Buildbot 发送一个构建请求。钩子为我提供了修订提交 ID,我如何提取有关作为此提交的一部分更改的文件的信息。

@has_kwargs({
'commit_ids': 'list of pushed commit_ids (sha1)',})
def _push_hook(*args, **kwargs):
     import mercurial # can I used this library to get this info?
     some_function(commit_id) # should return files changed

我可以使用 mercurial 库还是有其他方法可以使用 python 以编程方式获取此信息?

【问题讨论】:

    标签: mercurial buildbot mercurial-hook rhodecode


    【解决方案1】:

    使用 rhodecode:

    from rhodecode.model.db import Repository
    from rhodecode.api.utils import build_commit_data, Optional
    
    
    class Commit:
    
        def __init__(self, repo_name, commit_id):
            self._commit_id = commit_id
            repo = Repository.get_by_repo_name(repo_name)
            self.vcs_repo = repo.scm_instance(cache=False)
    
        def files_changed(self):
            changeset_details = self._changeset_details(self._commit_id)
            files_changed_ = [diff.get("filename") for diff in changeset_details["diff"]]
            return files_changed_
    
        def _changeset_details(self, commit_id):
            pre_load = ['author', 'branch', 'date', 'message', 'parents',
                        'status', '_commit', '_file_paths']
            changes_details = Optional.extract("full")
            changeset = self.vcs_repo.get_changeset(commit_id, pre_load=pre_load)
            changeset_data = changeset.__json__()
            changeset_data['diff'] = build_commit_data(changeset, changes_details)
            return changeset_data
    

    使用 HG:

    from mercurial import ui, hg
    hg_repo = hg.repository(ui.ui(), repo_path)
    node = hg_repo.changelog.node(revision)    
    log = hg_repo.changelog.read(node)
    manifest, user, (time, timezone), files_changed, desc, extra = log
    

    【讨论】:

      猜你喜欢
      • 2011-07-05
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 2012-11-22
      • 2019-12-06
      相关资源
      最近更新 更多