You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bazaar.rb 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2017 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require 'redmine/scm/adapters/bazaar_adapter'
  19. class Repository::Bazaar < Repository
  20. validates_presence_of :url, :log_encoding
  21. def self.human_attribute_name(attribute_key_name, *args)
  22. attr_name = attribute_key_name.to_s
  23. if attr_name == "url"
  24. attr_name = "path_to_repository"
  25. end
  26. super(attr_name, *args)
  27. end
  28. def self.scm_adapter_class
  29. Redmine::Scm::Adapters::BazaarAdapter
  30. end
  31. def self.scm_name
  32. 'Bazaar'
  33. end
  34. def entry(path=nil, identifier=nil)
  35. scm.bzr_path_encodig = log_encoding
  36. scm.entry(path, identifier)
  37. end
  38. def cat(path, identifier=nil)
  39. scm.bzr_path_encodig = log_encoding
  40. scm.cat(path, identifier)
  41. end
  42. def annotate(path, identifier=nil)
  43. scm.bzr_path_encodig = log_encoding
  44. scm.annotate(path, identifier)
  45. end
  46. def diff(path, rev, rev_to)
  47. scm.bzr_path_encodig = log_encoding
  48. scm.diff(path, rev, rev_to)
  49. end
  50. def scm_entries(path=nil, identifier=nil)
  51. scm.bzr_path_encodig = log_encoding
  52. entries = scm.entries(path, identifier)
  53. if entries
  54. entries.each do |e|
  55. next if e.lastrev.revision.blank?
  56. # Set the filesize unless browsing a specific revision
  57. if identifier.nil? && e.is_file?
  58. full_path = File.join(root_url, e.path)
  59. e.size = File.stat(full_path).size if File.file?(full_path)
  60. end
  61. c = Change.
  62. includes(:changeset).
  63. where("#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id).
  64. order("#{Changeset.table_name}.revision DESC").
  65. first
  66. if c
  67. e.lastrev.identifier = c.changeset.revision
  68. e.lastrev.name = c.changeset.revision
  69. e.lastrev.author = c.changeset.committer
  70. end
  71. end
  72. end
  73. entries
  74. end
  75. protected :scm_entries
  76. def fetch_changesets
  77. scm.bzr_path_encodig = log_encoding
  78. scm_info = scm.info
  79. if scm_info
  80. # latest revision found in database
  81. db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
  82. # latest revision in the repository
  83. scm_revision = scm_info.lastrev.identifier.to_i
  84. if db_revision < scm_revision
  85. logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
  86. identifier_from = db_revision + 1
  87. while (identifier_from <= scm_revision)
  88. # loads changesets by batches of 200
  89. identifier_to = [identifier_from + 199, scm_revision].min
  90. revisions = scm.revisions('', identifier_to, identifier_from)
  91. transaction do
  92. revisions.reverse_each do |revision|
  93. changeset = Changeset.create(:repository => self,
  94. :revision => revision.identifier,
  95. :committer => revision.author,
  96. :committed_on => revision.time,
  97. :scmid => revision.scmid,
  98. :comments => revision.message)
  99. revision.paths.each do |change|
  100. Change.create(:changeset => changeset,
  101. :action => change[:action],
  102. :path => change[:path],
  103. :revision => change[:revision])
  104. end
  105. end
  106. end unless revisions.nil?
  107. identifier_from = identifier_to + 1
  108. end
  109. end
  110. end
  111. end
  112. end