diff --git a/src/vcpkg/commands.add-version.cpp b/src/vcpkg/commands.add-version.cpp index 72e0b8afd7..8a57a582c4 100644 --- a/src/vcpkg/commands.add-version.cpp +++ b/src/vcpkg/commands.add-version.cpp @@ -85,15 +85,15 @@ namespace Json::Object serialize_baseline(const std::map>& baseline) { Json::Object port_entries_obj; - for (auto&& kv_pair : baseline) + for (auto&& [key, value] : baseline) { Json::Object baseline_version_obj; - insert_version_to_json_object(baseline_version_obj, kv_pair.second, JsonIdBaseline); - port_entries_obj.insert(kv_pair.first, baseline_version_obj); + insert_version_to_json_object(baseline_version_obj, value, JsonIdBaseline); + port_entries_obj.insert(key, std::move(baseline_version_obj)); } Json::Object baseline_obj; - baseline_obj.insert("default", port_entries_obj); + baseline_obj.insert(JsonIdDefault, std::move(port_entries_obj)); return baseline_obj; } @@ -109,7 +109,7 @@ namespace } Json::Object output_object; - output_object.insert(JsonIdVersions, versions_array); + output_object.insert(JsonIdVersions, std::move(versions_array)); return output_object; } @@ -128,15 +128,13 @@ namespace write_json_file(fs, serialize_versions(versions), output_path); } - UpdateResult update_baseline_version(const VcpkgPaths& paths, + UpdateResult update_baseline_version(const Filesystem& fs, const std::string& port_name, const Version& version, const Path& baseline_path, std::map>& baseline_map, bool print_success) { - auto& fs = paths.get_filesystem(); - auto it = baseline_map.find(port_name); if (it != baseline_map.end()) { @@ -452,12 +450,11 @@ namespace vcpkg auto baseline_map = [&]() -> std::map> { if (!fs.exists(baseline_path, IgnoreErrors{})) { - std::map> ret; - return ret; + return std::map>{}; } auto maybe_baseline_map = vcpkg::get_builtin_baseline(paths); - return maybe_baseline_map.value_or_exit(VCPKG_LINE_INFO); + return std::move(maybe_baseline_map).value_or_exit(VCPKG_LINE_INFO); }(); // Get tree-ish from local repository state. @@ -470,7 +467,7 @@ namespace vcpkg auto maybe_changes = git_ports_with_uncommitted_changes(git_config); if (auto changes = maybe_changes.get()) { - changed_ports.insert(changes->begin(), changes->end()); + changed_ports = std::move(*changes); } else if (verbose) { @@ -546,6 +543,7 @@ namespace vcpkg } const auto& git_tree = git_tree_it->second; + auto updated_versions_file = update_version_db_file(paths, port_name, schemed_version, @@ -555,7 +553,7 @@ namespace vcpkg add_all, skip_version_format_check); auto updated_baseline_file = update_baseline_version( - paths, port_name, schemed_version.version, baseline_path, baseline_map, verbose); + paths.get_filesystem(), port_name, schemed_version.version, baseline_path, baseline_map, verbose); if (verbose && updated_versions_file == UpdateResult::NotUpdated && updated_baseline_file == UpdateResult::NotUpdated) { diff --git a/src/vcpkg/commands.set-installed.cpp b/src/vcpkg/commands.set-installed.cpp index cf828600ba..a738aa7e54 100644 --- a/src/vcpkg/commands.set-installed.cpp +++ b/src/vcpkg/commands.set-installed.cpp @@ -55,74 +55,83 @@ namespace vcpkg const auto github_job = args.github_job.get(); const auto github_workflow = args.github_workflow.get(); const auto github_run_id = args.github_run_id.get(); - if (github_ref && github_sha && github_job && github_workflow && github_run_id) + if (!github_ref || !github_sha || !github_job || !github_workflow || !github_run_id) { - Json::Object detector; - detector.insert(JsonIdName, Json::Value::string("vcpkg")); - detector.insert(JsonIdUrl, Json::Value::string("https://github.com/microsoft/vcpkg")); - detector.insert(JsonIdVersion, Json::Value::string("1.0.0")); + return nullopt; + } + Json::Object snapshot; + { Json::Object job; job.insert(JsonIdId, Json::Value::string(*github_run_id)); job.insert(JsonIdCorrelator, Json::Value::string(fmt::format("{}-{}", *github_workflow, *github_run_id))); + snapshot.insert(JsonIdJob, std::move(job)); + } // destroy job - Json::Object snapshot; - snapshot.insert(JsonIdJob, job); - snapshot.insert(JsonIdVersion, Json::Value::integer(0)); - snapshot.insert(JsonIdSha, Json::Value::string(*github_sha)); - snapshot.insert(JsonIdRef, Json::Value::string(*github_ref)); - snapshot.insert(JsonIdScanned, Json::Value::string(CTime::now_string())); - snapshot.insert(JsonIdDetector, detector); + snapshot.insert(JsonIdVersion, Json::Value::integer(0)); + snapshot.insert(JsonIdSha, Json::Value::string(*github_sha)); + snapshot.insert(JsonIdRef, Json::Value::string(*github_ref)); + snapshot.insert(JsonIdScanned, Json::Value::string(CTime::now_string())); - Json::Object manifest; - manifest.insert(JsonIdName, FileVcpkgDotJson); + { + Json::Object detector; + detector.insert(JsonIdName, Json::Value::string("vcpkg")); + detector.insert(JsonIdUrl, Json::Value::string("https://github.com/microsoft/vcpkg")); + detector.insert(JsonIdVersion, Json::Value::string("1.0.0")); + snapshot.insert(JsonIdDetector, std::move(detector)); + } // destroy detector - std::unordered_map map; - for (auto&& action : action_plan.install_actions) + std::unordered_map map; + for (auto&& action : action_plan.install_actions) + { + const auto scfl = action.source_control_file_and_location.get(); + if (!scfl) { - const auto scfl = action.source_control_file_and_location.get(); - if (!scfl) - { - return nullopt; - } - auto spec = action.spec.to_string(); - map.insert( - {spec, fmt::format("pkg:github/vcpkg/{}@{}", spec, scfl->source_control_file->to_version())}); + return nullopt; } + auto spec = action.spec.to_string(); + map.emplace(spec, fmt::format("pkg:github/vcpkg/{}@{}", spec, scfl->source_control_file->to_version())); + } + + Json::Object manifest; + manifest.insert(JsonIdName, FileVcpkgDotJson); + { Json::Object resolved; for (auto&& action : action_plan.install_actions) { Json::Object resolved_item; - auto spec = action.spec.to_string(); - const auto found = map.find(spec); - if (found != map.end()) + const auto pkg_it = map.find(action.spec.to_string()); + if (pkg_it == map.end()) { - const auto& pkg_url = found->second; - resolved_item.insert(JsonIdPackageUnderscoreUrl, pkg_url); - resolved_item.insert(JsonIdRelationship, Json::Value::string(JsonIdDirect)); - Json::Array deps_list; - for (auto&& dep : action.package_dependencies) + continue; + } + + const auto& pkg_url = pkg_it->second; + resolved_item.insert(JsonIdPackageUnderscoreUrl, pkg_url); + resolved_item.insert(JsonIdRelationship, Json::Value::string("direct")); + Json::Array deps_list; + + for (auto&& dep : action.package_dependencies) + { + const auto dep_pkg_it = map.find(dep.to_string()); + if (dep_pkg_it != map.end()) { - const auto found_dep = map.find(dep.to_string()); - if (found_dep != map.end()) - { - deps_list.push_back(found_dep->second); - } + deps_list.push_back(dep_pkg_it->second); } - resolved_item.insert(JsonIdDependencies, deps_list); - resolved.insert(pkg_url, resolved_item); } + resolved_item.insert(JsonIdDependencies, std::move(deps_list)); + resolved.insert(pkg_url, std::move(resolved_item)); } + manifest.insert(JsonIdResolved, std::move(resolved)); + } // destroy resolved - manifest.insert(JsonIdResolved, resolved); - Json::Object manifests; - manifests.insert(JsonIdVcpkgDotJson, manifest); - snapshot.insert(JsonIdManifests, manifests); - Debug::print(Json::stringify(snapshot)); - return snapshot; - } - return nullopt; + Json::Object manifests; + manifests.insert(JsonIdVcpkgDotJson, std::move(manifest)); + snapshot.insert(JsonIdManifests, std::move(manifests)); + + Debug::print(Json::stringify(snapshot)); + return snapshot; } std::set adjust_action_plan_to_status_db(ActionPlan& action_plan, const StatusParagraphs& status_db) diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index e29e88f258..2dc6c00569 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -441,8 +441,8 @@ namespace vcpkg buildtime_times.push_back(Json::Value::number(buildtime.second)); } - properties.insert("buildnames_1", buildtime_names); - properties.insert("buildtimes", buildtime_times); + properties.insert("buildnames_1", std::move(buildtime_names)); + properties.insert("buildtimes", std::move(buildtime_times)); } Json::Object& measurements = base_data.insert("measurements", Json::Object());