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
ATTRIBUTE_KEY_NAMES =
{
  "url"          => "Root directory",
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Repository

available_scm, #branches, #cat, #committer_ids=, #committers, #default_branch, #diff, #entries, #entry, factory, fetch_changesets, #find_committer_user, #latest_changeset, #password, #password=, #properties, #relative_path, #root_url=, scan_changesets_for_issue_ids, #scan_changesets_for_issue_ids, #scm, #scm_adapter, scm_available, scm_command, #scm_name, scm_version_string, #supports_all_revisions?, #supports_annotate?, #supports_cat?, #tags, #url=

Methods included from Redmine::Ciphering

cipher_key, decrypt_text, encrypt_text, included

Class Method Details

.changeset_identifier(changeset) ⇒ Object

Returns the identifier for the given Mercurial changeset



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

def self.changeset_identifier(changeset)
  changeset.scmid
end

.format_changeset_identifier(changeset) ⇒ Object

Returns the readable identifier for the given mercurial changeset



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

def self.format_changeset_identifier(changeset)
  "#{changeset.revision}:#{changeset.scmid}"
end

.human_attribute_name(attribute_key_name) ⇒ Object



32
33
34
# File 'app/models/repository/mercurial.rb', line 32

def self.human_attribute_name(attribute_key_name)
  ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
end

.scm_adapter_classObject



36
37
38
# File 'app/models/repository/mercurial.rb', line 36

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

.scm_nameObject



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

def self.scm_name
  'Mercurial'
end

Instance Method Details

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



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

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

#fetch_changesetsObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/models/repository/mercurial.rb', line 124

def fetch_changesets
  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|
    transaction do
      scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
        cs = Changeset.create(:repository => self,
                              :revision => re.revision,
                              :scmid => re.scmid,
                              :committer => re.author,
                              :committed_on => re.time,
                              :comments => re.message)
        re.paths.each { |e| cs.create_change(e) }
      end
    end
  end
  self
end

#find_changeset_by_name(name) ⇒ Object

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



67
68
69
70
71
72
73
74
75
76
# File 'app/models/repository/mercurial.rb', line 67

def find_changeset_by_name(name)
  return nil if name.nil? || name.empty?
  if /[^\d]/ =~ name or name.to_s.size > 8
    e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s])
  else
    e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
  end
  return e if e
  changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"])  # last ditch
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?



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

def latest_changesets(path, rev, limit=10)
  changesets.find(:all, :include => :user,
                  :conditions => latest_changesets_cond(path, rev, limit),
                  :limit => limit, :order => "#{Changeset.table_name}.id DESC")
end

#repo_log_encodingObject



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

def repo_log_encoding
  'UTF-8'
end

#supports_directory_revisions?Boolean

Returns:

  • (Boolean)


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

def supports_directory_revisions?
  true
end