mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-06 20:42:10 +00:00
merge: make non-conflicted debug string for Merge
shorter
Resolves states are most common and the current format is pretty verbose. Let's print it as if `Merge` were an enum with `Resolved` and `Conflicted` variants instead.
This commit is contained in:
parent
831dc84c5b
commit
21b11df8a9
2 changed files with 36 additions and 35 deletions
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::iter::zip;
|
use std::iter::zip;
|
||||||
|
@ -104,12 +105,27 @@ where
|
||||||
/// There is exactly one more `adds()` than `removes()`. When interpreted as a
|
/// There is exactly one more `adds()` than `removes()`. When interpreted as a
|
||||||
/// series of diffs, the merge's (i+1)-st add is matched with the i-th
|
/// series of diffs, the merge's (i+1)-st add is matched with the i-th
|
||||||
/// remove. The zeroth add is considered a diff from the non-existent state.
|
/// remove. The zeroth add is considered a diff from the non-existent state.
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||||
pub struct Merge<T> {
|
pub struct Merge<T> {
|
||||||
removes: Vec<T>,
|
removes: Vec<T>,
|
||||||
adds: Vec<T>,
|
adds: Vec<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Debug> Debug for Merge<T> {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||||
|
// Format like an enum with two variants to make it less verbose in the common
|
||||||
|
// case of a resolved state.
|
||||||
|
if self.removes.is_empty() {
|
||||||
|
f.debug_tuple("Resolved").field(&self.adds[0]).finish()
|
||||||
|
} else {
|
||||||
|
f.debug_struct("Conflicted")
|
||||||
|
.field("removes", &self.removes)
|
||||||
|
.field("adds", &self.adds)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Merge<T> {
|
impl<T> Merge<T> {
|
||||||
/// Creates a new merge object from the given removes and adds.
|
/// Creates a new merge object from the given removes and adds.
|
||||||
pub fn new(removes: Vec<T>, adds: Vec<T>) -> Self {
|
pub fn new(removes: Vec<T>, adds: Vec<T>) -> Self {
|
||||||
|
|
|
@ -304,7 +304,7 @@ line 5 right
|
||||||
@r###"
|
@r###"
|
||||||
Some(
|
Some(
|
||||||
[
|
[
|
||||||
Merge {
|
Conflicted {
|
||||||
removes: [
|
removes: [
|
||||||
"line 1\nline 2\n",
|
"line 1\nline 2\n",
|
||||||
],
|
],
|
||||||
|
@ -313,13 +313,10 @@ line 5 right
|
||||||
"line 1 right\nline 2\n",
|
"line 1 right\nline 2\n",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Merge {
|
Resolved(
|
||||||
removes: [],
|
|
||||||
adds: [
|
|
||||||
"line 3\n",
|
"line 3\n",
|
||||||
],
|
),
|
||||||
},
|
Conflicted {
|
||||||
Merge {
|
|
||||||
removes: [
|
removes: [
|
||||||
"line 4\nline 5\n",
|
"line 4\nline 5\n",
|
||||||
],
|
],
|
||||||
|
@ -464,13 +461,10 @@ line 5
|
||||||
@r###"
|
@r###"
|
||||||
Some(
|
Some(
|
||||||
[
|
[
|
||||||
Merge {
|
Resolved(
|
||||||
removes: [],
|
|
||||||
adds: [
|
|
||||||
"line 1\n",
|
"line 1\n",
|
||||||
],
|
),
|
||||||
},
|
Conflicted {
|
||||||
Merge {
|
|
||||||
removes: [
|
removes: [
|
||||||
"line 2\nline 3\nline 4\n",
|
"line 2\nline 3\nline 4\n",
|
||||||
],
|
],
|
||||||
|
@ -479,12 +473,9 @@ line 5
|
||||||
"right\n",
|
"right\n",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Merge {
|
Resolved(
|
||||||
removes: [],
|
|
||||||
adds: [
|
|
||||||
"line 5\n",
|
"line 5\n",
|
||||||
],
|
),
|
||||||
},
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
"###
|
"###
|
||||||
|
@ -517,13 +508,10 @@ line 5
|
||||||
@r###"
|
@r###"
|
||||||
Some(
|
Some(
|
||||||
[
|
[
|
||||||
Merge {
|
Resolved(
|
||||||
removes: [],
|
|
||||||
adds: [
|
|
||||||
"line 1\n",
|
"line 1\n",
|
||||||
],
|
),
|
||||||
},
|
Conflicted {
|
||||||
Merge {
|
|
||||||
removes: [
|
removes: [
|
||||||
"line 2\nline 3\nline 4\n",
|
"line 2\nline 3\nline 4\n",
|
||||||
"line 2\nline 3\nline 4\n",
|
"line 2\nline 3\nline 4\n",
|
||||||
|
@ -534,12 +522,9 @@ line 5
|
||||||
"line 2\nforward\nline 3\nline 4\n",
|
"line 2\nforward\nline 3\nline 4\n",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Merge {
|
Resolved(
|
||||||
removes: [],
|
|
||||||
adds: [
|
|
||||||
"line 5\n",
|
"line 5\n",
|
||||||
],
|
),
|
||||||
},
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
"###
|
"###
|
||||||
|
|
Loading…
Reference in a new issue