annotate .svn/pristine/c1/c128d2ce14d4d2cfb1b77472bf159a0c56df467f.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require 'redmine/scm/adapters/cvs_adapter'
Chris@1517 19 require 'digest/sha1'
Chris@1517 20
Chris@1517 21 class Repository::Cvs < Repository
Chris@1517 22 validates_presence_of :url, :root_url, :log_encoding
Chris@1517 23
Chris@1517 24 safe_attributes 'root_url',
Chris@1517 25 :if => lambda {|repository, user| repository.new_record?}
Chris@1517 26
Chris@1517 27 def self.human_attribute_name(attribute_key_name, *args)
Chris@1517 28 attr_name = attribute_key_name.to_s
Chris@1517 29 if attr_name == "root_url"
Chris@1517 30 attr_name = "cvsroot"
Chris@1517 31 elsif attr_name == "url"
Chris@1517 32 attr_name = "cvs_module"
Chris@1517 33 end
Chris@1517 34 super(attr_name, *args)
Chris@1517 35 end
Chris@1517 36
Chris@1517 37 def self.scm_adapter_class
Chris@1517 38 Redmine::Scm::Adapters::CvsAdapter
Chris@1517 39 end
Chris@1517 40
Chris@1517 41 def self.scm_name
Chris@1517 42 'CVS'
Chris@1517 43 end
Chris@1517 44
Chris@1517 45 def entry(path=nil, identifier=nil)
Chris@1517 46 rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
Chris@1517 47 scm.entry(path, rev.nil? ? nil : rev.committed_on)
Chris@1517 48 end
Chris@1517 49
Chris@1517 50 def scm_entries(path=nil, identifier=nil)
Chris@1517 51 rev = nil
Chris@1517 52 if ! identifier.nil?
Chris@1517 53 rev = changesets.find_by_revision(identifier)
Chris@1517 54 return nil if rev.nil?
Chris@1517 55 end
Chris@1517 56 entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
Chris@1517 57 if entries
Chris@1517 58 entries.each() do |entry|
Chris@1517 59 if ( ! entry.lastrev.nil? ) && ( ! entry.lastrev.revision.nil? )
Chris@1517 60 change = filechanges.find_by_revision_and_path(
Chris@1517 61 entry.lastrev.revision,
Chris@1517 62 scm.with_leading_slash(entry.path) )
Chris@1517 63 if change
Chris@1517 64 entry.lastrev.identifier = change.changeset.revision
Chris@1517 65 entry.lastrev.revision = change.changeset.revision
Chris@1517 66 entry.lastrev.author = change.changeset.committer
Chris@1517 67 # entry.lastrev.branch = change.branch
Chris@1517 68 end
Chris@1517 69 end
Chris@1517 70 end
Chris@1517 71 end
Chris@1517 72 entries
Chris@1517 73 end
Chris@1517 74 protected :scm_entries
Chris@1517 75
Chris@1517 76 def cat(path, identifier=nil)
Chris@1517 77 rev = nil
Chris@1517 78 if ! identifier.nil?
Chris@1517 79 rev = changesets.find_by_revision(identifier)
Chris@1517 80 return nil if rev.nil?
Chris@1517 81 end
Chris@1517 82 scm.cat(path, rev.nil? ? nil : rev.committed_on)
Chris@1517 83 end
Chris@1517 84
Chris@1517 85 def annotate(path, identifier=nil)
Chris@1517 86 rev = nil
Chris@1517 87 if ! identifier.nil?
Chris@1517 88 rev = changesets.find_by_revision(identifier)
Chris@1517 89 return nil if rev.nil?
Chris@1517 90 end
Chris@1517 91 scm.annotate(path, rev.nil? ? nil : rev.committed_on)
Chris@1517 92 end
Chris@1517 93
Chris@1517 94 def diff(path, rev, rev_to)
Chris@1517 95 # convert rev to revision. CVS can't handle changesets here
Chris@1517 96 diff=[]
Chris@1517 97 changeset_from = changesets.find_by_revision(rev)
Chris@1517 98 if rev_to.to_i > 0
Chris@1517 99 changeset_to = changesets.find_by_revision(rev_to)
Chris@1517 100 end
Chris@1517 101 changeset_from.filechanges.each() do |change_from|
Chris@1517 102 revision_from = nil
Chris@1517 103 revision_to = nil
Chris@1517 104 if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
Chris@1517 105 revision_from = change_from.revision
Chris@1517 106 end
Chris@1517 107 if revision_from
Chris@1517 108 if changeset_to
Chris@1517 109 changeset_to.filechanges.each() do |change_to|
Chris@1517 110 revision_to = change_to.revision if change_to.path == change_from.path
Chris@1517 111 end
Chris@1517 112 end
Chris@1517 113 unless revision_to
Chris@1517 114 revision_to = scm.get_previous_revision(revision_from)
Chris@1517 115 end
Chris@1517 116 file_diff = scm.diff(change_from.path, revision_from, revision_to)
Chris@1517 117 diff = diff + file_diff unless file_diff.nil?
Chris@1517 118 end
Chris@1517 119 end
Chris@1517 120 return diff
Chris@1517 121 end
Chris@1517 122
Chris@1517 123 def fetch_changesets
Chris@1517 124 # some nifty bits to introduce a commit-id with cvs
Chris@1517 125 # natively cvs doesn't provide any kind of changesets,
Chris@1517 126 # there is only a revision per file.
Chris@1517 127 # we now take a guess using the author, the commitlog and the commit-date.
Chris@1517 128
Chris@1517 129 # last one is the next step to take. the commit-date is not equal for all
Chris@1517 130 # commits in one changeset. cvs update the commit-date when the *,v file was touched. so
Chris@1517 131 # we use a small delta here, to merge all changes belonging to _one_ changeset
Chris@1517 132 time_delta = 10.seconds
Chris@1517 133 fetch_since = latest_changeset ? latest_changeset.committed_on : nil
Chris@1517 134 transaction do
Chris@1517 135 tmp_rev_num = 1
Chris@1517 136 scm.revisions('', fetch_since, nil, :log_encoding => repo_log_encoding) do |revision|
Chris@1517 137 # only add the change to the database, if it doen't exists. the cvs log
Chris@1517 138 # is not exclusive at all.
Chris@1517 139 tmp_time = revision.time.clone
Chris@1517 140 unless filechanges.find_by_path_and_revision(
Chris@1517 141 scm.with_leading_slash(revision.paths[0][:path]),
Chris@1517 142 revision.paths[0][:revision]
Chris@1517 143 )
Chris@1517 144 cmt = Changeset.normalize_comments(revision.message, repo_log_encoding)
Chris@1517 145 author_utf8 = Changeset.to_utf8(revision.author, repo_log_encoding)
Chris@1517 146 cs = changesets.where(
Chris@1517 147 :committed_on => tmp_time - time_delta .. tmp_time + time_delta,
Chris@1517 148 :committer => author_utf8,
Chris@1517 149 :comments => cmt
Chris@1517 150 ).first
Chris@1517 151 # create a new changeset....
Chris@1517 152 unless cs
Chris@1517 153 # we use a temporaray revision number here (just for inserting)
Chris@1517 154 # later on, we calculate a continous positive number
Chris@1517 155 tmp_time2 = tmp_time.clone.gmtime
Chris@1517 156 branch = revision.paths[0][:branch]
Chris@1517 157 scmid = branch + "-" + tmp_time2.strftime("%Y%m%d-%H%M%S")
Chris@1517 158 cs = Changeset.create(:repository => self,
Chris@1517 159 :revision => "tmp#{tmp_rev_num}",
Chris@1517 160 :scmid => scmid,
Chris@1517 161 :committer => revision.author,
Chris@1517 162 :committed_on => tmp_time,
Chris@1517 163 :comments => revision.message)
Chris@1517 164 tmp_rev_num += 1
Chris@1517 165 end
Chris@1517 166 # convert CVS-File-States to internal Action-abbrevations
Chris@1517 167 # default action is (M)odified
Chris@1517 168 action = "M"
Chris@1517 169 if revision.paths[0][:action] == "Exp" && revision.paths[0][:revision] == "1.1"
Chris@1517 170 action = "A" # add-action always at first revision (= 1.1)
Chris@1517 171 elsif revision.paths[0][:action] == "dead"
Chris@1517 172 action = "D" # dead-state is similar to Delete
Chris@1517 173 end
Chris@1517 174 Change.create(
Chris@1517 175 :changeset => cs,
Chris@1517 176 :action => action,
Chris@1517 177 :path => scm.with_leading_slash(revision.paths[0][:path]),
Chris@1517 178 :revision => revision.paths[0][:revision],
Chris@1517 179 :branch => revision.paths[0][:branch]
Chris@1517 180 )
Chris@1517 181 end
Chris@1517 182 end
Chris@1517 183
Chris@1517 184 # Renumber new changesets in chronological order
Chris@1517 185 Changeset.
Chris@1517 186 order('committed_on ASC, id ASC').
Chris@1517 187 where("repository_id = ? AND revision LIKE 'tmp%'", id).
Chris@1517 188 each do |changeset|
Chris@1517 189 changeset.update_attribute :revision, next_revision_number
Chris@1517 190 end
Chris@1517 191 end # transaction
Chris@1517 192 @current_revision_number = nil
Chris@1517 193 end
Chris@1517 194
Chris@1517 195 private
Chris@1517 196
Chris@1517 197 # Returns the next revision number to assign to a CVS changeset
Chris@1517 198 def next_revision_number
Chris@1517 199 # Need to retrieve existing revision numbers to sort them as integers
Chris@1517 200 sql = "SELECT revision FROM #{Changeset.table_name} "
Chris@1517 201 sql << "WHERE repository_id = #{id} AND revision NOT LIKE 'tmp%'"
Chris@1517 202 @current_revision_number ||= (connection.select_values(sql).collect(&:to_i).max || 0)
Chris@1517 203 @current_revision_number += 1
Chris@1517 204 end
Chris@1517 205 end