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

Sybase ASE 12.5 error message about 'select into' option needing to be enabled

Sybase (ASE 12.5) error message I was getting when trying to modify a column's metadata/attributes:
   The 'select into' database option is not enabled for database 'myDbName'. ALTER TABLE with data copy cannot be done.
   Set the 'select into' database option and re-run.
 
Solution that worked for me (including the column-altering command in the middle):

USE master;
EXEC sp_dboption "myDbName","select into/bulkcopy",true;
COMMIT;
USE myDbName;
ALTER TABLE myTableName
MODIFY myColumnName varchar(60) NOT NULL;
USE master;
EXEC sp_dboption "myDbName","select into/bulkcopy",false;
COMMIT;

References:
Ed Barlow's "fix_db.pl" script, which I happened to find the solution in when grepping my local machine.
http://www.edbarlow.com/document/utilities/readme.htm

This page, where I stumbled across the solution eventually, as one of many google search results.  I had result pages open in several windows, and was looking through them when I noticed the grep results.
http://www.devx.com/vb2themax/Tip/18583
 

Wednesday, May 11, 2005

Build with ant, open source files in TextPad, jump to lines with compilation errors

I use cygwin and textpad in my day-to-day work, among many other things. To compile my current java project, I use ant. I'm always interested in integrating utilities to make everything more convenient, so this afternoon I set out to create an entry in the textpad "Tools" menu, to run ant and compile my source code.

I found what seemed like useful information here, so I was able to at least run ant from textpad. However, compilation errors would show up in the "Command Results" window, and the part on that web page about being able to click on a compilation error to jump to the offending file and line number was not working for me. I tried messing with the regex and switching my textpad regex type from POSIX to the textpad default type, but I could not get it to work.

So, I went a different route. I decided to attack it from the bash shell angle, by running ant and manipulating the output. What I ended up with is one string of commands that runs ant, then opens all source files with compilation errors into textpad, and jumps to the line numbers that the errors occurred on:

ant 2>/dev/null ¦ grep "\[javac\] [A-Za-z]:" ¦ sed -e "s/^ *\[javac\] \([A-Za-z]:[^:]*\):\([0-9]*\):.*$/\1(\2)/g" > /cygdrive/c/temp/textpadant.txt ; "/cygdrive/c/Program Files/TextPad 4/TextPad.exe" @c:\\temp\\textpadant.txt &

I will probably try to expand on this a little further when I have time, so I can initiate all this from inside textpad, as an entry in the "Tools" menu. It should be pretty easy, but I don't have time to mess with it any more right now. For now, the solution I came up with will already save me some time every day.

-dave