2011-05-12 11:16:20 +04:00
|
|
|
# Redmine - project management software
|
2014-01-30 02:45:39 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2007-06-13 00:12:05 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-12 11:16:20 +04:00
|
|
|
#
|
2007-06-13 00:12:05 +04:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-05-12 11:16:20 +04:00
|
|
|
#
|
2007-06-13 00:12:05 +04:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
require 'redmine/scm/adapters/cvs_adapter'
|
|
|
|
require 'digest/sha1'
|
|
|
|
|
|
|
|
class Repository::Cvs < Repository
|
2011-03-01 13:27:30 +03:00
|
|
|
validates_presence_of :url, :root_url, :log_encoding
|
2007-06-13 00:12:05 +04:00
|
|
|
|
2012-06-20 22:45:51 +04:00
|
|
|
safe_attributes 'root_url',
|
|
|
|
:if => lambda {|repository, user| repository.new_record?}
|
2012-06-19 23:47:54 +04:00
|
|
|
|
2011-12-18 17:20:19 +04:00
|
|
|
def self.human_attribute_name(attribute_key_name, *args)
|
2012-02-24 18:58:18 +04:00
|
|
|
attr_name = attribute_key_name.to_s
|
2011-04-23 11:40:23 +04:00
|
|
|
if attr_name == "root_url"
|
|
|
|
attr_name = "cvsroot"
|
|
|
|
elsif attr_name == "url"
|
|
|
|
attr_name = "cvs_module"
|
|
|
|
end
|
2011-12-18 17:20:19 +04:00
|
|
|
super(attr_name, *args)
|
2011-03-01 08:14:03 +03:00
|
|
|
end
|
|
|
|
|
2011-02-14 11:45:34 +03:00
|
|
|
def self.scm_adapter_class
|
2007-06-13 00:12:05 +04:00
|
|
|
Redmine::Scm::Adapters::CvsAdapter
|
|
|
|
end
|
2011-02-14 11:45:34 +03:00
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def self.scm_name
|
|
|
|
'CVS'
|
|
|
|
end
|
2011-02-14 11:45:34 +03:00
|
|
|
|
2008-06-15 19:47:28 +04:00
|
|
|
def entry(path=nil, identifier=nil)
|
|
|
|
rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
|
|
|
scm.entry(path, rev.nil? ? nil : rev.committed_on)
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2011-04-12 09:44:10 +04:00
|
|
|
|
2014-02-02 04:40:59 +04:00
|
|
|
def scm_entries(path=nil, identifier=nil)
|
2011-04-12 09:44:10 +04:00
|
|
|
rev = nil
|
|
|
|
if ! identifier.nil?
|
|
|
|
rev = changesets.find_by_revision(identifier)
|
|
|
|
return nil if rev.nil?
|
|
|
|
end
|
2008-04-06 14:35:55 +04:00
|
|
|
entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
|
2007-06-13 00:12:05 +04:00
|
|
|
if entries
|
|
|
|
entries.each() do |entry|
|
2011-03-11 15:06:05 +03:00
|
|
|
if ( ! entry.lastrev.nil? ) && ( ! entry.lastrev.revision.nil? )
|
2012-06-03 15:46:58 +04:00
|
|
|
change = filechanges.find_by_revision_and_path(
|
2011-03-11 03:43:24 +03:00
|
|
|
entry.lastrev.revision,
|
|
|
|
scm.with_leading_slash(entry.path) )
|
2007-06-13 00:12:05 +04:00
|
|
|
if change
|
2011-03-11 03:43:24 +03:00
|
|
|
entry.lastrev.identifier = change.changeset.revision
|
2011-03-11 15:06:05 +03:00
|
|
|
entry.lastrev.revision = change.changeset.revision
|
2011-03-11 03:43:24 +03:00
|
|
|
entry.lastrev.author = change.changeset.committer
|
2011-03-11 15:06:05 +03:00
|
|
|
# entry.lastrev.branch = change.branch
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
entries
|
|
|
|
end
|
2014-02-02 04:40:59 +04:00
|
|
|
protected :scm_entries
|
2011-04-11 19:43:50 +04:00
|
|
|
|
2008-06-15 19:47:28 +04:00
|
|
|
def cat(path, identifier=nil)
|
2011-04-11 17:12:37 +04:00
|
|
|
rev = nil
|
|
|
|
if ! identifier.nil?
|
|
|
|
rev = changesets.find_by_revision(identifier)
|
|
|
|
return nil if rev.nil?
|
|
|
|
end
|
2008-06-15 19:47:28 +04:00
|
|
|
scm.cat(path, rev.nil? ? nil : rev.committed_on)
|
|
|
|
end
|
2011-04-11 19:43:50 +04:00
|
|
|
|
|
|
|
def annotate(path, identifier=nil)
|
|
|
|
rev = nil
|
|
|
|
if ! identifier.nil?
|
|
|
|
rev = changesets.find_by_revision(identifier)
|
|
|
|
return nil if rev.nil?
|
|
|
|
end
|
|
|
|
scm.annotate(path, rev.nil? ? nil : rev.committed_on)
|
|
|
|
end
|
|
|
|
|
2008-06-08 20:28:42 +04:00
|
|
|
def diff(path, rev, rev_to)
|
2011-04-11 16:05:59 +04:00
|
|
|
# convert rev to revision. CVS can't handle changesets here
|
2007-06-13 00:12:05 +04:00
|
|
|
diff=[]
|
2011-04-11 16:05:59 +04:00
|
|
|
changeset_from = changesets.find_by_revision(rev)
|
2011-05-12 11:16:20 +04:00
|
|
|
if rev_to.to_i > 0
|
2011-04-11 16:05:59 +04:00
|
|
|
changeset_to = changesets.find_by_revision(rev_to)
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2012-06-03 15:46:58 +04:00
|
|
|
changeset_from.filechanges.each() do |change_from|
|
2011-04-10 03:22:22 +04:00
|
|
|
revision_from = nil
|
2011-05-12 11:16:20 +04:00
|
|
|
revision_to = nil
|
2011-04-10 03:22:22 +04:00
|
|
|
if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
|
2011-04-11 16:05:59 +04:00
|
|
|
revision_from = change_from.revision
|
2011-04-10 03:22:22 +04:00
|
|
|
end
|
2007-06-13 00:12:05 +04:00
|
|
|
if revision_from
|
|
|
|
if changeset_to
|
2012-06-03 15:46:58 +04:00
|
|
|
changeset_to.filechanges.each() do |change_to|
|
2011-05-12 11:16:20 +04:00
|
|
|
revision_to = change_to.revision if change_to.path == change_from.path
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
unless revision_to
|
2011-05-12 11:16:20 +04:00
|
|
|
revision_to = scm.get_previous_revision(revision_from)
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2008-06-14 14:51:15 +04:00
|
|
|
file_diff = scm.diff(change_from.path, revision_from, revision_to)
|
|
|
|
diff = diff + file_diff unless file_diff.nil?
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return diff
|
|
|
|
end
|
2011-04-10 03:22:22 +04:00
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def fetch_changesets
|
|
|
|
# some nifty bits to introduce a commit-id with cvs
|
2011-04-10 03:22:22 +04:00
|
|
|
# natively cvs doesn't provide any kind of changesets,
|
|
|
|
# there is only a revision per file.
|
2007-06-13 00:12:05 +04:00
|
|
|
# we now take a guess using the author, the commitlog and the commit-date.
|
2011-05-12 11:16:20 +04:00
|
|
|
|
|
|
|
# last one is the next step to take. the commit-date is not equal for all
|
2007-06-13 00:12:05 +04:00
|
|
|
# commits in one changeset. cvs update the commit-date when the *,v file was touched. so
|
|
|
|
# we use a small delta here, to merge all changes belonging to _one_ changeset
|
2011-04-13 15:54:42 +04:00
|
|
|
time_delta = 10.seconds
|
2008-03-12 23:28:49 +03:00
|
|
|
fetch_since = latest_changeset ? latest_changeset.committed_on : nil
|
2007-06-13 00:12:05 +04:00
|
|
|
transaction do
|
2008-03-12 23:28:49 +03:00
|
|
|
tmp_rev_num = 1
|
2011-04-14 19:39:00 +04:00
|
|
|
scm.revisions('', fetch_since, nil, :log_encoding => repo_log_encoding) do |revision|
|
2007-06-13 00:12:05 +04:00
|
|
|
# only add the change to the database, if it doen't exists. the cvs log
|
2011-05-12 11:16:20 +04:00
|
|
|
# is not exclusive at all.
|
2011-02-07 13:26:15 +03:00
|
|
|
tmp_time = revision.time.clone
|
2012-06-03 15:46:58 +04:00
|
|
|
unless filechanges.find_by_path_and_revision(
|
2011-04-13 15:54:42 +04:00
|
|
|
scm.with_leading_slash(revision.paths[0][:path]),
|
|
|
|
revision.paths[0][:revision]
|
|
|
|
)
|
2011-02-28 15:09:32 +03:00
|
|
|
cmt = Changeset.normalize_comments(revision.message, repo_log_encoding)
|
2011-04-14 19:01:55 +04:00
|
|
|
author_utf8 = Changeset.to_utf8(revision.author, repo_log_encoding)
|
2013-06-12 23:13:25 +04:00
|
|
|
cs = changesets.where(
|
|
|
|
:committed_on => tmp_time - time_delta .. tmp_time + time_delta,
|
|
|
|
:committer => author_utf8,
|
|
|
|
:comments => cmt
|
|
|
|
).first
|
2011-05-12 11:16:20 +04:00
|
|
|
# create a new changeset....
|
2008-03-12 23:28:49 +03:00
|
|
|
unless cs
|
|
|
|
# we use a temporaray revision number here (just for inserting)
|
2007-06-13 00:12:05 +04:00
|
|
|
# later on, we calculate a continous positive number
|
2011-02-07 13:26:15 +03:00
|
|
|
tmp_time2 = tmp_time.clone.gmtime
|
2011-04-13 15:54:42 +04:00
|
|
|
branch = revision.paths[0][:branch]
|
|
|
|
scmid = branch + "-" + tmp_time2.strftime("%Y%m%d-%H%M%S")
|
|
|
|
cs = Changeset.create(:repository => self,
|
|
|
|
:revision => "tmp#{tmp_rev_num}",
|
|
|
|
:scmid => scmid,
|
2011-05-12 11:16:20 +04:00
|
|
|
:committer => revision.author,
|
2011-02-07 13:26:15 +03:00
|
|
|
:committed_on => tmp_time,
|
2011-04-13 15:54:42 +04:00
|
|
|
:comments => revision.message)
|
2008-03-12 23:28:49 +03:00
|
|
|
tmp_rev_num += 1
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2011-04-13 15:54:42 +04:00
|
|
|
# convert CVS-File-States to internal Action-abbrevations
|
|
|
|
# default action is (M)odified
|
|
|
|
action = "M"
|
|
|
|
if revision.paths[0][:action] == "Exp" && revision.paths[0][:revision] == "1.1"
|
|
|
|
action = "A" # add-action always at first revision (= 1.1)
|
|
|
|
elsif revision.paths[0][:action] == "dead"
|
|
|
|
action = "D" # dead-state is similar to Delete
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2011-04-10 03:22:22 +04:00
|
|
|
Change.create(
|
|
|
|
:changeset => cs,
|
|
|
|
:action => action,
|
|
|
|
:path => scm.with_leading_slash(revision.paths[0][:path]),
|
|
|
|
:revision => revision.paths[0][:revision],
|
|
|
|
:branch => revision.paths[0][:branch]
|
|
|
|
)
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
end
|
2011-05-12 11:16:20 +04:00
|
|
|
|
2008-03-12 23:28:49 +03:00
|
|
|
# Renumber new changesets in chronological order
|
2013-06-12 23:13:25 +04:00
|
|
|
Changeset.
|
|
|
|
order('committed_on ASC, id ASC').
|
|
|
|
where("repository_id = ? AND revision LIKE 'tmp%'", id).
|
|
|
|
each do |changeset|
|
2014-02-13 11:13:59 +04:00
|
|
|
changeset.update_attribute :revision, next_revision_number
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
end # transaction
|
2011-02-07 13:25:52 +03:00
|
|
|
@current_revision_number = nil
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2011-04-10 03:22:22 +04:00
|
|
|
|
2008-04-24 21:28:55 +04:00
|
|
|
private
|
2011-04-10 03:22:22 +04:00
|
|
|
|
2008-04-24 21:28:55 +04:00
|
|
|
# Returns the next revision number to assign to a CVS changeset
|
|
|
|
def next_revision_number
|
|
|
|
# Need to retrieve existing revision numbers to sort them as integers
|
2011-02-07 13:25:52 +03:00
|
|
|
sql = "SELECT revision FROM #{Changeset.table_name} "
|
|
|
|
sql << "WHERE repository_id = #{id} AND revision NOT LIKE 'tmp%'"
|
|
|
|
@current_revision_number ||= (connection.select_values(sql).collect(&:to_i).max || 0)
|
2008-04-24 21:28:55 +04:00
|
|
|
@current_revision_number += 1
|
|
|
|
end
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|