SVN: Head revision number auto update in code files

1,545 views
Skip to first unread message

Eilers Stefan

unread,
Aug 14, 2013, 2:33:16 AM8/14/13
to us...@tortoisesvn.tigris.org

Dear Sir or Madam,

 

I want to implement the head revision number in my C project at the file version.h.

Unfortunately there is only the codeword $Revision$ to set the last revision where the file version.h was changed:

#define VERSION      " FW.Vers. 0.0 $Revision: 146 $\n"

 

Is it possible to implement the Keyword $Head$ to always (every commit) update the string to the head revision number?

e.G.:

#define VERSION      " FW.Vers. 0.0 $Head: 153 $\n"

The problem was detected e.G. here:

http://hobiger.org/blog/2013/04/18/svn-revision-number-in-c-code-an-impossible-task/

 

See SVN Manual (V1.8): 4.17.1.1. svn:keywords

 

Best regards

 

Stefan Eilers

M.Sc., Dipl.-Ing (FH)
Entwickler
IK Elektronik GmbH

Tel. +49 (0)351 426403-82
Fax +49 (0)351 426403-72
eilers...@ik-elektronik.com

 

Niederlassung Dresden:
Hugo-Junkers-Ring 5, Haus 107/W
D - 01109 Dresden


Hauptsitz Hammerbrücke:
Friedrichsgrüner Str. 11-13
D - 08262 Muldenhammer
Geschäftsführer: Jan-Erik Kunze
HRB 22126, Amtsgericht Chemnitz

www.ik-elektronik.com


Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Sollten Sie nicht der richtige Adressat sein oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.

 

Elias Gerber

unread,
Aug 14, 2013, 5:55:50 AM8/14/13
to us...@tortoisesvn.tigris.org
On 14.08.2013 08:33, Eilers Stefan wrote:

Dear Sir or Madam,

 

I want to implement the head revision number in my C project at the file version.h.

Unfortunately there is only the codeword $Revision$ to set the last revision where the file version.h was changed:

#define VERSION      " FW.Vers. 0.0 $Revision: 146 $\n"

 

Is it possible to implement the Keyword $Head$ to always (every commit) update the string to the head revision number?

e.G.:

#define VERSION      " FW.Vers. 0.0 $Head: 153 $\n"

The problem was detected e.G. here:

http://hobiger.org/blog/2013/04/18/svn-revision-number-in-c-code-an-impossible-task/


Why do you need the revision in the file commited? I guess you want to display the version somewhere in the binary program?
We do this by creating a file version.h.template that contains the $Revision keyword. In a pre-build step we copy the version.h.template to version.h, then run subwcrev to replace $Revision with the svn-revision value. Then we start the build-process that uses version.h.
version.h.template is added to svn (but it never changes) while version.h is ignored in svn, so that we dont run into the same chicken-egg-problem.
I dont know if this approach solves your task, just an idea.
Cheers Elias

Lorenz

unread,
Aug 14, 2013, 6:19:11 AM8/14/13
to us...@tortoisesvn.tigris.org
Eilers Stefan wrote:

>I want to implement the head revision number in my C project at the file version.h.

http://subversion.apache.org/faq.html#version-value-in-source
--

Lorenz

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=3062609

To unsubscribe from this discussion, e-mail: [users-un...@tortoisesvn.tigris.org].

Bob Archer

unread,
Aug 14, 2013, 11:20:39 AM8/14/13
to us...@tortoisesvn.tigris.org
> I want to implement the head revision number in my C project at the file
> version.h.
> Unfortunately there is only the codeword $Revision$ to set the last revision
> where the file version.h was changed:
> #define VERSION      " FW.Vers. 0.0 $Revision: 146 $\n"
>
> Is it possible to implement the Keyword $Head$ to always (every commit)
> update the string to the head revision number?
> e.G.:
> #define VERSION      " FW.Vers. 0.0 $Head: 153 $\n"
>
> The problem was detected e.G. here:
> http://hobiger.org/blog/2013/04/18/svn-revision-number-in-c-code-an-
> impossible-task/
>
> See SVN Manual (V1.8): 4.17.1.1. svn:keywords
>
> Best regards

I'm pretty sure keyword expansion is done on checkout/update not on commit. So, no, I doubt this would be possible. Generally you should have your build scripts set the version in your header file to match the HEAD revision.

BOb

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=3062623

Stefan Küng

