Friday, June 03, 2005

sorted list of number of changed lines in files that need to be checked into cvs

Sometimes I make one change to a set of files, sometimes even a large set of files. Say, for instance, that I changed which java package a class resides in. Then, I'd probably run a set of commands that would search and replace the import statements in all files that use that class. But, at that point I might now have 20 files in my source tree that need to be checked in, which all have the exact same change, to just one line in each file.

If my local source tree was up to date with CVS before that, the checkin would be easy. I could just cvs commit at the root of the tree, and enter one comment ("changed package of class X from a.b.c to a.d") to describe the change to all of them.

But, usually I've got at least a couple other things that need to be checked in, so I have to either go through all of the files, one at a time, or do something automated. The following is one set of commands that has proven useful to me for this purpose. I've got another, but it's not quite ready to share (that will come soon).

The commandline below will safely and quietly cvs update to get a list of modified files (marked with an "M"), then run cvs diff on each file and count the lines in the diff output.. then they are all sorted numerically by number of changed lines, and displayed. I can easily see that all of the files with 5? (i forget exactly.. however many lines show up in a 'cvs diff' for a single changed line in a source file) changed lines, and can probably check them all in with one comment.

(for f in `cvs -q -n update grep '^M' sed -e 's/^M //g'`; do echo `(cvs diff $f wc -l)` $f; done) sort -n

0 comments: