Use Result<Option<int>> instead of using 0 as a special value for failures
0 is a valid node id and filename id, so it's incorrect to use it as a special value. For example, on the example dataset before this commit:
cargo run ~/swh-environment/swh-graph/swh/graph/example_dataset/compressed/example --start-rev-swhid swh:1:rev:0000000000000000000000000000000000000018 --path README.md
Compiling graph-revs-log-for-path v0.1.0 (/home/dev/swh-environment/snippets/anlambert/graph-revs-log-for-path)
gc Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.43s
Running `target/debug/graph-revs-log-for-path /home/dev/swh-environment/swh-graph/swh/graph/example_dataset/compressed/example --start-rev-swhid 'swh:1:rev:0000000000000000000000000000000000000018' --path README.md`
[2025-03-11T13:22:09Z INFO graph_revs_log_for_path] Loading graph
[2025-03-11T13:22:09Z INFO graph_revs_log_for_path] Graph loaded
swh:1:rev:0000000000000000000000000000000000000018
swh:1:rev:0000000000000000000000000000000000000013
swh:1:rev:0000000000000000000000000000000000000003
even though swh:1:rev:0000000000000000000000000000000000000018 does not have a README.md at its root.
We could use usize::MAX instead, but it's more error-prone (easy to forget to handle this case) and less idiomatic in Rust.
This also distinguishes the error case (Err
) and the non-existence case (None
)