Mercurial scripting with python

后端 未结 7 1049
-上瘾入骨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条回答
  • 2020-12-13 05:15

    I wanted to do the same thing the OP wanted to do, get hg id -i from a script (get tip revision of the whole REPOSITORY, not of a single FILE in that repo) but I did not want to use popen, and the code from brendan got me started, but wasn't what I wanted.

    So I wrote this... Comments/criticism welcome. This gets the tip rev in hex as a string.

    from mercurial import ui, hg, revlog
    # from mercurial.node import hex  # should I have used this?
    
    def getrepohex(reporoot):
        repo = hg.repository(ui.ui(), reporoot)
        revs = repo.revs('tip')
        if len(revs)==1:
          return str(repo.changectx(revs[0]))
        else:
          raise Exception("Internal failure in getrepohex")
    
    0 讨论(0)
提交回复
热议问题