Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Find svn log revisions with log message matching a given string

by bellaire (Hermit)
on Jan 26, 2010 at 19:02 UTC ( [id://819750]=CUFP: print w/replies, xml ) Need Help??

To find the revision number where a particular string appears in the revision log, you can use grep and hope there's enough context for you to see the revision header. Or you could do this:
svn log svn_url | perl -e '$/="-"x72;while(<STDIN>){print"$r\n"if((($ +r)=split)&&/@ARGV/)}' search_term

Where svn_url is the repository path you're interested in, and search_term is the thing to search for. Basically, it just remembers the last revision number to have appeared before your search term, and prints it. Will break if for some reason you are fond of putting horizontal rules (i.e. 72 consecutive - characters) in your commit messages.

Note that search_term will be interpolated as a regex, so while you can use e.g. foo\|bar, if you use special characters (such as .) they will have their special meanings unless escaped.

I would rather do -n than while (<STDIN>) {...}, but perl then treats my search term as a file to be processed, which makes me sad. Suggestions for improvements are welcome.

Replies are listed 'Best First'.
Re: Find svn log revisions with log message matching a given string
by hossman (Prior) on Jan 27, 2010 at 02:30 UTC
    Will break if for some reason you are fond of putting horizontal rules (i.e. 72 consecutive - characters) in your commit messages.

    You're depending on some implementation specific markup that won't necessarily exist for every client. The XML format (svn log --xml {url}) is a bit more standard if you want to parse it with tools (or you might consider using SVN::Client)

    I would rather do -n than while (<STDIN>) {...}, but perl then treats my search term as a file to be processed, which makes me sad.

    That's because you are reading from @ARGV after the <> operator (generated by -n) is. Try something like...

    perl -ne 'BEGIN{$/="-"x72; $re = shift} print"$r\n"if((($r)=split)&&/$ +re/)' search_term

    ...or...

    perl -lne 'BEGIN{$/="-"x72; $re = shift} /$re/ and ($_)=split and prin +t' search_term
        You're depending on some implementation specific markup that won't necessarily exist for every client. The XML format (svn log --xml {url}) is a bit more standard if you want to parse it with tools (or you might consider using SVN::Client)

      Good point, that's true, but parsing XML properly is more of a full script than this. Once I've gone that far I'd want to include more features... beyond the intended scope of this solution. I have no problem with the fact that this method is limited to clients that produce output in this particular format.

        That's because you are reading from @ARGV after the <> operator (generated by -n) is. Try something like...

      Great, that's what I needed to know. :) I like the use of -l for the cleaner split and print as well.

Re: Find svn log revisions with log message matching a given string
by Anonymous Monk on May 18, 2014 at 22:39 UTC
    I am using windows activestate perl module, and this does work on windows. Any idea?
    C:\Users\HP>svn log --limit 10 https://mySVN | perl -ne 'BEGIN{$/="-"x +72; $re = shift} print"$r\n"if((($r) =split)&&/$re/)' 2.5996485 Can't find string terminator "'" anywhere before EOF at -e line 1.
      On Windows, single quotes are not special in the shell. Use double quotes instead.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Thanks for the response, but I tried with double quotes and I am getting following error.

        C:\Users\HP>svn log --limit 10 https://mySVN | perl -ne 'BEGIN{$/="-"x +72; $re = shift} print"$r\n"if((($r) =split)&&/$re/)' 2.5996485
        Backslash found where operator expected at -e line 1, near "$r\" (Missing operator before \?) Can't use an undefined value as a symbol reference at -e line 1, <> chunk 1.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://819750]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found