1

Is there a way to show the SVN version of a file, inside the file?

We use SVN for version control. We primarily code in PHP.

What I am trying to do:

So I would like to show what SVN version # the file is inside the head comment block. So I was curious if there is some set of SVN functions/tags that would do that automatically, without having to remember to update the number everytime you commit.

Or I just thought of this one, is there some kind of string replace tag that you could put into the file, that way when you commit to SVN, SVN would swap out the tag with the specific piece of information?

Thank you.

2 Answers 2

3

Yes using the SVN keyword $Revision - see v1.4 of the SVN book for other keywords and how to configure SVN to do the keyword substitution. The keywords can be placed in a comment block as in the following example:

<?php
/*
  $LastChangedDate$
  $Revision$
*/
?>

v1.6 of SVN introduced additional keywords which might be used, depending on the version you have installed. The latest SVN version at the time of writing is v1.7

Sign up to request clarification or add additional context in comments.

5 Comments

And where exactly would the OP put that into a plain old PHP script?
Oh, I see...SVN fills this information upon update, huh? Yeah, that makes sense...didn't know that either. I was looking at a more...dynamic approach.
@ATaylor Yes, when the file is committed SVN performs keyword substitution and fills in the values
@andyb you link to old version of the book
@WebnetMobile.com I did not want to recommend a keyword that might not exist but I take your point about being clearer. Updated answer coming up.
0

According to the PHP documentation, assuming you've got SVN via PHP enabled, you could run

$status = svn_status(__FILE__);
echo $status['revision'];

in the script, where you want to output the svn-revision. The documentation can be found here: http://www.php.net/manual/en/function.svn-status.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.