确实没有官方API,但是您可以通过阅读其他扩展(尤其是与hg捆绑在一起的扩展)来了解最佳做法。对于这个特殊的问题,我会做这样的事情:
from mercurial import ui, hg
from mercurial.node import hex
repo = hg.repository('/path/to/repo/root', ui.ui())
fctx = repo.filectx('/path/to/file', 'tip')
hexnode = hex(fctx.node())
在某些时候参数顺序已更改,现在是这样的:
repo = hg.repository(ui.ui(), '/path/to/repo/root' )