Mercurial > hg > soundsoftware-site
comparison app/models/repository/mercurial.rb @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | e248c7af89ec |
children | a1bdbf8a87d5 |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
57 'UTF-8' | 57 'UTF-8' |
58 end | 58 end |
59 | 59 |
60 # Returns the readable identifier for the given mercurial changeset | 60 # Returns the readable identifier for the given mercurial changeset |
61 def self.format_changeset_identifier(changeset) | 61 def self.format_changeset_identifier(changeset) |
62 "#{changeset.revision}:#{changeset.scmid}" | 62 "#{changeset.revision}:#{changeset.scmid[0, 12]}" |
63 end | 63 end |
64 | 64 |
65 # Returns the identifier for the given Mercurial changeset | 65 # Returns the identifier for the given Mercurial changeset |
66 def self.changeset_identifier(changeset) | 66 def self.changeset_identifier(changeset) |
67 changeset.scmid | 67 changeset.scmid |
68 end | 68 end |
69 | 69 |
70 def diff_format_revisions(cs, cs_to, sep=':') | 70 def diff_format_revisions(cs, cs_to, sep=':') |
71 super(cs, cs_to, ' ') | 71 super(cs, cs_to, ' ') |
72 end | 72 end |
73 | |
74 def modify_entry_lastrev_identifier(entry) | |
75 if entry.lastrev && entry.lastrev.identifier | |
76 entry.lastrev.identifier = scmid_for_inserting_db(entry.lastrev.identifier) | |
77 end | |
78 end | |
79 private :modify_entry_lastrev_identifier | |
80 | |
81 def entry(path=nil, identifier=nil) | |
82 entry = scm.entry(path, identifier) | |
83 return nil if entry.nil? | |
84 modify_entry_lastrev_identifier(entry) | |
85 entry | |
86 end | |
87 | |
88 def scm_entries(path=nil, identifier=nil) | |
89 entries = scm.entries(path, identifier) | |
90 return nil if entries.nil? | |
91 entries.each {|entry| modify_entry_lastrev_identifier(entry)} | |
92 entries | |
93 end | |
94 protected :scm_entries | |
73 | 95 |
74 # Finds and returns a revision with a number or the beginning of a hash | 96 # Finds and returns a revision with a number or the beginning of a hash |
75 def find_changeset_by_name(name) | 97 def find_changeset_by_name(name) |
76 return nil if name.blank? | 98 return nil if name.blank? |
77 s = name.to_s | 99 s = name.to_s |
98 limit(limit). | 120 limit(limit). |
99 order("#{Changeset.table_name}.id DESC"). | 121 order("#{Changeset.table_name}.id DESC"). |
100 all | 122 all |
101 end | 123 end |
102 | 124 |
125 def is_short_id_in_db? | |
126 return @is_short_id_in_db unless @is_short_id_in_db.nil? | |
127 cs = changesets.first | |
128 @is_short_id_in_db = (!cs.nil? && cs.scmid.length != 40) | |
129 end | |
130 private :is_short_id_in_db? | |
131 | |
132 def scmid_for_inserting_db(scmid) | |
133 is_short_id_in_db? ? scmid[0, 12] : scmid | |
134 end | |
135 | |
136 def nodes_in_branch(rev, branch_limit) | |
137 scm.nodes_in_branch(rev, :limit => branch_limit).collect do |b| | |
138 scmid_for_inserting_db(b) | |
139 end | |
140 end | |
141 | |
142 def tag_scmid(rev) | |
143 scmid = scm.tagmap[rev] | |
144 scmid.nil? ? nil : scmid_for_inserting_db(scmid) | |
145 end | |
146 | |
103 def latest_changesets_cond(path, rev, limit) | 147 def latest_changesets_cond(path, rev, limit) |
104 cond, args = [], [] | 148 cond, args = [], [] |
105 if scm.branchmap.member? rev | 149 if scm.branchmap.member? rev |
106 # Mercurial named branch is *stable* in each revision. | 150 # Mercurial named branch is *stable* in each revision. |
107 # So, named branch can be stored in database. | 151 # So, named branch can be stored in database. |
112 # So, in order to get correct limit, we need to get all revisions. | 156 # So, in order to get correct limit, we need to get all revisions. |
113 # But, it is very heavy. | 157 # But, it is very heavy. |
114 # Mercurial does not treat direcotry. | 158 # Mercurial does not treat direcotry. |
115 # So, "hg log DIR" is very heavy. | 159 # So, "hg log DIR" is very heavy. |
116 branch_limit = path.blank? ? limit : ( limit * 5 ) | 160 branch_limit = path.blank? ? limit : ( limit * 5 ) |
117 args << scm.nodes_in_branch(rev, :limit => branch_limit) | 161 args << nodes_in_branch(rev, branch_limit) |
118 elsif last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil | 162 elsif last = rev ? find_changeset_by_name(tag_scmid(rev) || rev) : nil |
119 cond << "#{Changeset.table_name}.id <= ?" | 163 cond << "#{Changeset.table_name}.id <= ?" |
120 args << last.id | 164 args << last.id |
121 end | 165 end |
122 unless path.blank? | 166 unless path.blank? |
123 cond << "EXISTS (SELECT * FROM #{Change.table_name} | 167 cond << "EXISTS (SELECT * FROM #{Change.table_name} |
139 | 183 |
140 logger.debug "Fetching changesets for repository #{url}" if logger | 184 logger.debug "Fetching changesets for repository #{url}" if logger |
141 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i| | 185 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i| |
142 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re| | 186 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re| |
143 transaction do | 187 transaction do |
144 parents = (re.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact | 188 parents = (re.parents || []).collect do |rp| |
189 find_changeset_by_name(scmid_for_inserting_db(rp)) | |
190 end.compact | |
145 cs = Changeset.create(:repository => self, | 191 cs = Changeset.create(:repository => self, |
146 :revision => re.revision, | 192 :revision => re.revision, |
147 :scmid => re.scmid, | 193 :scmid => scmid_for_inserting_db(re.scmid), |
148 :committer => re.author, | 194 :committer => re.author, |
149 :committed_on => re.time, | 195 :committed_on => re.time, |
150 :comments => re.message, | 196 :comments => re.message, |
151 :parents => parents) | 197 :parents => parents) |
152 unless cs.new_record? | 198 unless cs.new_record? |
153 re.paths.each { |e| cs.create_change(e) } | 199 re.paths.each do |e| |
200 if from_revision = e[:from_revision] | |
201 e[:from_revision] = scmid_for_inserting_db(from_revision) | |
202 end | |
203 cs.create_change(e) | |
204 end | |
154 end | 205 end |
155 end | 206 end |
156 end | 207 end |
157 end | 208 end |
158 end | 209 end |