diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/changeset.rb | 8 | ||||
-rw-r--r-- | app/models/repository.rb | 12 |
2 files changed, 19 insertions, 1 deletions
diff --git a/app/models/changeset.rb b/app/models/changeset.rb index fea170ddc..cf58c6e07 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -130,7 +130,7 @@ class Changeset < ActiveRecord::Base refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m| issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2] - if issue + if issue && !issue_linked_to_same_commit?(issue) referenced_issues << issue # Don't update issues or log time when importing old commits unless repository.created_on && committed_on && committed_on < repository.created_on @@ -214,6 +214,12 @@ class Changeset < ActiveRecord::Base private + # Returns true if the issue is already linked to the same commit + # from a different repository + def issue_linked_to_same_commit?(issue) + repository.same_commits_in_scope(issue.changesets, self).any? + end + # Updates the +issue+ according to +action+ def fix_issue(issue, action) # the issue may have been updated by the closure of another one (eg. duplicate) diff --git a/app/models/repository.rb b/app/models/repository.rb index fe08e95ce..25b0e1da8 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -442,6 +442,18 @@ class Repository < ActiveRecord::Base end end + # Returns a scope of changesets that come from the same commit as the given changeset + # in different repositories that point to the same backend + def same_commits_in_scope(scope, changeset) + scope = scope.joins(:repository).where(:repositories => {:url => url, :root_url => root_url, :type => type}) + if changeset.scmid.present? + scope = scope.where(:scmid => changeset.scmid) + else + scope = scope.where(:revision => changeset.revision) + end + scope + end + protected def check_default |