Build the document. `change` is `Some` for `atomic diff -c ` and `None` for a working-copy diff; `view` is populated only for the latter.
(
file_diffs: &[FileDiff],
stats: &DiffStats,
change: Option<(&Change, &Hash)>,
view: Option<&str>,
)
| 32 | /// `change` is `Some` for `atomic diff -c <hash>` and `None` for a |
| 33 | /// working-copy diff; `view` is populated only for the latter. |
| 34 | pub(super) fn new( |
| 35 | file_diffs: &[FileDiff], |
| 36 | stats: &DiffStats, |
| 37 | change: Option<(&Change, &Hash)>, |
| 38 | view: Option<&str>, |
| 39 | ) -> Self { |
| 40 | Self { |
| 41 | schema_version: DIFF_JSON_SCHEMA_VERSION, |
| 42 | view: view.map(str::to_string), |
| 43 | change: change.map(|(c, h)| JsonDiffChange::new(c, h)), |
| 44 | files: file_diffs.iter().map(JsonDiffFile::from).collect(), |
| 45 | stats: JsonDiffStats::from(stats), |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /// The all-zero document, used when there is nothing to diff so that |
| 50 | /// `--json` still emits valid parseable JSON. |