step twenty six: print refs
This commit is contained in:
parent
cf4e05e325
commit
a555ebf6c0
|
@ -108,6 +108,16 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"sha-1",
|
"sha-1",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "same-file"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -162,6 +172,17 @@ version = "0.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "walkdir"
|
||||||
|
version = "2.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
|
||||||
|
dependencies = [
|
||||||
|
"same-file",
|
||||||
|
"winapi",
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
@ -178,6 +199,15 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
|
|
@ -9,3 +9,4 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33.3"
|
clap = "2.33.3"
|
||||||
sha-1 = "0.9.1"
|
sha-1 = "0.9.1"
|
||||||
|
walkdir = "2"
|
||||||
|
|
21
src/data.rs
21
src/data.rs
|
@ -2,6 +2,7 @@ use sha1::{Digest, Sha1};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
static RGIT_DIR: &'static str = ".rgit";
|
static RGIT_DIR: &'static str = ".rgit";
|
||||||
|
|
||||||
|
@ -57,3 +58,23 @@ pub fn get_ref(reference: String) -> Result<String, Box<dyn std::error::Error +
|
||||||
let oid = fs::read_to_string(format!("{}/{}", RGIT_DIR, reference))?;
|
let oid = fs::read_to_string(format!("{}/{}", RGIT_DIR, reference))?;
|
||||||
return Ok(oid);
|
return Ok(oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn iter_refs() -> Vec<(String, String)> {
|
||||||
|
let mut refs: Vec<(String, String)> = vec![];
|
||||||
|
refs.push(("HEAD".to_owned(), get_ref("HEAD".to_owned()).unwrap()));
|
||||||
|
|
||||||
|
for entry in WalkDir::new(format!("{}/refs/", RGIT_DIR)) {
|
||||||
|
let item = entry.unwrap();
|
||||||
|
let metadata = item.metadata().unwrap();
|
||||||
|
|
||||||
|
if metadata.is_file() {
|
||||||
|
let relative_path = item.path().strip_prefix(RGIT_DIR).unwrap();
|
||||||
|
refs.push((
|
||||||
|
relative_path.to_str().unwrap().to_owned(),
|
||||||
|
get_ref(relative_path.to_str().unwrap().to_owned()).unwrap(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return refs;
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ fn main() {
|
||||||
.arg(Arg::with_name("name").index(1).required(true))
|
.arg(Arg::with_name("name").index(1).required(true))
|
||||||
.arg(Arg::with_name("oid").index(2).default_value("@")),
|
.arg(Arg::with_name("oid").index(2).default_value("@")),
|
||||||
)
|
)
|
||||||
|
.subcommand(SubCommand::with_name("k").about("visualize refs and commits"))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
match matches.subcommand_name() {
|
match matches.subcommand_name() {
|
||||||
|
@ -66,6 +67,7 @@ fn main() {
|
||||||
Some("log") => log_commits(matches),
|
Some("log") => log_commits(matches),
|
||||||
Some("checkout") => checkout(matches),
|
Some("checkout") => checkout(matches),
|
||||||
Some("tag") => tag(matches),
|
Some("tag") => tag(matches),
|
||||||
|
Some("k") => k(),
|
||||||
_ => println!("unknown sub command"),
|
_ => println!("unknown sub command"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,3 +150,9 @@ fn tag(matches: ArgMatches) {
|
||||||
base::create_tag(name, oid);
|
base::create_tag(name, oid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn k() {
|
||||||
|
for refinfo in data::iter_refs() {
|
||||||
|
println!("{} {}", refinfo.0, refinfo.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue