Skip to content

Commit

Permalink
Merge pull request #154 from jmcconnell26/ISSUE-16-RemoveNoLongerNeed…
Browse files Browse the repository at this point in the history
…edMappingFunctions

ISSUE-16 - Remove no longer needed mapping functions:
  • Loading branch information
anderejd authored Nov 30, 2020
2 parents d520b70 + 62d3d78 commit 31e66fa
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 260 deletions.
3 changes: 2 additions & 1 deletion cargo-geiger/src/format/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use crate::mapping::{
GetRepositoryFromCargoMetadataPackageId,
};

use cargo_metadata::PackageId;
use std::fmt;

pub struct Display<'a> {
pub cargo_metadata_parameters: &'a CargoMetadataParameters<'a>,
pub pattern: &'a Pattern,
pub package: &'a cargo_metadata::PackageId,
pub package: &'a PackageId,
}

impl<'a> fmt::Display for Display<'a> {
Expand Down
5 changes: 3 additions & 2 deletions cargo-geiger/src/format/pattern.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::format::parse::Parser;
use crate::format::{Chunk, RawChunk};
use crate::mapping::CargoMetadataParameters;

use super::display::Display;

use crate::mapping::CargoMetadataParameters;
use cargo_metadata::PackageId;
use std::error::Error;

#[derive(Debug, PartialEq)]
Expand All @@ -13,7 +14,7 @@ impl Pattern {
pub fn display<'a>(
&'a self,
cargo_metadata_parameters: &'a CargoMetadataParameters,
package: &'a cargo_metadata::PackageId,
package: &'a PackageId,
) -> Display<'a> {
Display {
cargo_metadata_parameters,
Expand Down
6 changes: 3 additions & 3 deletions cargo-geiger/src/format/table/handle_text_tree_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use super::total_package_counts::TotalPackageCounts;
use super::TableParameters;
use super::{table_row, table_row_empty};

use cargo_metadata::DependencyKind;
use cargo_metadata::{DependencyKind, PackageId};
use std::collections::HashSet;

pub struct HandlePackageParameters<'a> {
pub total_package_counts: &'a mut TotalPackageCounts,
pub visited_package_ids: &'a mut HashSet<cargo_metadata::PackageId>,
pub visited_package_ids: &'a mut HashSet<PackageId>,
pub warning_count: &'a mut u64,
}

Expand All @@ -36,7 +36,7 @@ pub fn handle_text_tree_line_package(
cargo_metadata_parameters: &CargoMetadataParameters,
emoji_symbols: &EmojiSymbols,
handle_package_parameters: &mut HandlePackageParameters,
package_id: cargo_metadata::PackageId,
package_id: PackageId,
table_lines: &mut Vec<String>,
table_parameters: &TableParameters,
tree_vines: String,
Expand Down
19 changes: 8 additions & 11 deletions cargo-geiger/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cargo::core::Workspace;
use cargo::util::interning::InternedString;
use cargo::util::CargoResult;
use cargo::Config;
use cargo_metadata::DependencyKind;
use cargo_metadata::{DependencyKind, PackageId};
use cargo_platform::{Cfg, Platform};
use petgraph::graph::NodeIndex;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -39,11 +39,8 @@ impl ExtraDeps {

/// Representation of the package dependency graph
pub struct Graph {
pub graph: petgraph::Graph<
cargo_metadata::PackageId,
cargo_metadata::DependencyKind,
>,
pub nodes: HashMap<cargo_metadata::PackageId, NodeIndex>,
pub graph: petgraph::Graph<PackageId, cargo_metadata::DependencyKind>,
pub nodes: HashMap<PackageId, NodeIndex>,
}

// Almost unmodified compared to the original in cargo-tree, should be fairly
Expand All @@ -53,7 +50,7 @@ pub fn build_graph<'a>(
args: &Args,
cargo_metadata_parameters: &'a CargoMetadataParameters,
config: &Config,
root_package_id: cargo_metadata::PackageId,
root_package_id: PackageId,
workspace: &Workspace,
) -> CargoResult<Graph> {
let config_host = config.load_global_rustc(Some(&workspace))?.host;
Expand Down Expand Up @@ -102,10 +99,10 @@ struct GraphConfiguration<'a> {

fn add_graph_node_if_not_present_and_edge(
dependency: &cargo_metadata::Dependency,
dependency_package_id: cargo_metadata::PackageId,
dependency_package_id: PackageId,
graph: &mut Graph,
index: NodeIndex,
pending_packages: &mut Vec<cargo_metadata::PackageId>,
pending_packages: &mut Vec<PackageId>,
) {
let dependency_index =
match graph.nodes.entry(dependency_package_id.clone()) {
Expand All @@ -122,10 +119,10 @@ fn add_graph_node_if_not_present_and_edge(

fn add_package_dependencies_to_graph(
cargo_metadata_parameters: &CargoMetadataParameters,
package_id: cargo_metadata::PackageId,
package_id: PackageId,
graph_configuration: &GraphConfiguration,
graph: &mut Graph,
pending_packages: &mut Vec<cargo_metadata::PackageId>,
pending_packages: &mut Vec<PackageId>,
) {
let index = graph.nodes[&package_id];
let package = cargo_metadata_parameters
Expand Down
7 changes: 1 addition & 6 deletions cargo-geiger/src/mapping.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod core;
mod geiger;
mod krates;
mod metadata;

use ::krates::Krates;
use cargo::core::dependency::DepKind;
use cargo_metadata::{DependencyKind, Metadata};
use cargo_metadata::Metadata;
use std::collections::HashSet;
use std::path::PathBuf;

Expand Down Expand Up @@ -92,10 +91,6 @@ pub trait ToCargoGeigerSource {
) -> cargo_geiger_serde::Source;
}

pub trait ToCargoMetadataDependencyKind {
fn to_cargo_metadata_dependency_kind(&self) -> DependencyKind;
}

pub trait ToCargoMetadataPackage {
fn to_cargo_metadata_package(
&self,
Expand Down
160 changes: 0 additions & 160 deletions cargo-geiger/src/mapping/core.rs

This file was deleted.

4 changes: 1 addition & 3 deletions cargo-geiger/src/mapping/geiger.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use super::ToCargoGeigerSource;

use crate::mapping::ToCargoMetadataPackage;
use super::{ToCargoGeigerSource, ToCargoMetadataPackage};

use cargo_metadata::Metadata;
use url::Url;
Expand Down
Loading

0 comments on commit 31e66fa

Please sign in to comment.