Skip to content

Commit 654366d

Browse files
authored
Move json data (microsoft#1348)
1 parent 13451b9 commit 654366d

File tree

3 files changed

+54
-52
lines changed

3 files changed

+54
-52
lines changed

src/vcpkg/commands.add-version.cpp

+13-19
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ namespace
8989
{
9090
Json::Object baseline_version_obj;
9191
insert_version_to_json_object(baseline_version_obj, kv_pair.second, JsonIdBaseline);
92-
port_entries_obj.insert(kv_pair.first, baseline_version_obj);
92+
port_entries_obj.insert(kv_pair.first, std::move(baseline_version_obj));
9393
}
9494

9595
Json::Object baseline_obj;
96-
baseline_obj.insert("default", port_entries_obj);
96+
baseline_obj.insert(JsonIdDefault, std::move(port_entries_obj));
9797
return baseline_obj;
9898
}
9999

@@ -109,7 +109,7 @@ namespace
109109
}
110110

111111
Json::Object output_object;
112-
output_object.insert(JsonIdVersions, versions_array);
112+
output_object.insert(JsonIdVersions, std::move(versions_array));
113113
return output_object;
114114
}
115115

@@ -128,15 +128,13 @@ namespace
128128
write_json_file(fs, serialize_versions(versions), output_path);
129129
}
130130

131-
UpdateResult update_baseline_version(const VcpkgPaths& paths,
131+
UpdateResult update_baseline_version(const Filesystem& fs,
132132
const std::string& port_name,
133133
const Version& version,
134134
const Path& baseline_path,
135135
std::map<std::string, vcpkg::Version, std::less<>>& baseline_map,
136136
bool print_success)
137137
{
138-
auto& fs = paths.get_filesystem();
139-
140138
auto it = baseline_map.find(port_name);
141139
if (it != baseline_map.end())
142140
{
@@ -452,27 +450,20 @@ namespace vcpkg
452450
auto baseline_map = [&]() -> std::map<std::string, vcpkg::Version, std::less<>> {
453451
if (!fs.exists(baseline_path, IgnoreErrors{}))
454452
{
455-
std::map<std::string, vcpkg::Version, std::less<>> ret;
456-
return ret;
453+
return std::map<std::string, vcpkg::Version, std::less<>>{};
457454
}
458455

459-
auto maybe_baseline_map = vcpkg::get_builtin_baseline(paths);
460-
return maybe_baseline_map.value_or_exit(VCPKG_LINE_INFO);
456+
return vcpkg::get_builtin_baseline(paths).value_or_exit(VCPKG_LINE_INFO);
461457
}();
462458

463459
// Get tree-ish from local repository state.
464460
auto maybe_git_tree_map = paths.git_get_local_port_treeish_map();
465461
auto& git_tree_map = maybe_git_tree_map.value_or_exit(VCPKG_LINE_INFO);
466462

467463
// Find ports with uncommitted changes
468-
std::set<std::string> changed_ports;
469464
auto git_config = paths.git_builtin_config();
470465
auto maybe_changes = git_ports_with_uncommitted_changes(git_config);
471-
if (auto changes = maybe_changes.get())
472-
{
473-
changed_ports.insert(changes->begin(), changes->end());
474-
}
475-
else if (verbose)
466+
if (!maybe_changes.has_value() && verbose)
476467
{
477468
msg::println_warning(msgAddVersionDetectLocalChangesError);
478469
}
@@ -524,9 +515,12 @@ namespace vcpkg
524515
}
525516

526517
// find local uncommitted changes on port
527-
if (Util::Sets::contains(changed_ports, port_name))
518+
if (auto changed_ports = maybe_changes.get())
528519
{
529-
msg::println_warning(msgAddVersionUncommittedChanges, msg::package_name = port_name);
520+
if (Util::Sets::contains(*changed_ports, port_name))
521+
{
522+
msg::println_warning(msgAddVersionUncommittedChanges, msg::package_name = port_name);
523+
}
530524
}
531525

532526
auto schemed_version = scfl->source_control_file->to_schemed_version();
@@ -555,7 +549,7 @@ namespace vcpkg
555549
add_all,
556550
skip_version_format_check);
557551
auto updated_baseline_file = update_baseline_version(
558-
paths, port_name, schemed_version.version, baseline_path, baseline_map, verbose);
552+
paths.get_filesystem(), port_name, schemed_version.version, baseline_path, baseline_map, verbose);
559553
if (verbose && updated_versions_file == UpdateResult::NotUpdated &&
560554
updated_baseline_file == UpdateResult::NotUpdated)
561555
{

src/vcpkg/commands.set-installed.cpp

+39-31
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,27 @@ namespace vcpkg
5858
const auto github_run_id = args.github_run_id.get();
5959
if (github_ref && github_sha && github_job && github_workflow && github_run_id)
6060
{
61-
Json::Object detector;
62-
detector.insert(JsonIdName, Json::Value::string("vcpkg"));
63-
detector.insert(JsonIdUrl, Json::Value::string("https://github.com/microsoft/vcpkg"));
64-
detector.insert(JsonIdVersion, Json::Value::string("1.0.0"));
65-
66-
Json::Object job;
67-
job.insert(JsonIdId, Json::Value::string(*github_run_id));
68-
job.insert(JsonIdCorrelator, Json::Value::string(fmt::format("{}-{}", *github_workflow, *github_run_id)));
69-
7061
Json::Object snapshot;
71-
snapshot.insert(JsonIdJob, job);
62+
{
63+
Json::Object job;
64+
job.insert(JsonIdId, Json::Value::string(*github_run_id));
65+
job.insert(JsonIdCorrelator,
66+
Json::Value::string(fmt::format("{}-{}", *github_workflow, *github_run_id)));
67+
snapshot.insert(JsonIdJob, std::move(job));
68+
} // destroy job
69+
7270
snapshot.insert(JsonIdVersion, Json::Value::integer(0));
7371
snapshot.insert(JsonIdSha, Json::Value::string(*github_sha));
7472
snapshot.insert(JsonIdRef, Json::Value::string(*github_ref));
7573
snapshot.insert(JsonIdScanned, Json::Value::string(CTime::now_string()));
76-
snapshot.insert(JsonIdDetector, detector);
7774

78-
Json::Object manifest;
79-
manifest.insert(JsonIdName, FileVcpkgDotJson);
75+
{
76+
Json::Object detector;
77+
detector.insert(JsonIdName, Json::Value::string("vcpkg"));
78+
detector.insert(JsonIdUrl, Json::Value::string("https://github.com/microsoft/vcpkg"));
79+
detector.insert(JsonIdVersion, Json::Value::string("1.0.0"));
80+
snapshot.insert(JsonIdDetector, std::move(detector));
81+
} // destroy detector
8082

8183
std::unordered_map<std::string, std::string> map;
8284
for (auto&& action : action_plan.install_actions)
@@ -87,42 +89,48 @@ namespace vcpkg
8789
return nullopt;
8890
}
8991
auto spec = action.spec.to_string();
90-
map.insert(
91-
{spec, fmt::format("pkg:github/vcpkg/{}@{}", spec, scfl->source_control_file->to_version())});
92+
map.emplace(spec, fmt::format("pkg:github/vcpkg/{}@{}", spec, scfl->source_control_file->to_version()));
9293
}
9394

