开发者

Using mercurial to manage linux kernel, tags, and hg id

Anybody using mercurial to manage a linux kernel? This is a bit long, but I'm not sure if there's an answer to this. I wanted to give some examples for help

Here's what I'm seeing:

Within the linux kernel, there's a command used when building called scripts/setlocalversion. Inside this script, it sets the kernel version based on the repository information. Currently, it understands git, mercurial, and svn repo's.

For git, it creates the tag with this code:

if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then

    # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it,
    # because this version is defined in the top level Makefile.
    if [ -z "`git describe --exact-match 2>/dev/null`" ]; then

        # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"),
        # we pretty print it.
        if atag="`git describe 2>/dev/null`"; then
            echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
.....

So, here's an example I did to understand how this works:

[1536][mcrowe:test]$ git tag -a -m"Creating a tag" KernelTest
[1537][mcrowe:test]$ git rev-parse --verify --short HEAD 
d024e76
[1537][mcrowe:test]$ git describe --exact-match
KernelTest
[1537][mcrowe:test]$ git describe
KernelTest

So, in this example, the local version would be set to "KernelTest" when the kernel builds.

In mercurial, however, the code to get the local version is this:

if hgid=`hg id 2>/dev/null`; then
    tag=`printf '%s' "$hgid" | cut -d' ' -f2`

    # Do we have an untagged version?
    if [ -z "$tag" -o "$tag" = tip ]; then
        id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
        printf '%s%s' -hg "$id"
    fi
....

My expectation was that I could tag a release, and have that tag be what this script uses, as happens in git. However, it appears that "hg id" never prints out the tag like this script expects:

[1546][mcrowe:test2]$ hg tag -m"Creat开发者_StackOverflowing a tag" KernelTest -r tip
[1548][mcrowe:test2]$ hg id
3ccda5e738ae+ tip
[1548][mcrowe:test2]$ hg tags
tip                              115:3ccda5e738ae
KernelTest                       114:be25df80ce76

So that act of tagging changes the revision so hg id will never show what the tag is.

Core Question: AFAIK, this would never work for the linux kernel. The question is how should this be implemented in the kernel tree to allow hg tag to perform like git tag?


Try doing:

hg log -r . --template '{latesttag}'

I think that does what you want.

There's also {latesttagdistance} which can let you know you're N commits past a tag for handy version string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