Mercurial > hg > soundsoftware-site
comparison app/models/repository/git.rb @ 441:cbce1fd3b1b7 redmine-1.2
Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author | Chris Cannam |
---|---|
date | Mon, 06 Jun 2011 14:24:13 +0100 |
parents | 051f544170fe |
children | 753f1380d6bc 0c939c159af4 |
comparison
equal
deleted
inserted
replaced
245:051f544170fe | 441:cbce1fd3b1b7 |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com | 3 # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com |
4 # | |
4 # This program is free software; you can redistribute it and/or | 5 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 6 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 7 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 8 # of the License, or (at your option) any later version. |
8 # | 9 # |
9 # This program is distributed in the hope that it will be useful, | 10 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
13 # | 14 # |
14 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 16 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 18 |
18 require 'redmine/scm/adapters/git_adapter' | 19 require 'redmine/scm/adapters/git_adapter' |
19 | 20 |
20 class Repository::Git < Repository | 21 class Repository::Git < Repository |
21 attr_protected :root_url | 22 attr_protected :root_url |
22 validates_presence_of :url | 23 validates_presence_of :url |
23 | 24 |
24 ATTRIBUTE_KEY_NAMES = { | |
25 "url" => "Path to repository", | |
26 } | |
27 def self.human_attribute_name(attribute_key_name) | 25 def self.human_attribute_name(attribute_key_name) |
28 ATTRIBUTE_KEY_NAMES[attribute_key_name] || super | 26 attr_name = attribute_key_name |
27 if attr_name == "url" | |
28 attr_name = "path_to_repository" | |
29 end | |
30 super(attr_name) | |
29 end | 31 end |
30 | 32 |
31 def self.scm_adapter_class | 33 def self.scm_adapter_class |
32 Redmine::Scm::Adapters::GitAdapter | 34 Redmine::Scm::Adapters::GitAdapter |
33 end | 35 end |
34 | 36 |
35 def self.scm_name | 37 def self.scm_name |
36 'Git' | 38 'Git' |
39 end | |
40 | |
41 def report_last_commit | |
42 extra_report_last_commit | |
43 end | |
44 | |
45 def extra_report_last_commit | |
46 return false if extra_info.nil? | |
47 v = extra_info["extra_report_last_commit"] | |
48 return false if v.nil? | |
49 v.to_s != '0' | |
50 end | |
51 | |
52 def supports_directory_revisions? | |
53 true | |
37 end | 54 end |
38 | 55 |
39 def repo_log_encoding | 56 def repo_log_encoding |
40 'UTF-8' | 57 'UTF-8' |
41 end | 58 end |
63 e = changesets.find(:first, :conditions => ['revision = ?', name.to_s]) | 80 e = changesets.find(:first, :conditions => ['revision = ?', name.to_s]) |
64 return e if e | 81 return e if e |
65 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) | 82 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) |
66 end | 83 end |
67 | 84 |
68 # With SCM's that have a sequential commit numbering, redmine is able to be | 85 def entries(path=nil, identifier=nil) |
69 # clever and only fetch changesets going forward from the most recent one | 86 scm.entries(path, |
70 # it knows about. However, with git, you never know if people have merged | 87 identifier, |
71 # commits into the middle of the repository history, so we should parse | 88 options = {:report_last_commit => extra_report_last_commit}) |
72 # the entire log. Since it's way too slow for large repositories, we only | 89 end |
73 # parse 1 week before the last known commit. | 90 |
91 # In Git and Mercurial, revisions are not in date order. | |
92 # Redmine Mercurial fixed issues. | |
93 # * Redmine Takes Too Long On Large Mercurial Repository | |
94 # http://www.redmine.org/issues/3449 | |
95 # * Sorting for changesets might go wrong on Mercurial repos | |
96 # http://www.redmine.org/issues/3567 | |
97 # | |
98 # Database revision column is text, so Redmine can not sort by revision. | |
99 # Mercurial has revision number, and revision number guarantees revision order. | |
100 # Redmine Mercurial model stored revisions ordered by database id to database. | |
101 # So, Redmine Mercurial model can use correct ordering revisions. | |
102 # | |
103 # Redmine Mercurial adapter uses "hg log -r 0:tip --limit 10" | |
104 # to get limited revisions from old to new. | |
105 # But, Git 1.7.3.4 does not support --reverse with -n or --skip. | |
106 # | |
74 # The repository can still be fully reloaded by calling #clear_changesets | 107 # The repository can still be fully reloaded by calling #clear_changesets |
75 # before fetching changesets (eg. for offline resync) | 108 # before fetching changesets (eg. for offline resync) |
76 def fetch_changesets | 109 def fetch_changesets |
77 c = changesets.find(:first, :order => 'committed_on DESC') | 110 scm_brs = branches |
78 since = (c ? c.committed_on - 7.days : nil) | 111 return if scm_brs.nil? || scm_brs.empty? |
79 | 112 h1 = extra_info || {} |
80 revisions = scm.revisions('', nil, nil, :all => true, :since => since) | 113 h = h1.dup |
81 return if revisions.nil? || revisions.empty? | 114 h["branches"] ||= {} |
82 | 115 h["db_consistent"] ||= {} |
83 recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since]) | 116 if changesets.count == 0 |
84 | 117 h["db_consistent"]["ordering"] = 1 |
85 # Clean out revisions that are no longer in git | 118 merge_extra_info(h) |
86 recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }} | 119 self.save |
87 | 120 elsif ! h["db_consistent"].has_key?("ordering") |
88 # Subtract revisions that redmine already knows about | 121 h["db_consistent"]["ordering"] = 0 |
89 recent_revisions = recent_changesets.map{|c| c.scmid} | 122 merge_extra_info(h) |
90 revisions.reject!{|r| recent_revisions.include?(r.scmid)} | 123 self.save |
91 | 124 end |
92 # Save the remaining ones to the database | 125 scm_brs.each do |br| |
93 unless revisions.nil? | 126 from_scmid = nil |
94 revisions.each do |rev| | 127 from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br] |
128 h["branches"][br] ||= {} | |
129 scm.revisions('', from_scmid, br, {:reverse => true}) do |rev| | |
130 db_rev = find_changeset_by_name(rev.revision) | |
95 transaction do | 131 transaction do |
96 changeset = Changeset.new( | 132 if db_rev.nil? |
97 :repository => self, | 133 save_revision(rev) |
98 :revision => rev.identifier, | |
99 :scmid => rev.scmid, | |
100 :committer => rev.author, | |
101 :committed_on => rev.time, | |
102 :comments => rev.message) | |
103 | |
104 if changeset.save | |
105 rev.paths.each do |file| | |
106 Change.create( | |
107 :changeset => changeset, | |
108 :action => file[:action], | |
109 :path => file[:path]) | |
110 end | |
111 end | 134 end |
135 h["branches"][br]["last_scmid"] = rev.scmid | |
136 merge_extra_info(h) | |
137 self.save | |
112 end | 138 end |
113 end | 139 end |
114 end | 140 end |
115 end | 141 end |
142 | |
143 def save_revision(rev) | |
144 changeset = Changeset.new( | |
145 :repository => self, | |
146 :revision => rev.identifier, | |
147 :scmid => rev.scmid, | |
148 :committer => rev.author, | |
149 :committed_on => rev.time, | |
150 :comments => rev.message | |
151 ) | |
152 if changeset.save | |
153 rev.paths.each do |file| | |
154 Change.create( | |
155 :changeset => changeset, | |
156 :action => file[:action], | |
157 :path => file[:path]) | |
158 end | |
159 end | |
160 end | |
161 private :save_revision | |
116 | 162 |
117 def latest_changesets(path,rev,limit=10) | 163 def latest_changesets(path,rev,limit=10) |
118 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false) | 164 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false) |
119 return [] if revisions.nil? || revisions.empty? | 165 return [] if revisions.nil? || revisions.empty? |
120 | 166 |
121 changesets.find( | 167 changesets.find( |
122 :all, | 168 :all, |
123 :conditions => [ | 169 :conditions => [ |
124 "scmid IN (?)", | 170 "scmid IN (?)", |
125 revisions.map!{|c| c.scmid} | 171 revisions.map!{|c| c.scmid} |
126 ], | 172 ], |
127 :order => 'committed_on DESC' | 173 :order => 'committed_on DESC' |
128 ) | 174 ) |
129 end | 175 end |