所以,我从您的问题中了解到的可能是您想列出一个 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 林头。