@@ -6,25 +6,27 @@ use std::io::Write;
66use bytelines:: ByteLines ;
77
88use crate :: ansi;
9+ use crate :: config:: delta_unreachable;
910use crate :: config:: Config ;
1011use crate :: features;
11- use crate :: handlers;
12+ use crate :: handlers:: { self , merge_conflict } ;
1213use crate :: paint:: Painter ;
1314use crate :: style:: DecorationStyle ;
1415
1516#[ derive( Clone , Debug , PartialEq ) ]
1617pub enum State {
17- CommitMeta , // In commit metadata section
18+ CommitMeta , // In commit metadata section
1819 DiffHeader ( DiffType ) , // In diff metadata section, between (possible) commit metadata and first hunk
19- HunkHeader ( DiffType , String , String ) , // In hunk metadata line (line, raw_line)
20- HunkZero ( Option < String > ) , // In hunk; unchanged line (prefix)
21- HunkMinus ( Option < String > , Option < String > ) , // In hunk; removed line (prefix, raw_line)
22- HunkPlus ( Option < String > , Option < String > ) , // In hunk; added line (prefix, raw_line)
23- SubmoduleLog , // In a submodule section, with gitconfig diff.submodule = log
20+ HunkHeader ( DiffType , String , String ) , // In hunk metadata line (diff_type, line, raw_line)
21+ HunkZero ( DiffType ) , // In hunk; unchanged line (prefix)
22+ HunkMinus ( DiffType , Option < String > ) , // In hunk; removed line (diff_type, raw_line)
23+ HunkPlus ( DiffType , Option < String > ) , // In hunk; added line (diff_type, raw_line)
24+ MergeConflict ( MergeParents , merge_conflict:: MergeConflictCommit ) ,
25+ SubmoduleLog , // In a submodule section, with gitconfig diff.submodule = log
2426 SubmoduleShort ( String ) , // In a submodule section, with gitconfig diff.submodule = short
2527 Blame ( String , Option < String > ) , // In a line of `git blame` output (commit, repeat_blame_line).
26- GitShowFile , // In a line of `git show $revision:./path/to/file.ext` output
27- Grep , // In a line of `git grep` output
28+ GitShowFile , // In a line of `git show $revision:./path/to/file.ext` output
29+ Grep , // In a line of `git grep` output
2830 Unknown ,
2931 // The following elements are created when a line is wrapped to display it:
3032 HunkZeroWrapped , // Wrapped unchanged line
@@ -35,7 +37,27 @@ pub enum State {
3537#[ derive( Clone , Debug , PartialEq ) ]
3638pub enum DiffType {
3739 Unified ,
38- Combined ( usize ) , // number of parent commits: https://git-scm.com/docs/git-diff#_combined_diff_format
40+ Combined ( MergeParents ) , // https://git-scm.com/docs/git-diff#_combined_diff_format
41+ }
42+
43+ #[ derive( Clone , Debug , PartialEq ) ]
44+ pub enum MergeParents {
45+ Number ( usize ) , // Number of parent commits == (number of @s in hunk header) - 1
46+ Prefix ( String ) , // Hunk line prefix, length == number of parent commits
47+ Unknown ,
48+ }
49+
50+ impl DiffType {
51+ pub fn n_parents ( & self ) -> usize {
52+ use DiffType :: * ;
53+ use MergeParents :: * ;
54+ match self {
55+ Combined ( Prefix ( prefix) ) => prefix. len ( ) ,
56+ Combined ( Number ( n_parents) ) => * n_parents,
57+ Unified => 1 ,
58+ Combined ( Unknown ) => delta_unreachable ( "Number of merge parents must be known." ) ,
59+ }
60+ }
3961}
4062
4163#[ derive( Debug , PartialEq ) ]
@@ -131,6 +153,7 @@ impl<'a> StateMachine<'a> {
131153 || self . handle_diff_header_misc_line ( ) ?
132154 || self . handle_submodule_log_line ( ) ?
133155 || self . handle_submodule_short_line ( ) ?
156+ || self . handle_merge_conflict_line ( ) ?
134157 || self . handle_hunk_line ( ) ?
135158 || self . handle_git_show_file_line ( ) ?
136159 || self . handle_blame_line ( ) ?
0 commit comments