summaryrefslogtreecommitdiffstats
path: root/app/models/repository
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-03-12 20:28:49 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-03-12 20:28:49 +0000
commit3a9b0988c7515371531e47f9eef9f8e60ce352aa (patch)
tree2a2deaedbd321dcf838c631dfed357f3c1110dbe /app/models/repository
parent6fcc512cb77a0851ab8c3c693fd178b564a600dd (diff)
downloadredmine-3a9b0988c7515371531e47f9eef9f8e60ce352aa.tar.gz
redmine-3a9b0988c7515371531e47f9eef9f8e60ce352aa.zip
Merged Git support branch (r1200 to r1226).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1236 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/repository')
-rw-r--r--app/models/repository/bazaar.rb2
-rw-r--r--app/models/repository/cvs.rb40
-rw-r--r--app/models/repository/darcs.rb9
-rw-r--r--app/models/repository/git.rb70
-rw-r--r--app/models/repository/subversion.rb2
5 files changed, 95 insertions, 28 deletions
diff --git a/app/models/repository/bazaar.rb b/app/models/repository/bazaar.rb
index 6e387f957..1b75066c2 100644
--- a/app/models/repository/bazaar.rb
+++ b/app/models/repository/bazaar.rb
@@ -51,7 +51,7 @@ class Repository::Bazaar < Repository
scm_info = scm.info
if scm_info
# latest revision found in database
- db_revision = latest_changeset ? latest_changeset.revision : 0
+ db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
# latest revision in the repository
scm_revision = scm_info.lastrev.identifier.to_i
if db_revision < scm_revision
diff --git a/app/models/repository/cvs.rb b/app/models/repository/cvs.rb
index 16d906316..a78b60806 100644
--- a/app/models/repository/cvs.rb
+++ b/app/models/repository/cvs.rb
@@ -82,9 +82,6 @@ class Repository::Cvs < Repository
end
def fetch_changesets
- #not the preferred way with CVS. maybe we should introduce always a cron-job for this
- last_commit = changesets.maximum(:committed_on)
-
# some nifty bits to introduce a commit-id with cvs
# natively cvs doesn't provide any kind of changesets, there is only a revision per file.
# we now take a guess using the author, the commitlog and the commit-date.
@@ -94,8 +91,10 @@ class Repository::Cvs < Repository
# we use a small delta here, to merge all changes belonging to _one_ changeset
time_delta=10.seconds
+ fetch_since = latest_changeset ? latest_changeset.committed_on : nil
transaction do
- scm.revisions('', last_commit, nil, :with_paths => true) do |revision|
+ tmp_rev_num = 1
+ scm.revisions('', fetch_since, nil, :with_paths => true) do |revision|
# only add the change to the database, if it doen't exists. the cvs log
# is not exclusive at all.
unless changes.find_by_path_and_revision(scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
@@ -107,18 +106,16 @@ class Repository::Cvs < Repository
})
# create a new changeset....
- unless cs
- # we use a negative changeset-number here (just for inserting)
+ unless cs
+ # we use a temporaray revision number here (just for inserting)
# later on, we calculate a continous positive number
- next_rev = changesets.minimum(:revision)
- next_rev = 0 if next_rev.nil? or next_rev > 0
- next_rev = next_rev - 1
-
- cs=Changeset.create(:repository => self,
- :revision => next_rev,
- :committer => revision.author,
- :committed_on => revision.time,
- :comments => revision.message)
+ latest = changesets.find(:first, :order => 'id DESC')
+ cs = Changeset.create(:repository => self,
+ :revision => "_#{tmp_rev_num}",
+ :committer => revision.author,
+ :committed_on => revision.time,
+ :comments => revision.message)
+ tmp_rev_num += 1
end
#convert CVS-File-States to internal Action-abbrevations
@@ -139,12 +136,13 @@ class Repository::Cvs < Repository
end
end
- next_rev = [changesets.maximum(:revision) || 0, 0].max
- changesets.find(:all, :conditions=>["revision < 0"], :order=>"committed_on ASC").each() do |changeset|
- next_rev = next_rev + 1
- changeset.revision = next_rev
- changeset.save!
+ # Renumber new changesets in chronological order
+ c = changesets.find(:first, :order => 'committed_on DESC, id DESC', :conditions => "revision NOT LIKE '_%'")
+ next_rev = c.nil? ? 1 : (c.revision.to_i + 1)
+ changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset|
+ changeset.update_attribute :revision, next_rev
+ next_rev += 1
end
- end
+ end # transaction
end
end
diff --git a/app/models/repository/darcs.rb b/app/models/repository/darcs.rb
index 48cc246fb..cc608d370 100644
--- a/app/models/repository/darcs.rb
+++ b/app/models/repository/darcs.rb
@@ -47,18 +47,19 @@ class Repository::Darcs < Repository
def diff(path, rev, rev_to, type)
patch_from = changesets.find_by_revision(rev)
+ return nil if patch_from.nil?
patch_to = changesets.find_by_revision(rev_to) if rev_to
if path.blank?
path = patch_from.changes.collect{|change| change.path}.join(' ')
end
- scm.diff(path, patch_from.scmid, patch_to.scmid, type)
+ patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil, type) : nil
end
def fetch_changesets
scm_info = scm.info
if scm_info
db_last_id = latest_changeset ? latest_changeset.scmid : nil
- next_rev = latest_changeset ? latest_changeset.revision + 1 : 1
+ next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
# latest revision in the repository
scm_revision = scm_info.lastrev.scmid
unless changesets.find_by_scmid(scm_revision)
@@ -71,9 +72,7 @@ class Repository::Darcs < Repository
:committer => revision.author,
:committed_on => revision.time,
:comments => revision.message)
-
- next if changeset.new_record?
-
+
revision.paths.each do |change|
Change.create(:changeset => changeset,
:action => change[:action],
diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb
new file mode 100644
index 000000000..7213588ac
--- /dev/null
+++ b/app/models/repository/git.rb
@@ -0,0 +1,70 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Copyright (C) 2007 Patrick Aljord patcito@Ĺ‹mail.com
+# 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.
+#
+# 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.
+#
+# 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/git_adapter'
+
+class Repository::Git < Repository
+ attr_protected :root_url
+ validates_presence_of :url
+
+ def scm_adapter
+ Redmine::Scm::Adapters::GitAdapter
+ end
+
+ def self.scm_name
+ 'Git'
+ end
+
+ def changesets_for_path(path)
+ Change.find(:all, :include => :changeset,
+ :conditions => ["repository_id = ? AND path = ?", id, path],
+ :order => "committed_on DESC, #{Changeset.table_name}.revision DESC").collect(&:changeset)
+ end
+
+ def fetch_changesets
+ scm_info = scm.info
+ if scm_info
+ # latest revision found in database
+ db_revision = latest_changeset ? latest_changeset.revision : nil
+ # latest revision in the repository
+ scm_revision = scm_info.lastrev.scmid
+
+ unless changesets.find_by_scmid(scm_revision)
+
+ revisions = scm.revisions('', db_revision, nil)
+ transaction do
+ revisions.reverse_each do |revision|
+ changeset = Changeset.create(:repository => self,
+ :revision => revision.identifier,
+ :scmid => revision.scmid,
+ :committer => revision.author,
+ :committed_on => revision.time,
+ :comments => revision.message)
+
+ revision.paths.each do |change|
+ Change.create(:changeset => changeset,
+ :action => change[:action],
+ :path => change[:path],
+ :from_path => change[:from_path],
+ :from_revision => change[:from_revision])
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/app/models/repository/subversion.rb b/app/models/repository/subversion.rb
index a0485608d..0c2239c43 100644
--- a/app/models/repository/subversion.rb
+++ b/app/models/repository/subversion.rb
@@ -39,7 +39,7 @@ class Repository::Subversion < Repository
scm_info = scm.info
if scm_info
# latest revision found in database
- db_revision = latest_changeset ? latest_changeset.revision : 0
+ db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
# latest revision in the repository
scm_revision = scm_info.lastrev.identifier.to_i
if db_revision < scm_revision