How to get the current revision number into a file after export?

不羁岁月 提交于 2019-12-08 08:41:15

问题


I'm maintaining a homebrew web-based CRM that I version-control with Subversion. What I want is to have the revision number written into a file after I do an export to the production server so that I can display it in the CRM's status page for debugging reasons.

Is there any way to do this with command-line tools?


回答1:


Technically, you can't be sure after doing the export, because another commit might have happened just in-between. Practically, you can get the information with svn info <URL>. You could of course do the svn info first, extract the revision and export that revision to make sure both correspond.

If you do a checkout instead of an export, the information is available through svn info <path>.

Another way to do that is to use keywords in one of your exported file (let's call it script.h), like this:

#define VERSION_STRING  "r$Revision$"
// ... rest of the file

If you give the svn:keywords property to your file (and commit it), the $Revision$ will be substituted at checkout or export:

svn propset svn:keywords "Revision" script.h

(there are other substitutions, check the SVN documentation for further details)




回答2:


You can use keyword substitution to always have the information present in a file.




回答3:


If you use Ant as your build tool, you can write a custom Ant task to grab the information from a remove Subversion server, store them into the Ant project's properties and use substitution to place these values into some properties/class.

Since you're certainly building you production application from a Subversion tags, you will not have the risk to display a wrong information (like RegGlyph mentioned)



来源:https://stackoverflow.com/questions/1620598/how-to-get-the-current-revision-number-into-a-file-after-export

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!