step fourty: show refs that point to each commit

master
Gonçalo Valério 2 years ago
parent 57d5f13acc
commit 7b46b2cbfa
  1. 20
      src/main.rs

@ -1,5 +1,5 @@
use clap::{App, Arg, ArgMatches, SubCommand};
use std::collections::{HashSet, VecDeque};
use std::collections::{HashMap, HashSet, VecDeque};
use std::fs;
use std::io::Write;
use std::process::{Command, Stdio};
@ -129,6 +129,16 @@ fn commit(matches: ArgMatches) {
fn log_commits(matches: ArgMatches) {
if let Some(cmd_matches) = matches.subcommand_matches("log") {
let provided_ref = cmd_matches.value_of("oid").unwrap().to_owned();
let mut refs: HashMap<String, Vec<String>> = HashMap::new();
for entry in data::iter_refs("", true) {
if refs.contains_key(&entry.1.value) {
refs.get_mut(&entry.1.value).unwrap().push(entry.0);
} else {
refs.insert(entry.1.value, vec![entry.0]);
}
}
let initial_oid = base::get_oid(provided_ref.to_owned());
let mut oids = VecDeque::new();
oids.push_back(initial_oid);
@ -136,7 +146,13 @@ fn log_commits(matches: ArgMatches) {
for oid in base::iter_commits_and_parents(oids) {
let commit = base::get_commit(oid.clone());
println!("commit {}", oid);
let ref_str = if refs.contains_key(&oid) {
refs.get_mut(&oid).unwrap().join(", ")
} else {
"".to_owned()
};
println!("commit {} {}", oid, ref_str);
println!("{}", commit.message);
println!("");

Loading…
Cancel
Save