Label Cloud

Tuesday, January 27, 2009

Batch converting Unicode files to ASCII in Subversion (utilizing Powershell)

Recently we’ve worked on importing our database structure into subversion. After scripting out the database schema into thousands .SQL files, and checking them in, we’ve realized that the files were creating in Unicode. Subversion used binary encoding when sending the files into the repository. Even though client side tools were able to work on files without any problems, all server-side tools (like FishEye, Bamboo, etc…) considered them binary, and were not able to properly process them. Batch converting them to ASCII took a little research, but overall was relatively straightforward.

After checking the structure out to the local drive, I’ve used a 1 line Powershell script convert the files to binary (note: this is one lone line)

dir --recurs -include *.sql | foreach {$FileName = $_; $fileData = get-content -path $_; out-file -filePath $FileName.FullName -inputObject $fileData -encoding ascii}

After having all files changed to ASCII, we had to remove the svn:mime-type property. To do that, run the following:

snv propdel svn:mime-type –R *.sql

Finally, we checked in the changes back into the repository.

Technorati Tags: ,


Share/Save/Bookmark

No comments: