Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/gitolite_public_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,34 @@ def edit
end

def delete
GitHostingObserver.set_update_active(false)
@gitolite_public_key[:active] = 0
@gitolite_public_key.save
redirect_to url_for(:controller => 'my', :action => 'account')
GitHostingObserver.set_update_active(true)
end

def update
GitHostingObserver.set_update_active(false)
if @gitolite_public_key.update_attributes(params[:public_key])
flash[:notice] = l(:notice_public_key_updated)
redirect_to url_for(:controller => 'my', :action => 'account')
else
render :action => 'edit'
end
GitHostingObserver.set_update_active(true)
end

def create
GitHostingObserver.set_update_active(false)
@gitolite_public_key = GitolitePublicKey.new(params[:public_key].merge(:user => @user))
if @gitolite_public_key.save
flash[:notice] = l(:notice_public_key_added)
else
@gitolite_public_key = GitolitePublicKey.new(:user => @user)
end
redirect_to url_for(:controller => 'my', :action => 'account')
GitHostingObserver.set_update_active(true)
end

protected
Expand Down
18 changes: 15 additions & 3 deletions app/models/git_hosting_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class GitHostingObserver < ActiveRecord::Observer
observe :project, :user, :gitolite_public_key, :member, :role, :repository

@@updating_active = true
@@updating_active_stack = 0
@@cached_project_updates = []

def reload_this_observer
Expand All @@ -12,14 +13,25 @@ def reload_this_observer


def self.set_update_active(is_active)
@@updating_active = is_active
if is_active
if !is_active
@@updating_active_stack += 1
else
@@updating_active_stack -= 1
if @@updating_active_stack < 0
@@updating_active_stack = 0
end
end

if is_active && @@updating_active_stack == 0
if @@cached_project_updates.length > 0
@@cached_project_updates = @@cached_project_updates.flatten.uniq.compact
GitHosting::update_repositories(@@cached_project_updates, false)
@@cached_project_updates = []
end
@@updating_active = true
else
@@updating_active = false
end
@@cached_project_updates = []
end


Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20111119170948_add_indexes_to_gitolite_public_key.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddIndexesToGitolitePublicKey < ActiveRecord::Migration
def self.up
add_index :gitolite_public_keys, :user_id
add_index :gitolite_public_keys, :identifier
end

def self.down
remove_index :gitolite_public_keys, :user_id
remove_index :gitolite_public_keys, :identifier
end
end
16 changes: 16 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@
require 'git_hosting/patches/git_repository_patch'
Repository::Git.send(:include, GitHosting::Patches::GitRepositoryPatch)

require_dependency 'sys_controller'
require 'git_hosting/patches/sys_controller_patch'
SysController.send(:include, GitHosting::Patches::SysControllerPatch)

require_dependency 'members_controller'
require 'git_hosting/patches/members_controller_patch'
MembersController.send(:include, GitHosting::Patches::MembersControllerPatch)

require_dependency 'users_controller'
require 'git_hosting/patches/users_controller_patch'
UsersController.send(:include, GitHosting::Patches::UsersControllerPatch)

require_dependency 'roles_controller'
require 'git_hosting/patches/roles_controller_patch'
RolesController.send(:include, GitHosting::Patches::RolesControllerPatch)

require_dependency 'git_hosting/patches/repository_cia_filters'
end

Expand Down
11 changes: 11 additions & 0 deletions lib/git_hosting/patches/git_repository_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ def extra_report_last_commit_with_always_true
true
end

def fetch_changesets_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
fetch_changesets_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end

def self.included(base)
base.class_eval do
Expand All @@ -17,6 +27,7 @@ def self.included(base)
begin
base.send(:alias_method_chain, :report_last_commit, :always_true)
base.send(:alias_method_chain, :extra_report_last_commit, :always_true)
base.send(:alias_method_chain, :fetch_changesets, :disable_update)
rescue
end

Expand Down
48 changes: 48 additions & 0 deletions lib/git_hosting/patches/members_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module GitHosting
module Patches
module MembersControllerPatch
def new_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
new_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end
def edit_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
edit_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end
def destroy_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
destroy_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end

def self.included(base)
base.class_eval do
unloadable
end
begin
base.send(:alias_method_chain, :new, :disable_update)
base.send(:alias_method_chain, :edit, :disable_update)
base.send(:alias_method_chain, :destroy, :disable_update)
rescue
end
end
end
end
end
13 changes: 11 additions & 2 deletions lib/git_hosting/patches/repository_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,27 @@ def factory_with_git_extra_init(klass_name, *args)
end
return new_repo
end
end
def fetch_changesets_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
fetch_changesets_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end
end

def self.included(base)
base.extend(ClassMethods)
base.class_eval do
unloadable
class << self
alias_method_chain :factory, :git_extra_init
alias_method_chain :fetch_changesets, :disable_update
end
end

end
end
end
Expand Down
36 changes: 36 additions & 0 deletions lib/git_hosting/patches/roles_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module GitHosting
module Patches
module RolesControllerPatch
def edit_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
edit_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end
def destroy_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
destroy_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end
def self.included(base)
base.class_eval do
unloadable
end
begin
base.send(:alias_method_chain, :edit, :disable_update)
base.send(:alias_method_chain, :destroy, :disable_update)
rescue
end
end
end
end
end
26 changes: 26 additions & 0 deletions lib/git_hosting/patches/sys_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module GitHosting
module Patches
module SysControllerPatch
def fetch_changesets_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
fetch_changesets_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end

def self.included(base)
base.class_eval do
unloadable
end
begin
base.send(:alias_method_chain, :fetch_changesets, :disable_update)
rescue
end
end
end
end
end
59 changes: 59 additions & 0 deletions lib/git_hosting/patches/users_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module GitHosting
module Patches
module UsersControllerPatch
def create_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
create_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end
def update_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
update_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end
def destroy_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
destroy_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end
def edit_membership_with_disable_update
# Turn of updates during repository update
GitHostingObserver.set_update_active(false);

# Do actual update
edit_membership_without_disable_update

# Reenable updates to perform a single update
GitHostingObserver.set_update_active(true);
end

def self.included(base)
base.class_eval do
unloadable
end
begin
base.send(:alias_method_chain, :create, :disable_update)
base.send(:alias_method_chain, :update, :disable_update)
base.send(:alias_method_chain, :destroy, :disable_update)
base.send(:alias_method_chain, :edit_membershipt, :disable_update)
rescue
end
end
end
end
end