Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Abstract the Repo class out to its own file

  • Loading branch information...
commit c81f4896c78ba8573314f524b57bc37e0abe81c3 1 parent 5d8e4cd
@wingrunr21 wingrunr21 authored
Showing with 73 additions and 69 deletions.
  1. +1 −69 lib/gitolite/config.rb
  2. +72 −0 lib/gitolite/config/repo.rb
View
70 lib/gitolite/config.rb
@@ -1,4 +1,5 @@
require 'tempfile'
+require File.join(File.dirname(__FILE__), 'config', 'repo')
module Gitolite
class Config
@@ -19,75 +20,6 @@ def self.init(filename = "gitolite.conf")
conf
end
- #Represents a repo inside the gitolite configuration. The name, permissions, and git config
- #options are all encapsulated in this class
- class Repo
- ALLOWED_PERMISSIONS = ['C', 'R', 'RW', 'RW+', 'RWC', 'RW+C', 'RWD', 'RW+D', 'RWCD', 'RW+CD', '-']
-
- attr_accessor :permissions, :name, :config, :owner, :description
-
- def initialize(name)
- @name = name
- @permissions = Array.new.push(Hash.new {|k,v| k[v] = Hash.new{|k2, v2| k2[v2] = [] }})
- @config = {}
- end
-
- def add_permission(perm, refex = "", *users)
- if ALLOWED_PERMISSIONS.include? perm
- #Handle deny rules
- if perm == '-'
- @permissions.push(Hash.new {|k,v| k[v] = Hash.new{|k2, v2| k2[v2] = [] }})
- end
-
- @permissions.last[perm][refex].concat users.flatten
- @permissions.last[perm][refex].uniq!
- else
- raise InvalidPermissionError, "#{perm} is not in the allowed list of permissions!"
- end
- end
-
- def set_git_config(key, value)
- @config[key] = value
- end
-
- def unset_git_config(key)
- @config.delete(key)
- end
-
- def to_s
- repo = "repo #{@name}\n"
-
- @permissions.each do |perm_hash|
- perm_hash.each do |perm, list|
- list.each do |refex, users|
- repo += " " + perm.ljust(6) + refex.ljust(25) + "= " + users.join(' ') + "\n"
- end
- end
- end
-
- @config.each do |k, v|
- repo += " config " + k + " = " + v + "\n"
- end
-
- repo
- end
-
- def gitweb_description
- if @description.nil?
- nil
- else
- desc = "#{@name} "
- desc += "\"#{@owner}\" " unless @owner.nil?
- desc += "= \"#{@description}\""
- end
- end
-
- #Gets raised if a permission that isn't in the allowed
- #list is passed in
- class InvalidPermissionError < ArgumentError
- end
- end
-
#TODO: merge repo unless overwrite = true
def add_repo(repo, overwrite = false)
raise ArgumentError, "Repo must be of type Gitolite::Config::Repo!" unless repo.instance_of? Gitolite::Config::Repo
View
72 lib/gitolite/config/repo.rb
@@ -0,0 +1,72 @@
+module Gitolite
+ class Config
+ #Represents a repo inside the gitolite configuration. The name, permissions, and git config
+ #options are all encapsulated in this class
+ class Repo
+ ALLOWED_PERMISSIONS = ['C', 'R', 'RW', 'RW+', 'RWC', 'RW+C', 'RWD', 'RW+D', 'RWCD', 'RW+CD', '-']
+
+ attr_accessor :permissions, :name, :config, :owner, :description
+
+ def initialize(name)
+ @name = name
+ @permissions = Array.new.push(Hash.new {|k,v| k[v] = Hash.new{|k2, v2| k2[v2] = [] }})
+ @config = {}
+ end
+
+ def add_permission(perm, refex = "", *users)
+ if ALLOWED_PERMISSIONS.include? perm
+ #Handle deny rules
+ if perm == '-'
+ @permissions.push(Hash.new {|k,v| k[v] = Hash.new{|k2, v2| k2[v2] = [] }})
+ end
+
+ @permissions.last[perm][refex].concat users.flatten
+ @permissions.last[perm][refex].uniq!
+ else
+ raise InvalidPermissionError, "#{perm} is not in the allowed list of permissions!"
+ end
+ end
+
+ def set_git_config(key, value)
+ @config[key] = value
+ end
+
+ def unset_git_config(key)
+ @config.delete(key)
+ end
+
+ def to_s
+ repo = "repo #{@name}\n"
+
+ @permissions.each do |perm_hash|
+ perm_hash.each do |perm, list|
+ list.each do |refex, users|
+ repo += " " + perm.ljust(6) + refex.ljust(25) + "= " + users.join(' ') + "\n"
+ end
+ end
+ end
+
+ @config.each do |k, v|
+ repo += " config " + k + " = " + v + "\n"
+ end
+
+ repo
+ end
+
+ def gitweb_description
+ if @description.nil?
+ nil
+ else
+ desc = "#{@name} "
+ desc += "\"#{@owner}\" " unless @owner.nil?
+ desc += "= \"#{@description}\""
+ end
+ end
+
+ #Gets raised if a permission that isn't in the allowed
+ #list is passed in
+ class InvalidPermissionError < ArgumentError
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.