| 245 | } |
| 246 | |
| 247 | bool BugsLoader::find(int64_t revision, brpc::TrackMeResponse* response) { |
| 248 | // Add reference to make sure the bug list is not deleted. |
| 249 | std::shared_ptr<BugList> local_list = _bug_list; |
| 250 | if (local_list.get() == NULL) { |
| 251 | return false; |
| 252 | } |
| 253 | // Reading the list in this function is always safe because a BugList |
| 254 | // is never changed after creation. |
| 255 | bool found = false; |
| 256 | for (size_t i = 0; i < local_list->size(); ++i) { |
| 257 | const RevisionInfo & info = (*local_list)[i]; |
| 258 | if (info.min_rev <= revision && revision <= info.max_rev) { |
| 259 | found = true; |
| 260 | if (info.severity > response->severity()) { |
| 261 | response->set_severity(info.severity); |
| 262 | } |
| 263 | if (info.severity != brpc::TrackMeOK) { |
| 264 | std::string* error = response->mutable_error_text(); |
| 265 | char prefix[64]; |
| 266 | if (info.min_rev != info.max_rev) { |
| 267 | snprintf(prefix, sizeof(prefix), "[r%lld-r%lld] ", |
| 268 | (long long)info.min_rev, (long long)info.max_rev); |
| 269 | } else { |
| 270 | snprintf(prefix, sizeof(prefix), "[r%lld] ", |
| 271 | (long long)info.min_rev); |
| 272 | } |
| 273 | error->append(prefix); |
| 274 | error->append(info.error_text); |
| 275 | error->append("; "); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | return found; |
| 280 | } |