Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ fixtures/*.ipynb
# IDE
.vscode/*
flamegraph.svg

# Terminal recording via VHS
*.tape
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ crossterm = "0.28.1"
log = "0.4.25"
env_logger = "0.11.6"
tui-textarea = "0.7.0"
tui-widget-list = "0.13.2"

[dev-dependencies]
cargo-llvm-cov = "0.6.14"
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ fn main() {
.id,
);
if *interactive {
view_operations(&operation_conn, &operations);
view_operations(&conn, &operation_conn, &operations);
} else {
let mut indicator = "";
println!(
Expand Down
11 changes: 11 additions & 0 deletions src/models/block_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ impl BlockGroup {
}
}

pub fn get_by_ids(conn: &Connection, ids: &[i64]) -> Vec<BlockGroup> {
let query = "SELECT * FROM block_groups WHERE id IN rarray(?1)";
Self::query(
conn,
query,
params!(Rc::new(
ids.iter().map(|i| SQLValue::from(*i)).collect::<Vec<_>>()
)),
)
}

pub fn clone(conn: &Connection, source_block_group_id: i64, target_block_group_id: i64) {
let existing_paths = Path::query(
conn,
Expand Down
47 changes: 35 additions & 12 deletions src/models/operations.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
use crate::graph::{all_simple_paths, OperationGraph};
use crate::graph::{all_simple_paths, GraphEdge, GraphNode, OperationGraph};
use crate::models::file_types::FileTypes;
use crate::models::traits::*;
use petgraph::graphmap::UnGraphMap;
use crate::operation_management::{
load_changeset, load_changeset_dependencies, load_changeset_models,
};
use crate::views::patch::get_change_graph;
use petgraph::graphmap::{DiGraphMap, UnGraphMap};
use petgraph::visit::{Dfs, Reversed};
use petgraph::Direction;
use rusqlite::session::ChangesetIter;
use rusqlite::types::Value;
use rusqlite::Error as SQLError;
use rusqlite::{params, params_from_iter, Connection, Result as SQLResult, Row};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::io::Read;
use std::string::ToString;
use thiserror::Error;

#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct Operation {
Expand All @@ -19,6 +27,12 @@ pub struct Operation {
pub change_type: String,
}

#[derive(Debug, Error, PartialEq)]
pub enum OperationError {
#[error("SQLite Error: {0}")]
SqliteError(#[from] SQLError),
}

impl Operation {
pub fn create(
conn: &Connection,
Expand Down Expand Up @@ -106,6 +120,23 @@ impl Operation {
graph
}

pub fn get_change_graph(
conn: &Connection,
hash: &str,
) -> Result<HashMap<i64, DiGraphMap<GraphNode, GraphEdge>>, OperationError> {
let operation = Operation::get_by_hash(conn, hash)?;

let changeset = load_changeset(&operation);
let dependencies = load_changeset_dependencies(&operation);

let input: &mut dyn Read = &mut changeset.as_slice();
let mut iter = ChangesetIter::start_strm(&input).unwrap();

let new_models = load_changeset_models(&mut iter);

Ok(get_change_graph(&new_models, &dependencies))
}

pub fn get_path_between(
conn: &Connection,
source_id: &str,
Expand Down Expand Up @@ -160,19 +191,11 @@ impl Operation {
patch_path
}

pub fn get(conn: &Connection, query: &str, placeholders: Vec<Value>) -> SQLResult<Operation> {
let mut stmt = conn.prepare(query).unwrap();
let mut rows = stmt.query_map(params_from_iter(placeholders), |row| {
Ok(Self::process_row(row))
})?;
rows.next().unwrap()
}

pub fn get_by_hash(conn: &Connection, op_hash: &str) -> SQLResult<Operation> {
Operation::get(
conn,
"select * from operation where hash LIKE ?1",
vec![Value::from(format!("{op_hash}%"))],
params![Value::from(format!("{op_hash}%"))],
)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/views.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod block_group;
pub mod block_group_viewer;
pub mod block_layout;
pub mod collection;
pub mod operations;
pub mod patch;
Loading