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
40 changes: 20 additions & 20 deletions src/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ fn hydrate_promised_entries(
if let Some(dir_oid) = git_utils::find_blob_oid_in_tree(repo, &tip_tree, &path)? {
// dir_oid is a tree — collect all blob entries in it
if let Ok(list_tree) = repo.find_tree(dir_oid) {
let mut oids = Vec::new();
for entry in list_tree.iter() {
let name = entry.name().unwrap_or("");
if name == types::TOMBSTONE_ROOT || name.starts_with("__") {
continue;
}
if entry.kind() == Some(git2::ObjectType::Blob) {
oids.push(entry.id());
}
}
let oids: Vec<_> = list_tree
.iter()
.filter(|e| {
let name = e.name().unwrap_or("");
!name.starts_with("__")
&& name != types::TOMBSTONE_ROOT
&& e.kind() == Some(git2::ObjectType::Blob)
})
.map(|e| e.id())
.collect();
if !oids.is_empty() {
pending.push(PendingEntry {
idx,
Expand All @@ -186,16 +186,16 @@ fn hydrate_promised_entries(
let set_path = format!("{}/{}", key_path, types::SET_VALUE_DIR);
if let Some(dir_oid) = git_utils::find_blob_oid_in_tree(repo, &tip_tree, &set_path)? {
if let Ok(set_tree) = repo.find_tree(dir_oid) {
let mut oids = Vec::new();
for entry in set_tree.iter() {
let name = entry.name().unwrap_or("");
if name == types::TOMBSTONE_ROOT || name.starts_with("__") {
continue;
}
if entry.kind() == Some(git2::ObjectType::Blob) {
oids.push(entry.id());
}
}
let oids: Vec<_> = set_tree
.iter()
.filter(|e| {
let name = e.name().unwrap_or("");
!name.starts_with("__")
&& name != types::TOMBSTONE_ROOT
&& e.kind() == Some(git2::ObjectType::Blob)
})
.map(|e| e.id())
.collect();
if !oids.is_empty() {
pending.push(PendingEntry {
idx,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/import.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::collections::HashSet;

use anyhow::{bail, Context, Result};
use chrono::Utc;
use git2::Repository;
use serde_json::Value;
use std::collections::HashSet;

use crate::db::Db;
use crate::git_utils;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
//! - `gmeta inspect <target-type>`: list all keys for that target type
//! - `gmeta inspect <target-type> <term>`: fuzzy-match keys/targets on term

use std::collections::BTreeMap;

use anyhow::Result;
use chrono::{Duration, Utc};
use std::collections::BTreeMap;

use crate::db::Db;
use crate::git_utils;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/materialize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, BTreeSet};

use anyhow::Result;
use chrono::Utc;
use std::collections::{BTreeMap, BTreeSet};

use crate::db::Db;
use crate::git_utils;
Expand Down
28 changes: 10 additions & 18 deletions src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,16 @@ pub fn run(dry_run: bool) -> Result<()> {

// Find the current serialized tree
let ref_name = git_utils::git2_local_ref(&repo)?;
let current_commit = match repo.find_reference(&ref_name) {
Ok(r) => match r.peel_to_commit() {
Ok(c) => c,
Err(_) => {
eprintln!(
"No serialized metadata found at {}. Run `gmeta serialize` first.",
ref_name
);
return Ok(());
}
},
Err(_) => {
eprintln!(
"No serialized metadata found at {}. Run `gmeta serialize` first.",
ref_name
);
return Ok(());
}
let Some(current_commit) = repo
.find_reference(&ref_name)
.ok()
.and_then(|r| r.peel_to_commit().ok())
else {
eprintln!(
"No serialized metadata found at {}. Run `gmeta serialize` first.",
ref_name
);
return Ok(());
};

let tree_oid = current_commit.tree()?.id();
Expand Down
12 changes: 4 additions & 8 deletions src/commands/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ pub fn run_add(url: &str, name: &str, namespace_override: Option<&str>) -> Resul
let url = expand_url(url);

// Check if this remote name already exists
let existing = repo.remotes()?;
for existing_name in existing.iter().flatten() {
if existing_name == name {
bail!("remote '{}' already exists", name);
}
if repo.remotes()?.iter().flatten().any(|n| n == name) {
bail!("remote '{}' already exists", name);
}

// Check the remote for meta refs before configuring
Expand Down Expand Up @@ -210,9 +207,8 @@ pub fn run_remove(name: &str) -> Result<()> {
// Verify this is a meta remote
let config = repo.config()?;
let meta_key = format!("remote.{}.meta", name);
match config.get_bool(&meta_key) {
Ok(true) => {}
_ => bail!("'{}' is not a metadata remote (no meta = true)", name),
if !matches!(config.get_bool(&meta_key), Ok(true)) {
bail!("'{}' is not a metadata remote (no meta = true)", name);
}

// Remove the git config section for this remote
Expand Down
3 changes: 2 additions & 1 deletion src/commands/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, BTreeSet};

use anyhow::{bail, Context, Result};
use chrono::Utc;
use std::collections::{BTreeMap, BTreeSet};

use crate::commands::auto_prune::{self, parse_since_to_cutoff_ms};
use crate::db::Db;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs;

use anyhow::{bail, Context, Result};
use chrono::Utc;
use std::fs;

use crate::db::Db;
use crate::git_utils;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/show.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! `gmeta show <commit-sha>` — display commit details with any associated metadata.

use std::process::Command;

use anyhow::{Context, Result};
use chrono::{TimeZone, Utc};
use git2::Repository;
use std::process::Command;

use crate::db::Db;
use crate::git_utils;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/stats.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use std::collections::BTreeMap;

use anyhow::Result;

use crate::db::Db;
use crate::git_utils;

Expand Down
7 changes: 4 additions & 3 deletions src/commands/watch.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use anyhow::{bail, Context, Result};
use chrono::Utc;
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::io::{BufRead, BufReader, Seek, SeekFrom};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::mpsc;
use std::time::{Duration, Instant};

use anyhow::{bail, Context, Result};
use chrono::Utc;
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};

use crate::db::Db;
use crate::git_utils;

Expand Down
3 changes: 2 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::path::Path;

use anyhow::{bail, Result};
use git2::Repository;
use rusqlite::{params, Connection};
use std::path::Path;

use crate::list_value::{encode_entries, ensure_unique_timestamp, parse_entries, ListEntry};
use crate::types::GIT_REF_THRESHOLD;
Expand Down
31 changes: 14 additions & 17 deletions src/git_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::{bail, Context, Result};
use git2::Repository;
use std::path::{Path, PathBuf};
use std::process::Command;

use anyhow::{bail, Context, Result};
use git2::Repository;

/// Discover the Git repository from the current directory (git2).
pub fn git2_discover_repo() -> Result<Repository> {
let repo = Repository::discover(".")
Expand Down Expand Up @@ -305,6 +306,14 @@ pub fn resolve_meta_remote(repo: &Repository, remote: Option<&str>) -> Result<St

// ── gix-based helpers (primary API) ──────────────────────────────────────────

fn gix_config_string(repo: &gix::Repository, key: &str, default: &str) -> String {
let config = repo.config_snapshot();
config
.string(key)
.map(|s| s.to_string())
.unwrap_or_else(|| default.to_string())
}

/// Discover the Git repository from the current directory.
pub fn discover_repo() -> Result<gix::Repository> {
let repo =
Expand All @@ -319,30 +328,18 @@ pub fn db_path(repo: &gix::Repository) -> Result<PathBuf> {

/// Get the user's email from Git config.
pub fn get_email(repo: &gix::Repository) -> Result<String> {
let config = repo.config_snapshot();
Ok(config
.string("user.email")
.map(|s| s.to_string())
.unwrap_or_else(|| "unknown".to_string()))
Ok(gix_config_string(repo, "user.email", "unknown"))
}

/// Get the user's name from Git config.
#[allow(dead_code)]
pub fn get_name(repo: &gix::Repository) -> Result<String> {
let config = repo.config_snapshot();
Ok(config
.string("user.name")
.map(|s| s.to_string())
.unwrap_or_else(|| "unknown".to_string()))
Ok(gix_config_string(repo, "user.name", "unknown"))
}

/// Get the meta namespace from Git config (defaults to "meta").
pub fn get_namespace(repo: &gix::Repository) -> Result<String> {
let config = repo.config_snapshot();
Ok(config
.string("meta.namespace")
.map(|s| s.to_string())
.unwrap_or_else(|| "meta".to_string()))
Ok(gix_config_string(repo, "meta.namespace", "meta"))
}

/// Get the local ref name for serialization.
Expand Down
Loading