【问题标题】:List all the Mercurial projects in Mercurial repo with python api使用 python api 列出 Mercurial repo 中的所有 Mercurial 项目
【发布时间】:2016-10-05 10:14:36
【问题描述】:

我想列出所有使用 Mercurial 和 Python 的项目。 我下载了“import hglib”包,但在文档、函数等中没有找到可以帮助我的。有人会知道怎么做吗?

PS:我在此链接中找到了一些信息: - https://www.mercurial-scm.org/wiki/MercurialApi - http://pythonhosted.org/hgapi/index.html#hgapi.hgapi.Repo.command

但这不是我想要的……

【问题讨论】:

    标签: python mercurial


    【解决方案1】:

    所以,我从您的问题中了解到的可能是您想列出一个 mercurial 存储库中的嵌套存储库。用更简单的术语来说,您必须使用 mercurial 森林,并且您想在下面列出子存储库,并且似乎有一个名为 hgnested 的 python 包用于处理 mercurial 森林。

    我拿了一段代码并用它来满足我们想要的,这就是我想出的。

    from mercurial import hg, ui
    import hgnested
    
    def getNestedRepos(ui, source, **opts):
        origsource = ui.expandpath(source)
        remotesource, remotebranch =hg.parseurl(origsource,opts.get('branch'))
        if hasattr(hg, 'peer'):
            remoterepo = hg.peer(ui, opts, remotesource)
            localrepo = remoterepo.local()
            if localrepo:
                remoterepo = localrepo
        else:
            remoterepo = hg.repository(hg.remoteui(ui, opts), remotesource)
        return remoterepo.nested
    
    print getNestedRepos(ui.ui(), <path to mercurial forest>)
    

    但是还有另一种scrapy方式,您需要递归访问所有子目录并查找 .hg 文件的存在。

    注意:如果您想列出远程存储库中的存储库,请确保在该远程服务器中安装 hgnested 包,并且您传递的存储库路径是一个 mercurial 林头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多