Java:如何获得用于程序的mercurial当前变更集编号 [英] Java: how to get mercurial current changeset number for use in program

查看:106
本文介绍了Java:如何获得用于程序的mercurial当前变更集编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始在Java项目中使用mercurial进行版本控制。当我运行我的程序时,它用于产生某些输出的输入参数被写入特定文件。如果我能将当前的mercurial变更集编号(表示我的程序的版本)添加到该输出文件中会很好。

I've recently started using mercurial for version control in a Java project. When I run my program, the input parameters it has used to produce certain a output, are written to a specific file. It would be nice if I could add the current mercurial changeset number (indicating the version of my program) to that output file as well.

最简单的方法是什么?在Windows上这样做?
我可以编写一个简单的Java解析器来获取 hg log -l 1 命令第一行的输出,但也许有一种更简单的方法(即,更少的代码行??

What would be the easiest way to do so on Windows? I could write a simple Java parser to fetch the output of the first line of the hg log -l 1 command, but perhaps there is an easier way (i.e., less code lines)?

推荐答案

你可以使用 hg identify

hg id 应该在打包步骤中,提交源并生成应用程序的打包(jar)版本。

在此步骤中,您可以生成包含此类信息的version.txt文件。

hg id should be during the packaging step, when the sources have been committed and you generate the packaged (jar) version of your application.
During that step, you can generate a version.txt file with that kind of information.

$ MY_VERSION=$(hg id)
$ echo $MY_VERSION
53efa13dec6f+ tip

(例如,参见 Python的构建标识

这篇关于Java:如何获得用于程序的mercurial当前变更集编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