You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Gavin 'Beau' Baumanis <ga...@thespidernet.com> on 2008/03/12 06:17:57 UTC

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

RE: Stats for a file.

Posted by "Reedick, Andrew" <jr...@ATT.COM>.
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@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



Re: Stats for a file.

Posted by Mark Reibert <sv...@reibert.com>.
On Wed, 2008-03-12 at 11:34 -0400, Paul Koning wrote:
> >>>>> "Gavin" == Gavin Baumanis <Gavin> writes:
> 
>  Gavin> Hi Everyone, i would a report of some description that will
>  Gavin> display how many lines were edited in a particular set of
>  Gavin> files between two revisions.  I.e. 1000 lines (combined total)
>  Gavin> were edit between revision X and HEAD in a, b, c, d, e, files.
> 
>  Gavin> And of course, if it is all possible what might be the
>  Gavin> required syntax to obtain such information!
> 
>  svn diff -r rev1:rev2 file | egrep '^[-+][^-+]' | wc -l

I believe that will double (or more) your "changed line" count. I think
in concept something like

diff --side-by-side --suppress-common-lines <foo> <bar> | wc -l

would get a more accurate changed line count. The trick is getting this
to work with "svn diff". The best I could come up with in short order
is:

svn diff --diff-cmd mydiff | egrep -v '^Index:|=+$' | wc -l

where mydiff is the following two-line script:

shift 1
diff --side-by-side --suppress-common-lines "$@"

(The "shift 1" gets rid of the "-u" argument, which conflicts with
--side-by-side.)

-- 
----------------------
Mark S. Reibert, Ph.D.
svn@reibert.com
----------------------


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

Re: Stats for a file.

Posted by Paul Koning <Pa...@dell.com>.
>>>>> "Gavin" == Gavin Baumanis <Gavin> writes:

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

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

 svn diff -r rev1:rev2 file | egrep '^[-+][^-+]' | wc -l

      paul


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