| 1 |
diff --cc src/delta.rs |
| 2 |
index 9a65aaa,ab08d84..0000000 |
| 3 |
--- a/src/delta.rs |
| 4 |
+++ b/src/delta.rs |
| 5 |
@@@ -21,7 -21,7 +21,13 @@@ pub enum State |
| 6 |
HunkZero(DiffType), // In hunk; unchanged line (prefix) |
| 7 |
HunkMinus(DiffType, Option<String>), // In hunk; removed line (diff_type, raw_line) |
| 8 |
HunkPlus(DiffType, Option<String>), // In hunk; added line (diff_type, raw_line) |
| 9 |
++<<<<<<< HEAD |
| 10 |
+ MergeConflict(MergeParents, merge_conflict::MergeConflictCommit), |
| 11 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 12 |
++ MergeConflict(merge_conflict::Source), |
| 13 |
++======= |
| 14 |
+ MergeConflict(merge_conflict::MergeConflictCommit), |
| 15 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 16 |
SubmoduleLog, // In a submodule section, with gitconfig diff.submodule = log |
| 17 |
SubmoduleShort(String), // In a submodule section, with gitconfig diff.submodule = short |
| 18 |
Blame(String, Option<String>), // In a line of `git blame` output (commit, repeat_blame_line). |
| 19 |
diff --cc src/handlers/hunk.rs |
| 20 |
index 26cb288,7df74ae..0000000 |
| 21 |
--- a/src/handlers/hunk.rs |
| 22 |
+++ b/src/handlers/hunk.rs |
| 23 |
@@@ -141,28 -141,19 +141,45 @@@ fn new_line_state(new_line: &str, prev_ |
| 24 |
| HunkZero(Unified) |
| 25 |
| HunkPlus(Unified, _) |
| 26 |
| HunkHeader(Unified, _, _) => Unified, |
| 27 |
++<<<<<<< HEAD |
| 28 |
+ HunkHeader(Combined(Number(n), InMergeConflict::No), _, _) => { |
| 29 |
+ Combined(Number(*n), InMergeConflict::No) |
| 30 |
+ } |
| 31 |
+ // The prefixes are specific to the previous line, but the number of merge parents remains |
| 32 |
+ // equal to the prefix length. |
| 33 |
+ HunkHeader(Combined(Prefix(prefix), InMergeConflict::No), _, _) => { |
| 34 |
+ Combined(Number(prefix.len()), InMergeConflict::No) |
| 35 |
+ } |
| 36 |
+ HunkMinus(Combined(Prefix(prefix), in_merge_conflict), _) |
| 37 |
+ | HunkZero(Combined(Prefix(prefix), in_merge_conflict)) |
| 38 |
+ | HunkPlus(Combined(Prefix(prefix), in_merge_conflict), _) => { |
| 39 |
+ Combined(Number(prefix.len()), in_merge_conflict.clone()) |
| 40 |
+ } |
| 41 |
+ _ => delta_unreachable(&format!( |
| 42 |
+ "Unexpected state in new_line_state: {:?}", |
| 43 |
+ prev_state |
| 44 |
+ )), |
| 45 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 46 |
++ HunkHeader(Combined(Number(n)), _, _) => Combined(Number(*n)), |
| 47 |
++ HunkMinus(Combined(Prefix(prefix)), _) |
| 48 |
++ | HunkZero(Combined(Prefix(prefix))) |
| 49 |
++ | HunkPlus(Combined(Prefix(prefix)), _) => Combined(Number(prefix.len())), |
| 50 |
++ _ => delta_unreachable(&format!("diff_type: unexpected state: {:?}", prev_state)), |
| 51 |
++======= |
| 52 |
+ HunkHeader(Combined(Number(n)), _, _) => Combined(Number(*n)), |
| 53 |
+ // The prefixes are specific to the previous line, but the number of merge parents remains |
| 54 |
+ // equal to the prefix length. |
| 55 |
+ HunkHeader(Combined(Prefix(prefix)), _, _) |
| 56 |
+ | HunkMinus(Combined(Prefix(prefix)), _) |
| 57 |
+ | HunkZero(Combined(Prefix(prefix))) |
| 58 |
+ | HunkPlus(Combined(Prefix(prefix)), _) => Combined(Number(prefix.len())), |
| 59 |
+ _ => delta_unreachable(&format!("diff_type: unexpected state: {:?}", prev_state)), |
| 60 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 61 |
}; |
| 62 |
|
| 63 |
- let (prefix_char, prefix) = match diff_type { |
| 64 |
- Unified => (new_line.chars().next(), None), |
| 65 |
- Combined(Number(n_parents)) => { |
| 66 |
+ let (prefix_char, prefix, in_merge_conflict) = match diff_type { |
| 67 |
+ Unified => (new_line.chars().next(), None, None), |
| 68 |
+ Combined(Number(n_parents), in_merge_conflict) => { |
| 69 |
let prefix = &new_line[..min(n_parents, new_line.len())]; |
| 70 |
let prefix_char = match prefix.chars().find(|c| c == &'-' || c == &'+') { |
| 71 |
Some(c) => Some(c), |
| 72 |
diff --cc src/handlers/merge_conflict.rs |
| 73 |
index a956f2e,3a7e7b9..0000000 |
| 74 |
--- a/src/handlers/merge_conflict.rs |
| 75 |
+++ b/src/handlers/merge_conflict.rs |
| 76 |
@@@ -1,9 -1,10 +1,18 @@@ |
| 77 |
-use std::cmp::min; |
| 78 |
use std::ops::{Index, IndexMut}; |
| 79 |
|
| 80 |
++<<<<<<< HEAD |
| 81 |
use super::draw; |
| 82 |
use crate::cli; |
| 83 |
use crate::config::{self, delta_unreachable}; |
| 84 |
+use crate::delta::{DiffType, InMergeConflict, MergeParents, State, StateMachine}; |
| 85 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 86 |
+ use crate::delta::{DiffType, MergeParents, State, StateMachine}; |
| 87 |
++======= |
| 88 |
++use super::draw; |
| 89 |
++use crate::cli; |
| 90 |
++use crate::config::{self, delta_unreachable}; |
| 91 |
++use crate::delta::{DiffType, MergeParents, State, StateMachine}; |
| 92 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 93 |
use crate::minusplus::MinusPlus; |
| 94 |
use crate::paint; |
| 95 |
use crate::style::DecorationStyle; |
| 96 |
@@@ -28,7 -29,8 +37,15 @@@ pub type MergeConflictCommitNames = Mer |
| 97 |
impl<'a> StateMachine<'a> { |
| 98 |
pub fn handle_merge_conflict_line(&mut self) -> std::io::Result<bool> { |
| 99 |
use DiffType::*; |
| 100 |
++<<<<<<< HEAD |
| 101 |
+ use MergeConflictCommit::*; |
| 102 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 103 |
++ use MergeParents::*; |
| 104 |
++ use Source::*; |
| 105 |
++======= |
| 106 |
+ use MergeConflictCommit::*; |
| 107 |
+ use MergeParents::*; |
| 108 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 109 |
use State::*; |
| 110 |
|
| 111 |
let mut handled_line = false; |
| 112 |
@@@ -36,36 -38,28 +53,113 @@@ |
| 113 |
return Ok(handled_line); |
| 114 |
} |
| 115 |
|
| 116 |
++<<<<<<< HEAD |
| 117 |
+ match self.state.clone() { |
| 118 |
+ HunkHeader(Combined(merge_parents, InMergeConflict::No), _, _) |
| 119 |
+ | HunkMinus(Combined(merge_parents, InMergeConflict::No), _) |
| 120 |
+ | HunkZero(Combined(merge_parents, InMergeConflict::No)) |
| 121 |
+ | HunkPlus(Combined(merge_parents, InMergeConflict::No), _) => { |
| 122 |
+ handled_line = self.enter_merge_conflict(&merge_parents) |
| 123 |
+ } |
| 124 |
+ MergeConflict(merge_parents, Ours) => { |
| 125 |
+ handled_line = self.enter_ancestral(&merge_parents) |
| 126 |
+ || self.enter_theirs(&merge_parents) |
| 127 |
+ || self.exit_merge_conflict(&merge_parents)? |
| 128 |
+ || self.store_line( |
| 129 |
+ Ours, |
| 130 |
+ HunkPlus(Combined(merge_parents, InMergeConflict::Yes), None), |
| 131 |
+ ); |
| 132 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 133 |
++ // TODO: don't allocate on heap at this point |
| 134 |
++ let prefix = self.line[..min(self.line.len(), 2)].to_string(); |
| 135 |
++ let diff_type = Combined(Prefix(prefix)); |
| 136 |
++ |
| 137 |
++ match self.state { |
| 138 |
++ // The only transition into a merge conflict is HunkZero => MergeConflict(Ours) |
| 139 |
++ // TODO: shouldn't this be HunkZero(Some(_))? |
| 140 |
++ HunkZero(_) => { |
| 141 |
++ if self.line.starts_with("++<<<<<<<") { |
| 142 |
++ self.state = MergeConflict(Ours); |
| 143 |
++ handled_line = true |
| 144 |
++ } |
| 145 |
+ } |
| 146 |
++ MergeConflict(Ours) => { |
| 147 |
++ if self.line.starts_with("++|||||||") { |
| 148 |
++ self.state = MergeConflict(Ancestral); |
| 149 |
++ } else if self.line.starts_with("++=======") { |
| 150 |
++ self.state = MergeConflict(Theirs); |
| 151 |
++ } else if self.line.starts_with("++>>>>>>>") { |
| 152 |
++ self.paint_buffered_merge_conflict_lines(diff_type)?; |
| 153 |
++ } else { |
| 154 |
++ let line = self.painter.prepare(&self.line, diff_type.n_parents()); |
| 155 |
++ self.painter.merge_conflict_lines[Ours].push((line, HunkPlus(diff_type, None))); |
| 156 |
++ } |
| 157 |
++ handled_line = true |
| 158 |
++======= |
| 159 |
+ // TODO: don't allocate on heap at this point |
| 160 |
+ let prefix = self.line[..min(self.line.len(), 2)].to_string(); |
| 161 |
+ let diff_type = Combined(Prefix(prefix)); |
| 162 |
+ |
| 163 |
+ match self.state { |
| 164 |
+ // The only transition into a merge conflict is HunkZero => MergeConflict(Ours) |
| 165 |
+ // TODO: shouldn't this be HunkZero(Some(_))? |
| 166 |
+ HunkZero(_) => handled_line = self.enter_merge_conflict(), |
| 167 |
+ MergeConflict(Ours) => { |
| 168 |
+ handled_line = self.enter_ancestral() |
| 169 |
+ || self.enter_theirs() |
| 170 |
+ || self.exit_merge_conflict(diff_type.clone())? |
| 171 |
+ || self.store_line(Ours, HunkPlus(diff_type, None)); |
| 172 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 173 |
+ } |
| 174 |
++<<<<<<< HEAD |
| 175 |
+ MergeConflict(merge_parents, Ancestral) => { |
| 176 |
+ handled_line = self.enter_theirs(&merge_parents) |
| 177 |
+ || self.exit_merge_conflict(&merge_parents)? |
| 178 |
+ || self.store_line( |
| 179 |
+ Ancestral, |
| 180 |
+ HunkMinus(Combined(merge_parents, InMergeConflict::Yes), None), |
| 181 |
+ ); |
| 182 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 183 |
++ MergeConflict(Ancestral) => { |
| 184 |
++ if self.line.starts_with("++=======") { |
| 185 |
++ self.state = MergeConflict(Theirs); |
| 186 |
++ } else if self.line.starts_with("++>>>>>>>") { |
| 187 |
++ self.paint_buffered_merge_conflict_lines(diff_type)?; |
| 188 |
++ } else { |
| 189 |
++ let line = self.painter.prepare(&self.line, diff_type.n_parents()); |
| 190 |
++ self.painter.merge_conflict_lines[Ancestral] |
| 191 |
++ .push((line, HunkMinus(diff_type, None))); |
| 192 |
++ } |
| 193 |
++ handled_line = true |
| 194 |
++======= |
| 195 |
+ MergeConflict(Ancestral) => { |
| 196 |
+ handled_line = self.enter_theirs() |
| 197 |
+ || self.exit_merge_conflict(diff_type.clone())? |
| 198 |
+ || self.store_line(Ancestral, HunkMinus(diff_type, None)); |
| 199 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 200 |
} |
| 201 |
++<<<<<<< HEAD |
| 202 |
+ MergeConflict(merge_parents, Theirs) => { |
| 203 |
+ handled_line = self.exit_merge_conflict(&merge_parents)? |
| 204 |
+ || self.store_line( |
| 205 |
+ Theirs, |
| 206 |
+ HunkPlus(Combined(merge_parents, InMergeConflict::Yes), None), |
| 207 |
+ ); |
| 208 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 209 |
++ MergeConflict(Theirs) => { |
| 210 |
++ if self.line.starts_with("++>>>>>>>") { |
| 211 |
++ self.paint_buffered_merge_conflict_lines(diff_type)?; |
| 212 |
++ } else { |
| 213 |
++ let line = self.painter.prepare(&self.line, diff_type.n_parents()); |
| 214 |
++ self.painter.merge_conflict_lines[Theirs] |
| 215 |
++ .push((line, HunkPlus(diff_type, None))); |
| 216 |
++ } |
| 217 |
++ handled_line = true |
| 218 |
++======= |
| 219 |
+ MergeConflict(Theirs) => { |
| 220 |
+ handled_line = self.exit_merge_conflict(diff_type.clone())? |
| 221 |
+ || self.store_line(Theirs, HunkPlus(diff_type, None)); |
| 222 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 223 |
} |
| 224 |
_ => {} |
| 225 |
} |
| 226 |
@@@ -73,65 -67,60 +167,124 @@@ |
| 227 |
Ok(handled_line) |
| 228 |
} |
| 229 |
|
| 230 |
++<<<<<<< HEAD |
| 231 |
+ fn enter_merge_conflict(&mut self, merge_parents: &MergeParents) -> bool { |
| 232 |
+ use State::*; |
| 233 |
+ if let Some(commit) = parse_merge_marker(&self.line, "++<<<<<<<") { |
| 234 |
+ self.state = MergeConflict(merge_parents.clone(), Ours); |
| 235 |
+ self.painter.merge_conflict_commit_names[Ours] = Some(commit.to_string()); |
| 236 |
+ true |
| 237 |
+ } else { |
| 238 |
+ false |
| 239 |
+ } |
| 240 |
+ } |
| 241 |
+ |
| 242 |
+ fn enter_ancestral(&mut self, merge_parents: &MergeParents) -> bool { |
| 243 |
+ use State::*; |
| 244 |
+ if let Some(commit) = parse_merge_marker(&self.line, "++|||||||") { |
| 245 |
+ self.state = MergeConflict(merge_parents.clone(), Ancestral); |
| 246 |
+ self.painter.merge_conflict_commit_names[Ancestral] = Some(commit.to_string()); |
| 247 |
+ true |
| 248 |
+ } else { |
| 249 |
+ false |
| 250 |
+ } |
| 251 |
+ } |
| 252 |
+ |
| 253 |
+ fn enter_theirs(&mut self, merge_parents: &MergeParents) -> bool { |
| 254 |
+ use State::*; |
| 255 |
+ if self.line.starts_with("++=======") { |
| 256 |
+ self.state = MergeConflict(merge_parents.clone(), Theirs); |
| 257 |
+ true |
| 258 |
+ } else { |
| 259 |
+ false |
| 260 |
+ } |
| 261 |
+ } |
| 262 |
+ |
| 263 |
+ fn exit_merge_conflict(&mut self, merge_parents: &MergeParents) -> std::io::Result<bool> { |
| 264 |
+ if let Some(commit) = parse_merge_marker(&self.line, "++>>>>>>>") { |
| 265 |
+ self.painter.merge_conflict_commit_names[Theirs] = Some(commit.to_string()); |
| 266 |
+ self.paint_buffered_merge_conflict_lines(merge_parents)?; |
| 267 |
+ Ok(true) |
| 268 |
+ } else { |
| 269 |
+ Ok(false) |
| 270 |
+ } |
| 271 |
+ } |
| 272 |
+ |
| 273 |
+ fn store_line(&mut self, commit: MergeConflictCommit, state: State) -> bool { |
| 274 |
+ use State::*; |
| 275 |
+ if let HunkMinus(diff_type, _) | HunkZero(diff_type) | HunkPlus(diff_type, _) = &state { |
| 276 |
+ let line = self.painter.prepare(&self.line, diff_type.n_parents()); |
| 277 |
+ self.painter.merge_conflict_lines[commit].push((line, state)); |
| 278 |
+ true |
| 279 |
+ } else { |
| 280 |
+ delta_unreachable(&format!("Invalid state: {:?}", state)) |
| 281 |
+ } |
| 282 |
+ } |
| 283 |
+ |
| 284 |
+ fn paint_buffered_merge_conflict_lines( |
| 285 |
+ &mut self, |
| 286 |
+ merge_parents: &MergeParents, |
| 287 |
+ ) -> std::io::Result<()> { |
| 288 |
+ use DiffType::*; |
| 289 |
+ use State::*; |
| 290 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 291 |
++ fn paint_buffered_merge_conflict_lines(&mut self, diff_type: DiffType) -> std::io::Result<()> { |
| 292 |
++======= |
| 293 |
+ fn enter_merge_conflict(&mut self) -> bool { |
| 294 |
+ use State::*; |
| 295 |
+ if let Some(commit) = parse_merge_marker(&self.line, "++<<<<<<<") { |
| 296 |
+ self.state = MergeConflict(Ours); |
| 297 |
+ self.painter.merge_conflict_commit_names[Ours] = Some(commit.to_string()); |
| 298 |
+ true |
| 299 |
+ } else { |
| 300 |
+ false |
| 301 |
+ } |
| 302 |
+ } |
| 303 |
+ |
| 304 |
+ fn enter_ancestral(&mut self) -> bool { |
| 305 |
+ use State::*; |
| 306 |
+ if let Some(commit) = parse_merge_marker(&self.line, "++|||||||") { |
| 307 |
+ self.state = MergeConflict(Ancestral); |
| 308 |
+ self.painter.merge_conflict_commit_names[Ancestral] = Some(commit.to_string()); |
| 309 |
+ true |
| 310 |
+ } else { |
| 311 |
+ false |
| 312 |
+ } |
| 313 |
+ } |
| 314 |
+ |
| 315 |
+ fn enter_theirs(&mut self) -> bool { |
| 316 |
+ use State::*; |
| 317 |
+ if self.line.starts_with("++=======") { |
| 318 |
+ self.state = MergeConflict(Theirs); |
| 319 |
+ true |
| 320 |
+ } else { |
| 321 |
+ false |
| 322 |
+ } |
| 323 |
+ } |
| 324 |
+ |
| 325 |
+ fn exit_merge_conflict(&mut self, diff_type: DiffType) -> std::io::Result<bool> { |
| 326 |
+ if let Some(commit) = parse_merge_marker(&self.line, "++>>>>>>>") { |
| 327 |
+ self.painter.merge_conflict_commit_names[Theirs] = Some(commit.to_string()); |
| 328 |
+ self.paint_buffered_merge_conflict_lines(diff_type)?; |
| 329 |
+ Ok(true) |
| 330 |
+ } else { |
| 331 |
+ Ok(false) |
| 332 |
+ } |
| 333 |
+ } |
| 334 |
+ |
| 335 |
+ fn store_line(&mut self, commit: MergeConflictCommit, state: State) -> bool { |
| 336 |
+ use State::*; |
| 337 |
+ if let HunkMinus(diff_type, _) | HunkZero(diff_type) | HunkPlus(diff_type, _) = &state { |
| 338 |
+ let line = self.painter.prepare(&self.line, diff_type.n_parents()); |
| 339 |
+ self.painter.merge_conflict_lines[commit].push((line, state)); |
| 340 |
+ true |
| 341 |
+ } else { |
| 342 |
+ delta_unreachable(&format!("Invalid state: {:?}", state)) |
| 343 |
+ } |
| 344 |
+ } |
| 345 |
+ |
| 346 |
+ fn paint_buffered_merge_conflict_lines(&mut self, diff_type: DiffType) -> std::io::Result<()> { |
| 347 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 348 |
self.painter.emit()?; |
| 349 |
|
| 350 |
write_merge_conflict_bar("▼", &mut self.painter, self.config)?; |
| 351 |
@@@ -163,6 -152,6 +316,7 @@@ |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
++<<<<<<< HEAD |
| 356 |
fn write_subhunk_header( |
| 357 |
derived_commit_type: &MergeConflictCommit, |
| 358 |
decoration_style: &str, |
| 359 |
@@@ -197,63 -186,63 +351,170 @@@ |
| 360 |
Ok(()) |
| 361 |
} |
| 362 |
|
| 363 |
+ #[allow(unused)] |
| 364 |
+ fn write_merge_conflict_line( |
| 365 |
+ painter: &mut paint::Painter, |
| 366 |
+ config: &config::Config, |
| 367 |
+ ) -> std::io::Result<()> { |
| 368 |
+ let (mut draw_fn, _pad, decoration_ansi_term_style) = draw::get_draw_function( |
| 369 |
+ DecorationStyle::from_str("bold ol", config.true_color, config.git_config.as_ref()), |
| 370 |
+ ); |
| 371 |
+ draw_fn( |
| 372 |
+ painter.writer, |
| 373 |
+ "", |
| 374 |
+ "", |
| 375 |
+ &config.decorations_width, |
| 376 |
+ config.hunk_header_style, |
| 377 |
+ decoration_ansi_term_style, |
| 378 |
+ )?; |
| 379 |
+ Ok(()) |
| 380 |
+ } |
| 381 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 382 |
++pub use Source::*; |
| 383 |
++======= |
| 384 |
++fn write_subhunk_header( |
| 385 |
++ derived_commit_type: &MergeConflictCommit, |
| 386 |
++ decoration_style: &str, |
| 387 |
++ painter: &mut paint::Painter, |
| 388 |
++ config: &config::Config, |
| 389 |
++) -> std::io::Result<()> { |
| 390 |
++ let (mut draw_fn, pad, decoration_ansi_term_style) = |
| 391 |
++ draw::get_draw_function(DecorationStyle::from_str( |
| 392 |
++ decoration_style, |
| 393 |
++ config.true_color, |
| 394 |
++ config.git_config.as_ref(), |
| 395 |
++ )); |
| 396 |
++ let derived_commit_name = &painter.merge_conflict_commit_names[derived_commit_type]; |
| 397 |
++ let text = if let Some(_ancestral_commit) = &painter.merge_conflict_commit_names[Ancestral] { |
| 398 |
++ format!( |
| 399 |
++ "ancestor {} {}{}", |
| 400 |
++ config.right_arrow, |
| 401 |
++ derived_commit_name.as_deref().unwrap_or("?"), |
| 402 |
++ if pad { " " } else { "" } |
| 403 |
++ ) |
| 404 |
++ } else { |
| 405 |
++ derived_commit_name.as_deref().unwrap_or("?").to_string() |
| 406 |
++ }; |
| 407 |
++ draw_fn( |
| 408 |
++ painter.writer, |
| 409 |
++ &text, |
| 410 |
++ &text, |
| 411 |
++ &config.decorations_width, |
| 412 |
++ config.hunk_header_style, |
| 413 |
++ decoration_ansi_term_style, |
| 414 |
++ )?; |
| 415 |
++ Ok(()) |
| 416 |
++} |
| 417 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 418 |
+ |
| 419 |
++<<<<<<< HEAD |
| 420 |
+ fn write_merge_conflict_bar( |
| 421 |
+ s: &str, |
| 422 |
+ painter: &mut paint::Painter, |
| 423 |
+ config: &config::Config, |
| 424 |
+ ) -> std::io::Result<()> { |
| 425 |
+ if let cli::Width::Fixed(width) = config.decorations_width { |
| 426 |
+ writeln!(painter.writer, "{}", s.repeat(width))?; |
| 427 |
+ } |
| 428 |
+ Ok(()) |
| 429 |
+ } |
| 430 |
+ |
| 431 |
+ fn parse_merge_marker<'a>(line: &'a str, marker: &str) -> Option<&'a str> { |
| 432 |
+ match line.strip_prefix(marker) { |
| 433 |
+ Some(suffix) => { |
| 434 |
+ let suffix = suffix.trim(); |
| 435 |
+ if !suffix.is_empty() { |
| 436 |
+ Some(suffix) |
| 437 |
+ } else { |
| 438 |
+ None |
| 439 |
+ } |
| 440 |
+ } |
| 441 |
+ None => None, |
| 442 |
+ } |
| 443 |
+ } |
| 444 |
+ |
| 445 |
+ pub use MergeConflictCommit::*; |
| 446 |
+ |
| 447 |
+ impl<T> Index<MergeConflictCommit> for MergeConflictCommits<T> { |
| 448 |
+ type Output = T; |
| 449 |
+ fn index(&self, commit: MergeConflictCommit) -> &Self::Output { |
| 450 |
+ match commit { |
| 451 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 452 |
++impl Index<Source> for MergeConflictLines { |
| 453 |
++ type Output = Vec<(String, State)>; |
| 454 |
++ fn index(&self, source: Source) -> &Self::Output { |
| 455 |
++ match source { |
| 456 |
++======= |
| 457 |
+#[allow(unused)] |
| 458 |
+fn write_merge_conflict_line( |
| 459 |
+ painter: &mut paint::Painter, |
| 460 |
+ config: &config::Config, |
| 461 |
+) -> std::io::Result<()> { |
| 462 |
+ let (mut draw_fn, _pad, decoration_ansi_term_style) = draw::get_draw_function( |
| 463 |
+ DecorationStyle::from_str("bold ol", config.true_color, config.git_config.as_ref()), |
| 464 |
+ ); |
| 465 |
+ draw_fn( |
| 466 |
+ painter.writer, |
| 467 |
+ "", |
| 468 |
+ "", |
| 469 |
+ &config.decorations_width, |
| 470 |
+ config.hunk_header_style, |
| 471 |
+ decoration_ansi_term_style, |
| 472 |
+ )?; |
| 473 |
+ Ok(()) |
| 474 |
+} |
| 475 |
+ |
| 476 |
+fn write_merge_conflict_bar( |
| 477 |
+ s: &str, |
| 478 |
+ painter: &mut paint::Painter, |
| 479 |
+ config: &config::Config, |
| 480 |
+) -> std::io::Result<()> { |
| 481 |
+ if let cli::Width::Fixed(width) = config.decorations_width { |
| 482 |
+ writeln!(painter.writer, "{}", s.repeat(width))?; |
| 483 |
+ } |
| 484 |
+ Ok(()) |
| 485 |
+} |
| 486 |
+ |
| 487 |
+fn parse_merge_marker<'a>(line: &'a str, marker: &str) -> Option<&'a str> { |
| 488 |
+ match line.strip_prefix(marker) { |
| 489 |
+ Some(suffix) => { |
| 490 |
+ let suffix = suffix.trim(); |
| 491 |
+ if !suffix.is_empty() { |
| 492 |
+ Some(suffix) |
| 493 |
+ } else { |
| 494 |
+ None |
| 495 |
+ } |
| 496 |
+ } |
| 497 |
+ None => None, |
| 498 |
+ } |
| 499 |
+} |
| 500 |
+ |
| 501 |
+pub use MergeConflictCommit::*; |
| 502 |
+ |
| 503 |
+impl<T> Index<MergeConflictCommit> for MergeConflictCommits<T> { |
| 504 |
+ type Output = T; |
| 505 |
+ fn index(&self, commit: MergeConflictCommit) -> &Self::Output { |
| 506 |
+ match commit { |
| 507 |
+ Ours => &self.ours, |
| 508 |
+ Ancestral => &self.ancestral, |
| 509 |
+ Theirs => &self.theirs, |
| 510 |
+ } |
| 511 |
+ } |
| 512 |
+} |
| 513 |
+ |
| 514 |
++impl<T> Index<&MergeConflictCommit> for MergeConflictCommits<T> { |
| 515 |
++ type Output = T; |
| 516 |
++ fn index(&self, commit: &MergeConflictCommit) -> &Self::Output { |
| 517 |
++ match commit { |
| 518 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 519 |
+ Ours => &self.ours, |
| 520 |
+ Ancestral => &self.ancestral, |
| 521 |
+ Theirs => &self.theirs, |
| 522 |
+ } |
| 523 |
+ } |
| 524 |
+ } |
| 525 |
+ |
| 526 |
++<<<<<<< HEAD |
| 527 |
impl<T> Index<&MergeConflictCommit> for MergeConflictCommits<T> { |
| 528 |
type Output = T; |
| 529 |
fn index(&self, commit: &MergeConflictCommit) -> &Self::Output { |
| 530 |
@@@ -268,6 -257,6 +529,15 @@@ |
| 531 |
impl<T> IndexMut<MergeConflictCommit> for MergeConflictCommits<T> { |
| 532 |
fn index_mut(&mut self, commit: MergeConflictCommit) -> &mut Self::Output { |
| 533 |
match commit { |
| 534 |
++||||||| parent of b2b28c8... Display merge conflict branches |
| 535 |
++impl IndexMut<Source> for MergeConflictLines { |
| 536 |
++ fn index_mut(&mut self, source: Source) -> &mut Self::Output { |
| 537 |
++ match source { |
| 538 |
++======= |
| 539 |
++impl<T> IndexMut<MergeConflictCommit> for MergeConflictCommits<T> { |
| 540 |
++ fn index_mut(&mut self, commit: MergeConflictCommit) -> &mut Self::Output { |
| 541 |
++ match commit { |
| 542 |
++>>>>>>> b2b28c8... Display merge conflict branches |
| 543 |
Ours => &mut self.ours, |
| 544 |
Ancestral => &mut self.ancestral, |
| 545 |
Theirs => &mut self.theirs, |