Skip to content

Commit da79538

Browse files
committed
Fix #12: octo-merge
1 parent 1d2e1ea commit da79538

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ git-graph --model my-model
101101
102102
* Summaries of merge commits (i.e. 1st line of message) should not be modified! git-graph needs them to categorize merged branches.
103103
* Supports only the primary remote repository `origin`.
104-
* Does currently not support "octopus merges" (i.e. no more than 2 parents)
105104
* On Windows PowerShell, piping to file output does not work properly (changes encoding), so you may want to use the default Windows console instead
106105
107106
## Contributing

src/graph.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl HeadInfo {
238238
pub struct CommitInfo {
239239
pub oid: Oid,
240240
pub is_merge: bool,
241-
pub parents: [Option<Oid>; 2],
241+
pub parents: Vec<Oid>,
242242
pub children: Vec<Oid>,
243243
pub branches: Vec<usize>,
244244
pub tags: Vec<usize>,
@@ -247,10 +247,11 @@ pub struct CommitInfo {
247247

248248
impl CommitInfo {
249249
fn new(commit: &Commit) -> Self {
250+
let parents = commit.parent_ids().collect();
250251
CommitInfo {
251252
oid: commit.id(),
252253
is_merge: commit.parent_count() > 1,
253-
parents: [commit.parent_id(0).ok(), commit.parent_id(1).ok()],
254+
parents,
254255
children: Vec::new(),
255256
branches: Vec::new(),
256257
tags: Vec::new(),
@@ -336,10 +337,10 @@ fn assign_children(commits: &mut [CommitInfo], indices: &HashMap<Oid, usize>) {
336337
for idx in 0..commits.len() {
337338
let (oid, parents) = {
338339
let info = &commits[idx];
339-
(info.oid, info.parents)
340+
(info.oid, info.parents.clone())
340341
};
341-
for par_oid in &parents {
342-
if let Some(par_idx) = par_oid.and_then(|oid| indices.get(&oid)) {
342+
for par_oid in parents {
343+
if let Some(par_idx) = indices.get(&par_oid) {
343344
commits[*par_idx].children.push(oid);
344345
}
345346
}
@@ -503,9 +504,7 @@ fn assign_sources_targets(
503504
let mut max_par_order = None;
504505
let mut source_branch_id = None;
505506
for par_oid in info.parents.iter() {
506-
let par_info = par_oid
507-
.and_then(|oid| indices.get(&oid))
508-
.and_then(|idx| commits.get(*idx));
507+
let par_info = indices.get(par_oid).and_then(|idx| commits.get(*idx));
509508
if let Some(par_info) = par_info {
510509
if par_info.branch_trace != info.branch_trace {
511510
if let Some(trace) = par_info.branch_trace {
@@ -966,6 +965,9 @@ fn branch_color<T: Clone>(
966965

967966
/// Tries to extract the name of a merged-in branch from the merge commit summary.
968967
pub fn parse_merge_summary(summary: &str, patterns: &MergePatterns) -> Option<String> {
968+
// TODO: Match octo-merge
969+
// Example with 3 parents, f1 is primary:
970+
// Merge branches 'f1', 'f2' and 'f3'
969971
for regex in &patterns.patterns {
970972
if let Some(captures) = regex.captures(summary) {
971973
if captures.len() == 2 && captures.get(1).is_some() {

src/print/svg.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ pub fn print_svg(graph: &GitGraph, settings: &Settings) -> Result<String, String
3636
max_column = branch.visual.column.unwrap();
3737
}
3838

39-
for parent in info.parents.iter() {
40-
let Some(par_oid) = parent else {
41-
continue;
42-
};
39+
for par_oid in info.parents.iter() {
4340
let Some(par_idx) = graph.indices.get(par_oid) else {
4441
// Parent is outside scope of graph.indices
4542
// so draw a vertical line to the bottom

src/print/unicode.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ pub fn print_unicode(graph: &GitGraph, settings: &Settings) -> Result<UnicodeGra
153153
branch_color,
154154
branch.persistence,
155155
);
156-
for (p, parent) in info.parents.iter().enumerate() {
157-
let Some(par_oid) = parent else {
158-
continue;
159-
};
156+
for (p, par_oid) in info.parents.iter().enumerate() {
160157
let Some(par_idx) = graph.indices.get(par_oid) else {
161158
// Parent is outside scope of graph.indices
162159
// so draw a vertical line to the bottom
@@ -490,10 +487,7 @@ fn get_inserts(graph: &GitGraph, compact: bool) -> HashMap<usize, Vec<Vec<Occ>>>
490487
let column = branch.visual.column.unwrap();
491488

492489
// Iterate through the two possible parents of the current commit.
493-
for (p, parent) in info.parents.iter().enumerate() {
494-
let Some(par_oid) = parent else {
495-
continue;
496-
};
490+
for (p, par_oid) in info.parents.iter().enumerate() {
497491
// Try to find the index of the parent commit in the `graph.commits` vector.
498492
if let Some(par_idx) = graph.indices.get(par_oid) {
499493
let par_info = &graph.commits[*par_idx];

0 commit comments

Comments
 (0)