[p4] How many lines of code have I written?
Chris Helck
Chris.Helck at us.icap.com
Mon Jan 11 10:38:33 PST 2010
We have to do something similar and it's not easy. In our case we have
to count the number of changed lines between releases. I use some Python
scripts that grab the source code for the old and new versions, run Unix
diff on them, and format the output. The Unix diffstat command is
useful.
It would be nice if the output of p4 diff was compatible with GNU diff
and diffstat in particular -- though perhaps this has changed, I'm stuck
on P4 2007.1.
One of the problems I've run into is handling integrations. If you move
a 1000 line file from one directory to another (or just rename it) then
most diff programs see 1000 lines removed, and another 1000 lines added.
I concluded that Perforce isn't much help with this problem, and that I
was better off just dealing with the source files directly.
Another issue we have is slightly conflicting requirements: our QA
engineers want to see a summary of file differences. This gives them an
idea of what actually changed in the release. The other requirement is
they want an overall number that they can use to predict how much time
the release will spend in QA. I think it is usefull to separate these
requirements into two tasks. Some people in my company use PspDashboard
to get the file differences, but I suspect there are plenty of tools
that can do directory based diffs.
The last issue that makes this hard, is that everyone hates counting
lines of code, and they'll tell you why you shouldn't do it instead of
telling you how to do it. A lot of it comes down to fear of idiots
looking at the data and coming to the wrong conclusion. But, in my
experience, idiots don't really need data to come to wrong conclusions
so what the heck count code if it helps.
Sorry for the rambling reply. Can you be more specific about what you're
looking for? Is it changes per developer per release?
Regards,
C. Helck
-----Original Message-----
From: perforce-user-bounces at perforce.com
[mailto:perforce-user-bounces at perforce.com] On Behalf Of Roy Smith
Sent: Monday, January 11, 2010 8:49 AM
To: perforce-user at perforce.com
Subject: [p4] How many lines of code have I written?
Somebody asked me how many lines of code I've written. How can I figure
this out with p4? Granted, the question is a bit ambigious, but let's
assume it really means something like "number of lines of new code, not
counting changes to existing code". And I just want to do this in our
main branch.
1) Find all the files I've added (on our main branch; no fair counting
the same lines N times as I integrate them into various maintenance
branches). I'm not even sure how to do that. I can do:
p4 filelog ... | grep ' add on .* by smithr3'
but that just gets me a list of changes. I can probably correlate those
back to the individual files that were added with a Python script, but
is there a more direct way? Once I know what files I've added, it's
easy to count the lines with "p4 print -q foo#1 | wc -l"
2) That's only part of the picture. Most of the lines of code I've
written were as edits. In fact, even when a new file is all my work,
the typical history will be me adding it as a stub and adding most of
the code as time goes by. How do I count those? About the best I can
some up with is to find every change I've made, do "p4 describe -dub"
on it, and count the lines that start with "+" and "-"; at first blush,
the "number of lines I've added" will be the difference between those.
But, again, is there an easier way?
-------------------
Roy Smith <smith_roy at emc.com>
Software Guy, EMC
1133 Westchester Ave, 3rd floor
White Plains, NY 10604
+1 914 461 3597
AIM: roysmith649
_______________________________________________
perforce-user mailing list - perforce-user at perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user
**********************************************************************
This communication and all information (including, but not limited to,
market prices/levels and data) contained therein (the "Information") is
for informational purposes only, is confidential, may be legally
privileged and is the intellectual property of ICAP plc and its affiliates
("ICAP") or third parties. No confidentiality or privilege is waived or
lost by any mistransmission. The Information is not, and should not
be construed as, an offer, bid or solicitation in relation to any
financial instrument or as an official confirmation of any transaction.
The Information is not warranted, including, but not limited, as to
completeness, timeliness or accuracy and is subject to change
without notice. ICAP assumes no liability for use or misuse of the
Information. All representations and warranties are expressly
disclaimed. The Information does not necessarily reflect the views of
ICAP. Access to the Information by anyone else other than the
recipient is unauthorized and any disclosure, copying, distribution or
any action taken or omitted to be taken in reliance on it is prohibited. If
you receive this message in error, please immediately delete it and all
copies of it from your system, destroy any hard copies of it and
notify the sender.
**********************************************************************
More information about the perforce-user
mailing list