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

Re: Syntax help for pre-commit hook

From: Ryan Schmidt <subversion-2006Q1_at_ryandesign.com>
Date: 2006-04-13 23:10:34 CEST

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
Received on Thu Apr 13 23:14:16 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.