NFTX
NFTX

Reputation: 53

SVN log - get only revisions with pattern in comments

I am trying to create a simple bash script that verify which revisions do not contain a certain pattern in its comment.

For example:

------------------------------------------------------------------------
r272876 | user | 2014-10-30 11:15:06 +0000 (Qui, 30 Out 2014) | 1 line

PATTERN-17278: My comment.
------------------------------------------------------------------------
r272877 | user | 2014-10-31 12:06:41 +0000 (Sex, 31 Out 2014) | 1 line

My problematic revision
------------------------------------------------------------------------
r273529 | user | 2014-10-20 17:45:36 +0000 (Seg, 20 Nov 2014) | 2 lines

PATTERN-17297: Erro no angulo do vetor velocidade
------------------------------------------------------------------------    
r273797 | user | 2014-10-14 11:35:05 +0000 (Ter, 4 Nov 2014) | 1 line

Other problematic revision
------------------------------------------------------------------------
r274096 | user | 2014-08-26 11:18:31 +0000 (Qua, 5 Nov 2014) | 1 line

And another

How do I easily print revisions like r272877, r273797 and r274096 in a list?

Upvotes: 2

Views: 336

Answers (1)

John1024
John1024

Reputation: 113864

First, let's define a shell variable that contains the dashed line that SVN uses to separate log entries:

RS='\n------------------------------------------------------------------------'

Now, we can print all all log entries that do not contain pattern:

svn log . | awk -v "RS=$RS" '!/pattern/{print RS,$0}'

Alternatively, if you wanted only log entries that do contain pattern, then use:

svn log . | awk -v "RS=$RS" '/pattern/{print RS,$0}'

How it works

  • -v "RS=$RS"

    awk divides its input into records and reads in one record at a time. Here, we define the record separator to be what SVN uses to separate log entries.

  • !/pattern/{print RS,$0}

    awk implicitly loops through every record in the input. This looks for records that do not contain pattern where pattern can be any regular expression. The exclamation point, !, means "not". Records that meet this criterion, are printed. print RS,$0 tells awk to print the record separator and then the contents of this log entry.

My version of subversion uses 72 dashes as the record separator. I don't know if this is subject to change from version to version. If it is, you may need to adjust the definition of RS appropriately.

Example

Using your sample log output as saved in a file called log, this prints all records not containing PATTERN-17278:

$ awk -v "RS=$RS" '!/PATTERN-17278/{print RS,$0}' log

------------------------------------------------------------------------ 
r272877 | user | 2014-10-31 12:06:41 +0000 (Sex, 31 Out 2014) | 1 line

My problematic revision

------------------------------------------------------------------------ 

Alternative output: Return only the revision numbers

The revision numbers are the first item after the record separator. To print out just revision numbers, use:

svn log . | awk -v "RS=$RS" '!/pattern/{print $1}'

Using the sample input [before question updated] as an example:

$ awk -v "RS=$RS" '!/PATTERN-17278/{print $1}' log2
r2728

Using a variable pattern

awk -v "RS=$RS" -v p='PATTERN-17278|PATTERN-17297' '$0 !~ p{print $1}' log3
r272877
r273797
r274096

Upvotes: 2

Related Questions