[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: tags pattern

From: Ryan Schmidt <subversion-2006q2_at_ryandesign.com>
Date: 2006-06-26 11:44:57 CEST

On Jun 26, 2006, at 08:46, annick collet wrote:

>>> I'd like to modify the pre-commit hook in order that whenever a
>>> transaction is a add in /tags folder, to check that the new-tag
>>> follows naming convention such as 9.9.9[R/T/A]
>>>
>>> How can I test that the tag name is with pattern ?
>>
>> Here's a pre-commit hook script to do this. You'll probably have
>> to adjust the path to svnlook within the script.
>>
>> I hope I got it to check what you wanted to check. I interpreted
>> "9.9.9[R/T/A]" to mean "number, dot, number, dot, number, and then
>> R or T or A". If you meant something different, you'll have to
>> adjust the regular expression.
>>
>> The script was developed on Mac OS X, so I hope it would also
>> work without problems on *BSD systems. Mac OS X uses the BSD
>> version of sed, and I'm worried that the script might not work on
>> Linux or other systems with the GNU sed implementation because it
>> has different switches. Mac OS X has the GNU version of grep.
>>
>> It obviously won't work at all on Windows. You'd need to write a
>> batch script, or a python script or a perl script or a visual
>> basic script or what have you.
>
> Thanks,
>
> Could you pls explain me the SVNLOOK ....... | $SED -E -n 's%
> ^A (.+/)?tags/%%p' | $SED -E 's%/.*$%%'
>
> SED -E ?

I can try. Since this explanation has gotten a bit long, I'm sending
it to the list too, in case anyone else had questions about the script.

The line in the script is:

TAGS=`$SVNLOOK changed -t "$TXN" "$REPOS" | $SED -E -n 's%^A (.+/)?
tags/%%p' | $SED -E 's%/.*$%%'`

The purpose is to set the variable TAGS to the list of all tags being
committed in the current transaction. The way it does this is as
follows:

First, it runs "svnlook changed" to get the list of all changed paths
in the transaction:

$SVNLOOK changed -t "$TXN" "$REPOS"

"svnlook changed" is described in the Subversion book at http://
svnbook.org/ and if you run it yourself against a revision of your
repository where you've added a tag, you'll see that its output looks
like this:

A tags/tagname/

Or, if you have several projects in one repo:

A projectname/tags/tagname/

There's always an A in the first column to indicate the thing was
added, then there's three spaces, and then there's the path that was
added. I want to get rid of the A and the spaces, the project path if
there is one, the word "tags," and the slashes. So I pipe the output
of svnlook through sed, the Stream EDitor:

$SED -E -n 's%^A (.+/)?tags/%%p'

The "-E" flag to sed, in the BSD version of sed which I used, makes
it use what we consider "normal" regular expressions today, instead
of the more-primitive regular expressions that were originally
available. Regular expressions are powerful and too complex to
explain here in their entirety, but there are many many references
that can help you learn them. Here's a place to start:

http://en.wikipedia.org/wiki/Regular_expressions

sed usually prints every line of input to its output. I didn't want
that, so I used the "-n" switch. Then I used the sed "s" command:

s%^A (.+/)?tags/%%p

"s" stands for "substitute." I'm matching the regular expression
"^A (.+/)?tags/", replacing it with the empty string (because
there's nothing between the second and third "%"), and the "p"
modifier at the end means that I want these matched lines printed out
(after the substitution). The regular expression matches the A, the
spaces, an optional project name, the word "tags" and the slash,
anchored to the beginning of the string, and strips it all off,
leaving just the name of the tag, and the slash at the end. (In my
example above, that would be "tagname/")

But I don't want the slash at the end either. So I run it through sed
a second time:

$SED -E 's%/.*$%%'`

Here the regular expression is much simpler: "/.*$". I match a slash,
followed by anything, anchored to the end of the string, and delete
it. We're left with just the tag name, and that's what's assigned to
the TAGS variable. If there are multiple tags, then they're all
assigned to the TAGS variable, over which the script then loops to
match each tag name against another regular expression to see if it
conforms to site policy.

I probably didn't need to call sed twice... Probably could have done
it in a single invocation, but I didn't think too much about it at
the time.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Mon Jun 26 11:46:53 2006

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.