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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.5]

### Fixed
- `list` is now strictly read-only and no longer rewrites `docs/rfcs/.index.json`
on every invocation. The index is persisted only when a real change is
detected during refresh.

## [0.1.4]

### Added
Expand Down
2 changes: 1 addition & 1 deletion 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,6 +1,6 @@
[package]
name = "rfc-cli"
version = "0.1.4"
version = "0.1.5"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::rfclib::index;
/// Executes the `list` command: shows table of all RFCs
pub fn execute(project_root: &Path, status_filter: Option<&str>) -> Result<(), String> {
let mut idx = index::load_index(project_root)?;
index::refresh_index(project_root, &mut idx)?;
index::refresh_index_readonly(project_root, &mut idx)?;

let mut rfcs: Vec<&index::IndexEntry> = idx.rfcs.iter().collect();

Expand Down
31 changes: 26 additions & 5 deletions src/rfclib/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,31 @@ pub fn compute_content_hash(content: &str) -> String {

/// Refreshes index: compares mtime of files with index entries,
/// reparses changed ones, adds new ones, removes stale ones.
/// Persists the index to disk only if any change was detected.
pub fn refresh_index(project_root: &Path, index: &mut Index) -> Result<(), String> {
let dirty = refresh_entries(project_root, index)?;
if dirty {
save_index(project_root, index)?;
}
Ok(())
}

/// Refreshes the in-memory index without ever writing to disk. Read-only.
pub fn refresh_index_readonly(project_root: &Path, index: &mut Index) -> Result<(), String> {
refresh_entries(project_root, index)?;
Ok(())
}

/// Scans RFC files and updates the in-memory index, returning `true` if the
/// index changed. Never writes to disk.
fn refresh_entries(project_root: &Path, index: &mut Index) -> Result<bool, String> {
let rfcs_dir = project_root.join("docs/rfcs");
if !rfcs_dir.exists() {
return Ok(());
return Ok(false);
}

let mut dirty = false;

// Scan all .md files in docs/rfcs/
let mut found_numbers: Vec<String> = Vec::new();
let entries = fs::read_dir(&rfcs_dir)
Expand Down Expand Up @@ -148,19 +167,21 @@ pub fn refresh_index(project_root: &Path, index: &mut Index) -> Result<(), Strin
// Remove old entry if exists, then add new one
index.rfcs.retain(|e| e.number != number);
index.rfcs.push(new_entry);
dirty = true;
}
}

// Remove entries for which files no longer exist
let before = index.rfcs.len();
index.rfcs.retain(|e| found_numbers.contains(&e.number));
if index.rfcs.len() != before {
dirty = true;
}

// Sort by number
index.rfcs.sort_by(|a, b| a.number.cmp(&b.number));

// Save
save_index(project_root, index)?;

Ok(())
Ok(dirty)
}

/// Completely rebuilds the index from scratch by scanning all RFC files.
Expand Down
Loading