Class: Repository::Mercurial

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

Overview

Since:

  • 0.5.1

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=

Methods included from Redmine::SafeAttributes

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

Methods included from Redmine::Ciphering

cipher_key, decrypt_text, encrypt_text, logger

Class Method Details

.changeset_identifier(changeset) ⇒ Object

Returns the identifier for the given Mercurial changeset

Since:

  • 1.2.0



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

def self.changeset_identifier(changeset)
  changeset.scmid
end

.format_changeset_identifier(changeset) ⇒ Object

Returns the readable identifier for the given mercurial changeset

Since:

  • 1.2.0



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

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

.human_attribute_name(attribute_key_name, *args) ⇒ Object

Since:

  • 1.2.0



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

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

Since:

  • 1.2.0



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

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

.scm_nameObject



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

def self.scm_name
  'Mercurial'
end

Instance Method Details

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

Since:

  • 1.2.0



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

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

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

Since:

  • 2.5.0



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

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



179
180
181
182
183
184
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
# File 'app/models/repository/mercurial.rb', line 179

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

Since:

  • 1.2.0



97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/repository/mercurial.rb', line 97

def find_changeset_by_name(name)
  return nil if name.blank?
  s = name.to_s
  if /[^\d]/ =~ s or s.size > 8
    cs = changesets.where(:scmid => s).first
  else
    cs = changesets.where(:revision => s).first
  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?

Since:

  • 1.1.0



116
117
118
119
120
121
122
123
124
# File 'app/models/repository/mercurial.rb', line 116

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

Since:

  • 2.5.0



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

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

Since:

  • 1.2.0



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

def repo_log_encoding
  'UTF-8'
end

#scmid_for_inserting_db(scmid) ⇒ Object

Since:

  • 2.5.0



133
134
135
# File 'app/models/repository/mercurial.rb', line 133

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

#supports_directory_revisions?Boolean

Returns:

  • (Boolean)

Since:

  • 1.2.0



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

def supports_directory_revisions?
  true
end

#supports_revision_graph?Boolean

Returns:

  • (Boolean)

Since:

  • 1.3.0



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

def supports_revision_graph?
  true
end

#tag_scmid(rev) ⇒ Object

Since:

  • 2.5.0



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

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