Created
December 25, 2008 19:34
-
-
Save patroza/39940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sixcore' | |
module SixCore | |
ConfigSvn = Struct.new(:program) | |
# Core module for Subversion | |
class Svn | |
attr_accessor(:repos, :user, :pass) | |
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') | |
def config | |
@@config | |
end | |
# repos:: String, Repository folder or URL | |
# user:: String, Username | |
# pass:: String, Password | |
def initialize(repos = '', user = '', pass = '') | |
@repos = repos | |
@user = user | |
@pass = pass | |
end | |
# Command Execution function | |
# cmd:: Command to execute, excl repositor, username, password | |
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 | |
# Generates diff list between revisions | |
# Returns diff list | |
# old:: String or Integer, start revision number | |
# new:: String or Integer, end revision number | |
def diff(old, new) | |
cmd("diff -r #{old}:#{new} --summarize").split("\n") | |
end | |
# Fetches SVN info | |
def info() | |
cmd('info').split("\n") | |
end | |
# Fetches SVN List | |
def list() | |
cmd('list').split("\n") | |
end | |
# Executes SVN Update | |
# Returns Array of Strings | |
def update() | |
cmd('update').split("\n") | |
end | |
# Generates log between revisions | |
# old:: String or Integer, start revision number | |
# new:: String or Integer, end revision number | |
# Returns Array of Strings (log) | |
def log(old, new) | |
cmd("log -r#{old}:#{new}").split("\n") | |
end | |
# 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 | |
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 | |
# Reads current revision number from repository | |
# Returns revision number | |
def read_rev() | |
inf = info() | |
inf.each do |line| return $1 if line[REGEX_REVISION] end | |
end | |
# 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] | |
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 | |
end | |
end | |
# Yay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment