Mercurial scripting with python

后端 未结 7 1051
-上瘾入骨i
-上瘾入骨i 2020-12-13 04:23

I am trying to get the mercurial revision number/id (it\'s a hash not a number) programmatically in python.

The reason is that I want to add it to the css/js files on

7条回答
  •  -上瘾入骨i
    2020-12-13 04:55

    It's true there's no official API, but you can get an idea about best practices by reading other extensions, particularly those bundled with hg. For this particular problem, I would do something like this:

    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())
    

    Update At some point the parameter order changed, now it's like this:

       repo = hg.repository(ui.ui(), '/path/to/repo/root' )
    

提交回复
热议问题