wire/answer/hunks.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! One file's patch text between two checkpoints.
7//!
8//! Its own file for the reason `Query::Hunks` is its own frame: a change
9//! list costs what the number of changed files costs and this costs what
10//! one file costs, so the two answers are kept apart everywhere they
11//! appear.
12
13use kernel::GitOid;
14use serde::{Deserialize, Serialize};
15
16/// One file's patch text between two checkpoints, and what could not be
17/// shown.
18///
19/// Both ends travel back with the answer because they are what makes it
20/// cacheable: two commit ids never change, so whoever asked may keep
21/// this for as long as they like.
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
24pub struct HunksAnswer {
25 pub oid_a: GitOid,
26 pub oid_b: GitOid,
27 pub path: String,
28 pub lines: Vec<PatchLine>,
29 /// Lines that matched a credential shape. They are named and not
30 /// echoed, for the reason a staged blob's scan gives about its own
31 /// hits: printing the bytes to prove a leak is the leak.
32 pub withheld: Vec<Withheld>,
33}
34
35/// One line of patch text, numbered from the top of the patch so a
36/// withheld line and the lines around it read as one list.
37#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
38#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
39pub struct PatchLine {
40 pub number: u32,
41 pub text: String,
42}
43
44/// One line that was not echoed, and what matched it.
45#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
46#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
47pub struct Withheld {
48 pub number: u32,
49 /// A provider's own key shape by name, or the entropy judgement when
50 /// no shape claimed it. Never the bytes.
51 pub reason: String,
52}