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

RE: Stats for a file.

From: Reedick, Andrew <jr9445_at_ATT.COM>
Date: Wed, 12 Mar 2008 11:43:01 -0500

Funny you should ask for that. I wrote a script yesterday to do that
very thing. However, AT&T owns the script. =/

 

It will walk each file in each revision for a range of revisions and get
the number of lines added and deleted per file revision in the
revision_range.

 

The general algorithm was

1) Get the revisions to search

                                cmd = 'svn log --xml -v --stop-on-copy
-r %d:1 %s' % (head ,branch)

2) Parse the xml to get the filename entries for each revision.
(However, there's no easy way to tell if a filename is a dir or file,
but we don't care (see below)) I used Python's xml.etree.ElementTree

3) Xml: for each logentry in /log

a. Xml: For each path in logentry/paths

                                                               i.
If the path/action is 'D', skip it

                                                             ii.
(optional) if the path's filename has '/vendor/' skip it

                                                            iii. If
path/copyfrom-path attribute exists, skip it (it's a product of 'svn
copy', No free lines for you!)

                                                           iv. Get
line count metrics

1. svn_path = url_root + path.text + '@' + str(revision) # Peg
revisions are important, especially if a file's parent dir was renamed

2. svn diff -c$Revision -x "-u -w -ignore-eol-style" svn_path

3. If diff is successful

a. Ignore the first pair of '-' and '++' lines

b. Count the '^-' as deletes

c. Count the '^+' as adds

4. Else diff had an error, which might be ok

a. If the stderr starts with 'svn: Unable to find repository
location for' then

 
i. We're ok. 'svn diff -c' will fail to run against the very first
revision of a file. We'll run 'svn cat...' instead (see below)

b. Else

 
i. Unknown error, print a warning

 
ii. Exit_code = 1

 
iii. Continue/next

c. For each line in 'svn cat -r $revision' svn _path'

 
i. Count each line as an add

d. If 'svn cat... ' threw an error, then

 
i. Ignore any error that starts with 'svn: warning: URL' and ends
with 'refers to a directory'

e. Else

 
i. Unknown error, print a warning

 
ii. Exit_code = 1

 
iii. Continue/next

5. Save statistics

4) Print statistics

5) Exit(exit_code)

 

 

 'svn diff' won't report on binary files, so no worries there ('svn
diff' returns no data instead of an error.)

 

 

 

From: Gavin 'Beau' Baumanis [mailto:gavin_at_thespidernet.com]
Sent: Wednesday, March 12, 2008 2:18 AM
To: Subversion Users
Subject: Stats for a file.

 

Hi Everyone,

i would a report of some description that will display how many lines
were edited in a particular set of files between two revisions.
I.e. 1000 lines (combined total) were edit between revision X and HEAD
in a, b, c, d, e, files.

And of course, if it is all possible what might be the required syntax
to obtain such information!

As always, thanks in advance for any assistance.

- Gavin

*****

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA623
Received on 2008-03-12 17:44:13 CET

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.