Parsing an SVN log and then selecting a version

I’m trying to write an script to pull the version information from a Subversion repository, parse it, serve it up in a display dialog for the user to select a particular revision, and then use the subsequent selection to perform an action through subversion.

I’ve written something, but it seems to fail in several cases and I can’t help but feeling that its rapidly becoming a gigantic kluge. Also, if anyone has any advice on prettying up the output a little I’d appreciate it. When the commit comments are long, my solution rapidly blows up the dialog box.

This is the version selector:

set svnLog to paragraphs of (do shell script "svn log " & fileName & "| grep -vE '^-|^$' | sed 'N;s/\\n/ \\| /'" | sed 's/r(\\d+)/r)

--return svnLog

set vList to {}

set text item delimiters to {" | "}

repeat with i from 1 to count of svnLog
	copy theSplit(item i of svnLog, " | ") to the end of vList
end repeat

--return vList

choose from list svnLog with title "Hi" with prompt "Pick one!"

set revNum to item 1 of theSplit(result, "|")

on theSplit(theString, theDelimiter)
	-- save delimiters to restore old settings
	set oldDelimiters to AppleScript's text item delimiters
	-- set delimiters to delimiter to be used
	set AppleScript's text item delimiters to theDelimiter
	-- create the array
	set theArray to every text item of theString
	-- restore the old setting
	set AppleScript's text item delimiters to oldDelimiters
	-- return the result
	return theArray
end theSplit

To clarify some of the coding decisions, the first line is a shell script which strips out the “---------” delimiters and blank lines from the raw SVN log and concatenates every two lines into one.

SVN logs typically look like this:

r14 | bob | 2014-01-13 19:18:37 -0600 (Mon, 13 Jan 2014) | 1 line

This commit represents a rollback to version 6 (the previous version)

r13 | frank | 2014-01-13 19:13:13 -0600 (Mon, 13 Jan 2014) | 1 line

Changed a line in the program to reflect my love of noodles

r6 | bob | 2014-01-06 15:40:29 -0600 (Mon, 06 Jan 2014) | 1 line

This is the primary text manipulation program. Created and committed for project X.


How does it fail?

One place it would fail, as I see it is if the user presses “Cancel” the return would then be false (as boolean ) and not a list. -You either get a false boolean or a list as a result of the choose from list.

set ml to {"Strawberries", "Blueberries"}
set what to choose from list ml default items item 1 of ml
	if what is false then
		set what to what as list -- Was a boolean, now an item in a list.
	end if
	set preferred to text 0 of what
on error e
	set ofs to offset of "{" in e
	display dialog text (ofs - 1) thru -2 of e
end try

Maybe you should strip out the comment, or just display up to the first newline. (offset of linefeed in comment_text)