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