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
Edit:
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