Class: SixCore::Svn
- Inherits:
-
Object
- Object
- SixCore::Svn
- Defined in:
- lib/sixcore/svn.rb
Overview
Core module for Subversion
Constant Summary collapse
- COMPONENT =
'SixCore::Svn'
- REGEX_LINE =
/------------------------------------------------------------------------/
- REGEX_INFO =
/r(.*) \| (.*) \| (.*) \| (.*) /
- REGEX_REVISION =
/Revision\: (.*)/
- REGEX_MOD =
/(^A )|(^M )|(^D )/
- REGEX_PBO =
/(.*)\.pbo(.*)/
- REGEX_FOLDER =
/(.*)\\(.*)/
- @@log =
SixCore.log
- @@config =
SixCore::read_config('svn', 'sixcore/config')
Instance Attribute Summary collapse
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#repos ⇒ Object
Returns the value of attribute repos.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#cmd(cmd) ⇒ Object
- Command Execution function cmd
-
Command to execute, excl repositor, username, password.
- #config ⇒ Object
-
#diff(old, new) ⇒ Object
- Generates diff list between revisions Returns diff list old
- String or Integer, start revision number new
-
String or Integer, end revision number.
-
#info ⇒ Object
Fetches SVN info.
-
#initialize(repos = '', user = '', pass = '') ⇒ Svn
constructor
- repos
- String, Repository folder or URL user
- String, Username pass
-
String, Password.
-
#list ⇒ Object
Fetches SVN List.
-
#log(old, new) ⇒ Object
- Generates log between revisions old
- String or Integer, start revision number new
-
String or Integer, end revision number Returns Array of Strings (log).
-
#log_split(old, new) ⇒ Object
- Generates array list of log entry information old
- String or Integer, start revision number new
-
String or Integer, end revision number Returns Array of log, split between revision number, committer, log, etc.
-
#parse_entry(entry, folders = true, slash = '/') ⇒ Object
- Parses log entry and returns type of change entry
- String, line of svn log folders
- Boolean, include folders? slash
-
String, what type of file system / \ should be used Returns Array, Per Entry format: [integer, formatted entry string].
-
#read_rev ⇒ Object
Reads current revision number from repository Returns revision number.
-
#update ⇒ Object
Executes SVN Update Returns Array of Strings.
Constructor Details
#initialize(repos = '', user = '', pass = '') ⇒ Svn
- repos
-
String, Repository folder or URL
- user
-
String, Username
- pass
-
String, Password
29 30 31 32 33 |
# File 'lib/sixcore/svn.rb', line 29 def initialize(repos = '', user = '', pass = '') @repos = repos @user = user @pass = pass end |
Instance Attribute Details
#pass ⇒ Object
Returns the value of attribute pass.
10 11 12 |
# File 'lib/sixcore/svn.rb', line 10 def pass @pass end |
#repos ⇒ Object
Returns the value of attribute repos.
10 11 12 |
# File 'lib/sixcore/svn.rb', line 10 def repos @repos end |
#user ⇒ Object
Returns the value of attribute user.
10 11 12 |
# File 'lib/sixcore/svn.rb', line 10 def user @user end |
Instance Method Details
#cmd(cmd) ⇒ Object
Command Execution function
- cmd
-
Command to execute, excl repositor, username, password
37 38 39 40 41 42 43 |
# File 'lib/sixcore/svn.rb', line 37 def cmd(cmd) @@log.debug SixCore::prep_msg('Command', :component => COMPONENT, :verbose => cmd) cmd = "#{cmd} #{@repos}" unless @repos.empty? cmd = "#{cmd} --username #{@user}" unless @user.empty? cmd = "#{cmd} --password #{@pass}" unless @pass.empty? SixCore::proc_cmd("#{@@config.program} #{cmd}") end |
#config ⇒ Object
22 23 24 |
# File 'lib/sixcore/svn.rb', line 22 def config @@config end |
#diff(old, new) ⇒ Object
Generates diff list between revisions Returns diff list
- old
-
String or Integer, start revision number
- new
-
String or Integer, end revision number
49 50 51 |
# File 'lib/sixcore/svn.rb', line 49 def diff(old, new) cmd("diff -r #{old}:#{new} --summarize").split("\n") end |
#info ⇒ Object
Fetches SVN info
54 55 56 |
# File 'lib/sixcore/svn.rb', line 54 def info() cmd('info').split("\n") end |
#list ⇒ Object
Fetches SVN List
59 60 61 |
# File 'lib/sixcore/svn.rb', line 59 def list() cmd('list').split("\n") end |
#log(old, new) ⇒ Object
Generates log between revisions
- old
-
String or Integer, start revision number
- new
-
String or Integer, end revision number
Returns Array of Strings (log)
73 74 75 |
# File 'lib/sixcore/svn.rb', line 73 def log(old, new) cmd("log -r#{old}:#{new}").split("\n") end |
#log_split(old, new) ⇒ Object
Generates array list of log entry information
- old
-
String or Integer, start revision number
- new
-
String or Integer, end revision number
Returns Array of log, split between revision number, committer, log, etc
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sixcore/svn.rb', line 81 def log_split(old, new) ar = log(old,new) log = [] i = -1 entry = [] com = [] ar.each do |line| if line =~ REGEX_LINE unless i == -1 entry << com log << entry end entry = [] com = [] i = 0 else i += 1 if i == 1 entry << [$1, $2, $3, $4] if line =~ REGEX_INFO elsif i > 2 com << line unless line.empty? end end end return log end |
#parse_entry(entry, folders = true, slash = '/') ⇒ Object
Parses log entry and returns type of change
- entry
-
String, line of svn log
- folders
-
Boolean, include folders?
- slash
-
String, what type of file system / \ should be used
Returns Array, Per Entry format: [integer, formatted entry string]
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/sixcore/svn.rb', line 121 def parse_entry(entry, folders = true, slash = '/') # TODO: slash! # substract everything after first \ if folders entrymod = entry.gsub(/\\(.*)/, '') else entrymod = entry end id = -1 case entrymod when REGEX_MOD unless $1.nil? if folders and entry =~ REGEX_FOLDER # subfolder, so it's a change id = 1 else id = 0 end end unless $2.nil? id = 1 end unless $3.nil? id = 2 unless entry =~ REGEX_PBO if folders and entry =~ REGEX_FOLDER # subfolder, so it's a change id = 1 end end end entrymod.gsub!(REGEX_MOD, '') return [id, entrymod] end end |
#read_rev ⇒ Object
Reads current revision number from repository Returns revision number
110 111 112 113 |
# File 'lib/sixcore/svn.rb', line 110 def read_rev() inf = info() inf.each do |line| return $1 if line[REGEX_REVISION] end end |
#update ⇒ Object
Executes SVN Update Returns Array of Strings
65 66 67 |
# File 'lib/sixcore/svn.rb', line 65 def update() cmd('update').split("\n") end |