step forty nine: merge, support multiple parents
This commit is contained in:
parent
8a8b028150
commit
2e9b5f6a4d
16
src/base.rs
16
src/base.rs
|
@ -11,7 +11,7 @@ mod diff;
|
||||||
|
|
||||||
pub struct Commit {
|
pub struct Commit {
|
||||||
pub tree: String,
|
pub tree: String,
|
||||||
pub parent: String,
|
pub parents: Vec<String>,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ pub fn commit(message: &str) -> String {
|
||||||
pub fn get_commit(oid: String) -> Commit {
|
pub fn get_commit(oid: String) -> Commit {
|
||||||
let commit = data::get_object(oid, "commit".to_owned());
|
let commit = data::get_object(oid, "commit".to_owned());
|
||||||
let tree: String;
|
let tree: String;
|
||||||
let mut parent: String = "".to_owned();
|
let mut parents = vec![];
|
||||||
let message: String;
|
let message: String;
|
||||||
let mut message_start = 2;
|
let mut message_start = 2;
|
||||||
|
|
||||||
|
@ -108,15 +108,17 @@ pub fn get_commit(oid: String) -> Commit {
|
||||||
|
|
||||||
line_items = lines[1].splitn(2, " ").collect();
|
line_items = lines[1].splitn(2, " ").collect();
|
||||||
if line_items[0] == "parent" {
|
if line_items[0] == "parent" {
|
||||||
parent = line_items[1].to_owned();
|
parents.push(line_items[1].to_owned());
|
||||||
message_start = 3;
|
message_start = 3;
|
||||||
|
} else {
|
||||||
|
parents.push("".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
message = lines[message_start..].join("\n");
|
message = lines[message_start..].join("\n");
|
||||||
|
|
||||||
return Commit {
|
return Commit {
|
||||||
tree,
|
tree,
|
||||||
parent,
|
parents,
|
||||||
message,
|
message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -135,7 +137,11 @@ pub fn iter_commits_and_parents(mut oids: VecDeque<String>) -> Vec<String> {
|
||||||
|
|
||||||
let commit = get_commit(oid);
|
let commit = get_commit(oid);
|
||||||
// Deal with parent next
|
// 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;
|
return oid_sequence;
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -173,7 +173,7 @@ fn log_commits(matches: ArgMatches) {
|
||||||
|
|
||||||
print_commit(oid, &commit, refs.clone());
|
print_commit(oid, &commit, refs.clone());
|
||||||
|
|
||||||
if commit.parent == "" {
|
if commit.parents[0] == "" {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,9 +214,9 @@ fn k() {
|
||||||
oid,
|
oid,
|
||||||
&oid[0..10]
|
&oid[0..10]
|
||||||
));
|
));
|
||||||
if commit.parent != "" {
|
if commit.parents[0] != "" {
|
||||||
println!("Parent: {}", commit.parent);
|
println!("Parent: {}", commit.parents[0]);
|
||||||
dot.push_str(&format!("\"{}\" -> \"{}\"\n", oid, commit.parent));
|
dot.push_str(&format!("\"{}\" -> \"{}\"\n", oid, commit.parents[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dot.push_str("}");
|
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 oid = base::get_oid(cmd_matches.value_of("oid").unwrap().to_owned());
|
||||||
let commit = base::get_commit(oid.clone());
|
let commit = base::get_commit(oid.clone());
|
||||||
let refs: HashMap<String, Vec<String>> = HashMap::new();
|
let refs: HashMap<String, Vec<String>> = HashMap::new();
|
||||||
let parent_tree = if commit.parent != "".to_owned() {
|
let parent_tree = if commit.parents[0] != "".to_owned() {
|
||||||
base::get_commit(commit.parent.clone()).tree
|
base::get_commit(commit.parents[0].clone()).tree
|
||||||
} else {
|
} else {
|
||||||
"".to_owned()
|
"".to_owned()
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue