Commit c5329abf90371ff2377bcb6f087abb59605bcea4:
    commit draft minutes using only tmpdirs


Branch: refs/heads/master
Author: Sam Ruby <[email protected]>
Committer: Sam Ruby <[email protected]>
Pusher: rubys <[email protected]>

------------------------------------------------------------
lib/whimsy/asf/svn.rb                                        | ++++++ ---
www/board/agenda/views/actions/draft.json.rb                 | ++++ -----
------------------------------------------------------------
42 changes: 20 additions, 22 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index 4982479..86add8a 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -94,9 +94,12 @@ def self.update(path, msg, env, _)
           contents = yield tmpdir, ''
         end
      
-        # update the temporary copy
+        # create/update the temporary copy
         if contents and not contents.empty?
           File.write tmpfile, contents
+          _.system ['svn', 'add',
+            ['--username', env.user, '--password', env.password],
+            tmpfile]
         elsif File.file? tmpfile
           File.unlink tmpfile
           _.system ['svn', 'delete',
@@ -105,12 +108,12 @@ def self.update(path, msg, env, _)
         end
 
         # commit the changes
-        _.system ['svn', 'commit', '--message', msg.untaint,
+        rc = _.system ['svn', 'commit', '--message', msg.untaint,
           ['--username', env.user, '--password', env.password],
           tmpfile]
 
         # fail if there are pending changes
-        unless `svn st`.empty?
+        unless rc == 0 and `svn st`.empty?
           raise "svn failure #{File.join(svn, basename)}"
         end
       ensure
diff --git a/www/board/agenda/views/actions/draft.json.rb 
b/www/board/agenda/views/actions/draft.json.rb
index 57fefb5..e720939 100644
--- a/www/board/agenda/views/actions/draft.json.rb
+++ b/www/board/agenda/views/actions/draft.json.rb
@@ -6,25 +6,20 @@
 agenda_file.untaint if @agenda =~ /^board_agenda_\d+_\d+_\d+.txt$/
 minutes_file = agenda_file.sub('_agenda', '_minutes')
 
-unless File.exist? minutes_file
-  `svn cp #{agenda_file} #{minutes_file}` if File.exist? agenda_file
-
-  File.write(minutes_file, @text)
-
-  `svn add #{minutes_file}` unless File.exist? agenda_file
-
-  commit = ['svn', 'commit', '-m', @message, minutes_file,
-    '--no-auth-cache', '--non-interactive']
-
-  if env.password
-    commit += ['--username', env.user, '--password', env.password]
-  end
-
-  require 'shellwords'
-  output = `#{Shellwords.join(commit).untaint} 2>&1`
-  if $?.exitstatus != 0
-    _.error (output.empty? ? 'svn commit failed' : output)
-    raise Exception.new('svn commit failed')
+ASF::SVN.update minutes_file, @message, env, _ do |tmpdir, old_contents|
+  if old_contents and not old_contents.empty?
+    old_contents
+  else
+    # retrieve the agenda on which these minutes are based
+    _.system ['svn', 'update',
+      ['--username', env.user, '--password', env.password],
+      "#{tmpdir}/#{File.basename agenda_file}"]
+
+    # copy the agenda to the minutes (produces better diff)
+    _.system ['svn', 'cp', "#{tmpdir}/#{@agenda}",
+      "#{tmpdir}/#{File.basename minutes_file}"]
+
+    @text
   end
 end
 

Reply via email to