unread,
Aug 14, 2013, 3:09:34 PM8/14/13
to us...@tortoisesvn.tigris.org
On 14.08.2013 12:19, Lorenz wrote:
> Eilers Stefan wrote:
>
>> I want to implement the head revision number in my C project at the file version.h.
>
> http://subversion.apache.org/faq.html#version-value-in-source
>

Better:
http://tortoisesvn.net/faq.html#subwcrev

Stefan

--
___
oo // \\ "De Chelonian Mobile"
(_,\/ \_/ \ TortoiseSVN
\ \_/_\_/> The coolest interface to (Sub)version control
/_/ \_\ http://tortoisesvn.net

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=3062635

Lorenz

unread,
Aug 15, 2013, 2:20:07 AM8/15/13
to us...@tortoisesvn.tigris.org
Stefan Küng wrote:

>On 14.08.2013 12:19, Lorenz wrote:
>> Eilers Stefan wrote:
>>
>>> I want to implement the head revision number in my C project at the file version.h.
>>
>> http://subversion.apache.org/faq.html#version-value-in-source
>>
>
>Better:
>http://tortoisesvn.net/faq.html#subwcrev

if you're on windows 8-)
--

Lorenz

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=3062662

Ulrich Eckhardt

unread,
Aug 15, 2013, 3:17:48 AM8/15/13
to us...@tortoisesvn.tigris.org
Am 14.08.2013 08:33, schrieb Eilers Stefan:
> I want to implement the head revision number in my C project at the
> file version.h.
>
> Unfortunately there is only the codeword $Revision$ to set the last
> revision where the file version.h was changed:
>
> #define VERSION " FW.Vers. 0.0 $Revision: 146 $\n"

In most cases when someone asks for something like this, their desire
for this is to use it to achieve something else. Using the repository's
revision number is a bad idea though, because all it represents is the
sequence number of its internal state. For determining versions of
projects, it is useless and even confusing, because it is incremented on
any change in any branch of any project contained in that repository.
Even worse, checking out an old revision will not give you the same HEAD
revision as before the last commit. Lastly, you have to remember, SVN
doesn't define the term "project" at all, let alone support it in any
way, but just versions a tree of files in a repository.

Therefore: Use proper branches/tags where you assign meaningful names
and then use e.g. the $Id$ keyword to retrieve that part of the name or
maybe even set it in the according commit. Alternatively, stop
complaining that some solution doesn't work for your problem and
describe the actual problem instead.

Uli
**************************************************************************************
Domino Laser GmbH, Fangdieckstra�e 75a, 22547 Hamburg, Deutschland
Gesch�ftsf�hrer: Hans Robert Dapprich, Amtsgericht Hamburg HR B62 932
**************************************************************************************
Visit our website at http://www.dominolaser.com
**************************************************************************************
Diese E-Mail einschlie�lich s�mtlicher Anh�nge ist nur f�r den Adressaten bestimmt und kann vertrauliche Informationen enthalten. Bitte benachrichtigen Sie den Absender umgehend, falls Sie nicht der beabsichtigte Empf�nger sein sollten. Die E-Mail ist in diesem Fall zu l�schen und darf weder gelesen, weitergeleitet, ver�ffentlicht oder anderweitig benutzt werden.
E-Mails k�nnen durch Dritte gelesen werden und Viren sowie nichtautorisierte �nderungen enthalten. Domino Laser GmbH ist f�r diese Folgen nicht verantwortlich.
**************************************************************************************

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=3062663

Bob Archer

unread,
Aug 15, 2013, 12:48:48 PM8/15/13
to us...@tortoisesvn.tigris.org
> On 14.08.2013 12:19, Lorenz wrote:
> > Eilers Stefan wrote:
> >
> >> I want to implement the head revision number in my C project at the file
> version.h.
> >
> > http://subversion.apache.org/faq.html#version-value-in-source
> >
>
> Better:
> http://tortoisesvn.net/faq.html#subwcrev
>
> Stefan

When I try to hit the link in this topic to see the version.in file, I get a basic auth prompt. Is the tsvn repo not readable by anon callers?

BOb

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=3062688

Sergey Azarkevich

unread,
Aug 26, 2013, 12:25:19 AM8/26/13
to us...@tortoisesvn.tigris.org

When I try to hit the link in this topic to see the version.in file, I get a basic auth prompt. Is the tsvn repo not readable by anon callers?

BOb


Reply all
Reply to author
Forward
0 new messages