3

I am wanting to display in my application current commit number. I use SVN and my code is C#.

I wonder if I can update automatically a text file WITHIN REPOSITORY so it will contain a commit number, eg, displaying it to user.

Currently I am thinking of making a post-commit hook (a shell script that receives several environment variables containing commit info) and "echo" the commit number into that text file. Is it a valid thing to do, to interfere with text files from repository on server side?

Any other means to store build number? I know SVN can modify source codes for some keywords, but then I need to commit these files to get modified. I want to be able to get that revision number updated ALWAYS, not when I commit a particular file.

cspolton
  • 4,495
  • 4
  • 26
  • 34
onkami
  • 8,791
  • 17
  • 90
  • 176
  • 3
    Have you considered using the svn info command during your configure script (or equivalent) to pull the svn revision info during the build instead of storing it directly in the repository? – Perkins Oct 23 '12 at 15:15

4 Answers4

2

What you want to display is not a commit number, but a revision number.

Check the svn info command which outputs the latest revision number in a repository. You can make your application to issue the svn info to know the latest repo revision number.

bahrep
  • 29,961
  • 12
  • 103
  • 150
  • 1
    What if the application is being run by someone who doesn't have access to the repository? Or if the application version isn't the same as the latest commit? – Rawling Oct 23 '12 at 15:25
  • 2
    @Rawling - `svn info` have to be used by developer, only once at build stage, results of command **stored and used** – Lazy Badger Oct 24 '12 at 02:36
  • Ah, as a build step. For some reason I thought you meant have the app get it live :-/ – Rawling Oct 24 '12 at 07:09
1
  1. You haven't to have additional file with global revision number in repository, because repository already have this meta-information
  2. You must not (and can't really) modify repository in post-commit hook
  3. You can get RevID on build-stage only ("build" can be plain export from repo, compile etc...) and write in some unversioned source

If you c#-code, you use Windows, yes?! In this case, except svn info, which output you must pre-parse for usage, you can consider using SubWCRev (part of TortoiseSVN), which transform versioned template file with SubWCRev-keywords into unversioned data file with keywords replaced by actual data from repository-info

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • In order for this to work I should install TortoiseSVN on the machine? I.e. it makes TortoiseSVN a dependency? – bahrep Oct 23 '12 at 15:44
  • 1
    @bahrep - Can't say... Never tried (and haven't) SubWCRev without TSVN. You can test it - you have to have only SubWCRev and WorkingCopy on clean host – Lazy Badger Oct 23 '12 at 15:50
1

Take a look at svn:keywords. You can put $Revision$in your file, and if you have svn:keywords set for that file, Subversion will add the revision number to that string.

From:

 Revision = $Revision$

To:

 Revision = $Revision: 12343$

That shows you that this file was committed in revision 12,343.

Tobias
  • 2,481
  • 3
  • 26
  • 38
David W.
  • 105,218
  • 39
  • 216
  • 337
  • Bad idea, because - 1/ keyword can not be used "as is" 2/ file with keyword must be included in auto-commit list in order to reflect global revision number (HEAD) of repo, not "revision of last change in **this file**" – Lazy Badger Oct 24 '12 at 02:35
  • Expanded keyword seems evn worse, than you wrote `$Revision: 1189 $` (note whitespaces around) – Lazy Badger Oct 24 '12 at 02:42
  • @LazyBadger: This shouldn't be a problem when coding. In Python, for example, I'd write `revision = int('$Revision$'[10:-1])` and have a number. In other languages, you should at least be able to provide an "`extract_number`" function which does this job. – Tobias Nov 14 '19 at 10:05
0

As David pointed out, you can use the svn "$Revision$" keyword. This, of course, will tell you about the revision in which that particular file was changed last.

To know about the overall latest revision in your project, you can use the svnversion commandline tool. After an svn update, you'll always have a single number (but this will be the HEAD revision of the total repository); using the -c or --commited switch, you'll get a first:last range almost certainly, but after the : you'll have the head revision of your project.

Tobias
  • 2,481
  • 3
  • 26
  • 38