annotate .svn/pristine/a5/a50c8a4fc61822f00307fa81cf3630d9ac86b4c0.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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