You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Phil <pl...@gmail.com> on 2006/04/12 17:20:10 UTC

Syntax help for pre-commit hook

Hi,

I need help with the syntax for a pre commit hook script.
I want to check that svn:need-lock is set on files before the are commited.

I looked at the default pre-commit hook but I am not much of a programmer
and I cannot figure out the syntax for what I want to accomplish.

Thanks for your help.

Re: Syntax help for pre-commit hook

Posted by Phil <pl...@gmail.com>.
I take it back it does work. Thanks alot!!!!!!

On 4/13/06, Phil <pl...@gmail.com> wrote:
>
> I tried it and it did not work.
>
> I have subversion installed on a linux box and I put in the correct path's
> for svnlook and sed... any change we can chat again on Monday to see how to
> make this work?
>
>
> On 4/12/06, Phil <pl...@gmail.com> wrote:
> >
> > Thanks I will try it out and let you know if it worked...
> > That SED line looks very complicated... almost every symbol on the
> > keyboard other than the numbers and letters... :)
> >
> > Thanks
> >
> >
> > On 4/12/06, Ryan Schmidt <su...@ryandesign.com> wrote:
> > >
> > > On Apr 12, 2006, at 19:20, Phil wrote:
> > >
> > > > I need help with the syntax for a pre commit hook script.
> > > > I want to check that svn:need-lock is set on files before the are
> > > > commited.
> > > >
> > > > I looked at the default pre-commit hook but I am not much of a
> > > > programmer and I cannot figure out the syntax for what I want to
> > > > accomplish.
> > >
> > > I wrote the attached script for you which seems to work, assuming you
> > > have a Unix-like server. You'll need to configure the paths to the
> > > svnlook and sed executables. Unfortunately I'm not one enough with
> > > sed to understand why, but the way I used sed only seems to work with
> > > GNU sed, not BSD sed. Outrageous theories about this are gladly
> > > accepted. If you have a Windows server, then someone will first have
> > > to convert this shell script to something that runs on Windows.
> > >
> > >
> > >
> > >
> > >
> >
>

Re: Syntax help for pre-commit hook

Posted by Phil <pl...@gmail.com>.
I tried it and it did not work.

I have subversion installed on a linux box and I put in the correct path's
for svnlook and sed... any change we can chat again on Monday to see how to
make this work?

On 4/12/06, Phil <pl...@gmail.com> wrote:
>
> Thanks I will try it out and let you know if it worked...
> That SED line looks very complicated... almost every symbol on the
> keyboard other than the numbers and letters... :)
>
> Thanks
>
>
> On 4/12/06, Ryan Schmidt <su...@ryandesign.com> wrote:
> >
> > On Apr 12, 2006, at 19:20, Phil wrote:
> >
> > > I need help with the syntax for a pre commit hook script.
> > > I want to check that svn:need-lock is set on files before the are
> > > commited.
> > >
> > > I looked at the default pre-commit hook but I am not much of a
> > > programmer and I cannot figure out the syntax for what I want to
> > > accomplish.
> >
> > I wrote the attached script for you which seems to work, assuming you
> > have a Unix-like server. You'll need to configure the paths to the
> > svnlook and sed executables. Unfortunately I'm not one enough with
> > sed to understand why, but the way I used sed only seems to work with
> > GNU sed, not BSD sed. Outrageous theories about this are gladly
> > accepted. If you have a Windows server, then someone will first have
> > to convert this shell script to something that runs on Windows.
> >
> >
> >
> >
> >
>

Re: Syntax help for pre-commit hook

Posted by Phil <pl...@gmail.com>.
Thanks I will try it out and let you know if it worked...
That SED line looks very complicated... almost every symbol on the keyboard
other than the numbers and letters... :)

Thanks

On 4/12/06, Ryan Schmidt <su...@ryandesign.com> wrote:
>
> On Apr 12, 2006, at 19:20, Phil wrote:
>
> > I need help with the syntax for a pre commit hook script.
> > I want to check that svn:need-lock is set on files before the are
> > commited.
> >
> > I looked at the default pre-commit hook but I am not much of a
> > programmer and I cannot figure out the syntax for what I want to
> > accomplish.
>
> I wrote the attached script for you which seems to work, assuming you
> have a Unix-like server. You'll need to configure the paths to the
> svnlook and sed executables. Unfortunately I'm not one enough with
> sed to understand why, but the way I used sed only seems to work with
> GNU sed, not BSD sed. Outrageous theories about this are gladly
> accepted. If you have a Windows server, then someone will first have
> to convert this shell script to something that runs on Windows.
>
>
>
>
>

Re: Syntax help for pre-commit hook

Posted by Phil <pl...@gmail.com>.
WOW...
Thanks for the explanation...
I will need to read up on Sed... However I have used the explanation to help
me modify another script that I needed.


