Class: Repository::Mercurial

Inherits:
Repository
  • Object
show all
Defined in:
app/models/repository/mercurial.rb

Constant Summary collapse

FETCH_AT_ONCE =

number of changesets to fetch at once

100

Constants inherited from Repository

IDENTIFIER_MAX_LENGTH

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Repository

#<=>, available_scm, #branches, #cat, #committer_ids=, #committers, #default_branch, #diff, #entries, #extra_info, factory, fetch_changesets, find_by_identifier_param, #find_committer_user, #identifier=, #identifier_frozen?, #identifier_param, #latest_changeset, #merge_extra_info, #name, #password, #password=, #properties, #relative_path, #repo_create_validation, #report_last_commit, repository_class, #root_url=, #same_commits_in_scope, #scan_changesets_for_issue_ids, scan_changesets_for_issue_ids, #scm, #scm_adapter, scm_available, scm_command, #scm_name, scm_version_string, #set_as_default?, #stats_by_author, #supports_all_revisions?, #supports_annotate?, #supports_cat?, #tags, #url=, #valid_name?

Methods included from Redmine::SafeAttributes

#delete_unsafe_attributes, included, #safe_attribute?, #safe_attribute_names, #safe_attributes=

Methods included from Redmine::Ciphering

cipher_key, decrypt_text, encrypt_text, included, logger

Class Method Details

.changeset_identifier(changeset) ⇒ Object

Returns the identifier for the given Mercurial changeset



67
68
69
# File 'app/models/repository/mercurial.rb', line 67

def self.changeset_identifier(changeset)
  changeset.scmid
end

.format_changeset_identifier(changeset) ⇒ Object

Returns the readable identifier for the given mercurial changeset



62
63
64
# File 'app/models/repository/mercurial.rb', line 62

def self.format_changeset_identifier(changeset)
  "#{changeset.revision}:#{changeset.scmid[0, 12]}"
end

.human_attribute_name(attribute_key_name, *args) ⇒ Object



33
34
35
36
37
38
39
# File 'app/models/repository/mercurial.rb', line 33

def self.human_attribute_name(attribute_key_name, *args)
  attr_name = attribute_key_name.to_s
  if attr_name == "url"
    attr_name = "path_to_repository"
  end
  super(attr_name, *args)
end

.scm_adapter_classObject



41
42
43
# File 'app/models/repository/mercurial.rb', line 41

def self.scm_adapter_class
  Redmine::Scm::Adapters::MercurialAdapter
end

.scm_nameObject



45
46
47
# File 'app/models/repository/mercurial.rb', line 45

def self.scm_name
  'Mercurial'
end

Instance Method Details

#diff_format_revisions(cs, cs_to, sep = ':') ⇒ Object



71
72
73
# File 'app/models/repository/mercurial.rb', line 71

def diff_format_revisions(cs, cs_to, sep=':')
  super(cs, cs_to, ' ')
end

#entry(path = nil, identifier = nil) ⇒ Object



82
83
84
85
86
87
88
# File 'app/models/repository/mercurial.rb', line 82

def entry(path=nil, identifier=nil)
  entry = scm.entry(path, identifier)
  return nil if entry.nil?

  modify_entry_lastrev_identifier(entry)
  entry
end

#fetch_changesetsObject



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'app/models/repository/mercurial.rb', line 185

def fetch_changesets
  return if scm.info.nil?

  scm_rev = scm.info.lastrev.revision.to_i
  db_rev  = latest_changeset ? latest_changeset.revision.to_i : -1
  return unless db_rev < scm_rev  # already up-to-date

  logger.debug "Fetching changesets for repository #{url}" if logger
  (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
    scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
      transaction do
        parents = (re.parents || []).collect do |rp|
          find_changeset_by_name(scmid_for_inserting_db(rp))
        end.compact
        cs = Changeset.create(:repository   => self,
                              :revision     => re.revision,
                              :scmid        => scmid_for_inserting_db(re.scmid),
                              :committer    => re.author,
                              :committed_on => re.time,
                              :comments     => re.message,
                              :parents      => parents)
        unless cs.new_record?
          re.paths.each do |e|
            if from_revision = e[:from_revision]
              e[:from_revision] = scmid_for_inserting_db(from_revision)
            end
            cs.create_change(e)
          end
        end
      end
    end
  end
end

#find_changeset_by_name(name) ⇒ Object

Finds and returns a revision with a number or the beginning of a hash



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/repository/mercurial.rb', line 100

def find_changeset_by_name(name)
  return nil if name.blank?

  s = name.to_s
  if /[^\d]/.match?(s) || s.size > 8
    cs = changesets.where(:scmid => s).first
  else
    cs = changesets.find_by(:revision => s)
  end
  return cs if cs

  changesets.where('scmid LIKE ?', "#{s}%").first
end

#latest_changesets(path, rev, limit = 10) ⇒ Object

Returns the latest changesets for path; sorted by revision number

Because :order => ‘id DESC’ is defined at ‘has_many’, there is no need to set ‘order’. But, MySQL test fails. Sqlite3 and PostgreSQL pass. Is this MySQL bug?



121
122
123
124
125
126
127
128
129
# File 'app/models/repository/mercurial.rb', line 121

def latest_changesets(path, rev, limit=10)
  changesets.
    includes(:user).
    where(latest_changesets_cond(path, rev, limit)).
    references(:user).
    limit(limit).
    order("#{Changeset.table_name}.id DESC").
    to_a
end

#nodes_in_branch(rev, branch_limit) ⇒ Object



143
144
145
146
147
# File 'app/models/repository/mercurial.rb', line 143

def nodes_in_branch(rev, branch_limit)
  scm.nodes_in_branch(rev, :limit => branch_limit).collect do |b|
    scmid_for_inserting_db(b)
  end
end

#repo_log_encodingObject



57
58
59
# File 'app/models/repository/mercurial.rb', line 57

def repo_log_encoding
  'UTF-8'
end

#scmid_for_inserting_db(scmid) ⇒ Object



139
140
141
# File 'app/models/repository/mercurial.rb', line 139

def scmid_for_inserting_db(scmid)
  is_short_id_in_db? ? scmid[0, 12] : scmid
end

#supports_directory_revisions?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/repository/mercurial.rb', line 49

def supports_directory_revisions?
  true
end

#supports_revision_graph?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/repository/mercurial.rb', line 53

def supports_revision_graph?
  true
end

#tag_scmid(rev) ⇒ Object



149
150
151
152
# File 'app/models/repository/mercurial.rb', line 149

def tag_scmid(rev)
  scmid = scm.tagmap[rev]
  scmid.nil? ? nil : scmid_for_inserting_db(scmid)
end