本文介绍了如何在PHP页面上显示hg存储库的当前工作副本版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在大多数项目中都使用Mercurial,并且在部署网站时,我只需要在生产服务器上执行hg clone,然后在其中执行hg pull -u.我想做的是在网站的页脚中添加一小段代码,该代码段显示当前的修订号(十进制和十六进制)以及当前的分支.堆栈溢出和BitBucket都可以满足我的需求.

I use Mercurial for most of my projects and when I deploy a web site, I simply just do an hg clone on the production server and hg pull -u from there. What I'd like to do is add a small snippet to my site's footer which displays the current revision number (both decimal and hex) as well as perhaps the current branch. Stack Overflow and BitBucket both do a variation of what I'm looking for.

我短暂地尝试解析exec('hg summary')的输出,但是在想知道是否还有更好的方法之前,我遇到了一些权限问题.有没有更好的方法,还是exec是我的最佳选择?

I briefly tried parsing the output of exec('hg summary'), but I ran into a couple permissions problems before wondering if there was any better way to do it. Is there a better way, or is exec my best option?

推荐答案

您可以使用更新后挂钩将信息放入文件中.在网站的.hg/hgrc中,您应该输入以下内容:

You could use a post-update hook to put the information in a file. In the site's .hg/hgrc you'd put something like this:

[hooks]
post-update = hg id --rev > VERSION ; hg id --id >> VERSION

然后您可以从php内部访问该文件.您仍然需要确保运行hg pull -u的用户信任hgrc文件,并且VERSION文件具有权限,以便网络服务器可以读取它.

then you can access that file from inside your php. You'll still need to make sure that the user running the hg pull -u trusts the hgrc file and that the VERSION file has permissions such that the webserver can read it.

这篇关于如何在PHP页面上显示hg存储库的当前工作副本版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 21:41