Review Board 1.5.5

Part 1 of merge r1025:r1064 from release branch into trunk: Some modifications to Repository library

Updated 2 years, 2 months ago

Severin Gehwolf Reviewers
trunk markus_developers
None MarkUs Source Code Repository
When I merged the changes from the release_0.5 branch into trunk and ran the unit tests, I got approximately 90 failures/errors. The reason for all these changes are: Get test to pass again. Simplify/Unify repository library configuration. It takes a configuration hash now, when the factory is called (e.g. Repository.get_class("svn", conf)). I also removed the repository_factory.rb file and merged it into repository.rb

Please take your time when looking at it (there are more parts to come) Aside: The diff of my local changes 3000 something lines is probably to big for ReviewBoard. It seg-faults or whatever when trying to create a review with the large diff. Feedback is very welcome!
for this part:

lib/repo/test/memory_repository_test.rb
lib/repo/test/subversion_repository_test.rb

both pass.
trunk/lib/repo/memory_repository.rb
Revision 1064 New Change
... 21 lines hidden [Expand]
class MemoryRepository < Repository::AbstractRepository
22
  #############################################################
22
  #############################################################
23
  
23
  
24
  # Constructor: Connects to an existing Memory
24
  # Constructor: Connects to an existing Memory
25
  # repository; Note: A repository has to be created using
25
  # repository; Note: A repository has to be created using
26
  # MemoryRepository.create(), if it is not yet existent
26
  # MemoryRepository.create(), if it is not yet existent
27
  # Generally: Do not(!) call it with 3 parameters, use MemoryRepository.create() instead!
27
  # Generally: Do not(!) call it with 2 parameters, use MemoryRepository.create() instead!
28
  def initialize(location, is_admin=true, is_create_call=false)
28
  def initialize(location)
29
    
29
    
30
    # variables
30
    # variables
31
    @users = {}                                 # hash of users (key) with corresponding permissions (value)
31
    @users = {}                                 # hash of users (key) with corresponding permissions (value)
32
    @current_revision = MemoryRevision.new(0)   # the latest revision (we start from 0)
32
    @current_revision = MemoryRevision.new(0)   # the latest revision (we start from 0)
33
    @revision_history = []                      # a list (array) of old revisions (i.e. < @current_revision)
33
    @revision_history = []                      # a list (array) of old revisions (i.e. < @current_revision)
34
    # mapping (hash) of timestamps and revisions
34
    # mapping (hash) of timestamps and revisions
35
    @timestamps_revisions = {}
35
    @timestamps_revisions = {}
36
    @timestamps_revisions[Time.now._dump.to_s] = @current_revision   # push first timestamp-revision mapping
36
    @timestamps_revisions[Time.now._dump.to_s] = @current_revision   # push first timestamp-revision mapping
37
    @repository_location = location
37
    @repository_location = location
38
    
38
    
39
    
39
    
40
    # hack(ish) functionality
40
    if MemoryRepository.repository_exists?(location)
41
    if !is_create_call
41
      raise RepositoryCollision.new("There is already a repository at #{location}")
42
      begin

   
43
        super(location) # dummy super() call to be ruby conformant (in fact, does nothing but raising an exception) 

   
44
      rescue NotImplementedError; end

   
45
      if !self.class.repository_exists?(location)

   
46
        raise "Could not open repository at location #{location}"

   
47
      end

   
48
      return @@repositories[location] # return reference in question

   
49
    else

   
50
      if MemoryRepository.repository_exists?(location)

   
51
        raise RepositoryCollision.new("There is already a repository at #{location}")

   
52
      end

   
53
      @@repositories[location] = self             # push new MemoryRepository onto repository list

   
54
    end
42
    end

   
43
    @@repositories[location] = self             # push new MemoryRepository onto repository list
55
    
44
    
56
  end
45
  end
57
  
46
  
58
  # Checks if a memory repository exists at 'path'
47
  # Checks if a memory repository exists at 'path'
59
  def self.repository_exists?(path)
48
  def self.repository_exists?(path)
60
    @@repositories.each do |location, repo|
49
    @@repositories.each do |location, repo|
61
      if path == location
50
      if path == location
62
        return true
51
        return true
63
      end
52
      end
64
    end
53
    end
65
    return false
54
    return false
66
  end
55
  end
67
  
56
  
68
  # Open repository at specified location (dummy permission file to unify API)
57
  # Open repository at specified location
69
  def self.open(location, is_admin=true, perm_file=nil)
58
  def self.open(location)
70
    return @@repositories[location]
59
    if !self.repository_exists?(location)
71
    #return MemoryRepository.new(location, is_admin)
60
        raise "Could not open repository at location #{location}"

   
61
      end

   
62
    return @@repositories[location] # return reference in question
72
  end
63
  end
73
  
64
  
74
  # Creates memory repository at "virtual" location (they are identifiable by location)
65
  # Creates memory repository at "virtual" location (they are identifiable by location)
75
  # perm_file is a parameter, which exists to conform with the API
66
  def self.create(location)
76
  def self.create(location, is_admin=true, perm_file=nil)
