diff: Limit highlight source context
58a0c1b3ca0c617910fe3650c9d468adced89ce4
Fetch bounded source context for first highlight batches instead of asking Git for effectively full-file context. This keeps cold syntax highlighting tied to visible context size rather than the source line number of the change. The highlight benchmark now models a high source line number with bounded context, and source construction keeps leading blank lines without the extra Vec-and-join allocation. Assisted-by: Codex:gpt-5.5
1 parent
612a1f73
crates/diff/benches/highlight.rs
+40 -30
| 1 | 1 | //! Highlight pipeline benchmarks for `rustik-diff`. |
|
| 2 | 2 | //! |
|
| 3 | 3 | //! The benchmark mirrors the interactive pager's slow path more closely than |
|
| 4 | - | //! the render benchmark: it times built-in grammar/theme setup, full-context |
|
| 4 | + | //! the render benchmark: it times built-in grammar/theme setup, bounded context |
|
| 5 | 5 | //! patch decode, source extraction, visible request collection, and the final |
|
| 6 | 6 | //! highlight/apply/render pass. |
|
| 7 | 7 | //! |
|
| 8 | 8 | //! Run with `cargo bench -p rustik-diff --bench highlight`. |
|
| 9 | 9 |
| 20 | 20 | use rustik_highlight as syntax; |
|
| 21 | 21 | use rustik_tui::{Buffer, Color, Constraint, Label, Rect, Scroll, Style, Table, TableOptions}; |
|
| 22 | 22 | ||
| 23 | 23 | /// Fixed terminal-sized render area. |
|
| 24 | 24 | const AREA: Rect = Rect::new(0, 0, 120, 40); |
|
| 25 | - | /// Default source rows generated for the full-context file. |
|
| 25 | + | /// Default source line number targeted by the generated patch. |
|
| 26 | 26 | const DEFAULT_LINES: usize = 100_000; |
|
| 27 | + | /// Default source context rows generated around the changed line. |
|
| 28 | + | const DEFAULT_CONTEXT_LINES: usize = 256; |
|
| 27 | 29 | /// Default number of independent timed runs. |
|
| 28 | 30 | const DEFAULT_RUNS: usize = 3; |
|
| 29 | - | /// Rows per hunk in the sparse viewport document. |
|
| 30 | - | const SPARSE_HUNK_LINES: usize = 64; |
|
| 31 | + | /// Context rows in the sparse viewport document. |
|
| 32 | + | const SPARSE_CONTEXT_LINES: usize = 32; |
|
| 31 | 33 | /// Theme name used by the interactive pager. |
|
| 32 | 34 | const THEME_NAME: &str = "rustik-catppuccin-mocha"; |
|
| 33 | 35 | /// Built-in syntax theme JSON used by the interactive pager. |
|
| 34 | 36 | const THEME: &str = include_str!("../src/themes/rustik-catppuccin-mocha.json"); |
|
| 35 | 37 | /// Low-emphasis report text color. |
| 38 | 40 | const DURATION_FORMAT: &str = "000000.0 ms"; |
|
| 39 | 41 | ||
| 40 | 42 | /// Runs the benchmark. |
|
| 41 | 43 | fn main() { |
|
| 42 | 44 | let args = Args::parse(); |
|
| 43 | - | let sparse_patch = synthetic_diff("src/slow.rs", args.lines, SPARSE_HUNK_LINES); |
|
| 44 | - | let full_patch = synthetic_diff("src/slow.rs", args.lines, args.lines); |
|
| 45 | + | let sparse_patch = synthetic_context_diff("src/slow.rs", args.lines, SPARSE_CONTEXT_LINES); |
|
| 46 | + | let context_patch = synthetic_context_diff("src/slow.rs", args.lines, args.context_lines); |
|
| 45 | 47 | let sparse_document = decode_patch(&sparse_patch); |
|
| 46 | 48 | let widths = ReportWidths::new(); |
|
| 47 | 49 | let mut totals = StageDurations::default(); |
|
| 48 | 50 | let mut checksum = 0usize; |
|
| 49 | 51 | ||
| 50 | 52 | for _ in 0..args.runs { |
|
| 51 | - | let report = run_once(&sparse_document, &full_patch); |
|
| 53 | + | let report = run_once(&sparse_document, &context_patch); |
|
| 52 | 54 | totals += report.stages; |
|
| 53 | 55 | checksum ^= report.checksum; |
|
| 54 | 56 | } |
|
| 55 | 57 | let stats = totals.div(args.runs); |
|
| 56 | 58 |
| 65 | 67 | } |
|
| 66 | 68 | ||
| 67 | 69 | /// Benchmark command-line arguments. |
|
| 68 | 70 | #[derive(Clone, Copy, Debug)] |
|
| 69 | 71 | struct Args { |
|
| 70 | - | /// Source rows generated for the full-context file. |
|
| 72 | + | /// Source line number targeted by the generated patch. |
|
| 71 | 73 | lines: usize, |
|
| 74 | + | /// Source context rows generated around the changed line. |
|
| 75 | + | context_lines: usize, |
|
| 72 | 76 | /// Number of independent timed runs. |
|
| 73 | 77 | runs: usize, |
|
| 74 | 78 | } |
|
| 75 | 79 | ||
| 76 | 80 | impl Args { |
|
| 77 | 81 | /// Parses benchmark arguments from the process environment. |
|
| 78 | 82 | fn parse() -> Self { |
|
| 79 | 83 | let mut parsed = Self { |
|
| 80 | 84 | lines: DEFAULT_LINES, |
|
| 85 | + | context_lines: DEFAULT_CONTEXT_LINES, |
|
| 81 | 86 | runs: DEFAULT_RUNS, |
|
| 82 | 87 | }; |
|
| 83 | 88 | let mut args = std::env::args().skip(1); |
|
| 84 | 89 | ||
| 85 | 90 | while let Some(arg) = args.next() { |
|
| 86 | 91 | match arg.as_str() { |
|
| 87 | 92 | "--lines" => parsed.lines = next_usize(&mut args, parsed.lines), |
|
| 93 | + | "--context" => parsed.context_lines = next_usize(&mut args, parsed.context_lines), |
|
| 88 | 94 | "--runs" => parsed.runs = next_usize(&mut args, parsed.runs).max(1), |
|
| 89 | 95 | "--help" | "-h" => { |
|
| 90 | 96 | println!( |
|
| 91 | - | "usage: cargo bench -p rustik-diff --bench highlight -- [--lines N] [--runs N]" |
|
| 97 | + | "usage: cargo bench -p rustik-diff --bench highlight -- [--lines N] [--context N] [--runs N]" |
|
| 92 | 98 | ); |
|
| 93 | 99 | std::process::exit(0); |
|
| 94 | 100 | } |
|
| 95 | 101 | _ => {} |
|
| 96 | 102 | } |
| 102 | 108 | /// Stage timings from one benchmark run. |
|
| 103 | 109 | #[derive(Clone, Copy, Debug, Default)] |
|
| 104 | 110 | struct StageDurations { |
|
| 105 | 111 | /// Built-in theme and grammar setup. |
|
| 106 | 112 | assets: Duration, |
|
| 107 | - | /// Full-context unified-diff decode. |
|
| 113 | + | /// Bounded-context unified-diff decode. |
|
| 108 | 114 | context_decode: Duration, |
|
| 109 | - | /// Full-file source extraction from decoded diff data. |
|
| 115 | + | /// Context source extraction from decoded diff data. |
|
| 110 | 116 | source_build: Duration, |
|
| 111 | 117 | /// Visible highlight request collection. |
|
| 112 | 118 | requests: Duration, |
|
| 113 | 119 | /// Syntax highlight, cache apply, and highlighted render. |
|
| 114 | 120 | land: Duration, |
| 173 | 179 | .and_then(|value| value.parse().ok()) |
|
| 174 | 180 | .unwrap_or(fallback) |
|
| 175 | 181 | } |
|
| 176 | 182 | ||
| 177 | 183 | /// Runs one timed highlight pipeline pass. |
|
| 178 | - | fn run_once(sparse_document: &DiffDocument, full_patch: &str) -> BenchReport { |
|
| 184 | + | fn run_once(sparse_document: &DiffDocument, context_patch: &str) -> BenchReport { |
|
| 179 | 185 | let mut stages = StageDurations::default(); |
|
| 180 | 186 | let mut checksum = 0usize; |
|
| 181 | 187 | ||
| 182 | 188 | let start = Instant::now(); |
|
| 183 | 189 | let mut highlighter = build_highlighter(); |
|
| 184 | 190 | stages.assets = start.elapsed(); |
|
| 185 | 191 | ||
| 186 | 192 | let start = Instant::now(); |
|
| 187 | - | let full_document = decode_patch(full_patch); |
|
| 193 | + | let context_document = decode_patch(context_patch); |
|
| 188 | 194 | stages.context_decode = start.elapsed(); |
|
| 189 | 195 | ||
| 190 | 196 | let start = Instant::now(); |
|
| 191 | - | let full_sources = full_sources(&full_document); |
|
| 197 | + | let context_sources = context_sources(&context_document); |
|
| 192 | 198 | stages.source_build = start.elapsed(); |
|
| 193 | 199 | ||
| 194 | 200 | let mut viewer = DiffViewer::new(sparse_document.clone(), DiffOptions::default()); |
|
| 195 | 201 | let rows = rustik_tui::Widget::size(&viewer, Constraint::UNBOUNDED).rows; |
|
| 196 | 202 | viewer.apply(DiffAction::Scroll(Scroll::Lines((rows / 2) as isize)), AREA); |
| 198 | 204 | let start = Instant::now(); |
|
| 199 | 205 | let requests = viewer.highlight_requests(AREA); |
|
| 200 | 206 | stages.requests = start.elapsed(); |
|
| 201 | 207 | ||
| 202 | 208 | let start = Instant::now(); |
|
| 203 | - | let requests = full_source_requests(requests, &full_sources); |
|
| 209 | + | let requests = context_source_requests(requests, &context_sources); |
|
| 204 | 210 | let results = highlighter.highlight_requests(requests); |
|
| 205 | 211 | ||
| 206 | 212 | checksum ^= results.len(); |
|
| 207 | 213 | viewer.apply_highlights(results); |
|
| 208 | 214 |
| 260 | 266 | std::process::exit(1); |
|
| 261 | 267 | } |
|
| 262 | 268 | } |
|
| 263 | 269 | } |
|
| 264 | 270 | ||
| 265 | - | /// Extracts full-file sources from a full-context diff document. |
|
| 266 | - | fn full_sources(document: &DiffDocument) -> BTreeMap<(PathBuf, DiffSide), HighlightSource> { |
|
| 271 | + | /// Extracts bounded context sources from a context diff document. |
|
| 272 | + | fn context_sources(document: &DiffDocument) -> BTreeMap<(PathBuf, DiffSide), Vec<HighlightSource>> { |
|
| 267 | 273 | let mut sources = BTreeMap::new(); |
|
| 268 | 274 | ||
| 269 | 275 | for file in &document.files { |
|
| 270 | 276 | for side in [DiffSide::Old, DiffSide::New] { |
|
| 271 | 277 | let Some(path) = file.source_path(side) else { |
|
| 272 | 278 | continue; |
|
| 273 | 279 | }; |
|
| 274 | - | let Some(source) = file.highlight_source(side) else { |
|
| 275 | - | continue; |
|
| 276 | - | }; |
|
| 277 | - | sources.insert((path, side), source); |
|
| 280 | + | let side_sources = file |
|
| 281 | + | .hunks |
|
| 282 | + | .iter() |
|
| 283 | + | .map(|hunk| hunk.highlight_source(side)) |
|
| 284 | + | .collect::<Vec<_>>(); |
|
| 285 | + | sources.insert((path, side), side_sources); |
|
| 278 | 286 | } |
|
| 279 | 287 | } |
|
| 280 | 288 | sources |
|
| 281 | 289 | } |
|
| 282 | 290 | ||
| 283 | - | /// Replaces sparse hunk sources with full-file sources where line text matches. |
|
| 284 | - | fn full_source_requests( |
|
| 291 | + | /// Replaces sparse hunk sources with context sources where line text matches. |
|
| 292 | + | fn context_source_requests( |
|
| 285 | 293 | requests: Vec<HighlightRequest>, |
|
| 286 | - | sources: &BTreeMap<(PathBuf, DiffSide), HighlightSource>, |
|
| 294 | + | sources: &BTreeMap<(PathBuf, DiffSide), Vec<HighlightSource>>, |
|
| 287 | 295 | ) -> Vec<HighlightRequest> { |
|
| 288 | 296 | requests |
|
| 289 | 297 | .into_iter() |
|
| 290 | 298 | .map(|mut request| { |
|
| 291 | 299 | let Some(path) = request.path.as_ref() else { |
|
| 292 | 300 | return request; |
|
| 293 | 301 | }; |
|
| 294 | 302 | let key = (path.clone(), request.key.side); |
|
| 295 | - | if let Some(source) = sources.get(&key) |
|
| 296 | - | && source.line(request.key.source_line) |
|
| 297 | - | == request.source.line(request.key.source_line) |
|
| 298 | - | { |
|
| 303 | + | if let Some(source) = sources.get(&key).and_then(|sources| { |
|
| 304 | + | sources.iter().find(|source| { |
|
| 305 | + | source.line(request.key.source_line) |
|
| 306 | + | == request.source.line(request.key.source_line) |
|
| 307 | + | }) |
|
| 308 | + | }) { |
|
| 299 | 309 | request.source = source.clone(); |
|
| 300 | 310 | } |
|
| 301 | 311 | request |
|
| 302 | 312 | }) |
|
| 303 | 313 | .collect() |
|
| 304 | 314 | } |
|
| 305 | 315 | ||
| 306 | - | /// Creates a deterministic Git-style unified diff for one file. |
|
| 307 | - | fn synthetic_diff(path: &str, lines: usize, hunk_lines: usize) -> String { |
|
| 316 | + | /// Creates a deterministic Git-style unified diff for one centered file hunk. |
|
| 317 | + | fn synthetic_context_diff(path: &str, lines: usize, context_lines: usize) -> String { |
|
| 308 | 318 | let mut diff = String::new(); |
|
| 309 | 319 | ||
| 310 | 320 | diff.push_str(&format!(" |
{path}\n"));
+0 -0
crates/diff/src/bin/rustik-diff/session.rs
+31 -22
| 25 | 25 | const FOOTER_ROWS: usize = 1; |
|
| 26 | 26 | /// Foreground color for dim footer text. |
|
| 27 | 27 | const FOOTER_FG: Color = Color::Fixed(240); |
|
| 28 | 28 | /// Background color for the footer row. |
|
| 29 | 29 | const FOOTER_BG: Color = Color::Fixed(233); |
|
| 30 | - | /// Unified context width used for full-file highlight context. |
|
| 31 | - | const HIGHLIGHT_CONTEXT_LINES: usize = 999_999; |
|
| 30 | + | /// Source context lines fetched around highlighted rows. |
|
| 31 | + | const HIGHLIGHT_CONTEXT_LINES: usize = 256; |
|
| 32 | 32 | ||
| 33 | 33 | /// Terminal backend used by the interactive viewer. |
|
| 34 | 34 | type DiffTerminal = Terminal<tui_termion::TermionBackend<tui_termion::term::TerminalScreen>>; |
|
| 35 | 35 | ||
| 36 | 36 | /// Runs the terminal event loop. |
| 189 | 189 | struct HighlightWorker { |
|
| 190 | 190 | /// Built-in syntax highlighter. |
|
| 191 | 191 | highlighter: BuiltinHighlighter, |
|
| 192 | 192 | /// Git-backed repo used for direct Git invocations. |
|
| 193 | 193 | repo: Option<GitRepo>, |
|
| 194 | - | /// Full-file highlight source cache keyed by diff file and side. |
|
| 195 | - | full_sources: BTreeMap<(FileId, DiffSide), HighlightSource>, |
|
| 194 | + | /// Highlight source context cache keyed by diff file and side. |
|
| 195 | + | context_sources: BTreeMap<(FileId, DiffSide), Vec<HighlightSource>>, |
|
| 196 | 196 | } |
|
| 197 | 197 | ||
| 198 | 198 | impl HighlightWorker { |
|
| 199 | 199 | /// Creates a background worker. |
|
| 200 | 200 | fn new(document: &DiffDocument, repo: Option<GitRepo>) -> Self { |
|
| 201 | 201 | Self { |
|
| 202 | 202 | highlighter: Builtins::highlighter(document) |
|
| 203 | 203 | .unwrap_or_else(|_| BuiltinHighlighter::new(Default::default(), "")), |
|
| 204 | 204 | repo, |
|
| 205 | - | full_sources: BTreeMap::new(), |
|
| 205 | + | context_sources: BTreeMap::new(), |
|
| 206 | 206 | } |
|
| 207 | 207 | } |
|
| 208 | 208 | ||
| 209 | 209 | /// Highlights one batch after enriching it with repo-backed context. |
|
| 210 | 210 | fn highlight(&mut self, mut requests: Vec<HighlightRequest>) -> Vec<HighlightResult> { |
|
| 211 | - | self.load_full_sources(&requests); |
|
| 211 | + | self.load_context_sources(&requests); |
|
| 212 | 212 | for request in &mut requests { |
|
| 213 | - | let key = (request.key.file, request.key.side); |
|
| 214 | - | if let Some(source) = self.full_sources.get(&key) |
|
| 215 | - | && source.line(request.key.source_line) |
|
| 216 | - | == request.source.line(request.key.source_line) |
|
| 217 | - | { |
|
| 213 | + | if let Some(source) = self.context_source_for(request) { |
|
| 218 | 214 | request.source = source.clone(); |
|
| 219 | 215 | } |
|
| 220 | 216 | } |
|
| 221 | 217 | self.highlighter.highlight_batch(requests) |
|
| 222 | 218 | } |
|
| 223 | 219 | ||
| 224 | - | /// Loads full-file source context for uncached request paths. |
|
| 225 | - | fn load_full_sources(&mut self, requests: &[HighlightRequest]) { |
|
| 220 | + | /// Loads bounded source context for uncached request paths. |
|
| 221 | + | fn load_context_sources(&mut self, requests: &[HighlightRequest]) { |
|
| 226 | 222 | let Some(repo) = self.repo.as_ref() else { |
|
| 227 | 223 | return; |
|
| 228 | 224 | }; |
|
| 229 | 225 | let mut targets = BTreeMap::new(); |
|
| 230 | 226 | for request in requests { |
|
| 231 | 227 | let key = (request.key.file, request.key.side); |
|
| 232 | - | if self.full_sources.contains_key(&key) { |
|
| 228 | + | if self.context_sources.contains_key(&key) { |
|
| 233 | 229 | continue; |
|
| 234 | 230 | } |
|
| 235 | 231 | if let Some(path) = request.path.as_deref() { |
|
| 236 | 232 | targets.insert((path.to_path_buf(), request.key.side), request.key.file); |
|
| 237 | 233 | } |
| 259 | 255 | continue; |
|
| 260 | 256 | }; |
|
| 261 | 257 | let Some(file_id) = targets.get(&(path, side)).copied() else { |
|
| 262 | 258 | continue; |
|
| 263 | 259 | }; |
|
| 264 | - | let Some(source) = file.highlight_source(side) else { |
|
| 265 | - | continue; |
|
| 266 | - | }; |
|
| 267 | - | if side == DiffSide::New |
|
| 268 | - | && let Some(head) = source.text.lines().next() |
|
| 269 | - | { |
|
| 270 | - | let _ = Builtins::load_head_grammars(&mut self.highlighter, head); |
|
| 260 | + | let sources = file |
|
| 261 | + | .hunks |
|
| 262 | + | .iter() |
|
| 263 | + | .map(|hunk| hunk.highlight_source(side)) |
|
| 264 | + | .collect::<Vec<_>>(); |
|
| 265 | + | for source in &sources { |
|
| 266 | + | if side == DiffSide::New |
|
| 267 | + | && source.head == 1 |
|
| 268 | + | && let Some(head) = source.text.lines().next() |
|
| 269 | + | { |
|
| 270 | + | let _ = Builtins::load_head_grammars(&mut self.highlighter, head); |
|
| 271 | + | } |
|
| 271 | 272 | } |
|
| 272 | - | self.full_sources.insert((file_id, side), source); |
|
| 273 | + | self.context_sources.insert((file_id, side), sources); |
|
| 273 | 274 | } |
|
| 274 | 275 | } |
|
| 275 | 276 | } |
|
| 276 | 277 | ||
| 278 | + | /// Returns cached context that contains the requested source row. |
|
| 279 | + | fn context_source_for(&self, request: &HighlightRequest) -> Option<&HighlightSource> { |
|
| 280 | + | let key = (request.key.file, request.key.side); |
|
| 281 | + | self.context_sources.get(&key)?.iter().find(|source| { |
|
| 282 | + | source.line(request.key.source_line) == request.source.line(request.key.source_line) |
|
| 283 | + | }) |
|
| 284 | + | } |
|
| 285 | + | ||
| 277 | 286 | /// Refetches and decodes one context update. |
|
| 278 | 287 | fn context(&mut self, request: ContextRequest) -> Option<ContextUpdate> { |
|
| 279 | 288 | let repo = self.repo.as_ref()?; |
|
| 280 | 289 | let paths = request.paths().collect::<Vec<_>>(); |
|
| 281 | 290 | let patch = repo.diff(request.context_lines(), &paths).ok()?; |
crates/diff/src/highlight.rs
+22 -12
| 187 | 187 | } |
|
| 188 | 188 | ||
| 189 | 189 | impl Hunk { |
|
| 190 | 190 | /// Builds contiguous source text for one hunk side. |
|
| 191 | 191 | pub fn highlight_source(&self, side: DiffSide) -> HighlightSource { |
|
| 192 | - | let text = side_lines(self, side).collect::<Vec<_>>().join("\n"); |
|
| 192 | + | let mut text = String::new(); |
|
| 193 | + | push_hunk_source_lines(self, side, &mut text); |
|
| 193 | 194 | HighlightSource::new(text, hunk_head(self, side)) |
|
| 194 | 195 | } |
|
| 195 | 196 | } |
|
| 196 | 197 | ||
| 197 | 198 | impl FileDiff { |
| 206 | 207 | ||
| 207 | 208 | /// Builds contiguous source text for one file side. |
|
| 208 | 209 | /// |
|
| 209 | 210 | /// Returns `None` when the file's hunks are not contiguous on `side`. |
|
| 210 | 211 | pub fn highlight_source(&self, side: DiffSide) -> Option<HighlightSource> { |
|
| 211 | - | let mut lines: Vec<&str> = Vec::new(); |
|
| 212 | + | let mut text = String::new(); |
|
| 212 | 213 | let mut head = None; |
|
| 213 | 214 | let mut next_line = None; |
|
| 214 | 215 | ||
| 215 | 216 | for hunk in &self.hunks { |
|
| 216 | 217 | let hunk_head = hunk_head(hunk, side); |
|
| 217 | 218 | if next_line.is_some_and(|line| line != hunk_head) { |
|
| 218 | 219 | return None; |
|
| 219 | 220 | } |
|
| 220 | 221 | head.get_or_insert(hunk_head); |
|
| 221 | - | lines.extend(side_lines(hunk, side)); |
|
| 222 | + | push_hunk_source_lines(hunk, side, &mut text); |
|
| 222 | 223 | let len = hunk |
|
| 223 | 224 | .lines |
|
| 224 | 225 | .iter() |
|
| 225 | 226 | .map(|line| source_len(line, side)) |
|
| 226 | 227 | .sum::<u32>(); |
|
| 227 | 228 | next_line = Some(hunk_head + len); |
|
| 228 | 229 | } |
|
| 229 | - | head.map(|head| HighlightSource::new(lines.join("\n"), head)) |
|
| 230 | + | head.map(|head| HighlightSource::new(text, head)) |
|
| 230 | 231 | } |
|
| 231 | 232 | } |
|
| 232 | 233 | ||
| 233 | - | /// Yields the source-side text of every line present on `side`. |
|
| 234 | + | /// Appends source-side hunk lines to `text`. |
|
| 234 | 235 | /// |
|
| 235 | - | /// Lines are joined with `\n` by callers; blank lines are kept so a |
|
| 236 | - | /// [`HighlightSource`] line index stays aligned with its source line number. |
|
| 237 | - | fn side_lines(hunk: &Hunk, side: DiffSide) -> impl Iterator<Item = &str> { |
|
| 238 | - | hunk.lines |
|
| 239 | - | .iter() |
|
| 240 | - | .filter(move |line| source_len(line, side) != 0) |
|
| 241 | - | .map(|line| line.text.as_str()) |
|
| 236 | + | /// Blank lines are kept so a [`HighlightSource`] line index stays aligned with |
|
| 237 | + | /// its source line number. |
|
| 238 | + | fn push_hunk_source_lines(hunk: &Hunk, side: DiffSide, text: &mut String) { |
|
| 239 | + | let mut first = text.is_empty(); |
|
| 240 | + | ||
| 241 | + | for line in &hunk.lines { |
|
| 242 | + | if source_len(line, side) == 0 { |
|
| 243 | + | continue; |
|
| 244 | + | } |
|
| 245 | + | if first { |
|
| 246 | + | first = false; |
|
| 247 | + | } else { |
|
| 248 | + | text.push('\n'); |
|
| 249 | + | } |
|
| 250 | + | text.push_str(&line.text); |
|
| 251 | + | } |
|
| 242 | 252 | } |
|
| 243 | 253 | ||
| 244 | 254 | /// Returns the first source line for one hunk side. |
|
| 245 | 255 | fn hunk_head(hunk: &Hunk, side: DiffSide) -> u32 { |
|
| 246 | 256 | match side { |
a.css
+0 -0
a.rs\n",
+0 -0
crates/diff/src/viewer.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
src/a.rs
+0 -0
src/b.rs
+0 -0
README.md
+0 -0
src/app/a.rs
+0 -0
src/lib/b.rs
+0 -0
README.md
+0 -0
assets/css/style.css
+0 -0
assets/css/style.css
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0