diff --git a/src/base.rs b/src/base.rs index a9edbb0..87a594c 100644 --- a/src/base.rs +++ b/src/base.rs @@ -11,7 +11,7 @@ mod diff; pub struct Commit { pub tree: String, - pub parent: String, + pub parents: Vec, pub message: String, } @@ -98,7 +98,7 @@ pub fn commit(message: &str) -> String { pub fn get_commit(oid: String) -> Commit { let commit = data::get_object(oid, "commit".to_owned()); let tree: String; - let mut parent: String = "".to_owned(); + let mut parents = vec![]; let message: String; let mut message_start = 2; @@ -108,15 +108,17 @@ pub fn get_commit(oid: String) -> Commit { line_items = lines[1].splitn(2, " ").collect(); if line_items[0] == "parent" { - parent = line_items[1].to_owned(); + parents.push(line_items[1].to_owned()); message_start = 3; + } else { + parents.push("".to_owned()); } message = lines[message_start..].join("\n"); return Commit { tree, - parent, + parents, message, }; } @@ -135,7 +137,11 @@ pub fn iter_commits_and_parents(mut oids: VecDeque) -> Vec { let commit = get_commit(oid); // Deal with parent next - oids.push_front(commit.parent); + oids.push_front(commit.parents[0].clone()); + // Deal with other parent later + if commit.parents.len() > 1 { + oids.push_back(commit.parents[1].clone()); + } } return oid_sequence; diff --git a/src/main.rs b/src/main.rs index 7eef1fb..141202e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -173,7 +173,7 @@ fn log_commits(matches: ArgMatches) { print_commit(oid, &commit, refs.clone()); - if commit.parent == "" { + if commit.parents[0] == "" { break; } } @@ -214,9 +214,9 @@ fn k() { oid, &oid[0..10] )); - if commit.parent != "" { - println!("Parent: {}", commit.parent); - dot.push_str(&format!("\"{}\" -> \"{}\"\n", oid, commit.parent)); + if commit.parents[0] != "" { + println!("Parent: {}", commit.parents[0]); + dot.push_str(&format!("\"{}\" -> \"{}\"\n", oid, commit.parents[0])); } } dot.push_str("}"); @@ -287,8 +287,8 @@ fn show(matches: ArgMatches) { let oid = base::get_oid(cmd_matches.value_of("oid").unwrap().to_owned()); let commit = base::get_commit(oid.clone()); let refs: HashMap> = HashMap::new(); - let parent_tree = if commit.parent != "".to_owned() { - base::get_commit(commit.parent.clone()).tree + let parent_tree = if commit.parents[0] != "".to_owned() { + base::get_commit(commit.parents[0].clone()).tree } else { "".to_owned() };