Skip to content

Commit

Permalink
Merge cleanup and nitpicks.
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyONeal committed Jan 17, 2025
1 parent 01edae1 commit a66ae60
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 66 deletions.
24 changes: 10 additions & 14 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ namespace
Json::Object serialize_baseline(const std::map<std::string, Version, std::less<>>& baseline)
{
Json::Object port_entries_obj;
for (auto&& [key, value] : baseline)
for (auto&& kv_pair : baseline)
{
Json::Object baseline_version_obj;
insert_version_to_json_object(baseline_version_obj, value, JsonIdBaseline);
port_entries_obj.insert(key, std::move(baseline_version_obj));
insert_version_to_json_object(baseline_version_obj, kv_pair.second, JsonIdBaseline);
port_entries_obj.insert(kv_pair.first, std::move(baseline_version_obj));
}

Json::Object baseline_obj;
Expand Down Expand Up @@ -453,23 +453,17 @@ namespace vcpkg
return std::map<std::string, vcpkg::Version, std::less<>>{};
}

auto maybe_baseline_map = vcpkg::get_builtin_baseline(paths);
return std::move(maybe_baseline_map).value_or_exit(VCPKG_LINE_INFO);
return vcpkg::get_builtin_baseline(paths).value_or_exit(VCPKG_LINE_INFO);
}();

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

// Find ports with uncommitted changes
std::set<std::string> changed_ports;
auto git_config = paths.git_builtin_config();
auto maybe_changes = git_ports_with_uncommitted_changes(git_config);
if (auto changes = maybe_changes.get())
{
changed_ports = std::move(*changes);
}
else if (verbose)
if (!maybe_changes.has_value() && verbose)
{
msg::println_warning(msgAddVersionDetectLocalChangesError);
}
Expand Down Expand Up @@ -521,9 +515,12 @@ namespace vcpkg
}

// find local uncommitted changes on port
if (Util::Sets::contains(changed_ports, port_name))
if (auto changed_ports = maybe_changes.get())
{
msg::println_warning(msgAddVersionUncommittedChanges, msg::package_name = port_name);
if (Util::Sets::contains(*changed_ports, port_name))
{
msg::println_warning(msgAddVersionUncommittedChanges, msg::package_name = port_name);
}
}

auto schemed_version = scfl->source_control_file->to_schemed_version();
Expand All @@ -543,7 +540,6 @@ namespace vcpkg
}

const auto& git_tree = git_tree_it->second;

auto updated_versions_file = update_version_db_file(paths,
port_name,
schemed_version,
Expand Down
103 changes: 51 additions & 52 deletions src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,83 +55,82 @@ 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)
{
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

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 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

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 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<std::string, std::string> map;
for (auto&& action : action_plan.install_actions)
{
const auto scfl = action.source_control_file_and_location.get();
if (!scfl)
{
return nullopt;
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<std::string, std::string> map;
for (auto&& action : action_plan.install_actions)
{
const auto scfl = action.source_control_file_and_location.get();
if (!scfl)
{
return nullopt;
}
auto spec = action.spec.to_string();
map.emplace(spec, fmt::format("pkg:github/vcpkg/{}@{}", spec, scfl->source_control_file->to_version()));
}
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 manifest;
manifest.insert(JsonIdName, FileVcpkgDotJson);

{
Json::Object resolved;
for (auto&& action : action_plan.install_actions)
{
Json::Object resolved_item;
const auto pkg_it = map.find(action.spec.to_string());
if (pkg_it == map.end())
const auto found = map.find(action.spec.to_string());
if (found == map.end())
{
continue;
}

const auto& pkg_url = pkg_it->second;
const auto& pkg_url = found->second;
Json::Object resolved_item;
resolved_item.insert(JsonIdPackageUnderscoreUrl, pkg_url);
resolved_item.insert(JsonIdRelationship, Json::Value::string("direct"));
Json::Array deps_list;
resolved_item.insert(JsonIdRelationship, Json::Value::string(JsonIdDirect));

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(dep_pkg_it->second);
deps_list.push_back(found_dep->second);
}
}

resolved_item.insert(JsonIdDependencies, std::move(deps_list));
resolved.insert(pkg_url, std::move(resolved_item));
}
manifest.insert(JsonIdResolved, std::move(resolved));
} // destroy resolved

Json::Object manifests;
manifests.insert(JsonIdVcpkgDotJson, std::move(manifest));
snapshot.insert(JsonIdManifests, std::move(manifests));
manifest.insert(JsonIdResolved, std::move(resolved));
Json::Object manifests;
manifests.insert(JsonIdVcpkgDotJson, manifest);
snapshot.insert(JsonIdManifests, manifests);
Debug::print(Json::stringify(snapshot));
return snapshot;
}

Debug::print(Json::stringify(snapshot));
return snapshot;
return nullopt;
}

std::set<PackageSpec> adjust_action_plan_to_status_db(ActionPlan& action_plan, const StatusParagraphs& status_db)
Expand Down

0 comments on commit a66ae60

Please sign in to comment.