| 135 | } |
| 136 | |
| 137 | pub(super) fn resolve(repo: &Repository, args: &IncrementalArgs) -> CliResult<IncrementalReport> { |
| 138 | let from = args |
| 139 | .from |
| 140 | .as_deref() |
| 141 | .ok_or_else(|| invalid("--from requires --to and vice versa"))?; |
| 142 | let to = args |
| 143 | .to |
| 144 | .as_deref() |
| 145 | .ok_or_else(|| invalid("--from requires --to and vice versa"))?; |
| 146 | if [from, to] |
| 147 | .iter() |
| 148 | .any(|name| name.is_empty() || name.trim() != *name) |
| 149 | { |
| 150 | return Err(invalid("Comparison view names must be exact and nonempty")); |
| 151 | } |
| 152 | if args.view.is_some() |
| 153 | || args.change.is_some() |
| 154 | || args.turn.is_some() |
| 155 | || args.intent.is_some() |
| 156 | || args.findings.is_some() |
| 157 | || args.risk_profile.is_some() |
| 158 | { |
| 159 | return Err(invalid("--from/--to cannot be combined with snapshot/change/turn/intent selectors, supplied change findings or a change-risk profile")); |
| 160 | } |
| 161 | let mut before = super::view_snapshot::collect(repo, to)?; |
| 162 | let mut after = super::view_snapshot::collect(repo, from)?; |
| 163 | let before_view = before.view_snapshot.take().unwrap(); |
| 164 | let after_view = after.view_snapshot.take().unwrap(); |
| 165 | let from_pin = ViewPin::from(&after_view); |
| 166 | let to_pin = ViewPin::from(&before_view); |
| 167 | let source_ref = format!( |
| 168 | "urn:atomic:view-comparison:{}", |
| 169 | Hash::of( |
| 170 | &serde_json::to_vec(&json!({"schema":"source-target-v1","from":from_pin,"to":to_pin})) |
| 171 | .map_err(|error| CliError::Internal(error.into()))? |
| 172 | ) |
| 173 | .to_base32() |
| 174 | ); |
| 175 | let before_ids = identities(repo, &before_view)?; |
| 176 | let after_ids = identities(repo, &after_view)?; |
| 177 | let pairs = pair_paths(&before_ids, &after_ids); |
| 178 | let before_index = SideIndex::new(&before_view); |
| 179 | let after_index = SideIndex::new(&after_view); |
| 180 | let mut files = Vec::new(); |
| 181 | for (old, new) in pairs { |
| 182 | let old_id = old.as_ref().and_then(|path| before_ids.get(path)).cloned(); |
| 183 | let new_id = new.as_ref().and_then(|path| after_ids.get(path)).cloned(); |
| 184 | let old_hash = old |
| 185 | .as_ref() |
| 186 | .and_then(|path| before_view.content_hashes.get(path)) |
| 187 | .cloned(); |
| 188 | let new_hash = new |
| 189 | .as_ref() |
| 190 | .and_then(|path| after_view.content_hashes.get(path)) |
| 191 | .cloned(); |
| 192 | let content_status = match (&old_hash, &new_hash) { |
| 193 | (Some(a), Some(b)) => { |
| 194 | if a == b { |