Skip to content
Merged
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
32 changes: 16 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["crates/gmeta-core", "crates/gmeta-cli", "crates/gmeta-bench"]
members = ["crates/gmeta", "crates/gmeta-cli", "crates/gmeta-bench"]
resolver = "2"

[workspace.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/gmeta-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
gmeta-core = { path = "../gmeta-core", features = ["internal"] }
gmeta = { path = "../gmeta", features = ["internal"] }
anyhow = { workspace = true }
gix = { workspace = true }
serde_json = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/gmeta-bench/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Result;
use std::time::{Duration, Instant};

use gmeta_core::types::{Target, TargetType};
use gmeta_core::Session;
use gmeta::types::{Target, TargetType};
use gmeta::Session;

const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
Expand Down
10 changes: 5 additions & 5 deletions crates/gmeta-bench/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use gix::prelude::ObjectIdExt;
use std::io::Write;
use std::time::Instant;

use gmeta_core::db::Store;
use gmeta_core::tree_paths;
use gmeta_core::types::{Target, TargetType, ValueType};
use gmeta::db::Store;
use gmeta::tree_paths;
use gmeta::types::{Target, TargetType, ValueType};

const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
Expand Down Expand Up @@ -201,9 +201,9 @@ fn do_serialize(repo: &gix::Repository, db: &Store, ref_name: &str) -> Result<()
#[allow(clippy::unwrap_used, clippy::expect_used)]
fn build_bench_tree(
repo: &gix::Repository,
metadata_entries: &[gmeta_core::db::types::SerializableEntry],
metadata_entries: &[gmeta::db::types::SerializableEntry],
) -> Result<gix::ObjectId> {
use gmeta_core::types::Target;
use gmeta::types::Target;
use std::collections::BTreeMap;

let mut files: BTreeMap<String, Vec<u8>> = BTreeMap::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/gmeta-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bench = ["dep:gmeta-bench"]

[dependencies]
gmeta-bench = { path = "../gmeta-bench", optional = true }
gmeta-core = { path = "../gmeta-core", features = ["internal"] }
gmeta = { path = "../gmeta", features = ["internal"] }
anyhow = { workspace = true }
clap = { version = "4", features = ["derive"] }
dialoguer = "0.11"
Expand Down
10 changes: 5 additions & 5 deletions crates/gmeta-cli/src/commands/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{bail, Result};

use crate::context::CommandContext;
use gmeta_core::types::{validate_key, MetaValue, Target};
use gmeta::types::{validate_key, MetaValue, Target};

const CONFIG_PREFIX: &str = "meta:";

Expand Down Expand Up @@ -40,13 +40,13 @@ fn project_target() -> Target {
Target::project()
}

fn run_set(handle: &gmeta_core::SessionTargetHandle<'_>, key: &str, value: &str) -> Result<()> {
fn run_set(handle: &gmeta::SessionTargetHandle<'_>, key: &str, value: &str) -> Result<()> {
let meta_value = MetaValue::String(value.to_string());
handle.set(key, meta_value)?;
Ok(())
}

fn run_get(handle: &gmeta_core::SessionTargetHandle<'_>, key: &str) -> Result<()> {
fn run_get(handle: &gmeta::SessionTargetHandle<'_>, key: &str) -> Result<()> {
if let Some(meta_value) = handle.get_value(key)? {
match meta_value {
MetaValue::String(s) => println!("{s}"),
Expand All @@ -56,7 +56,7 @@ fn run_get(handle: &gmeta_core::SessionTargetHandle<'_>, key: &str) -> Result<()
Ok(())
}

fn run_list(handle: &gmeta_core::SessionTargetHandle<'_>) -> Result<()> {
fn run_list(handle: &gmeta::SessionTargetHandle<'_>) -> Result<()> {
let entries = handle.get_all_values(Some("meta"))?;
for (key, value) in entries {
let display = match value {
Expand All @@ -68,7 +68,7 @@ fn run_list(handle: &gmeta_core::SessionTargetHandle<'_>) -> Result<()> {
Ok(())
}

fn run_unset(handle: &gmeta_core::SessionTargetHandle<'_>, key: &str) -> Result<()> {
fn run_unset(handle: &gmeta::SessionTargetHandle<'_>, key: &str) -> Result<()> {
let removed = handle.remove(key)?;
if !removed {
eprintln!("key '{key}' not found");
Expand Down
20 changes: 9 additions & 11 deletions crates/gmeta-cli/src/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use gix::prelude::ObjectIdExt;
use serde_json::{json, Map, Value};

use crate::context::CommandContext;
use gmeta_core::db::Store;
use gmeta_core::tree_paths;
use gmeta_core::types::{Target, TargetType, ValueType};
use gmeta::db::Store;
use gmeta::tree_paths;
use gmeta::types::{Target, TargetType, ValueType};

const NODE_VALUE_KEY: &str = "__value";
const SET_VALUE_DIR: &str = "__set";
Expand Down Expand Up @@ -113,7 +113,7 @@ pub fn run(
/// Hydrate promised entries by looking up their blob OIDs in the tip tree
/// and fetching any that aren't already local. Returns the number hydrated.
fn hydrate_promised_entries(
session: &gmeta_core::Session,
session: &gmeta::Session,
target_type: &TargetType,
entries: &[(String, String)], // (target_value, key)
) -> Result<usize> {
Expand Down Expand Up @@ -150,9 +150,7 @@ fn hydrate_promised_entries(

// Try __value (string) first
if let Ok(path) = tree_paths::tree_path(&parsed_target, key) {
if let Some(oid) =
gmeta_core::git_utils::find_blob_oid_in_tree(repo, tip_tree_id, &path)?
{
if let Some(oid) = gmeta::git_utils::find_blob_oid_in_tree(repo, tip_tree_id, &path)? {
pending.push(PendingEntry {
idx,
oids: vec![oid],
Expand All @@ -165,7 +163,7 @@ fn hydrate_promised_entries(
// Try __list directory
if let Ok(path) = tree_paths::list_dir_path(&parsed_target, key) {
if let Some(dir_oid) =
gmeta_core::git_utils::find_blob_oid_in_tree(repo, tip_tree_id, &path)?
gmeta::git_utils::find_blob_oid_in_tree(repo, tip_tree_id, &path)?
{
// dir_oid is a tree — collect all blob entries in it
let list_tree = dir_oid.attach(repo).object()?.into_tree();
Expand Down Expand Up @@ -199,7 +197,7 @@ fn hydrate_promised_entries(
if let Ok(key_path) = tree_paths::key_tree_path(&parsed_target, key) {
let set_path = format!("{key_path}/{SET_VALUE_DIR}");
if let Some(dir_oid) =
gmeta_core::git_utils::find_blob_oid_in_tree(repo, tip_tree_id, &set_path)?
gmeta::git_utils::find_blob_oid_in_tree(repo, tip_tree_id, &set_path)?
{
let set_tree = dir_oid.attach(repo).object()?.into_tree();
let oids: Vec<_> = set_tree
Expand Down Expand Up @@ -259,13 +257,13 @@ fn hydrate_promised_entries(
}

if !missing.is_empty() {
let remote_name = gmeta_core::git_utils::resolve_meta_remote(repo, None)?;
let remote_name = gmeta::git_utils::resolve_meta_remote(repo, None)?;
eprintln!(
"Fetching {} blob{} from remote...",
missing.len(),
if missing.len() == 1 { "" } else { "s" }
);
gmeta_core::git_utils::fetch_blob_oids(repo, &remote_name, &missing)?;
gmeta::git_utils::fetch_blob_oids(repo, &remote_name, &missing)?;
}

// Now read blobs and update DB
Expand Down
33 changes: 13 additions & 20 deletions crates/gmeta-cli/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use anyhow::{bail, Context, Result};
use serde_json::Value;

use crate::context::CommandContext;
use gmeta_core::db::Store;
use gmeta_core::types::{TargetType, ValueType, GIT_REF_THRESHOLD};
use gmeta::db::Store;
use gmeta::types::{TargetType, ValueType, GIT_REF_THRESHOLD};

/// Supported import source formats.
#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -205,7 +205,7 @@ fn import_checkpoints_from_commits(

// Skip if already imported
if let Some(db) = db {
let commit_target = gmeta_core::types::Target::from_parts(
let commit_target = gmeta::types::Target::from_parts(
TargetType::Commit,
Some(commit_sha.clone()),
);
Expand Down Expand Up @@ -522,12 +522,12 @@ fn import_session(
if !lines.is_empty() {
let mut entries = Vec::new();
for (i, line) in lines.iter().enumerate() {
entries.push(gmeta_core::ListEntry {
entries.push(gmeta::ListEntry {
value: line.to_string(),
timestamp: *ts + i as i64,
});
}
let encoded = gmeta_core::list_value::encode_entries(&entries)?;
let encoded = gmeta::list_value::encode_entries(&entries)?;
count += set_value(
repo,
db,
Expand Down Expand Up @@ -713,12 +713,12 @@ fn import_trails(
if !arr.is_empty() {
let mut entries = Vec::new();
for (i, item) in arr.iter().enumerate() {
entries.push(gmeta_core::ListEntry {
entries.push(gmeta::ListEntry {
value: serde_json::to_string(item)?,
timestamp: ts + i as i64,
});
}
let encoded = gmeta_core::list_value::encode_entries(&entries)?;
let encoded = gmeta::list_value::encode_entries(&entries)?;
count += set_value(
repo,
db,
Expand Down Expand Up @@ -789,12 +789,9 @@ fn set_value(

if let Some(db) = db {
let target = if *target_type == TargetType::Project {
gmeta_core::types::Target::project()
gmeta::types::Target::project()
} else {
gmeta_core::types::Target::from_parts(
target_type.clone(),
Some(target_value.to_string()),
)
gmeta::types::Target::from_parts(target_type.clone(), Some(target_value.to_string()))
};
if use_git_ref {
let blob_oid: gix::ObjectId = repo.write_blob(value.as_bytes())?.into();
Expand Down Expand Up @@ -979,10 +976,8 @@ fn run_git_ai(dry_run: bool, since_epoch: Option<i64>) -> Result<()> {

// Check whether we already have data for this commit
if let Some(db) = db {
let commit_target = gmeta_core::types::Target::from_parts(
TargetType::Commit,
Some(commit_sha.clone()),
);
let commit_target =
gmeta::types::Target::from_parts(TargetType::Commit, Some(commit_sha.clone()));
if db.get(&commit_target, "agent.blame")?.is_some() {
skipped_exists += 1;
continue;
Expand All @@ -1001,10 +996,8 @@ fn run_git_ai(dry_run: bool, since_epoch: Option<i64>) -> Result<()> {
);

if let Some(db) = db {
let commit_target = gmeta_core::types::Target::from_parts(
TargetType::Commit,
Some(commit_sha.clone()),
);
let commit_target =
gmeta::types::Target::from_parts(TargetType::Commit, Some(commit_sha.clone()));
// agent.blame -- store as git blob ref if large
let (blame_val, is_ref) = if parsed.blame.len() > GIT_REF_THRESHOLD {
let oid: gix::ObjectId = repo.write_blob(parsed.blame.as_bytes())?.into();
Expand Down
15 changes: 7 additions & 8 deletions crates/gmeta-cli/src/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use anyhow::Result;
use time::{Duration, OffsetDateTime};

use crate::context::CommandContext;
use gmeta_core::db::Store;
use gmeta::db::Store;

const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
Expand Down Expand Up @@ -157,10 +157,10 @@ fn run_promisor_list(db: &Store, target_type: Option<&str>) -> Result<()> {
/// List keys for a specific target type, optionally fuzzy-filtered.
fn run_list(db: &Store, target_type: &str, term: Option<&str>) -> Result<()> {
let all = db.get_all_metadata()?;
let target_type_parsed = target_type.parse::<gmeta_core::TargetType>()?;
let target_type_parsed = target_type.parse::<gmeta::TargetType>()?;

// Filter to target type
let mut entries: Vec<&gmeta_core::db::types::SerializableEntry> = all
let mut entries: Vec<&gmeta::db::types::SerializableEntry> = all
.iter()
.filter(|e| e.target_type == target_type_parsed)
.collect();
Expand All @@ -176,7 +176,7 @@ fn run_list(db: &Store, target_type: &str, term: Option<&str>) -> Result<()> {
entries.retain(|e| {
fuzzy_matches(&lower_term, &e.target_value)
|| fuzzy_matches(&lower_term, &e.key)
|| (e.value_type == gmeta_core::types::ValueType::String
|| (e.value_type == gmeta::types::ValueType::String
&& fuzzy_matches(&lower_term, &decode_string_value(&e.value)))
});
}
Expand All @@ -190,8 +190,7 @@ fn run_list(db: &Store, target_type: &str, term: Option<&str>) -> Result<()> {
let term_width = terminal_width();

// Group by target_value
let mut by_target: BTreeMap<&str, Vec<&&gmeta_core::db::types::SerializableEntry>> =
BTreeMap::new();
let mut by_target: BTreeMap<&str, Vec<&&gmeta::db::types::SerializableEntry>> = BTreeMap::new();
for entry in &entries {
by_target
.entry(&entry.target_value)
Expand Down Expand Up @@ -294,11 +293,11 @@ fn run_timeline(db: &Store) -> Result<()> {
/// Format a value for one-line display, fitting within available width.
fn format_value_oneline(
value: &str,
value_type: &gmeta_core::types::ValueType,
value_type: &gmeta::types::ValueType,
term_width: usize,
key_len: usize,
) -> String {
use gmeta_core::types::ValueType;
use gmeta::types::ValueType;
// 2 spaces indent + key + 2 spaces gap = overhead
let overhead = 2 + key_len + 2;
let available = if term_width > overhead + 5 {
Expand Down
2 changes: 1 addition & 1 deletion crates/gmeta-cli/src/commands/list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;

use crate::context::CommandContext;
use gmeta_core::types::Target;
use gmeta::types::Target;

pub fn run_push(target_str: &str, key: &str, value: &str) -> Result<()> {
let ctx = CommandContext::open(None)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/gmeta-cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use gix::bstr::ByteSlice;
use gix::prelude::ObjectIdExt;

use crate::context::CommandContext;
use gmeta_core::types::{Target, TargetType};
use gmeta::types::{Target, TargetType};

const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
Expand Down
Loading
Loading