67
    if !MemoryRepository.repository_exists?(location)
77
    MemoryRepository.new(location, is_admin, true) # want to create a repository
68
      MemoryRepository.new(location) # create a repository if it doesn't exist
78
    return MemoryRepository.open(location, is_admin)
69
    end

   
70
    return true
79
  end
71
  end
80
  
72
  
81
  # Destroys all repositories
73
  # Destroys all repositories
82
  def self.purge_all()
74
  def self.purge_all()
83
    @@repositories = {}
75
    @@repositories = {}
... 116 lines hidden [Expand]
def get_revision_by_timestamp(timestamp)
200
    if @users.key?(user_id)
192
    if @users.key?(user_id)
201
      raise UserAlreadyExistent.new(user_id +" exists already")
193
      raise UserAlreadyExistent.new(user_id +" exists already")
202
    end
194
    end
203
    @users[user_id] = permissions
195
    @users[user_id] = permissions
204
  end
196
  end
205
  
197

   
198
  # Semi-private - used by the bulk permissions assignments

   
199
  def has_user?(user_id)

   
200
    return @users.key?(user_id)

   
201
  end    

   
202
   
206
  # Removes a user from from the repository
203
  # Removes a user from from the repository
207
  def remove_user(user_id)
204
  def remove_user(user_id)
208
    if !@users.key?(user_id)
205
    if !@users.key?(user_id)
209
      raise UserNotFound.new(user_id + " not found")
206
      raise UserNotFound.new(user_id + " not found")
210
    end
207
    end
... 30 lines hidden [Expand]
def get_permissions(user_id)
241
      raise UserNotFound.new(user_id + " not found")
238
      raise UserNotFound.new(user_id + " not found")
242
    end
239
    end
243
    return @users[user_id]
240
    return @users[user_id]
244
  end
241
  end
245
  
242
  
246
  private
243
  # Set permissions for many repositories

   
244
  def self.set_bulk_permissions(repo_names, user_id_permissions_map)

   
245
    repo_names.each do |repo_name|

   
246
      repo = self.open(repo_name)

   
247
      user_id_permissions_map.each do |user_id, permissions|

   
248
        if(!repo.has_user?(user_id)) 

   
249
          repo.add_user(user_id, permissions)

   
250
        else

   
251
          repo.set_permissions(user_id, permissions)

   
252
        end

   
253
      end

   
254
    end

   
255
    return true

   
256
  end
247
  
257
  

   
258
  # Delete permissions for many repositories

   
259
  def self.delete_bulk_permissions(repo_names, user_ids)

   
260
    repo_names.each do |repo_name|

   
261
      repo = self.open(repo_name)

   
262
      user_ids.each do |user_id|

   
263
        if(repo.has_user?(user_id))

   
264
          repo.remove_user(user_id)

   
265
        end

   
266
      end

   
267
    end

   
268
    return true

   
269
  end

   
270

   

   
271
  

   
272
  private
248
  # Creates a directory as part of the provided revision
273
  # Creates a directory as part of the provided revision
249
  def make_directory(rev, full_path)
274
  def make_directory(rev, full_path)
250
    if rev.path_exists?(full_path)
275
    if rev.path_exists?(full_path)
251
      raise FileExistsConflict # raise conflict if path exists 
276
      raise FileExistsConflict # raise conflict if path exists 
252
    end
277
    end
... 239 lines hidden [Expand]
def __add_directory(dir)
492
    @revision_number += 1
517
    @revision_number += 1
493
  end
518
  end
494
  
519
  
495
  private
520
  private
496
  
521
  

   
522
  
497
  def files_at_path_helper(path="/", only_changed=false, type=RevisionFile)
523
  def files_at_path_helper(path="/", only_changed=false, type=RevisionFile)
498
    # Automatically append a root slash if not supplied
524
    # Automatically append a root slash if not supplied
499
    result = Hash.new(nil)
525
    result = Hash.new(nil)
500
    @files.each do |object|
526
    @files.each do |object|
501
      alt_path = ""
527
      alt_path = ""
... 21 lines hidden [Expand]
trunk/lib/repo/repository.rb
Revision 1064 New Change
 
trunk/lib/repo/repository_factory.rb
Revision 1064 New Change
 
trunk/lib/repo/subversion_repository.rb
Revision 1064 New Change
 
trunk/lib/repo/test/memory_repository_test.rb
Revision 1064 New Change
 
trunk/lib/repo/test/repository_abstract_tests.rb
Revision 1064 New Change
 
trunk/lib/repo/test/subversion_repository_test.rb
Revision 1064 New Change
 
  1. trunk/lib/repo/memory_repository.rb: Loading...
  2. trunk/lib/repo/repository.rb: Loading...
  3. trunk/lib/repo/repository_factory.rb: Loading...
  4. trunk/lib/repo/subversion_repository.rb: Loading...
  5. trunk/lib/repo/test/memory_repository_test.rb: Loading...
  6. trunk/lib/repo/test/repository_abstract_tests.rb: Loading...
  7. trunk/lib/repo/test/subversion_repository_test.rb: Loading...