Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy way to embed svn revision number in page in PHP?

Notice in the bottom right hand corner of this page it has the SVN revision id? I'm assuming that's dynamic.

I'd love to add that to some of my sites, just as a comment in the source to make sure code pushes are going through.

NOTE: You can also assume that the working directory of the site in question is an svn checkout of the repo in question.

Edit: I'm looking for the global revision number, not the revision number of the file I'm looking at.

like image 305
Brent Avatar asked Sep 28 '08 08:09

Brent


People also ask

How do I find my SVN revision number?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

What is head revision and revision in SVN?

The HEAD revision refers to the most current revision in a repository. If you are browsing the HEAD revision of your repository and one of your teammates commits a change, those new changes will be included when you decide to check out a working copy of that revision or fetch specific information about it.

What is a revision in SVN?

Every time you commit a set of changes, you create one new “revision” in the repository. Each revision represents the state of the repository tree at a certain point in its history. If you want to go back in time you can examine the repository as it was at revision N.

How does SVN revision number work?

Unlike most version control systems, Subversion's revision numbers apply to the entire repository tree, not individual files. Each revision number selects an entire tree, a particular state of the repository after some committed change.


2 Answers

The keyword subsitution method isn't reliable because it will provide the revision of the file rather than the whole codebase that you're deploying, which I presume is what you're after.

Typically I use ANT to deploy from subversion, and in the build script I'd use the replace task to substitue a revision token in a layout template or common header file with the revision number of the codebase that I'm deploying - see below. Although if anyone has a better method I'd love to hear it!

 <svn username="${svn.username}" password="${svn.password}" javaHL="${svn.javahl}">      
   <status path="${dir.build}" revisionProperty="svn.status.revision" />
 </svn>

 <replace dir="${dir.build}" token="%revision%" value="${svn.status.revision}">
   <include name="**/*.php" />
 </replace>
like image 39
Brian Sadler Avatar answered Oct 13 '22 01:10

Brian Sadler


You can use the svnversion CLI utility to get a more specific look at the revision, including the highest number. You could then use regular expressions to parse this.

Subversion has no concept of a global revision; rather, you'd have to recursively look through the working copy to find the highest revision number. svnversion does that for you.

like image 175
Sören Kuklau Avatar answered Oct 12 '22 23:10

Sören Kuklau