Project

General

Profile

Actions

Feature #13945

closed

Disable autofetching of repository changesets if projects are closed

Added by Mischa The Evil over 11 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
SCM
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

When Setting.autofetch_changesets == true repository changesets are automatically fetched (and added) when Repository#show is executed.
This behavior feels a bit weird if a project is closed and thus read-only.

It can be disabled by adding a new condition to the if construct in source:/trunk/app/controllers/repositories_controller.rb@11784#L114, like:

Index: app/controllers/repositories_controller.rb
===================================================================
--- app/controllers/repositories_controller.rb  (revision 11784)
+++ app/controllers/repositories_controller.rb  (working copy)
@@ -111,7 +111,7 @@
   end

   def show
-    @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
+    @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty? && @project.active?

     @entries = @repository.entries(@path, @rev)
     @changeset = @repository.find_changeset_by_name(@rev)

Actions #1

Updated by Mischa The Evil over 11 years ago

  • Description updated (diff)
Actions #2

Updated by Toshi MARUYAMA over 11 years ago

I think it is better to skip in Repository#fetch_changesets.

diff --git a/app/models/repository.rb b/app/models/repository.rb
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -327,6 +327,10 @@ class Repository < ActiveRecord::Base
   # Can be called periodically by an external script
   # eg. ruby script/runner "Repository.fetch_changesets" 
   def self.fetch_changesets
+    unless @project.active?
+      logger.warn "#{@project.name} is not active" 
+      return 
+    end
     Project.active.has_module(:repository).all.each do |project|
       project.repositories.each do |repository|
         begin
Actions #3

Updated by Toshi MARUYAMA over 11 years ago

Sorry, Repository#fetch_changesets is class method, so note-2 is wrong.
This is correct code.

diff --git a/app/models/repository.rb b/app/models/repository.rb
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -328,6 +328,10 @@ class Repository < ActiveRecord::Base
   # eg. ruby script/runner "Repository.fetch_changesets" 
   def self.fetch_changesets
     Project.active.has_module(:repository).all.each do |project|
+      unless project.active?
+        logger.warn "#{project.name} is not active" 
+        next
+      end
       project.repositories.each do |repository|
         begin
           repository.fetch_changesets

Actions #4

Updated by Toshi MARUYAMA over 11 years ago

Sorry, skipping is need in both view and Repository#fetch_changesets.

Actions #5

Updated by Fernando Hartmann over 11 years ago

+1

Actions #6

Updated by Mischa The Evil over 11 years ago

  • Description updated (diff)

Toshi MARUYAMA wrote:

Sorry, skipping is need in both view and Repository#fetch_changesets.

I've spent some time reviewing and testing this. I don't think we need to change Repository.fetch_changesets (the class method) at all, only the Repository#show method in the repositories controller needs to be modified.
The reason for this lies in the situation that Repository.fetch_changesets is already scoped to iterate only over projects which are active (as in STATUS_ACTIVE, as opposed to STATUS_CLOSED and STATUS_ARCHIVED) as a result of the use of the active scope (defined in source:/trunk/app/models/project.rb@11784#L89):

Project.active.has_module(:repository).all.each do |project|
 ...
end

I think by the way that the change I proposed in the description can be optimized by changing the order of the conditions (source:/trunk/app/controllers/repositories_controller.rb@11784#L114):

Index: app/controllers/repositories_controller.rb
===================================================================
--- app/controllers/repositories_controller.rb  (revision 11784)
+++ app/controllers/repositories_controller.rb  (working copy)
@@ -111,7 +111,7 @@
   end

   def show
-    @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
+    @repository.fetch_changesets if @project.active? && Setting.autofetch_changesets? && @path.empty?

     @entries = @repository.entries(@path, @rev)
     @changeset = @repository.find_changeset_by_name(@rev)

I've did a quick scan for any affected tests but couldn't find any. I do think that it would be good if this controller behavior is tested before it gets committed.

Actions #7

Updated by Toshi MARUYAMA over 11 years ago

  • Target version set to 2.4.0
Actions #8

Updated by Jean-Philippe Lang over 11 years ago

  • Status changed from New to Closed
  • Resolution set to Fixed

Patch committed with tests in r11838, thanks.

Actions

Also available in: Atom PDF