On 4/13/06, Ryan Schmidt <su...@ryandesign.com> wrote:
>
> Hi Phil. I'll CC the users list on this reply in case anyone else was
> wondering.
>
>
> On Apr 13, 2006, at 22:21, Phil wrote:
>
> > I have two questions about the script. It works great. In fact it
> > helped me modify another script so that I could add comments to the
> > error output.
> >
> > 1- $SED -n 's/^\(A\|.U\)\s*\(.*[^/]\)$/\2/p'`   what is this part
> > doing :)
>
> Ah, regular expressions. My favorite. :-) sed is not my favorite. But
> it'll do in a pinch.
>
> sed normally prints all lines of its input. I wanted only certain
> lines. So "-n" tells it not to print by default, and the "p" at the
> end of the line says to print the things that match the preceding
> regular expression.
>
> The "s" at the beginning of the argument to sed means "substitute." I
> want to replace the thing I match with another thing. What I match is
> this:
>
> ^\(A\|.U\)\s*\(.*[^/]\)$
>
> Breaking it down:
>
> ^           anchor the match to the beginning of the line
> \(A\|.U\)   an "A" as the first character (meaning the item was
> added), or
>              a "U" as the second character (meaning its properties
> were updated)
> \s*         any amount of whitespace
> \(.*[^/]\)  any amount of anything that doesn't end in a slash -- so
> this
>              is how the directories are excluded, since they end in a
> slash
> $           anchor the match to the end of the line
>
> Then, after the next slash, is what I replace this all with: \2,
> meaning the second parenthesized expression above, meaning the path
> of the file.
>
>
> > 2- # Attempt to get the svn:needs-lock property.
> >     $SVNLOOK propget -t "$TXN" "$REPO" svn:needs-lock "$a_file" >/
> > dev/null 2>&1
> >
> >     # Exit and alert if an error occurred doing that.
> >     if [ $? -ne 0 ]; then
> >         echo "File $a_file doesn't have the svn:needs-lock property
> > set." 1>&2
> >         echo "Repository policy dictates that all files must set
> > the svn:needs-lock property." 1>&2
> >         exit 1
> >     fi
> >
> > why is is I need the 2>1& and the 1>2& added to these lines?
>
> I only cared about the exit code of svnlook. I didn't care about its
> stdout or stderr output and wanted to throw it away. So I directed
> stdout to the trash (">/dev/null") and sent stderr to the same place
> I'd just sent stdout ("2>&1").
>
> If a pre-commit hook exits with a nonzero status, then the svn client
> will output to the user's screen anything that the hook emitted on
> stderr. Anything sent to stdout is ignored. echo sends its output to
> stdout, not stderr, so I had to redirect stdout (stream 1) to stderr
> (stream 2) for it to go to the right place for the svn client to see it.
>
>
>
>

Re: Syntax help for pre-commit hook

Posted by Ryan Schmidt <su...@ryandesign.com>.
Hi Phil. I'll CC the users list on this reply in case anyone else was  
wondering.


On Apr 13, 2006, at 22:21, Phil wrote:

> I have two questions about the script. It works great. In fact it  
> helped me modify another script so that I could add comments to the  
> error output.
>
> 1- $SED -n 's/^\(A\|.U\)\s*\(.*[^/]\)$/\2/p'`   what is this part  
> doing :)

Ah, regular expressions. My favorite. :-) sed is not my favorite. But  
it'll do in a pinch.

sed normally prints all lines of its input. I wanted only certain  
lines. So "-n" tells it not to print by default, and the "p" at the  
end of the line says to print the things that match the preceding  
regular expression.

The "s" at the beginning of the argument to sed means "substitute." I  
want to replace the thing I match with another thing. What I match is  
this:

^\(A\|.U\)\s*\(.*[^/]\)$

Breaking it down:

^           anchor the match to the beginning of the line
\(A\|.U\)   an "A" as the first character (meaning the item was  
added), or
             a "U" as the second character (meaning its properties  
were updated)
\s*         any amount of whitespace
\(.*[^/]\)  any amount of anything that doesn't end in a slash -- so  
this
             is how the directories are excluded, since they end in a  
slash
$           anchor the match to the end of the line

Then, after the next slash, is what I replace this all with: \2,  
meaning the second parenthesized expression above, meaning the path  
of the file.


> 2- # Attempt to get the svn:needs-lock property.
>     $SVNLOOK propget -t "$TXN" "$REPO" svn:needs-lock "$a_file" >/ 
> dev/null 2>&1
>
>     # Exit and alert if an error occurred doing that.
>     if [ $? -ne 0 ]; then
>         echo "File $a_file doesn't have the svn:needs-lock property  
> set." 1>&2
>         echo "Repository policy dictates that all files must set  
> the svn:needs-lock property." 1>&2
>         exit 1
>     fi
>
> why is is I need the 2>1& and the 1>2& added to these lines?

I only cared about the exit code of svnlook. I didn't care about its  
stdout or stderr output and wanted to throw it away. So I directed  
stdout to the trash (">/dev/null") and sent stderr to the same place  
I'd just sent stdout ("2>&1").

If a pre-commit hook exits with a nonzero status, then the svn client  
will output to the user's screen anything that the hook emitted on  
stderr. Anything sent to stdout is ignored. echo sends its output to  
stdout, not stderr, so I had to redirect stdout (stream 1) to stderr  
(stream 2) for it to go to the right place for the svn client to see it.




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

Re: Syntax help for pre-commit hook

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Apr 12, 2006, at 19:20, Phil wrote:

> I need help with the syntax for a pre commit hook script.
> I want to check that svn:need-lock is set on files before the are  
> commited.
>
> I looked at the default pre-commit hook but I am not much of a  
> programmer and I cannot figure out the syntax for what I want to  
> accomplish.

I wrote the attached script for you which seems to work, assuming you  
have a Unix-like server. You'll need to configure the paths to the  
svnlook and sed executables. Unfortunately I'm not one enough with  
sed to understand why, but the way I used sed only seems to work with  
GNU sed, not BSD sed. Outrageous theories about this are gladly  
accepted. If you have a Windows server, then someone will first have  
to convert this shell script to something that runs on Windows.