step eighteen: log from oid parameter
This commit is contained in:
parent
f1dc7d9cb6
commit
7f36be1c01
41
src/main.rs
41
src/main.rs
|
@ -38,7 +38,11 @@ fn main() {
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(SubCommand::with_name("log").about("List all commits"))
|
.subcommand(
|
||||||
|
SubCommand::with_name("log")
|
||||||
|
.about("List all commits")
|
||||||
|
.arg(Arg::with_name("oid").index(1).required(false)),
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
match matches.subcommand_name() {
|
match matches.subcommand_name() {
|
||||||
|
@ -48,7 +52,7 @@ fn main() {
|
||||||
Some("write-tree") => write_tree(),
|
Some("write-tree") => write_tree(),
|
||||||
Some("read-tree") => read_tree(matches),
|
Some("read-tree") => read_tree(matches),
|
||||||
Some("commit") => commit(matches),
|
Some("commit") => commit(matches),
|
||||||
Some("log") => log_commits(),
|
Some("log") => log_commits(matches),
|
||||||
_ => println!("unknown sub command"),
|
_ => println!("unknown sub command"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,19 +101,28 @@ fn commit(matches: ArgMatches) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log_commits() {
|
fn log_commits(matches: ArgMatches) {
|
||||||
let mut oid = data::get_head().expect("Cannot read HEAD file");
|
if let Some(cmd_matches) = matches.subcommand_matches("log") {
|
||||||
loop {
|
let provided_oid = cmd_matches.value_of("oid").unwrap_or("");
|
||||||
let commit = base::get_commit(oid.clone());
|
let mut oid;
|
||||||
|
if provided_oid == "" {
|
||||||
println!("commit {}", oid);
|
oid = data::get_head().expect("Cannot read HEAD file");
|
||||||
println!("{}", commit.message);
|
} else {
|
||||||
println!("");
|
oid = provided_oid.to_owned();
|
||||||
|
|
||||||
if commit.parent == "" {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oid = commit.parent;
|
loop {
|
||||||
|
let commit = base::get_commit(oid.clone());
|
||||||
|
|
||||||
|
println!("commit {}", oid);
|
||||||
|
println!("{}", commit.message);
|
||||||
|
println!("");
|
||||||
|
|
||||||
|
if commit.parent == "" {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
oid = commit.parent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue