You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Mycroft Holmes <ps...@gmail.com> on 2008/03/18 17:24:43 UTC

hint for improved keyword substitution

Here's a modest proposal for svn 1.5 final.
the $PROPERTY: VALUE $ syntax is a nightmare in C/C++ sources.

I'd like to have some directive that replaces the FIRST occurrence of  
a user-specified keyword in the following lines.
imagine something like:

//
// this is a comment
//
// $Revision:  MY_DUMMY_KEYWORD $
//
// svn will leave intact the line above and replace the first  
occurrence of the keyword with its value...
//

#define SVN_REVISION_NUMBER	 MY_DUMMY_KEYWORD


int main()
{
}


Hope someone is listening... :)
MH


Re: hint for improved keyword substitution

Posted by Erik Huelsmann <eh...@gmail.com>.
> >  but this procedure is going to cause BIG problems, since code CHECKED
> >  OUT will build, but code EXPORTED from the repo will not!
> >  so I'm firmly convinced this is an issue for svn.
> >  furthermore, I don't see any practical use for keyword substitution
> >  AS IS, except cosmetic (?) reasons (don't tell me that $REV: nnnn$ is
> >  pleasant :)
> >
> >
>
> Of course SCCS, RCS, and CVS (and I'm sure other version control systems) have
> used this method successfully for a very long time...

I too seem to be missing the point. The standard C approach:

char *derive_revision(void)
{
  static char version[20];
  sscanf("$Revision$", "$Revision: %19s", &version);
  return &version;
}

(Note: untested!)

Bye,

Erik.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: hint for improved keyword substitution

Posted by Troy Curtis Jr <tr...@gmail.com>.
On Wed, Mar 19, 2008 at 3:52 AM, Mycroft Holmes <ps...@gmail.com> wrote:
>
>  On 18 Mar 2008, at 20:34, John Peacock wrote:
>
>  > That's not going to be possible, because the keyword stuff is
>  > strictly line-oriented (by which I mean that it only reads and
>  > processes a single line at a time).
>  >
>
>
>  if this is a problem, I'll modify my proposal: let the $template$ be
>  slightly customizable.
>  for example instead of replacing "$REV$" with "$REV: nnnn $" I'd like
>  svn to replace "// REV$" with "nnnn // REV: nnnn$"
>  (note that the ": nnnn" part is necessary to match the leftmost
>  "nnnn" in a second pass)
>
>  this will do, because I can write
>
>  #define VERSION // REV$
>
>  and svn will change to
>
>  #define VERSION 1234 // REV: 1234$
>
>
>
>
>
>
>  > Perhaps you would like this instead?
>  >
>  >       http://subversion.tigris.org/faq.html#version-value-in-source
>
>  no :)
>  because I want finer granularity: in my project, each source file has
>  its own version number, as an integer (not as a string).
>  at the moment the only way to get this is:
>
>  1) every file X.h starts with
>  #include "version/X.txt"
>
>  (note that this is bad practice, since every file must know its own
>  name...)
>
>  the companion text files (which are not versioned) just state:
>  #define SVN_REV nnnn
>
>  2) before building, preprocess every file and generate all the
>  companion files parsing 'svn info' ...
>
>
>  but this procedure is going to cause BIG problems, since code CHECKED
>  OUT will build, but code EXPORTED from the repo will not!
>  so I'm firmly convinced this is an issue for svn.
>  furthermore, I don't see any practical use for keyword substitution
>  AS IS, except cosmetic (?) reasons (don't tell me that $REV: nnnn$ is
>  pleasant :)
>
>

Of course SCCS, RCS, and CVS (and I'm sure other version control systems) have
used this method successfully for a very long time...

Troy

-- 
Beware of spyware. If you can, use the Firefox browser. - USA Today
Download now at http://getfirefox.com
Registered Linux User #354814 ( http://counter.li.org/)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org


Re: hint for improved keyword substitution

Posted by Martin Furter <mf...@rola.ch>.

On Thu, 20 Mar 2008, John Peacock wrote:

> Mycroft Holmes wrote:
>> the most general approach is to have a macro that resolves to an _integer_ 
>> literal.
>> this enables, for example, statements like:
>> 
>> #if SVN_VERSION < 3000
>
> Please do as I suggested and look at the existing Subversion subst.c code and 
> see if you can suggest something useful.  This "meta design" discussion is 
> not helpful.
>
> These are the design limitations of the current keywords support:
>
> 1) All keywords must be delimited by a known [single] character (currently 
> hardcoded to '$'), in order to be parsed from the character stream;
>
> 2) All keywords must be stored unexpanded in the repository (to mark their 
> location) and will only be expanded in a working copy (or checkout) by the 
> client code;
>
> 3) All expanded keywords must include the keyword as part of the expansion 
> (so that the WC client code can unexpand them again while performing diff, 
> for example);
>
> 4) Expanded keywords cannot span multiple lines.

If custom keywords could contain text and variables it could be done the 
following way:

Define a keyword $commentrev$ which expands to (where 1234 is the rev):
   $commentrev: */ 1234 /* $

Use it like this:
#define SVN_VERSION  /* $commentrev$ */

Expanded it would look like this:
#define SVN_VERSION  /* $commentrev: */ 1234 /* $ */

Just a random idea I had...
Sorry for the noise.
Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: hint for improved keyword substitution

Posted by John Peacock <jo...@havurah-software.org>.
Mycroft Holmes wrote:
> the most general approach is to have a macro that resolves to an 
> _integer_ literal.
> this enables, for example, statements like:
> 
> #if SVN_VERSION < 3000

Please do as I suggested and look at the existing Subversion subst.c code and 
see if you can suggest something useful.  This "meta design" discussion is not 
helpful.

These are the design limitations of the current keywords support:

1) All keywords must be delimited by a known [single] character (currently 
hardcoded to '$'), in order to be parsed from the character stream;

2) All keywords must be stored unexpanded in the repository (to mark their 
location) and will only be expanded in a working copy (or checkout) by the 
client code;

3) All expanded keywords must include the keyword as part of the expansion (so 
that the WC client code can unexpand them again while performing diff, for example);

4) Expanded keywords cannot span multiple lines.

If you can come up with a backwards compatible extension that would make it 
easier to have custom keyword expansions, please feel free to enlighten us.

There is support for enabling custom keywords already in the codebase (by 
building up new keywords based on the elements already present).  But there 
hasn't been an acceptable design to expose that functionality (which comes down 
to a lack of server-resident client configuration).  See this ticket for some 
details:

	http://subversion.tigris.org/issues/show_bug.cgi?id=1974

John

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: hint for improved keyword substitution

Posted by Mycroft Holmes <ps...@gmail.com>.

On 19 Mar 2008, at 20:04, Erik Huelsmann wrote:
>> p.s: the standard approach of embedding a keyword string in  
>> function is
>> waaaay limited: more work at runtime, can't use version numer in
>> preprocessor directives, can't use in templates... and I'm sure I  
>> could list
>> some more serious limitations
>
> Right. Because I don't see how "using it in preprocessor directives"
> can be a serious limitation:

using? _not_ using.
a string literal, as I pointed out, has very limited usage.

the most general approach is to have a macro that resolves to an  
_integer_ literal.
this enables, for example, statements like:

#if SVN_VERSION < 3000



Re: hint for improved keyword substitution

Posted by Erik Huelsmann <eh...@gmail.com>.
On Wed, Mar 19, 2008 at 6:14 PM, Mycroft Holmes <ps...@gmail.com> wrote:
>
>
>
> On 3/19/08, John Peacock <jo...@havurah-software.org> wrote:
> > Mycroft Holmes wrote:
> > > if this is a problem, I'll modify my proposal: let the $template$ be
> > > slightly customizable.
> > > for example instead of replacing "$REV$" with "$REV: nnnn $" I'd like
> > > svn to replace "// REV$" with "nnnn // REV: nnnn$"
> > > (note that the ": nnnn" part is necessary to match the leftmost "nnnn"
> > > in a second pass)
> >
> >
> > This is very C++ biased
>
>
> it is, but you missed my point: note that I said "let the template be
> customizable" and "for example".
> maybe I wasn't totally clear, but I meant to show an _example_ of a possible
> user customization.
>
> a more flexible keyword engine could solve many problems, including mine.
> that's why I propose to change the code... (I vaguely guessed delimiters are
> hardcoded to $ :)
>
> I don't want to say "how general" the solution should be -- simply because I
> don't know, and in fact I specified only what I'd like to do.
>
>
>
>  >I suggest that you actually look at the Subversion source code
>  >(specifically subversion/libsvn_subr/subst.c) and try to come up with a
>  >more general fix
>
> thanks for pointing it out.
>
>
> p.s: the standard approach of embedding a keyword string in function is
> waaaay limited: more work at runtime, can't use version numer in
> preprocessor directives, can't use in templates... and I'm sure I could list
> some more serious limitations

Right. Because I don't see how "using it in preprocessor directives"
can be a serious limitation: it's only the name of something which
resides in your repository.

bye,

Erik.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: hint for improved keyword substitution

