mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-27 07:10:58 +08:00
Merge remote-tracking branch 'origin/cloudhead/hunk-ranges'
* origin/cloudhead/hunk-ranges: surf: Add hunk lines ranges Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
//! Types that represent diff(s) in a Git repo.
|
||||
|
||||
use std::{borrow::Cow, path::PathBuf, string::FromUtf8Error};
|
||||
use std::{borrow::Cow, ops::Range, path::PathBuf, string::FromUtf8Error};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{ser, ser::SerializeStruct, Serialize, Serializer};
|
||||
@@ -358,6 +358,10 @@ pub struct Stats {
|
||||
pub struct Hunk<T> {
|
||||
pub header: Line,
|
||||
pub lines: Vec<T>,
|
||||
/// Old line range.
|
||||
pub old: Range<u32>,
|
||||
/// New line range.
|
||||
pub new: Range<u32>,
|
||||
}
|
||||
|
||||
/// A set of [`Hunk`] changes.
|
||||
|
||||
@@ -179,7 +179,12 @@ impl TryFrom<git2::Patch<'_>> for DiffContent {
|
||||
let line = Modification::try_from(line)?;
|
||||
lines.push(line);
|
||||
}
|
||||
hunks.push(Hunk { header, lines });
|
||||
hunks.push(Hunk {
|
||||
header,
|
||||
lines,
|
||||
old: hunk.old_start()..hunk.old_start() + hunk.old_lines(),
|
||||
new: hunk.new_start()..hunk.new_start() + hunk.new_lines(),
|
||||
});
|
||||
}
|
||||
let eof = match (old_missing_eof, new_missing_eof) {
|
||||
(true, true) => EofNewLine::BothMissing,
|
||||
|
||||
+50
-38
@@ -44,6 +44,8 @@ fn test_initial_diff() -> Result<(), Error> {
|
||||
.to_vec(),
|
||||
1,
|
||||
)],
|
||||
old: 0..0,
|
||||
new: 1..2,
|
||||
}]
|
||||
.into(),
|
||||
eof: EofNewLine::default(),
|
||||
@@ -93,6 +95,8 @@ fn test_diff_file() -> Result<(), Error> {
|
||||
Modification::addition(b"This repository is a data source for the Upstream front-end tests and the\n".to_vec(), 1),
|
||||
Modification::addition(b"[`radicle-surf`](https://github.com/radicle-dev/git-platinum) unit tests.\n".to_vec(), 2),
|
||||
],
|
||||
old: 1..2,
|
||||
new: 1..3,
|
||||
}]
|
||||
.into(),
|
||||
eof: EofNewLine::default(),
|
||||
@@ -129,6 +133,8 @@ fn test_diff() -> Result<(), Error> {
|
||||
Modification::addition(b"This repository is a data source for the Upstream front-end tests and the\n".to_vec(), 1),
|
||||
Modification::addition(b"[`radicle-surf`](https://github.com/radicle-dev/git-platinum) unit tests.\n".to_vec(), 2),
|
||||
],
|
||||
old: 1..2,
|
||||
new: 1..3,
|
||||
}]
|
||||
.into(),
|
||||
eof: EofNewLine::default(),
|
||||
@@ -228,7 +234,9 @@ fn test_diff_serde() -> Result<(), Error> {
|
||||
"line": "\n",
|
||||
"lineNo": 2,
|
||||
"type": "addition",
|
||||
}]
|
||||
}],
|
||||
"old": { "start": 0, "end": 0 },
|
||||
"new": { "start": 1, "end": 3 },
|
||||
}],
|
||||
"eof": "noneMissing",
|
||||
},
|
||||
@@ -248,42 +256,44 @@ fn test_diff_serde() -> Result<(), Error> {
|
||||
"hunks": [{
|
||||
"header": "@@ -1,7 +0,0 @@\n",
|
||||
"lines": [
|
||||
{
|
||||
"line": " ;;;;; ;;;;; ;;;;;\n",
|
||||
"lineNo": 1,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ;;;;; ;;;;; ;;;;;\n",
|
||||
"lineNo": 2,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ;;;;; ;;;;; ;;;;;\n",
|
||||
"lineNo": 3,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ;;;;; ;;;;; ;;;;;\n",
|
||||
"lineNo": 4,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": "..;;;;;.. ..;;;;;.. ..;;;;;..\n",
|
||||
"lineNo": 5,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ':::::' ':::::' ':::::'\n",
|
||||
"lineNo": 6,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ':` ':` ':`\n",
|
||||
"lineNo": 7,
|
||||
"type": "deletion",
|
||||
},
|
||||
]
|
||||
{
|
||||
"line": " ;;;;; ;;;;; ;;;;;\n",
|
||||
"lineNo": 1,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ;;;;; ;;;;; ;;;;;\n",
|
||||
"lineNo": 2,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ;;;;; ;;;;; ;;;;;\n",
|
||||
"lineNo": 3,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ;;;;; ;;;;; ;;;;;\n",
|
||||
"lineNo": 4,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": "..;;;;;.. ..;;;;;.. ..;;;;;..\n",
|
||||
"lineNo": 5,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ':::::' ':::::' ':::::'\n",
|
||||
"lineNo": 6,
|
||||
"type": "deletion",
|
||||
},
|
||||
{
|
||||
"line": " ':` ':` ':`\n",
|
||||
"lineNo": 7,
|
||||
"type": "deletion",
|
||||
},
|
||||
],
|
||||
"old": { "start": 1, "end": 8 },
|
||||
"new": { "start": 0, "end": 0 },
|
||||
}],
|
||||
"eof": "noneMissing",
|
||||
},
|
||||
@@ -316,7 +326,9 @@ fn test_diff_serde() -> Result<(), Error> {
|
||||
"line": "[`radicle-surf`](https://github.com/radicle-dev/radicle-surf) unit tests.\n",
|
||||
"type": "addition"
|
||||
},
|
||||
]
|
||||
],
|
||||
"old": { "start": 1, "end": 3 },
|
||||
"new": { "start": 1, "end": 3 },
|
||||
}],
|
||||
"eof": "noneMissing",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user