Run cargo fmt on all Rust source files
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -60,7 +60,9 @@ fn is_note_file(path: &Path) -> bool {
|
||||
}
|
||||
|
||||
// data/projects/*/index.md
|
||||
if path_str.contains("projects") && path.file_name().and_then(|s| s.to_str()) == Some("index.md") {
|
||||
if path_str.contains("projects")
|
||||
&& path.file_name().and_then(|s| s.to_str()) == Some("index.md")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -123,7 +125,10 @@ pub fn normalize_path(path: &Path) -> String {
|
||||
} else {
|
||||
&path_str
|
||||
};
|
||||
stripped.replace('\\', "/").trim_start_matches('/').to_string()
|
||||
stripped
|
||||
.replace('\\', "/")
|
||||
.trim_start_matches('/')
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// Read a full note by deterministic ID.
|
||||
@@ -326,9 +331,7 @@ pub fn atomic_write(path: &Path, contents: &[u8]) -> Result<(), String> {
|
||||
let parent = path.parent().ok_or("Invalid path")?;
|
||||
let temp_name = format!(
|
||||
".{}.tmp",
|
||||
path.file_name()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("file")
|
||||
path.file_name().and_then(|s| s.to_str()).unwrap_or("file")
|
||||
);
|
||||
let temp_path = parent.join(temp_name);
|
||||
|
||||
|
||||
@@ -165,8 +165,14 @@ mod tests {
|
||||
let (fm, body, has_fm) = parse_frontmatter(content);
|
||||
|
||||
assert!(has_fm);
|
||||
assert_eq!(fm.get(&Value::from("id")).unwrap().as_str().unwrap(), "test");
|
||||
assert_eq!(fm.get(&Value::from("title")).unwrap().as_str().unwrap(), "Test Note");
|
||||
assert_eq!(
|
||||
fm.get(&Value::from("id")).unwrap().as_str().unwrap(),
|
||||
"test"
|
||||
);
|
||||
assert_eq!(
|
||||
fm.get(&Value::from("title")).unwrap().as_str().unwrap(),
|
||||
"Test Note"
|
||||
);
|
||||
assert!(body.contains("Body content"));
|
||||
}
|
||||
|
||||
|
||||
@@ -161,8 +161,7 @@ pub fn get_status() -> Result<RepoStatus, String> {
|
||||
Some(CommitInfo {
|
||||
id: commit.id().to_string()[..8].to_string(),
|
||||
message: commit.message()?.trim().to_string(),
|
||||
timestamp: chrono::DateTime::from_timestamp(commit.time().seconds(), 0)?
|
||||
.to_rfc3339(),
|
||||
timestamp: chrono::DateTime::from_timestamp(commit.time().seconds(), 0)?.to_rfc3339(),
|
||||
})
|
||||
});
|
||||
|
||||
@@ -311,14 +310,16 @@ pub fn push_to_remote() -> Result<(), String> {
|
||||
.map_err(|e| format!("Remote 'origin' not found: {}", e))?;
|
||||
|
||||
// Check if remote URL is configured
|
||||
let remote_url = remote.url().ok_or_else(|| "No remote URL configured".to_string())?;
|
||||
let remote_url = remote
|
||||
.url()
|
||||
.ok_or_else(|| "No remote URL configured".to_string())?;
|
||||
if remote_url.is_empty() {
|
||||
return Err("No remote URL configured".to_string());
|
||||
}
|
||||
|
||||
// Create callbacks for authentication
|
||||
let mut callbacks = git2::RemoteCallbacks::new();
|
||||
|
||||
|
||||
// Try to use credential helper from git config
|
||||
callbacks.credentials(|_url, username_from_url, _allowed_types| {
|
||||
// Try SSH agent first
|
||||
@@ -402,9 +403,7 @@ pub fn get_log(limit: Option<usize>) -> Result<Vec<CommitDetail>, String> {
|
||||
let commit_tree = commit.tree().ok();
|
||||
|
||||
if let (Some(pt), Some(ct)) = (parent_tree, commit_tree) {
|
||||
let diff = repo
|
||||
.diff_tree_to_tree(Some(&pt), Some(&ct), None)
|
||||
.ok();
|
||||
let diff = repo.diff_tree_to_tree(Some(&pt), Some(&ct), None).ok();
|
||||
diff.map(|d| d.deltas().count()).unwrap_or(0)
|
||||
} else {
|
||||
0
|
||||
@@ -418,10 +417,9 @@ pub fn get_log(limit: Option<usize>) -> Result<Vec<CommitDetail>, String> {
|
||||
.unwrap_or(0)
|
||||
};
|
||||
|
||||
let timestamp =
|
||||
chrono::DateTime::from_timestamp(commit.time().seconds(), 0)
|
||||
.map(|dt| dt.to_rfc3339())
|
||||
.unwrap_or_else(|| "Unknown".to_string());
|
||||
let timestamp = chrono::DateTime::from_timestamp(commit.time().seconds(), 0)
|
||||
.map(|dt| dt.to_rfc3339())
|
||||
.unwrap_or_else(|| "Unknown".to_string());
|
||||
|
||||
commits.push(CommitDetail {
|
||||
id: oid.to_string(),
|
||||
@@ -449,10 +447,7 @@ pub fn get_working_diff() -> Result<DiffInfo, String> {
|
||||
let repo = Repository::open(data_path).map_err(|e| format!("Not a git repository: {}", e))?;
|
||||
|
||||
// Get HEAD tree (or empty tree if no commits)
|
||||
let head_tree = repo
|
||||
.head()
|
||||
.ok()
|
||||
.and_then(|h| h.peel_to_tree().ok());
|
||||
let head_tree = repo.head().ok().and_then(|h| h.peel_to_tree().ok());
|
||||
|
||||
// Diff against working directory
|
||||
let diff = repo
|
||||
@@ -495,7 +490,7 @@ fn parse_diff(diff: &git2::Diff) -> Result<DiffInfo, String> {
|
||||
|
||||
for delta_idx in 0..diff.deltas().count() {
|
||||
let delta = diff.get_delta(delta_idx).ok_or("Missing delta")?;
|
||||
|
||||
|
||||
let path = delta
|
||||
.new_file()
|
||||
.path()
|
||||
@@ -609,10 +604,7 @@ pub fn get_remote_info() -> Result<Option<RemoteInfo>, String> {
|
||||
let (ahead, behind) = if let Some(ref up) = upstream {
|
||||
// Calculate ahead/behind
|
||||
let local_oid = head.target().unwrap_or_else(git2::Oid::zero);
|
||||
let upstream_oid = up
|
||||
.get()
|
||||
.target()
|
||||
.unwrap_or_else(git2::Oid::zero);
|
||||
let upstream_oid = up.get().target().unwrap_or_else(git2::Oid::zero);
|
||||
|
||||
repo.graph_ahead_behind(local_oid, upstream_oid)
|
||||
.unwrap_or((0, 0))
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
@@ -3,4 +3,4 @@ pub mod frontmatter;
|
||||
pub mod git;
|
||||
pub mod locks;
|
||||
pub mod markdown;
|
||||
pub mod search;
|
||||
pub mod search;
|
||||
|
||||
@@ -33,7 +33,10 @@ pub fn search_notes(query: &str) -> Result<Vec<SearchResult>, String> {
|
||||
match search_with_ripgrep(query) {
|
||||
Ok(results) => return Ok(results),
|
||||
Err(e) => {
|
||||
tracing::debug!("ripgrep not available, falling back to manual search: {}", e);
|
||||
tracing::debug!(
|
||||
"ripgrep not available, falling back to manual search: {}",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +49,12 @@ fn search_with_ripgrep(query: &str) -> Result<Vec<SearchResult>, String> {
|
||||
let data_dir_str = config::data_dir().to_string_lossy();
|
||||
let output = Command::new("rg")
|
||||
.args([
|
||||
"--json", // JSON output for parsing
|
||||
"--ignore-case", // Case insensitive
|
||||
"--type", "md", // Only markdown files
|
||||
"--max-count", "5", // Max 5 matches per file
|
||||
"--json", // JSON output for parsing
|
||||
"--ignore-case", // Case insensitive
|
||||
"--type",
|
||||
"md", // Only markdown files
|
||||
"--max-count",
|
||||
"5", // Max 5 matches per file
|
||||
query,
|
||||
&data_dir_str,
|
||||
])
|
||||
@@ -88,13 +93,13 @@ fn parse_ripgrep_output(output: &[u8]) -> Result<Vec<SearchResult>, String> {
|
||||
let normalized_path = normalize_path(path_str);
|
||||
let title = extract_title_from_path(&normalized_path);
|
||||
|
||||
let result = results_map.entry(normalized_path.clone()).or_insert_with(|| {
|
||||
SearchResult {
|
||||
let result = results_map
|
||||
.entry(normalized_path.clone())
|
||||
.or_insert_with(|| SearchResult {
|
||||
path: normalized_path,
|
||||
title,
|
||||
matches: Vec::new(),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
result.matches.push(SearchMatch {
|
||||
line_number,
|
||||
|
||||
Reference in New Issue
Block a user