Posted by Mycroft Holmes <ps...@gmail.com>.
On 3/19/08, John Peacock <jo...@havurah-software.org> wrote:
>
> Mycroft Holmes wrote:
> > if this is a problem, I'll modify my proposal: let the $template$ be
> > slightly customizable.
> > for example instead of replacing "$REV$" with "$REV: nnnn $" I'd like
> > svn to replace "// REV$" with "nnnn // REV: nnnn$"
> > (note that the ": nnnn" part is necessary to match the leftmost "nnnn"
> > in a second pass)
>
>
> This is very C++ biased


it is, but you missed my point: note that I said "let the template be
customizable" and "for example".
maybe I wasn't totally clear, but I meant to show an _example_ of a possible
user customization.

a more flexible keyword engine could solve many problems, including mine.
that's why I propose to change the code... (I vaguely guessed delimiters are
hardcoded to $ :)

I don't want to say "how general" the solution should be -- simply because I
don't know, and in fact I specified only what I'd like to do.


>I suggest that you actually look at the Subversion source code
>(specifically subversion/libsvn_subr/subst.c) and try to come up with a
>more general fix

thanks for pointing it out.


p.s: the standard approach of embedding a keyword string in function is
waaaay limited: more work at
runtime, can't use version numer in preprocessor directives, can't use
in templates... and I'm sure I could list some
more serious limitations

Re: hint for improved keyword substitution

Posted by John Peacock <jo...@havurah-software.org>.
Mycroft Holmes wrote:
> if this is a problem, I'll modify my proposal: let the $template$ be 
> slightly customizable.
> for example instead of replacing "$REV$" with "$REV: nnnn $" I'd like 
> svn to replace "// REV$" with "nnnn // REV: nnnn$"
> (note that the ": nnnn" part is necessary to match the leftmost "nnnn" 
> in a second pass)

This is very C++ biased and won't work for languages that don't support 
// as a end-of-line comment.  Plus the current code assumes a single 
character delimiter on either side of the raw keyword (obviously 
currently hardcoded to '$'), so your format would be problematic.

I suggest that you actually look at the Subversion source code 
(specifically subversion/libsvn_subr/subst.c) and try to come up with a 
more general fix that would resolve situations other than just your own. 
  This is a much more likely way that something will get added to the 
core code.  Lobbing hacks to the current syntax over the wall probably 
won't get very far... ;-)

John

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: hint for improved keyword substitution

Posted by Mycroft Holmes <ps...@gmail.com>.
On 18 Mar 2008, at 20:34, John Peacock wrote:

> That's not going to be possible, because the keyword stuff is  
> strictly line-oriented (by which I mean that it only reads and  
> processes a single line at a time).
>


if this is a problem, I'll modify my proposal: let the $template$ be  
slightly customizable.
for example instead of replacing "$REV$" with "$REV: nnnn $" I'd like  
svn to replace "// REV$" with "nnnn // REV: nnnn$"
(note that the ": nnnn" part is necessary to match the leftmost  
"nnnn" in a second pass)

this will do, because I can write

#define VERSION // REV$

and svn will change to

#define VERSION 1234 // REV: 1234$





> Perhaps you would like this instead?
>
> 	http://subversion.tigris.org/faq.html#version-value-in-source

no :)
because I want finer granularity: in my project, each source file has  
its own version number, as an integer (not as a string).
at the moment the only way to get this is:

1) every file X.h starts with
#include "version/X.txt"

(note that this is bad practice, since every file must know its own  
name...)

the companion text files (which are not versioned) just state:
#define SVN_REV nnnn

2) before building, preprocess every file and generate all the  
companion files parsing 'svn info' ...


but this procedure is going to cause BIG problems, since code CHECKED  
OUT will build, but code EXPORTED from the repo will not!
so I'm firmly convinced this is an issue for svn.
furthermore, I don't see any practical use for keyword substitution  
AS IS, except cosmetic (?) reasons (don't tell me that $REV: nnnn$ is  
pleasant :)


Re: hint for improved keyword substitution

Posted by John Peacock <jo...@havurah-software.org>.
Mycroft Holmes wrote:
> 
> Here's a modest proposal for svn 1.5 final.

1.5 is rapidly approaching release candidate status; new features are 
not going to be added now.

> the $PROPERTY: VALUE $ syntax is a nightmare in C/C++ sources.


> I'd like to have some directive that replaces the FIRST occurrence of a 
> user-specified keyword in the following lines.
> imagine something like:

That's not going to be possible, because the keyword stuff is strictly 
line-oriented (by which I mean that it only reads and processes a single 
line at a time).

Perhaps you would like this instead?

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

Either of those recipes will DTRT (for some value of "DTRT")...

John

John

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org