Project

General

Profile

Patch #24434 » redmine-mercurial.patch

Ewan Makepeace, 2016-11-23 05:21

View differences:

app/models/changeset.rb Tue Nov 22 06:41:11 2016 +0000 → app/models/changeset.rb Tue Nov 22 06:59:03 2016 +0000
112 112
    )
113 113
    /x
114
  # Return mercurial branch name
115
  def hg_branch(rev)
116
    branch = nil
117
    hg = Redmine::Configuration['scm_mercurial_command'] || "hg"
118
    cmd = %x(#{hg} -R #{repository.url} log --rev #{rev})
119
    cmd.scan(/^branch.*(RM\d+)/i) do |m|
120
      branch = m[0]
121
    end
122
    branch
123
  end
124

  
114 125
  def scan_comment_for_issue_ids
115 126
    return if comments.blank?
116 127
    # keywords used to reference issues
......
124 135
    referenced_issues = []
125
    comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
126
      action, refs = match[2].to_s.downcase, match[3]
127
      next unless action.present? || ref_keywords_any
128

  
129
      refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
130
        issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
136
    if repository.type == "Repository::Mercurial"
137
      branch = hg_branch(revision)
138
      return if branch.blank?
139
      branch.scan(/(\d+)/) do |match|
140
        issue = find_referenced_issue_by_id(match[0].to_i)
131 141
        if issue && !issue_linked_to_same_commit?(issue)
132 142
          referenced_issues << issue
133
          # Don't update issues or log time when importing old commits
134
          unless repository.created_on && committed_on && committed_on < repository.created_on
135
            fix_issue(issue, action) if fix_keywords.include?(action)
136
            log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
143
        end
144
      end
145
    else
146
      comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
147
        action, refs = match[2].to_s.downcase, match[3]
148
        next unless action.present? || ref_keywords_any
149

  
150
        refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
151
          issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
152
          if issue && !issue_linked_to_same_commit?(issue)
153
            referenced_issues << issue
154
            # Don't update issues or log time when importing old commits
155
            unless repository.created_on && committed_on && committed_on < repository.created_on
156
              fix_issue(issue, action) if fix_keywords.include?(action)
157
              log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
158
            end
137 159
          end
138 160
        end
139 161
      end
140 162
    end
141

  
142 163
    referenced_issues.uniq!
143 164
    self.issues = referenced_issues unless referenced_issues.empty?
144 165
  end
    (1-1/1)