Files
Fintan Halpenny b570fa1435 Re-License to "MIT OR Aapache-2.0"
The main dependant of `radicle-git`, and its crates, is [`heartwood`].
It is licensed under MIT or Apache-2.0, which has been incompatible with the GPL-3.0 license.
Since the intellectual property of this code base is with the Better Internet Foundation, it was
decided to re-license code in this repository to make the upstream repository compatible.

 - Remove the license headers (and instructions to add them)
 - Add MIT and Apache-2.0 licenses
 - Remove the GPL-3.0 license
 - Change the license declarations in the `Cargo.toml` files

[`heartwood`]: https://app.radicle.xyz/nodes/seed.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
2025-11-14 12:52:22 +01:00

50 lines
1.4 KiB
Rust

//! An example of browsing a git repo using `radicle-surf`.
//!
//! How to run:
//!
//! cargo run --example browsing <git_repo_path>
//!
//! This program browses the given repo and prints out the files and
//! the directories in a tree-like structure.
use radicle_surf::{
fs::{self, Directory},
Repository,
};
use std::{env, time::Instant};
fn main() {
let repo_path = match env::args().nth(1) {
Some(path) => path,
None => {
print_usage();
return;
}
};
let repo = Repository::discover(repo_path).unwrap();
let now = Instant::now();
let head = repo.head().unwrap();
let root = repo.root_dir(head).unwrap();
print_directory(&root, &repo, 0);
let elapsed_millis = now.elapsed().as_millis();
println!("browse with print: {elapsed_millis} ms");
}
fn print_directory(d: &Directory, repo: &Repository, indent_level: usize) {
let indent = " ".repeat(indent_level * 4);
println!("{}{}/", &indent, d.name());
for entry in d.entries(repo).unwrap() {
match entry {
fs::Entry::File(f) => println!(" {}{}", &indent, f.name()),
fs::Entry::Directory(d) => print_directory(&d, repo, indent_level + 1),
fs::Entry::Submodule(s) => println!(" {}{}", &indent, s.name()),
}
}
}
fn print_usage() {
println!("Usage:");
println!("cargo run --example browsing <repo_path>");
}