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