Skip to content

Commit 5ce13c9

Browse files
authored
Remove println from production code (#85)
1 parent 0aef257 commit 5ce13c9

71 files changed

Lines changed: 1075 additions & 314 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,24 @@ on:
88
- main
99

1010
jobs:
11+
pre-commit:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: '3.11'
18+
- uses: pre-commit/action@v3.0.1
19+
1120
test:
21+
needs: pre-commit
1222
strategy:
1323
matrix:
1424
feature_flags: ["no-default-features", "all-features"]
1525
runs-on: ubuntu-latest
1626
steps:
17-
18-
- uses: actions/checkout@v2
1927

20-
- name: fmt
21-
run: cargo fmt --all -- --check
28+
- uses: actions/checkout@v4
2229

2330
- name: build
2431
run: cargo build --all --verbose

.github/workflows/pre-commit.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Pre-commit
2+
3+
on:
4+
pull_request:
5+
types: [opened, ready_for_review, synchronize]
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
pre-commit:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0 # Fetch full history for better pre-commit performance
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Cache pre-commit
25+
uses: actions/cache@v4
26+
with:
27+
path: ~/.cache/pre-commit
28+
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
29+
30+
- name: Install pre-commit
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install pre-commit
34+
35+
- name: Run pre-commit on all files
36+
run: pre-commit run --all-files
37+
38+
- name: Run pre-commit on changed files (for PRs)
39+
if: github.event_name == 'pull_request'
40+
run: pre-commit run --from-ref origin/${{ github.base_ref }} --to-ref HEAD

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: license-check
5+
name: License Header Check
6+
entry: scripts/check-license.sh
7+
language: script
8+
files: \.(rs|py)$
9+
pass_filenames: true
10+
stages: [pre-commit]
11+
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v4.4.0
14+
hooks:
15+
- id: trailing-whitespace
16+
- id: end-of-file-fixer
17+
- id: check-yaml
18+
- id: check-toml
19+
- id: check-merge-conflict
20+
- id: check-added-large-files
21+
22+
- repo: local
23+
hooks:
24+
- id: cargo-fmt
25+
name: Cargo format
26+
entry: cargo fmt --all -- --check
27+
language: rust
28+
files: \.rs$
29+
pass_filenames: false

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
[![License](https://img.shields.io/crates/l/prollytree.svg)](https://github.com/yourusername/prollytree/blob/main/LICENSE)
66
[![Downloads](https://img.shields.io/crates/d/prollytree.svg)](https://crates.io/crates/prollytree)
77

8-
A Prolly Tree is a hybrid data structure that combines the features of B-trees and Merkle trees to provide
9-
both efficient data access and verifiable integrity. It is specifically designed to handle the requirements
10-
of distributed systems and large-scale databases, making indexes syncable and distributable over
8+
A Prolly Tree is a hybrid data structure that combines the features of B-trees and Merkle trees to provide
9+
both efficient data access and verifiable integrity. It is specifically designed to handle the requirements
10+
of distributed systems and large-scale databases, making indexes syncable and distributable over
1111
peer-to-peer (P2P) networks.
1212

1313
## Key Features
@@ -111,23 +111,23 @@ use prollytree::git::GitVersionedKvStore;
111111
fn main() -> Result<(), Box<dyn std::error::Error>> {
112112
// Initialize git-backed store
113113
let mut store = GitVersionedKvStore::init("./my-data")?;
114-
114+
115115
// Set values (automatically stages changes)
116116
store.set(b"config/api_key", b"secret123")?;
117117
store.set(b"config/timeout", b"30")?;
118-
118+
119119
// Commit changes
120120
store.commit("Update API configuration")?;
121-
121+
122122
// Create a branch for experiments
123123
store.checkout_new_branch("feature/new-settings")?;
124124
store.set(b"config/timeout", b"60")?;
125125
store.commit("Increase timeout")?;
126-
126+
127127
// Switch back and see the difference
128128
store.checkout("main")?;
129129
let timeout = store.get(b"config/timeout")?; // Returns b"30"
130-
130+
131131
Ok(())
132132
}
133133
```
@@ -143,23 +143,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
143143
// Initialize SQL-capable storage
144144
let storage = ProllyStorage::<32>::init("./data")?;
145145
let mut glue = Glue::new(storage);
146-
146+
147147
// Create table and insert data
148148
glue.execute("CREATE TABLE users (id INTEGER, name TEXT, age INTEGER)").await?;
149149
glue.execute("INSERT INTO users VALUES (1, 'Alice', 30)").await?;
150150
glue.execute("INSERT INTO users VALUES (2, 'Bob', 25)").await?;
151-
151+
152152
// Query with SQL
153153
let result = glue.execute("SELECT * FROM users WHERE age > 26").await?;
154154
// Returns: [(1, 'Alice', 30)]
155-
155+
156156
// Time travel query (requires commit)
157157
glue.storage.commit("Initial user data").await?;
158158
glue.execute("UPDATE users SET age = 31 WHERE id = 1").await?;
159-
159+
160160
// Query previous version
161161
let old_data = glue.storage.query_at_commit("HEAD~1", "SELECT * FROM users").await?;
162-
162+
163163
Ok(())
164164
}
165165
```
@@ -176,19 +176,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
176176
let mut memory = AgentMemorySystem::init_with_thread_safe_git(
177177
"./agent_memory", "assistant_001".to_string(), None
178178
)?;
179-
179+
180180
// Store conversation in short-term memory
181181
memory.short_term.store_conversation_turn(
182182
"session_123", "user", "What's the weather in Tokyo?", None
183183
).await?;
184-
184+
185185
// Store facts in semantic memory
186186
memory.semantic.store_fact(
187187
"location", "tokyo",
188188
json!({"timezone": "JST", "temp": "22°C"}),
189189
0.9, "weather_api"
190190
).await?;
191-
191+
192192
// Query memories
193193
let query = MemoryQuery {
194194
namespace: None,
@@ -201,11 +201,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
201201
include_expired: false,
202202
};
203203
let results = memory.semantic.query(query).await?;
204-
204+
205205
// Create checkpoint
206206
let commit_id = memory.checkpoint("Weather session").await?;
207207
println!("Stored {} memories, checkpoint: {}", results.len(), commit_id);
208-
208+
209209
Ok(())
210210
}
211211
```
@@ -219,19 +219,19 @@ use prollytree::storage::InMemoryNodeStorage;
219219
fn main() {
220220
let storage = InMemoryNodeStorage::<32>::new();
221221
let mut tree = ProllyTree::new(storage, Default::default());
222-
222+
223223
// Insert sensitive data
224224
tree.insert(b"balance:alice".to_vec(), b"1000".to_vec());
225225
tree.insert(b"balance:bob".to_vec(), b"500".to_vec());
226-
226+
227227
// Generate cryptographic proof
228228
let proof = tree.generate_proof(b"balance:alice").unwrap();
229229
let root_hash = tree.root_hash();
230-
230+
231231
// Verify proof (can be done by third party)
232232
let is_valid = tree.verify_proof(&proof, b"balance:alice", b"1000");
233233
assert!(is_valid);
234-
234+
235235
// Root hash changes if any data changes
236236
tree.update(b"balance:alice".to_vec(), b"1100".to_vec());
237237
let new_root = tree.root_hash();
@@ -249,4 +249,4 @@ Contributions are welcome! Please submit a pull request or open an issue to disc
249249

250250
## License
251251

252-
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.
252+
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.

benches/sql.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async fn setup_database(record_count: usize) -> (Glue<ProllyStorage<32>>, TempDi
4343
// Insert test data
4444
for i in 0..record_count {
4545
let insert_sql = format!(
46-
"INSERT INTO users (id, name, email, age, city, created_at)
46+
"INSERT INTO users (id, name, email, age, city, created_at)
4747
VALUES ({}, 'User{}', 'user{}@example.com', {}, 'City{}', TIMESTAMP '2024-01-{:02} 12:00:00')",
4848
i, i, i, 20 + (i % 50), i % 10, (i % 28) + 1
4949
);
@@ -147,7 +147,7 @@ fn bench_sql_join(c: &mut Criterion) {
147147
// Insert orders
148148
for i in 0..size * 2 {
149149
let sql = format!(
150-
"INSERT INTO orders (id, user_id, amount, status)
150+
"INSERT INTO orders (id, user_id, amount, status)
151151
VALUES ({}, {}, {}, '{}')",
152152
i,
153153
i % size,
@@ -198,7 +198,7 @@ fn bench_sql_aggregation(c: &mut Criterion) {
198198
runtime.block_on(async {
199199
let result = glue
200200
.execute(
201-
"SELECT city,
201+
"SELECT city,
202202
COUNT(*) as user_count,
203203
AVG(age) as avg_age,
204204
MIN(age) as min_age,
@@ -237,8 +237,8 @@ fn bench_sql_update(c: &mut Criterion) {
237237
// Update multiple records
238238
let result = glue
239239
.execute(
240-
"UPDATE users
241-
SET age = age + 1,
240+
"UPDATE users
241+
SET age = age + 1,
242242
city = 'UpdatedCity'
243243
WHERE age < 30",
244244
)
@@ -368,16 +368,16 @@ fn bench_sql_complex_query(c: &mut Criterion) {
368368
// Complex query with subqueries
369369
let result = glue
370370
.execute(
371-
"SELECT
371+
"SELECT
372372
u.city,
373373
COUNT(DISTINCT u.id) as user_count,
374-
(SELECT COUNT(*)
375-
FROM users u2
374+
(SELECT COUNT(*)
375+
FROM users u2
376376
WHERE u2.city = u.city AND u2.age > 40) as senior_count,
377377
AVG(u.age) as avg_age
378378
FROM users u
379379
WHERE u.id IN (
380-
SELECT id FROM users
380+
SELECT id FROM users
381381
WHERE age BETWEEN 25 AND 45
382382
)
383383
GROUP BY u.city

docs/git.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ git-prolly diff main feature/preferences
267267
git-prolly diff main feature/preferences --format=detailed
268268
# Output: Detailed Key-Value Changes (main -> feature/preferences):
269269
# ═══════════════════════════════════════
270-
#
270+
#
271271
# Key: pref:123:notifications
272272
# Status: Added
273273
# Value: "enabled"
274-
#
274+
#
275275
# Key: user:123
276276
# Status: Modified
277277
# Old Value: "John Doe"
@@ -307,7 +307,7 @@ git-prolly show HEAD
307307
# Output: Commit: f1e2d3c4 - Add user preferences
308308
# Author: Developer
309309
# Date: 2024-01-15 10:30:00
310-
#
310+
#
311311
# Key-Value Changes:
312312
# + pref:123:notifications = "enabled"
313313
# ~ user:123 = "John Doe" -> "John A. Doe"
@@ -350,7 +350,7 @@ git-prolly history user:123 --format=detailed
350350
# Date: 2024-01-15 10:30:00 UTC
351351
# Author: Developer
352352
# Message: Update user profile
353-
#
353+
#
354354
# Commit: a1b2c3d4e5f6789012345678901234567890abcd
355355
# Date: 2024-01-15 09:15:00 UTC
356356
# Author: Developer
@@ -686,4 +686,4 @@ For issues, questions, or contributions:
686686

687687
## License
688688

689-
Licensed under the Apache License, Version 2.0.
689+
Licensed under the Apache License, Version 2.0.

docs/sql.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CREATE TABLE products (
8888
category TEXT
8989
);
9090
91-
INSERT INTO products VALUES
91+
INSERT INTO products VALUES
9292
(1, 'Laptop', 1200, 'Electronics'),
9393
(2, 'Book', 25, 'Education');
9494
EOF
@@ -191,16 +191,16 @@ CREATE TABLE products (
191191

192192
```sql
193193
-- Single row insert
194-
INSERT INTO users (id, name, email)
194+
INSERT INTO users (id, name, email)
195195
VALUES (1, 'Alice Johnson', 'alice@example.com');
196196

197197
-- Multiple row insert
198-
INSERT INTO users (id, name, email) VALUES
198+
INSERT INTO users (id, name, email) VALUES
199199
(2, 'Bob Smith', 'bob@example.com'),
200200
(3, 'Charlie Brown', 'charlie@example.com');
201201

202202
-- Insert without specifying columns (must match table structure)
203-
INSERT INTO products VALUES
203+
INSERT INTO products VALUES
204204
(1, 'Laptop', 1200, true, 'High-performance laptop');
205205
```
206206

@@ -443,7 +443,7 @@ ORDER BY revenue DESC
443443
LIMIT 10;
444444

445445
-- Customer purchase history
446-
SELECT c.name, COUNT(DISTINCT s.id) as purchase_count,
446+
SELECT c.name, COUNT(DISTINCT s.id) as purchase_count,
447447
SUM(s.quantity * s.price) as total_spent
448448
FROM customers c
449449
JOIN sales s ON c.id = s.customer_id
@@ -471,7 +471,7 @@ INSERT INTO users_new (id, name, email)
471471
SELECT id, name, email FROM users;
472472
473473
-- Update new fields
474-
UPDATE users_new SET
474+
UPDATE users_new SET
475475
created_at = '2024-01-01',
476476
updated_at = '2024-01-01',
477477
status = 'active';
@@ -489,7 +489,7 @@ git prolly sql -f migrate_v2.sql
489489
```bash
490490
# Generate daily report
491491
git prolly sql -o json "
492-
SELECT
492+
SELECT
493493
DATE(order_date) as date,
494494
COUNT(*) as orders,
495495
SUM(quantity * price) as revenue
@@ -713,4 +713,4 @@ The `git prolly sql` command brings the power of SQL to ProllyTree's versioned s
713713
- Track data history over time
714714
- Export data in multiple formats
715715

716-
For more examples and advanced usage, see the `examples/sql_example.rs` file in the repository.
716+
For more examples and advanced usage, see the `examples/sql_example.rs` file in the repository.

0 commit comments

Comments
 (0)