Ayende @ Rahien

Unnatural acts on source code

Processing invalid patches

I just got a patch file that SVN couldn't handle. I handled the issue with this piece of code, here for future reference:

import System.IO

 

file = """random.patch""";

lines = File.ReadAllLines(file)

currentFile as TextWriter

for line in lines:

      if line.StartsWith("+++"):#new file

            currentFile.Dispose() if currentFile is not null

            fileName = line.Replace("+++","").Replace("(revision 0)","").Trim()

            currentFile = File.CreateText(fileName)

            print fileName

            continue

      continue if not line.StartsWith("+")

      currentFile.WriteLine( line.Substring(1) )

I love Boo!

Comments

hammett
03/20/2007 01:17 PM by
hammett

Can't you say

"continue unless line.StartsWith("+")" ?

Ayende Rahien
03/21/2007 08:15 AM by
Ayende Rahien

Yes, as a matter of fact I can, just didn't think of it.

Comments have been closed on this topic.