You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2016/03/31 15:58:48 UTC

[whimsy.git] [1/1] Commit 2d290d3: add a method to extract revision and contents

Commit 2d290d3f1e5ba57bfdf03f5477288e4657ee8ca6:
    add a method to extract revision and contents


Branch: refs/heads/master
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@apache.org>

------------------------------------------------------------
lib/whimsy/asf/svn.rb                                        | +++++++++++++++ 
------------------------------------------------------------
29 changes: 29 additions, 0 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index 86add8a..91d3aab 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -63,6 +63,35 @@ def self.find!(name)
       result
     end
 
+    # retrieve revision, content for a file in svn
+    def self.get(path, user=nil, password=nil)
+      # build svn info command
+      cmd = ['svn', 'info', path, '--non-interactive']
+
+      # password was supplied, add credentials
+      if password
+        cmd += ['--username', user, '--password', password, '--no-auth-cache']
+      end
+
+      # default the values to return
+      revision = '0'
+      content = nil
+
+      # issue svn info command
+      stdout, status = Open3.capture2(*cmd)
+      if status.success?
+        # extract revision number
+        revision = stdout[/^Revision: (\d+)/, 1]
+
+        # extract contents
+        cmd[1] = 'cat'
+        content, status = Open3.capture2(*cmd)
+      end
+
+      # return results
+      return revision, content
+    end
+
     # update a file in SVN, working entirely in a temporary directory
     def self.update(path, msg, env, _)
       dir = File.dirname(path)