95+
Json::Object manifest;
96+
manifest.insert(JsonIdName, FileVcpkgDotJson);
97+
9498
Json::Object resolved;
9599
for (auto&& action : action_plan.install_actions)
96100
{
101+
const auto found = map.find(action.spec.to_string());
102+
if (found == map.end())
103+
{
104+
continue;
105+
}
106+
107+
const auto& pkg_url = found->second;
97108
Json::Object resolved_item;
98-
auto spec = action.spec.to_string();
99-
const auto found = map.find(spec);
100-
if (found != map.end())
109+
resolved_item.insert(JsonIdPackageUnderscoreUrl, pkg_url);
110+
resolved_item.insert(JsonIdRelationship, Json::Value::string(JsonIdDirect));
111+
112+
Json::Array deps_list;
113+
for (auto&& dep : action.package_dependencies)
101114
{
102-
const auto& pkg_url = found->second;
103-
resolved_item.insert(JsonIdPackageUnderscoreUrl, pkg_url);
104-
resolved_item.insert(JsonIdRelationship, Json::Value::string(JsonIdDirect));
105-
Json::Array deps_list;
106-
for (auto&& dep : action.package_dependencies)
115+
const auto found_dep = map.find(dep.to_string());
116+
if (found_dep != map.end())
107117
{
108-
const auto found_dep = map.find(dep.to_string());
109-
if (found_dep != map.end())
110-
{
111-
deps_list.push_back(found_dep->second);
112-
}
118+
deps_list.push_back(found_dep->second);
113119
}
114-
resolved_item.insert(JsonIdDependencies, deps_list);
115-
resolved.insert(pkg_url, resolved_item);
116120
}
121+
122+
resolved_item.insert(JsonIdDependencies, std::move(deps_list));
123+
resolved.insert(pkg_url, std::move(resolved_item));
117124
}
118125

119-
manifest.insert(JsonIdResolved, resolved);
126+
manifest.insert(JsonIdResolved, std::move(resolved));
120127
Json::Object manifests;
121128
manifests.insert(JsonIdVcpkgDotJson, manifest);
122129
snapshot.insert(JsonIdManifests, manifests);
123130
Debug::print(Json::stringify(snapshot));
124131
return snapshot;
125132
}
133+
126134
return nullopt;
127135
}
128136

src/vcpkg/metrics.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ namespace vcpkg
441441
buildtime_times.push_back(Json::Value::number(buildtime.second));
442442
}
443443

444-
properties.insert("buildnames_1", buildtime_names);
445-
properties.insert("buildtimes", buildtime_times);
444+
properties.insert("buildnames_1", std::move(buildtime_names));
445+
properties.insert("buildtimes", std::move(buildtime_times));
446446
}
447447

448448
Json::Object& measurements = base_data.insert("measurements", Json::Object());

0 commit comments

Comments
 (0)