| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | | use super::*; |
| 11 | | use std::process::{Command, Stdio}; |
| 12 | | use std::sync::Arc; |
| 13 | |
|
| 14 | | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
| 15 | | pub struct GitImportReport { |
| 16 | | pub commits: usize, |
| 17 | | pub merges: usize, |
| 18 | | |
| 19 | | pub submodules: usize, |
| 20 | | pub heads: usize, |
| 21 | | } |
| 22 | |
|
| 23 | |
|
| 24 | | struct CatFile { |
| 25 | | child: std::process::Child, |
| 26 | | stdin: std::process::ChildStdin, |
| 27 | | stdout: std::io::BufReader<std::process::ChildStdout>, |
| 28 | | } |
| 29 | |
|
| 30 | | impl CatFile { |
| 31 | 22× | fn start(git_dir: &Path) -> Result<CatFile> { |
| 32 | 22× | let mut child = Command::new("git") |
| 33 | 22× | .arg("-C") |
| 34 | 22× | .arg(git_dir) |
| 35 | 22× | .args(["cat-file", "--batch"]) |
| 36 | 22× | .stdin(Stdio::piped()) |
| 37 | 22× | .stdout(Stdio::piped()) |
| 38 | 22× | .stderr(Stdio::null()) |
| 39 | 22× | .spawn() |
| 40 | 22× | .map_err(|e| RepoError::Msg(format!("running git cat-file: {e}")))?; |
| 41 | 22× | let stdin = child.stdin.take().unwrap(); |
| 42 | 22× | let stdout = std::io::BufReader::new(child.stdout.take().unwrap()); |
| 43 | 22× | Ok(CatFile { |
| 44 | 22× | child, |
| 45 | 22× | stdin, |
| 46 | 22× | stdout, |
| 47 | 22× | }) |
| 48 | 22× | } |
| 49 | |
|
| 50 | 123× | fn read(&mut self, sha: &str) -> Result<Vec<u8>> { |
| 51 | | use std::io::{BufRead, Read}; |
| 52 | 123× | writeln!(self.stdin, "{sha}")?; |
| 53 | 123× | self.stdin.flush()?; |
| 54 | 123× | let mut header = String::new(); |
| 55 | 123× | self.stdout.read_line(&mut header)?; |
| 56 | 123× | let parts: Vec<&str> = header.trim_end().split(' ').collect(); |
| 57 | 123× | if parts.len() != 3 { |
| 58 | 0× | return fail(format!("git cat-file: object {sha} not found")); |
| 59 | 123× | } |
| 60 | 123× | let size: usize = parts[2] |
| 61 | 123× | .parse() |
| 62 | 123× | .map_err(|_| RepoError::Msg("git cat-file: bad size".into()))?; |
| 63 | 123× | let mut body = vec![0u8; size]; |
| 64 | 123× | self.stdout.read_exact(&mut body)?; |
| 65 | 123× | let mut nl = [0u8; 1]; |
| 66 | 123× | self.stdout.read_exact(&mut nl)?; |
| 67 | 123× | Ok(body) |
| 68 | 123× | } |
| 69 | | } |
| 70 | |
|
| 71 | | impl Drop for CatFile { |
| 72 | 22× | fn drop(&mut self) { |
| 73 | 22× | let _ = self.child.kill(); |
| 74 | 22× | let _ = self.child.wait(); |
| 75 | 22× | } |
| 76 | | } |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | | type TreeDiff = Vec<(String, Option<(String, String)>)>; |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | | struct DiffTree { |
| 87 | | child: std::process::Child, |
| 88 | | stdout: std::io::BufReader<std::process::ChildStdout>, |
| 89 | | feeder: Option<std::thread::JoinHandle<()>>, |
| 90 | | |
| 91 | | next: Option<String>, |
| 92 | | } |
| 93 | |
|
| 94 | | impl DiffTree { |
| 95 | 14× | fn start(git_dir: &Path, pairs: Vec<(String, String)>) -> Result<DiffTree> { |
| 96 | 14× | let mut child = Command::new("git") |
| 97 | 14× | .arg("-C") |
| 98 | 14× | .arg(git_dir) |
| 99 | 14× | .args([ |
| 100 | 14× | "diff-tree", |
| 101 | 14× | "--stdin", |
| 102 | 14× | "--always", |
| 103 | 14× | "-r", |
| 104 | 14× | "-z", |
| 105 | 14× | "--no-renames", |
| 106 | 14× | ]) |
| 107 | 14× | .stdin(Stdio::piped()) |
| 108 | 14× | .stdout(Stdio::piped()) |
| 109 | 14× | .stderr(Stdio::null()) |
| 110 | 14× | .spawn() |
| 111 | 14× | .map_err(|e| RepoError::Msg(format!("running git diff-tree: {e}")))?; |
| 112 | 14× | let mut stdin = child.stdin.take().unwrap(); |
| 113 | 14× | let stdout = std::io::BufReader::new(child.stdout.take().unwrap()); |
| 114 | | |
| 115 | 14× | let feeder = std::thread::spawn(move || { |
| 116 | 14× | let mut w = std::io::BufWriter::new(&mut stdin); |
| 117 | 66× | for (c, p) in pairs { |
| 118 | 66× | if writeln!(w, "{c} {p}").is_err() { |
| 119 | 0× | return; |
| 120 | 66× | } |
| 121 | | } |
| 122 | 14× | let _ = w.flush(); |
| 123 | 14× | }); |
| 124 | 14× | Ok(DiffTree { |
| 125 | 14× | child, |
| 126 | 14× | stdout, |
| 127 | 14× | feeder: Some(feeder), |
| 128 | 14× | next: None, |
| 129 | 14× | }) |
| 130 | 14× | } |
| 131 | |
|
| 132 | 243× | fn field(&mut self) -> Result<Option<String>> { |
| 133 | | use std::io::BufRead; |
| 134 | 243× | let mut buf = Vec::new(); |
| 135 | 243× | if self.stdout.read_until(0, &mut buf)? == 0 { |
| 136 | 13× | return Ok(None); |
| 137 | 230× | } |
| 138 | 230× | if buf.last() == Some(&0) { |
| 139 | 230× | buf.pop(); |
| 140 | 230× | } |
| 141 | 230× | Ok(Some(String::from_utf8_lossy(&buf).into_owned())) |
| 142 | 243× | } |
| 143 | |
|
| 144 | | |
| 145 | 66× | fn diff(&mut self, sha: &str) -> Result<TreeDiff> { |
| 146 | 66× | let header = match self.next.take() { |
| 147 | 53× | Some(h) => Some(h), |
| 148 | 13× | None => self.field()?, |
| 149 | | }; |
| 150 | 66× | if header.as_deref() != Some(sha) { |
| 151 | 0× | return fail(format!("git diff-tree: expected {sha}, got {header:?}")); |
| 152 | 66× | } |
| 153 | 66× | let mut out = Vec::new(); |
| 154 | 148× | while let Some(f) = self.field()? { |
| 155 | 135× | let Some(meta) = f.strip_prefix(':') else { |
| 156 | 53× | self.next = Some(f); |
| 157 | 53× | break; |
| 158 | | }; |
| 159 | 82× | let Some(path) = self.field()? else { |
| 160 | 0× | return fail("git diff-tree: record without a path"); |
| 161 | | }; |
| 162 | | |
| 163 | 82× | let m: Vec<&str> = meta.split(' ').collect(); |
| 164 | 82× | if m.len() != 5 { |
| 165 | 0× | return fail(format!("git diff-tree: bad record {f:?}")); |
| 166 | 82× | } |
| 167 | 82× | let entry = if m[4].starts_with('D') { |
| 168 | 14× | None |
| 169 | | } else { |
| 170 | 68× | Some((m[1].to_string(), m[3].to_string())) |
| 171 | | }; |
| 172 | 82× | out.push((path, entry)); |
| 173 | | } |
| 174 | 66× | Ok(out) |
| 175 | 66× | } |
| 176 | | } |
| 177 | |
|
| 178 | | impl Drop for DiffTree { |
| 179 | 14× | fn drop(&mut self) { |
| 180 | 14× | let _ = self.child.kill(); |
| 181 | 14× | let _ = self.child.wait(); |
| 182 | 14× | if let Some(f) = self.feeder.take() { |
| 183 | 14× | let _ = f.join(); |
| 184 | 14× | } |
| 185 | 14× | } |
| 186 | | } |
| 187 | |
|
| 188 | |
|
| 189 | | struct GitCommit { |
| 190 | | sha: String, |
| 191 | | parents: Vec<String>, |
| 192 | | author_secs: u64, |
| 193 | | author: String, |
| 194 | | message: String, |
| 195 | | } |
| 196 | |
|
| 197 | 22× | fn list_commits(git_dir: &Path, branch: &str) -> Result<Vec<GitCommit>> { |
| 198 | 22× | let out = Command::new("git") |
| 199 | 22× | .arg("-C") |
| 200 | 22× | .arg(git_dir) |
| 201 | 22× | .args([ |
| 202 | 22× | "log", |
| 203 | 22× | "--reverse", |
| 204 | 22× | "--topo-order", |
| 205 | 22× | "--format=%H%x00%P%x00%at%x00%an <%ae>%x00%B%x1e", |
| 206 | 22× | branch, |
| 207 | 22× | ]) |
| 208 | 22× | .output() |
| 209 | 22× | .map_err(|e| RepoError::Msg(format!("running git log: {e}")))?; |
| 210 | 22× | if !out.status.success() { |
| 211 | 0× | return fail(format!( |
| 212 | | "git log {branch} failed: {}", |
| 213 | 0× | String::from_utf8_lossy(&out.stderr).trim() |
| 214 | | )); |
| 215 | 22× | } |
| 216 | 22× | let text = String::from_utf8_lossy(&out.stdout); |
| 217 | 22× | let mut commits = Vec::new(); |
| 218 | 162× | for record in text.split('\x1e') { |
| 219 | 162× | let record = record.trim_start_matches('\n'); |
| 220 | 162× | if record.trim().is_empty() { |
| 221 | 22× | continue; |
| 222 | 140× | } |
| 223 | 140× | let f: Vec<&str> = record.splitn(5, '\0').collect(); |
| 224 | 140× | if f.len() != 5 { |
| 225 | 0× | return fail("unexpected git log record"); |
| 226 | 140× | } |
| 227 | 140× | commits.push(GitCommit { |
| 228 | 140× | sha: f[0].to_string(), |
| 229 | 140× | parents: f[1].split_whitespace().map(str::to_string).collect(), |
| 230 | 140× | author_secs: f[2].parse().unwrap_or(0), |
| 231 | 140× | author: f[3].to_string(), |
| 232 | 140× | message: f[4].trim_end().to_string(), |
| 233 | 140× | }); |
| 234 | | } |
| 235 | 22× | Ok(commits) |
| 236 | 22× | } |
| 237 | |
|
| 238 | |
|
| 239 | 70× | fn list_tree(git_dir: &Path, sha: &str) -> Result<BTreeMap<String, (String, String)>> { |
| 240 | 70× | let text = git(git_dir, &["ls-tree", "-r", "-z", sha])?; |
| 241 | 70× | let mut out = BTreeMap::new(); |
| 242 | 229× | for entry in text.split('\0') { |
| 243 | 229× | if entry.is_empty() { |
| 244 | 70× | continue; |
| 245 | 159× | } |
| 246 | 159× | let Some((meta, path)) = entry.split_once('\t') else { |
| 247 | 0× | continue; |
| 248 | | }; |
| 249 | 159× | let m: Vec<&str> = meta.split(' ').collect(); |
| 250 | 159× | if m.len() == 3 { |
| 251 | 159× | out.insert(path.to_string(), (m[0].to_string(), m[2].to_string())); |
| 252 | 159× | } |
| 253 | | } |
| 254 | 70× | Ok(out) |
| 255 | 70× | } |
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | 80× | fn change_id_for(sha: &str, message: &str) -> ChangeId { |
| 260 | 80× | for line in message.lines().rev() { |
| 261 | 80× | if let Some(v) = line.strip_prefix("Change-Id:") { |
| 262 | 4× | if let Some(id) = ChangeId::from_hex(v.trim()) { |
| 263 | 4× | return id; |
| 264 | 0× | } |
| 265 | 76× | } |
| 266 | | } |
| 267 | 76× | let h = blake3::hash(sha.as_bytes()); |
| 268 | 76× | ChangeId(h.as_bytes()[..16].try_into().unwrap()) |
| 269 | 80× | } |
| 270 | |
|
| 271 | |
|
| 272 | | struct GitKnown { |
| 273 | | |
| 274 | | imported: HashMap<String, ChangeHash>, |
| 275 | | |
| 276 | | exported: HashMap<String, ObjectRef>, |
| 277 | | } |
| 278 | |
|
| 279 | | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
| 280 | | pub struct GitExportReport { |
| 281 | | pub exported: usize, |
| 282 | | pub skipped: usize, |
| 283 | | |
| 284 | | pub skipped_subrepos: usize, |
| 285 | | pub branch: String, |
| 286 | | pub heads: usize, |
| 287 | | } |
| 288 | |
|
| 289 | |
|
| 290 | | const MERGE_SHED_COMMITS: usize = 100; |
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | | const KEPT_ATOMS: usize = 1_500_000; |
| 295 | |
|
| 296 | | const KEPT_GRAPHS: usize = 2000; |
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | | const MERGE_BATCH: usize = 500; |
| 303 | |
|
| 304 | | thread_local! { |
| 305 | | |
| 306 | | |
| 307 | | static MERGE_BATCH_OVERRIDE: std::cell::Cell<Option<usize>> = const { std::cell::Cell::new(None) }; |
| 308 | | } |
| 309 | |
|
| 310 | | #[cfg(test)] |
| 311 | 4× | pub(crate) fn set_merge_batch_for_tests(n: Option<usize>) { |
| 312 | 4× | MERGE_BATCH_OVERRIDE.with(|c| c.set(n)); |
| 313 | 4× | } |
| 314 | |
|
| 315 | 45× | fn merge_batch() -> usize { |
| 316 | 45× | MERGE_BATCH_OVERRIDE |
| 317 | 45× | .with(|c| c.get()) |
| 318 | 45× | .filter(|n| *n > 0) |
| 319 | 45× | .or_else(|| { |
| 320 | 19× | std::env::var("OXY_MERGE_BATCH") |
| 321 | 19× | .ok() |
| 322 | 19× | .and_then(|v| v.parse().ok()) |
| 323 | 19× | }) |
| 324 | 45× | .unwrap_or(MERGE_BATCH) |
| 325 | 45× | } |
| 326 | |
|
| 327 | | impl Repo { |
| 328 | | |
| 329 | | |
| 330 | | |
| 331 | | |
| 332 | 7× | fn materialize_batched( |
| 333 | 7× | &self, |
| 334 | 7× | base: &mut State, |
| 335 | 7× | need: &[crate::ids::NodeId], |
| 336 | 7× | skip: &HashSet<crate::ids::NodeId>, |
| 337 | 7× | ) -> Result<crate::state::Snapshot> { |
| 338 | | use crate::graph::Materialized; |
| 339 | | use crate::state::{FileContent, FileState}; |
| 340 | | use rayon::prelude::*; |
| 341 | 7× | let view = base.tree().view(); |
| 342 | 7× | let mut rendered: HashMap<crate::ids::NodeId, (Vec<u8>, Materialized)> = |
| 343 | 7× | HashMap::with_capacity(need.len()); |
| 344 | 7× | let mut keep_built: Vec<crate::ids::NodeId> = Vec::new(); |
| 345 | 18× | for batch in need.chunks(merge_batch()) { |
| 346 | 18× | let t = std::time::Instant::now(); |
| 347 | 18× | let graphs = self.build_graphs_detached(base, batch)?; |
| 348 | 18× | crate::timing::add("render: build graphs, batch", t.elapsed()); |
| 349 | 18× | let t = std::time::Instant::now(); |
| 350 | 18× | let batch_rendered: Vec<(crate::ids::NodeId, Vec<u8>, Materialized)> = graphs |
| 351 | 18× | .par_iter() |
| 352 | 18× | .map(|(node, g)| { |
| 353 | 18× | let (bytes, m) = base.render_graph(g); |
| 354 | 18× | (*node, bytes, m) |
| 355 | 18× | }) |
| 356 | 18× | .collect(); |
| 357 | 18× | drop(graphs); |
| 358 | 18× | crate::timing::add("render: render, batch", t.elapsed()); |
| 359 | 18× | for (node, bytes, m) in batch_rendered { |
| 360 | 18× | if m.is_conflicted() |
| 361 | 18× | || m.live_atoms().len() != crate::diff::split_lines(&bytes).len() |
| 362 | 0× | { |
| 363 | 0× | keep_built.push(node); |
| 364 | 18× | } |
| 365 | 18× | rendered.insert(node, (bytes, m)); |
| 366 | | } |
| 367 | | } |
| 368 | 7× | if !keep_built.is_empty() { |
| 369 | 0× | self.load_graphs_of(base, &keep_built)?; |
| 370 | 7× | } |
| 371 | 7× | let mut files = BTreeMap::new(); |
| 372 | 7× | let mut unrendered = BTreeSet::new(); |
| 373 | 22× | for (path, e) in view.entries.iter() { |
| 374 | 22× | let f = if e.kind == NodeKind::File && !e.mode.opaque { |
| 375 | 22× | match rendered.remove(&e.node) { |
| 376 | 18× | Some((bytes, materialized)) => FileState { |
| 377 | 18× | node: e.node, |
| 378 | 18× | kind: e.kind, |
| 379 | 18× | mode: e.mode, |
| 380 | 18× | content: FileContent::Text { |
| 381 | 18× | bytes, |
| 382 | 18× | materialized, |
| 383 | 18× | }, |
| 384 | 18× | }, |
| 385 | 4× | None if skip.contains(&e.node) => { |
| 386 | 4× | unrendered.insert(path.clone()); |
| 387 | 4× | FileState { |
| 388 | 4× | node: e.node, |
| 389 | 4× | kind: e.kind, |
| 390 | 4× | mode: e.mode, |
| 391 | 4× | content: FileContent::Text { |
| 392 | 4× | bytes: Vec::new(), |
| 393 | 4× | materialized: Materialized::default(), |
| 394 | 4× | }, |
| 395 | 4× | } |
| 396 | | } |
| 397 | | None => { |
| 398 | | |
| 399 | | |
| 400 | 0× | self.load_graphs_of(base, &[e.node])?; |
| 401 | 0× | base.entry_state(e) |
| 402 | | } |
| 403 | | } |
| 404 | | } else { |
| 405 | 0× | base.entry_state(e) |
| 406 | | }; |
| 407 | 22× | files.insert(path.clone(), f); |
| 408 | | } |
| 409 | 7× | Ok(crate::state::Snapshot { |
| 410 | 7× | tree: view, |
| 411 | 7× | files, |
| 412 | 7× | unrendered, |
| 413 | 7× | }) |
| 414 | 7× | } |
| 415 | | } |
| 416 | |
|
| 417 | 145× | fn git(dir: &Path, args: &[&str]) -> Result<String> { |
| 418 | 145× | let out = Command::new("git") |
| 419 | 145× | .arg("-C") |
| 420 | 145× | .arg(dir) |
| 421 | 145× | .args(args) |
| 422 | 145× | .output() |
| 423 | 145× | .map_err(|e| RepoError::Msg(format!("running git: {e}")))?; |
| 424 | 145× | if !out.status.success() { |
| 425 | 0× | return fail(format!( |
| 426 | | "git {} failed: {}", |
| 427 | 0× | args.join(" "), |
| 428 | 0× | String::from_utf8_lossy(&out.stderr).trim() |
| 429 | | )); |
| 430 | 145× | } |
| 431 | 145× | Ok(String::from_utf8_lossy(&out.stdout).trim().to_string()) |
| 432 | 145× | } |
| 433 | |
|
| 434 | | impl Repo { |
| 435 | 41× | fn git_marks_dir(&self, git_dir: &Path) -> Result<PathBuf> { |
| 436 | 41× | let canonical = git_dir |
| 437 | 41× | .canonicalize() |
| 438 | 41× | .unwrap_or_else(|_| git_dir.to_path_buf()); |
| 439 | 41× | let key = hash_object(ObjectType::Chunk, canonical.to_string_lossy().as_bytes()).short(16); |
| 440 | 41× | let dir = self.oxy.join("git").join(key); |
| 441 | 41× | fs::create_dir_all(&dir)?; |
| 442 | 41× | Ok(dir) |
| 443 | 41× | } |
| 444 | |
|
| 445 | | |
| 446 | | |
| 447 | 41× | fn read_git_states(path: &Path) -> Result<BTreeMap<ObjectRef, String>> { |
| 448 | 41× | let mut out = BTreeMap::new(); |
| 449 | 41× | if let Ok(text) = fs::read_to_string(path) { |
| 450 | 12× | for line in text.lines() { |
| 451 | 12× | if let Some((h, sha)) = line.split_once(' ') { |
| 452 | 12× | if let Some(h) = ObjectRef::from_hex(h) { |
| 453 | 12× | out.insert(h, sha.trim().to_string()); |
| 454 | 12× | } |
| 455 | 0× | } |
| 456 | | } |
| 457 | 31× | } |
| 458 | 41× | Ok(out) |
| 459 | 41× | } |
| 460 | |
|
| 461 | 13× | fn record_git_state(&self, git_dir: &Path, state: &ObjectRef, sha: &str) -> Result<()> { |
| 462 | 13× | let path = self.git_marks_dir(git_dir)?.join("git-states"); |
| 463 | 13× | let mut states = Self::read_git_states(&path)?; |
| 464 | 13× | states.insert(*state, sha.to_string()); |
| 465 | 13× | let text: String = states |
| 466 | 13× | .iter() |
| 467 | 14× | .map(|(h, s)| format!("{} {s}\n", h.to_hex())) |
| 468 | 13× | .collect(); |
| 469 | 13× | write_atomic(&path, text.as_bytes()) |
| 470 | 13× | } |
| 471 | |
|
| 472 | | |
| 473 | 7× | fn git_mirror(&self, url: &str) -> Result<PathBuf> { |
| 474 | 7× | let key = hash_object(ObjectType::Chunk, url.as_bytes()).short(16); |
| 475 | 7× | let dir = self.oxy.join("git").join(key).join("mirror.git"); |
| 476 | 7× | if !dir.join("HEAD").exists() { |
| 477 | 1× | fs::create_dir_all(&dir)?; |
| 478 | 1× | git(&dir, &["init", "--bare", "-q"])?; |
| 479 | 6× | } |
| 480 | 7× | Ok(dir) |
| 481 | 7× | } |
| 482 | |
|
| 483 | | |
| 484 | 26× | pub(crate) fn imported_commits(&self) -> Result<HashMap<String, ChangeHash>> { |
| 485 | 26× | let mut map = HashMap::new(); |
| 486 | 100× | for e in self.log()? { |
| 487 | 100× | if e.is_working_copy { |
| 488 | 26× | continue; |
| 489 | 74× | } |
| 490 | 74× | if let Some(sha) = e |
| 491 | 74× | .change |
| 492 | 74× | .message |
| 493 | 74× | .lines() |
| 494 | 74× | .rev() |
| 495 | 142× | .find_map(|l| l.strip_prefix("Git-Commit: ")) |
| 496 | 68× | { |
| 497 | 68× | map.insert(sha.trim().to_string(), e.hash); |
| 498 | 68× | } |
| 499 | | } |
| 500 | 26× | Ok(map) |
| 501 | 26× | } |
| 502 | |
|
| 503 | | |
| 504 | | |
| 505 | 7× | fn git_mirror_fetch(&self, mirror: &Path, url: &str, branch: &str) -> Result<()> { |
| 506 | 7× | let spec = format!("+refs/heads/{branch}:refs/heads/{branch}"); |
| 507 | 7× | match git(mirror, &["fetch", "-q", url, &spec]) { |
| 508 | 7× | Ok(_) => Ok(()), |
| 509 | 0× | Err(e) => { |
| 510 | 0× | let ls = git(mirror, &["ls-remote", "--heads", url, branch]).unwrap_or_default(); |
| 511 | 0× | if ls.trim().is_empty() { |
| 512 | 0× | Ok(()) |
| 513 | | } else { |
| 514 | 0× | Err(e) |
| 515 | | } |
| 516 | | } |
| 517 | | } |
| 518 | 7× | } |
| 519 | |
|
| 520 | | |
| 521 | | |
| 522 | | |
| 523 | | |
| 524 | 3× | pub fn git_fetch(&self, url: &str, branch: &str) -> Result<GitImportReport> { |
| 525 | 3× | let mirror = self.git_mirror(url)?; |
| 526 | 3× | self.git_mirror_fetch(&mirror, url, branch)?; |
| 527 | 3× | if git( |
| 528 | 3× | &mirror, |
| 529 | 3× | &[ |
| 530 | 3× | "rev-parse", |
| 531 | 3× | "--verify", |
| 532 | 3× | "-q", |
| 533 | 3× | &format!("refs/heads/{branch}"), |
| 534 | 3× | ], |
| 535 | 3× | ) |
| 536 | 3× | .is_err() |
| 537 | | { |
| 538 | 0× | return fail(format!("{url} has no branch {branch:?}")); |
| 539 | 3× | } |
| 540 | 3× | self.import_git_commits( |
| 541 | 3× | &mirror, |
| 542 | 3× | branch, |
| 543 | 3× | &format!("oxy git fetch {url} {branch}"), |
| 544 | 1× | &mut |_| {}, |
| 545 | | ) |
| 546 | 3× | } |
| 547 | |
|
| 548 | | |
| 549 | | |
| 550 | | |
| 551 | 4× | pub fn git_push(&self, url: &str, branch: &str) -> Result<GitExportReport> { |
| 552 | 4× | let mirror = self.git_mirror(url)?; |
| 553 | 4× | self.git_mirror_fetch(&mirror, url, branch)?; |
| 554 | 4× | if let Ok(tip) = git( |
| 555 | 4× | &mirror, |
| 556 | 4× | &[ |
| 557 | 4× | "rev-parse", |
| 558 | 4× | "--verify", |
| 559 | 4× | "-q", |
| 560 | 4× | &format!("refs/heads/{branch}"), |
| 561 | 4× | ], |
| 562 | 4× | ) { |
| 563 | 4× | let known = self.git_known(&mirror)?; |
| 564 | 4× | if !known.imported.contains_key(&tip) && !known.exported.contains_key(&tip) { |
| 565 | 1× | return fail(format!( |
| 566 | | "{url} {branch} has commits not yet fetched; run `oxy git fetch {url}` first" |
| 567 | | )); |
| 568 | 3× | } |
| 569 | 0× | } |
| 570 | 3× | let report = self.git_export_as(&mirror, branch)?; |
| 571 | 3× | let spec = format!("refs/heads/{branch}:refs/heads/{branch}"); |
| 572 | 3× | git(&mirror, &["push", "-q", url, &spec])?; |
| 573 | 3× | Ok(report) |
| 574 | 4× | } |
| 575 | |
|
| 576 | 28× | fn read_oxy_marks(path: &Path) -> Result<BTreeMap<ObjectRef, u64>> { |
| 577 | 28× | let mut out = BTreeMap::new(); |
| 578 | 28× | if let Ok(text) = fs::read_to_string(path) { |
| 579 | 13× | for line in text.lines() { |
| 580 | 13× | if let Some((h, m)) = line.split_once(' ') { |
| 581 | 13× | if let (Some(h), Ok(m)) = (ObjectRef::from_hex(h), m.parse()) { |
| 582 | 13× | out.insert(h, m); |
| 583 | 13× | } |
| 584 | 0× | } |
| 585 | | } |
| 586 | 19× | } |
| 587 | 28× | Ok(out) |
| 588 | 28× | } |
| 589 | |
|
| 590 | | |
| 591 | | |
| 592 | | |
| 593 | | |
| 594 | 7× | pub fn git_export(&self, git_dir: &Path) -> Result<GitExportReport> { |
| 595 | 7× | let bookmark = self.config.bookmark.clone(); |
| 596 | 7× | self.git_export_as(git_dir, &bookmark) |
| 597 | 7× | } |
| 598 | |
|
| 599 | | |
| 600 | | |
| 601 | | |
| 602 | 10× | pub fn git_export_as(&self, git_dir: &Path, branch: &str) -> Result<GitExportReport> { |
| 603 | 10× | if !git_dir.join("HEAD").exists() && !git_dir.join(".git").exists() { |
| 604 | 4× | fs::create_dir_all(git_dir)?; |
| 605 | 4× | git(git_dir, &["init", "--bare", "-q"])?; |
| 606 | 6× | } |
| 607 | 10× | let marks_dir = self.git_marks_dir(git_dir)?; |
| 608 | 10× | let git_marks = marks_dir.join("git-marks"); |
| 609 | 10× | let oxy_marks_path = marks_dir.join("oxy-marks"); |
| 610 | 10× | let mut marks = Self::read_oxy_marks(&oxy_marks_path)?; |
| 611 | 10× | let git_states = Self::read_git_states(&marks_dir.join("git-states"))?; |
| 612 | 10× | let mut next_mark = marks.values().copied().max().unwrap_or(0) + 1; |
| 613 | |
|
| 614 | 10× | let bookmark = self.config.bookmark.clone(); |
| 615 | 10× | let mut stream: Vec<u8> = Vec::new(); |
| 616 | 10× | let mut report = GitExportReport { |
| 617 | 10× | branch: branch.to_string(), |
| 618 | 10× | heads: self.bookmark_heads()?.len(), |
| 619 | 10× | ..Default::default() |
| 620 | | }; |
| 621 | |
|
| 622 | | |
| 623 | 10× | let mut ops = self.op_log()?; |
| 624 | 10× | ops.reverse(); |
| 625 | 10× | let mut prev: Option<(ObjectRef, Vec<ChangeHash>)> = None; |
| 626 | | |
| 627 | 10× | let mut last_parent: Option<String> = None; |
| 628 | 44× | for (_, op) in &ops { |
| 629 | 44× | let Some(state_ref) = op.view.bookmarks.get(&bookmark).copied() else { |
| 630 | 0× | continue; |
| 631 | | }; |
| 632 | 44× | if prev.as_ref().is_some_and(|(p, _)| *p == state_ref) { |
| 633 | 12× | continue; |
| 634 | 32× | } |
| 635 | 32× | let Ok(state) = self.store.get_state(&state_ref) else { |
| 636 | 0× | continue; |
| 637 | | }; |
| 638 | 32× | if state.heads.is_empty() { |
| 639 | 10× | prev = Some((state_ref, vec![])); |
| 640 | 10× | continue; |
| 641 | 22× | } |
| 642 | 22× | if let Some(sha) = git_states.get(&state_ref) { |
| 643 | 4× | report.skipped += 1; |
| 644 | 4× | last_parent = Some(sha.clone()); |
| 645 | 4× | prev = Some((state_ref, state.heads.clone())); |
| 646 | 4× | continue; |
| 647 | 18× | } |
| 648 | 18× | if let Some(m) = marks.get(&state_ref) { |
| 649 | 9× | report.skipped += 1; |
| 650 | 9× | last_parent = Some(format!(":{m}")); |
| 651 | 9× | prev = Some((state_ref, state.heads.clone())); |
| 652 | 9× | continue; |
| 653 | 9× | } |
| 654 | 9× | let prev_heads = prev.as_ref().map(|(_, h)| h.clone()).unwrap_or_default(); |
| 655 | 9× | let added = self |
| 656 | 9× | .negotiate(&prev_heads, &state.heads) |
| 657 | 9× | .unwrap_or_default(); |
| 658 | 9× | let loaded = self.load_state(&state.heads)?; |
| 659 | 9× | let snapshot = loaded.materialize(); |
| 660 | 9× | let (author, secs, mut message) = match added.as_slice() { |
| 661 | 6× | [h] => { |
| 662 | 6× | let c = self.store.get_change(h)?; |
| 663 | 6× | let mut m = c.message.clone(); |
| 664 | 6× | if !m.ends_with('\n') { |
| 665 | 6× | m.push('\n'); |
| 666 | 6× | } |
| 667 | 6× | m.push_str(&format!( |
| 668 | 6× | "\nChange-Id: {}\nOxy-Hash: {}\n", |
| 669 | 6× | c.change_id.to_hex(), |
| 670 | 6× | h.to_hex() |
| 671 | 6× | )); |
| 672 | 6× | (self.git_author(&c), c.hlc.wall_ms / 1000, m) |
| 673 | | } |
| 674 | 3× | [] => ( |
| 675 | 0× | "oxy <oxy@localhost>".to_string(), |
| 676 | 0× | op.hlc.wall_ms / 1000, |
| 677 | 0× | format!("oxy: {}\n\n", op.command), |
| 678 | 0× | ), |
| 679 | 3× | many => { |
| 680 | 3× | let mut m = format!("oxy: {} ({} changes)\n\n", op.command, many.len()); |
| 681 | 22× | for h in many { |
| 682 | 22× | let c = self.store.get_change(h)?; |
| 683 | 22× | m.push_str(&format!( |
| 684 | 22× | "- {} {}\n", |
| 685 | 22× | c.change_id.short(8), |
| 686 | 22× | c.message.lines().next().unwrap_or("") |
| 687 | 22× | )); |
| 688 | | } |
| 689 | 3× | m.push_str(&format!( |
| 690 | | "\nOxy-Changes: {}\n", |
| 691 | 3× | many.iter() |
| 692 | 22× | .map(|h| h.to_hex()) |
| 693 | 3× | .collect::<Vec<_>>() |
| 694 | 3× | .join(" ") |
| 695 | | )); |
| 696 | 3× | ("oxy <oxy@localhost>".to_string(), op.hlc.wall_ms / 1000, m) |
| 697 | | } |
| 698 | | }; |
| 699 | 9× | message.push_str(&format!("Oxy-State: {}\n", state_ref.to_hex())); |
| 700 | 9× | if snapshot.is_conflicted() { |
| 701 | 0× | message.push_str("Oxy-Conflicted: true\n"); |
| 702 | 9× | } |
| 703 | 9× | let mark = next_mark; |
| 704 | 9× | next_mark += 1; |
| 705 | 9× | let parents: Vec<String> = last_parent.clone().into_iter().collect(); |
| 706 | 9× | self.write_commit( |
| 707 | 9× | &mut stream, |
| 708 | 9× | "refs/oxy/export", |
| 709 | 9× | mark, |
| 710 | 9× | &author, |
| 711 | 9× | secs, |
| 712 | 9× | &message, |
| 713 | 9× | &parents, |
| 714 | 9× | &snapshot, |
| 715 | 0× | )?; |
| 716 | 9× | marks.insert(state_ref, mark); |
| 717 | 9× | last_parent = Some(format!(":{mark}")); |
| 718 | 9× | prev = Some((state_ref, state.heads.clone())); |
| 719 | 9× | report.exported += 1; |
| 720 | | } |
| 721 | 10× | if let Some(p) = &last_parent { |
| 722 | 10× | stream.extend_from_slice(format!("reset refs/heads/{branch}\nfrom {p}\n\n").as_bytes()); |
| 723 | 10× | } |
| 724 | | |
| 725 | | |
| 726 | 10× | for t in self.tags()? { |
| 727 | 0× | let target = match (git_states.get(&t.state), marks.get(&t.state)) { |
| 728 | 0× | (Some(sha), _) => sha.clone(), |
| 729 | 0× | (None, Some(m)) => format!(":{m}"), |
| 730 | | (None, None) => { |
| 731 | 0× | let loaded = self.load_state(&t.heads)?; |
| 732 | 0× | let snapshot = loaded.materialize(); |
| 733 | 0× | let mark = next_mark; |
| 734 | 0× | next_mark += 1; |
| 735 | 0× | let message = format!( |
| 736 | | "oxy: tag {}\n\n{}Oxy-State: {}\n", |
| 737 | | t.name, |
| 738 | 0× | if t.message.is_empty() { |
| 739 | 0× | String::new() |
| 740 | | } else { |
| 741 | 0× | format!("{}\n\n", t.message) |
| 742 | | }, |
| 743 | 0× | t.state.to_hex() |
| 744 | | ); |
| 745 | 0× | self.write_commit( |
| 746 | 0× | &mut stream, |
| 747 | 0× | "refs/oxy/export", |
| 748 | 0× | mark, |
| 749 | 0× | "oxy <oxy@localhost>", |
| 750 | 0× | Hlc::now().wall_ms / 1000, |
| 751 | 0× | &message, |
| 752 | 0× | &[], |
| 753 | 0× | &snapshot, |
| 754 | 0× | )?; |
| 755 | 0× | marks.insert(t.state, mark); |
| 756 | 0× | report.exported += 1; |
| 757 | 0× | format!(":{mark}") |
| 758 | | } |
| 759 | | }; |
| 760 | 0× | stream.extend_from_slice( |
| 761 | 0× | format!("reset refs/tags/{}\nfrom {target}\n\n", t.name).as_bytes(), |
| 762 | | ); |
| 763 | | } |
| 764 | 10× | stream.extend_from_slice(b"done\n"); |
| 765 | |
|
| 766 | 10× | let mut cmd = Command::new("git"); |
| 767 | | |
| 768 | 10× | cmd.arg("-C") |
| 769 | 10× | .arg(git_dir) |
| 770 | 10× | .args(["fast-import", "--quiet", "--done", "--force"]) |
| 771 | 10× | .arg(format!("--export-marks={}", git_marks.display())); |
| 772 | 10× | if git_marks.exists() { |
| 773 | 5× | cmd.arg(format!("--import-marks={}", git_marks.display())); |
| 774 | 5× | } |
| 775 | 10× | let mut child = cmd |
| 776 | 10× | .stdin(Stdio::piped()) |
| 777 | 10× | .stdout(Stdio::null()) |
| 778 | 10× | .stderr(Stdio::piped()) |
| 779 | 10× | .spawn() |
| 780 | 10× | .map_err(|e| RepoError::Msg(format!("running git fast-import: {e}")))?; |
| 781 | 10× | child.stdin.take().unwrap().write_all(&stream)?; |
| 782 | 10× | let out = child.wait_with_output()?; |
| 783 | 10× | if !out.status.success() { |
| 784 | 0× | return fail(format!( |
| 785 | | "git fast-import failed: {}", |
| 786 | 0× | String::from_utf8_lossy(&out.stderr).trim() |
| 787 | | )); |
| 788 | 10× | } |
| 789 | 10× | let text: String = marks |
| 790 | 10× | .iter() |
| 791 | 18× | .map(|(h, m)| format!("{} {m}\n", h.to_hex())) |
| 792 | 10× | .collect(); |
| 793 | 10× | write_atomic(&oxy_marks_path, text.as_bytes())?; |
| 794 | 10× | let _ = git(git_dir, &["update-ref", "-d", "refs/oxy/export"]); |
| 795 | 10× | report.skipped_subrepos = self.git_export_skipped.replace(0); |
| 796 | 10× | Ok(report) |
| 797 | 10× | } |
| 798 | |
|
| 799 | | |
| 800 | | |
| 801 | | |
| 802 | | |
| 803 | 11× | pub fn import_git(&self, git_dir: &Path, branch: &str) -> Result<GitImportReport> { |
| 804 | 11× | self.import_git_with(git_dir, branch, &mut |_| {}) |
| 805 | 11× | } |
| 806 | |
|
| 807 | | |
| 808 | | |
| 809 | | |
| 810 | 11× | pub fn import_git_with( |
| 811 | 11× | &self, |
| 812 | 11× | git_dir: &Path, |
| 813 | 11× | branch: &str, |
| 814 | 11× | progress: crate::store::Progress<'_>, |
| 815 | 11× | ) -> Result<GitImportReport> { |
| 816 | 11× | if !self.bookmark_heads()?.is_empty() { |
| 817 | 0× | return fail("git import needs an empty bookmark; import into a fresh repository"); |
| 818 | 11× | } |
| 819 | 11× | self.import_git_commits( |
| 820 | 11× | git_dir, |
| 821 | 11× | branch, |
| 822 | 11× | &format!("oxy git import {} {branch}", git_dir.display()), |
| 823 | 11× | progress, |
| 824 | | ) |
| 825 | 11× | } |
| 826 | |
|
| 827 | | |
| 828 | | |
| 829 | 14× | fn import_git_commits( |
| 830 | 14× | &self, |
| 831 | 14× | git_dir: &Path, |
| 832 | 14× | branch: &str, |
| 833 | 14× | command: &str, |
| 834 | 14× | progress: crate::store::Progress<'_>, |
| 835 | 14× | ) -> Result<GitImportReport> { |
| 836 | 14× | let batch = self.store.begin_batch()?; |
| 837 | 14× | let result = self.import_git_commits_batched(git_dir, branch, command, progress); |
| 838 | 14× | batch.finish()?; |
| 839 | 14× | result |
| 840 | 14× | } |
| 841 | |
|
| 842 | 14× | fn import_git_commits_batched( |
| 843 | 14× | &self, |
| 844 | 14× | git_dir: &Path, |
| 845 | 14× | branch: &str, |
| 846 | 14× | command: &str, |
| 847 | 14× | progress: crate::store::Progress<'_>, |
| 848 | 14× | ) -> Result<GitImportReport> { |
| 849 | 14× | let commits = list_commits(git_dir, branch)?; |
| 850 | 14× | let mut cat = CatFile::start(git_dir)?; |
| 851 | 14× | let mut report = GitImportReport::default(); |
| 852 | 14× | let mut known = self.git_known(git_dir)?; |
| 853 | 14× | let old_heads = self.bookmark_heads()?; |
| 854 | | |
| 855 | | |
| 856 | | |
| 857 | 14× | let mut heads_now: BTreeSet<ChangeHash> = old_heads.iter().copied().collect(); |
| 858 | | |
| 859 | | |
| 860 | | |
| 861 | | |
| 862 | | |
| 863 | | |
| 864 | 14× | let max_kept: usize = std::env::var("OXY_IMPORT_KEEP") |
| 865 | 14× | .ok() |
| 866 | 14× | .and_then(|v| v.parse().ok()) |
| 867 | 14× | .unwrap_or(8); |
| 868 | 14× | let mut waiting: HashMap<&str, usize> = HashMap::new(); |
| 869 | 85× | for gc in &commits { |
| 870 | 85× | if let Some(p1) = gc.parents.first() { |
| 871 | 69× | *waiting.entry(p1.as_str()).or_default() += 1; |
| 872 | 69× | } |
| 873 | | } |
| 874 | | type Kept = (State, BTreeMap<String, (String, String)>); |
| 875 | 14× | let mut kept: HashMap<String, Kept> = HashMap::new(); |
| 876 | | |
| 877 | 14× | let pairs: Vec<(String, String)> = commits |
| 878 | 14× | .iter() |
| 879 | 85× | .filter(|gc| { |
| 880 | 85× | !known.imported.contains_key(&gc.sha) && !known.exported.contains_key(&gc.sha) |
| 881 | 85× | }) |
| 882 | 80× | .filter_map(|gc| Some((gc.sha.clone(), gc.parents.first()?.clone()))) |
| 883 | 14× | .collect(); |
| 884 | 14× | let mut diffs = DiffTree::start(git_dir, pairs)?; |
| 885 | 14× | let mut rebuilt = 0usize; |
| 886 | 14× | let mut kept_order: std::collections::VecDeque<String> = std::collections::VecDeque::new(); |
| 887 | 14× | let mut last: Option<String> = None; |
| 888 | 14× | let mut blob_cache: HashMap<String, Vec<u8>> = HashMap::new(); |
| 889 | 14× | let mut cache_bytes: usize = 0; |
| 890 | | |
| 891 | 14× | let mut spent = [std::time::Duration::ZERO; 6]; |
| 892 | 14× | let mut clock = std::time::Instant::now(); |
| 893 | | |
| 894 | | |
| 895 | | |
| 896 | 14× | let trace = std::env::var_os("OXY_IMPORT_TRACE").is_some(); |
| 897 | 14× | let rss_mb = || -> u64 { |
| 898 | 0× | std::fs::read_to_string("/proc/self/statm") |
| 899 | 0× | .ok() |
| 900 | 0× | .and_then(|s| s.split_whitespace().nth(1)?.parse::<u64>().ok()) |
| 901 | 0× | .map(|pages| (pages * 4096) >> 20) |
| 902 | 0× | .unwrap_or(0) |
| 903 | 0× | }; |
| 904 | 14× | let mut done = 0usize; |
| 905 | | |
| 906 | | |
| 907 | 14× | let kept_atoms: usize = std::env::var("OXY_IMPORT_KEPT_ATOMS") |
| 908 | 14× | .ok() |
| 909 | 14× | .and_then(|v| v.parse().ok()) |
| 910 | 14× | .unwrap_or(KEPT_ATOMS); |
| 911 | | |
| 912 | 14× | let mut shed = 0usize; |
| 913 | 480× | let mut lap = |i: usize, clock: &mut std::time::Instant| { |
| 914 | 480× | let now = std::time::Instant::now(); |
| 915 | 480× | spent[i] += now - *clock; |
| 916 | 480× | *clock = now; |
| 917 | 480× | }; |
| 918 | |
|
| 919 | 14× | let total = commits.len(); |
| 920 | 85× | for (index, gc) in commits.iter().enumerate() { |
| 921 | 85× | if known.imported.contains_key(&gc.sha) || known.exported.contains_key(&gc.sha) { |
| 922 | 5× | continue; |
| 923 | 80× | } |
| 924 | 80× | if index % 500 == 0 { |
| 925 | 12× | progress(&format!( |
| 926 | 12× | "{index} of {total} commits, {} merges; at {} {}", |
| 927 | 12× | report.merges, |
| 928 | 12× | &gc.sha[..12.min(gc.sha.len())], |
| 929 | 12× | gc.message |
| 930 | 12× | .lines() |
| 931 | 12× | .next() |
| 932 | 12× | .unwrap_or("") |
| 933 | 12× | .chars() |
| 934 | 12× | .take(60) |
| 935 | 12× | .collect::<String>() |
| 936 | 12× | )); |
| 937 | 68× | } |
| 938 | 80× | let mut base_how = "root"; |
| 939 | | |
| 940 | | |
| 941 | | |
| 942 | 80× | let (mut base, prev_tree) = match gc.parents.first() { |
| 943 | 66× | Some(p1) => { |
| 944 | 66× | let left = waiting.get_mut(p1.as_str()).map(|n| { |
| 945 | 66× | *n -= 1; |
| 946 | 66× | *n |
| 947 | 66× | }); |
| 948 | 66× | let found = if left == Some(0) { |
| 949 | 65× | kept_order.retain(|k| k != p1); |
| 950 | 47× | kept.remove(p1.as_str()) |
| 951 | | } else { |
| 952 | 19× | kept.get(p1.as_str()).cloned() |
| 953 | | }; |
| 954 | 66× | let how = match (&found, left) { |
| 955 | 46× | (Some(_), Some(0)) => "kept", |
| 956 | 19× | (Some(_), _) => "cloned", |
| 957 | 1× | (None, _) => "rebuilt", |
| 958 | | }; |
| 959 | 66× | if trace { |
| 960 | 0× | base_how = how; |
| 961 | 66× | } |
| 962 | 66× | match found { |
| 963 | 65× | Some((st, tree)) => (st, Some(tree)), |
| 964 | | None => { |
| 965 | | |
| 966 | | |
| 967 | | |
| 968 | 1× | let mut st = State::new_history_only(); |
| 969 | 1× | self.add_git_ancestors(&mut st, git_dir, &[p1.as_str()], &known)?; |
| 970 | | |
| 971 | | |
| 972 | 1× | rebuilt += 1; |
| 973 | 1× | (st, Some(list_tree(git_dir, p1)?)) |
| 974 | | } |
| 975 | | } |
| 976 | | } |
| 977 | 14× | None => (State::new_history_only(), None), |
| 978 | | }; |
| 979 | | |
| 980 | | |
| 981 | 80× | let mut touched: HashSet<NodeId> = HashSet::new(); |
| 982 | 80× | let mut merged = 0usize; |
| 983 | 80× | if gc.parents.len() > 1 { |
| 984 | 23× | report.merges += 1; |
| 985 | 23× | let mut args: Vec<String> = gc.parents[1..].to_vec(); |
| 986 | 23× | args.push(format!("^{}", gc.parents[0])); |
| 987 | 23× | let refs: Vec<&str> = args.iter().map(String::as_str).collect(); |
| 988 | | |
| 989 | | |
| 990 | | |
| 991 | | |
| 992 | | |
| 993 | | |
| 994 | 23× | if base.built_count() > 0 { |
| 995 | 19× | let mut count_args = vec!["rev-list", "--count"]; |
| 996 | 19× | count_args.extend(refs.iter().copied()); |
| 997 | 19× | let others: usize = git(git_dir, &count_args)?.trim().parse().unwrap_or(0); |
| 998 | 19× | let shed_at = std::env::var("OXY_MERGE_SHED") |
| 999 | 19× | .ok() |
| 1000 | 19× | .and_then(|v| v.parse().ok()) |
| 1001 | 19× | .unwrap_or(MERGE_SHED_COMMITS); |
| 1002 | 19× | if others > shed_at { |
| 1003 | 0× | shed += base.shed_graphs(|b| self.store_blob(b))?; |
| 1004 | 19× | } |
| 1005 | 4× | } |
| 1006 | 23× | let before = base.len(); |
| 1007 | 23× | self.add_git_ancestors_touching(&mut base, git_dir, &refs, &known, &mut touched)?; |
| 1008 | 23× | merged = base.len() - before; |
| 1009 | 57× | } |
| 1010 | 80× | lap(0, &mut clock); |
| 1011 | | |
| 1012 | | |
| 1013 | 80× | let diff = match gc.parents.first() { |
| 1014 | 66× | Some(_) => Some(diffs.diff(&gc.sha)?), |
| 1015 | 14× | None => None, |
| 1016 | | }; |
| 1017 | 80× | let (tree, changed) = match (prev_tree, diff) { |
| 1018 | 66× | (Some(mut t), Some(diff)) => { |
| 1019 | 66× | let mut changed: HashSet<String> = HashSet::new(); |
| 1020 | 82× | for (path, entry) in diff { |
| 1021 | 82× | match entry { |
| 1022 | 68× | Some(v) => { |
| 1023 | 68× | t.insert(path.clone(), v); |
| 1024 | 68× | } |
| 1025 | 14× | None => { |
| 1026 | 14× | t.remove(&path); |
| 1027 | 14× | } |
| 1028 | | } |
| 1029 | 82× | changed.insert(path); |
| 1030 | | } |
| 1031 | 66× | (t, Some(changed)) |
| 1032 | | } |
| 1033 | 14× | _ => (list_tree(git_dir, &gc.sha)?, None), |
| 1034 | | }; |
| 1035 | 80× | lap(1, &mut clock); |
| 1036 | | |
| 1037 | | |
| 1038 | | |
| 1039 | | |
| 1040 | 80× | let mut same: HashMap<&str, NodeId> = HashMap::new(); |
| 1041 | | |
| 1042 | | |
| 1043 | 80× | let mut same_opaque: HashSet<&str> = HashSet::new(); |
| 1044 | | |
| 1045 | | |
| 1046 | | |
| 1047 | | |
| 1048 | | |
| 1049 | 80× | let partial = changed.is_some() |
| 1050 | 66× | && gc.parents.len() == 1 |
| 1051 | 107× | && !tree.values().any(|(mode, _)| mode == "160000"); |
| 1052 | 80× | let mut rel: BTreeSet<&str> = BTreeSet::new(); |
| 1053 | 80× | let base_snapshot = if let (true, Some(changed)) = (partial, &changed) { |
| 1054 | 42× | let view = base.tree().view(); |
| 1055 | 42× | rel.extend(changed.iter().map(String::as_str)); |
| 1056 | 42× | rel.extend( |
| 1057 | 42× | tree.keys() |
| 1058 | 42× | .map(String::as_str) |
| 1059 | 104× | .filter(|p| *p == ".oxyattributes" || p.ends_with("/.oxyattributes")), |
| 1060 | | ); |
| 1061 | 42× | let mut dirs: BTreeSet<&str> = BTreeSet::new(); |
| 1062 | 61× | for p in changed.iter().filter(|p| !tree.contains_key(*p)) { |
| 1063 | 14× | let mut end = p.len(); |
| 1064 | 24× | while let Some(i) = p[..end].rfind('/') { |
| 1065 | 10× | if !dirs.insert(&p[..i]) { |
| 1066 | 0× | break; |
| 1067 | 10× | } |
| 1068 | 10× | end = i; |
| 1069 | | } |
| 1070 | | } |
| 1071 | 42× | let need: Vec<NodeId> = rel |
| 1072 | 42× | .iter() |
| 1073 | 61× | .filter_map(|p| view.entries.get(*p)) |
| 1074 | 42× | .filter(|e| e.kind == NodeKind::File && !e.mode.opaque) |
| 1075 | 42× | .map(|e| e.node) |
| 1076 | 42× | .collect(); |
| 1077 | 42× | crate::timing::add("render: same and need", clock.elapsed()); |
| 1078 | 42× | let t = std::time::Instant::now(); |
| 1079 | 42× | self.load_graphs_of(&mut base, &need)?; |
| 1080 | 42× | crate::timing::add("render: load graphs", t.elapsed()); |
| 1081 | 42× | let t = std::time::Instant::now(); |
| 1082 | 42× | let snap = base.materialize_paths(view, rel.iter().chain(dirs.iter()).copied()); |
| 1083 | 42× | crate::timing::add("render: materialize", t.elapsed()); |
| 1084 | 42× | snap |
| 1085 | | } else { |
| 1086 | 38× | if let Some(changed) = &changed { |
| 1087 | 24× | let view = base.tree().view(); |
| 1088 | 73× | for path in tree.keys() { |
| 1089 | | |
| 1090 | 73× | if changed.contains(path) || path == ".gitmodules" || path == ".oxymodules" |
| 1091 | | { |
| 1092 | 21× | continue; |
| 1093 | 52× | } |
| 1094 | 52× | if let Some(e) = view.entries.get(path) { |
| 1095 | 48× | if touched.contains(&e.node) { |
| 1096 | 8× | continue; |
| 1097 | 40× | } |
| 1098 | 40× | let opaque = e.kind == NodeKind::Symlink |
| 1099 | 40× | || (e.kind == NodeKind::File && e.mode.opaque); |
| 1100 | 40× | if e.kind == NodeKind::File && !e.mode.opaque { |
| 1101 | 32× | same.insert(path.as_str(), e.node); |
| 1102 | 32× | } else if opaque && base.live_blobs(&e.node).len() == 1 { |
| 1103 | 8× | same_opaque.insert(path.as_str()); |
| 1104 | 8× | } |
| 1105 | 4× | } |
| 1106 | | } |
| 1107 | 14× | } |
| 1108 | | |
| 1109 | 38× | let skip: HashSet<NodeId> = same.values().copied().collect(); |
| 1110 | 38× | let need: Vec<NodeId> = base |
| 1111 | 38× | .tree() |
| 1112 | 38× | .view() |
| 1113 | 38× | .entries |
| 1114 | 38× | .values() |
| 1115 | 88× | .filter(|e| { |
| 1116 | 88× | e.kind == NodeKind::File && !e.mode.opaque && !skip.contains(&e.node) |
| 1117 | 88× | }) |
| 1118 | 38× | .map(|e| e.node) |
| 1119 | 38× | .collect(); |
| 1120 | 38× | crate::timing::add("render: same and need", clock.elapsed()); |
| 1121 | 38× | let t = std::time::Instant::now(); |
| 1122 | 38× | let snap = if need.len() > merge_batch() { |
| 1123 | | |
| 1124 | | |
| 1125 | 7× | self.materialize_batched(&mut base, &need, &skip)? |
| 1126 | | } else { |
| 1127 | 31× | self.load_graphs_of(&mut base, &need)?; |
| 1128 | 31× | base.materialize_except(&skip) |
| 1129 | | }; |
| 1130 | 38× | crate::timing::add("render: whole tree", t.elapsed()); |
| 1131 | 38× | snap |
| 1132 | | }; |
| 1133 | |
|
| 1134 | 80× | lap(2, &mut clock); |
| 1135 | | |
| 1136 | 80× | let mut entries: BTreeMap<String, FsEntry> = BTreeMap::new(); |
| 1137 | 80× | let mut gitlinks: Vec<(String, String)> = Vec::new(); |
| 1138 | 80× | let listed: Box<dyn Iterator<Item = (&String, &(String, String))>> = if partial { |
| 1139 | 61× | Box::new(rel.iter().filter_map(|p| tree.get_key_value(*p))) |
| 1140 | | } else { |
| 1141 | 38× | Box::new(tree.iter()) |
| 1142 | | }; |
| 1143 | 145× | for (path, (mode, sha)) in listed { |
| 1144 | 145× | let (path, sha) = (path.clone(), sha.clone()); |
| 1145 | 145× | let (kind, exec) = match mode.as_str() { |
| 1146 | 145× | "100644" | "100664" => (NodeKind::File, false), |
| 1147 | 21× | "100755" => (NodeKind::File, true), |
| 1148 | 1× | "120000" => (NodeKind::Symlink, false), |
| 1149 | 1× | "160000" => { |
| 1150 | 1× | gitlinks.push((path, sha)); |
| 1151 | 1× | continue; |
| 1152 | | } |
| 1153 | 0× | _ => continue, |
| 1154 | | }; |
| 1155 | 144× | if same.contains_key(path.as_str()) || same_opaque.contains(path.as_str()) { |
| 1156 | 40× | let mut e = FsEntry::new(kind, exec, Vec::new()); |
| 1157 | 40× | e.unchanged = true; |
| 1158 | 40× | entries.insert(path, e); |
| 1159 | 40× | continue; |
| 1160 | 104× | } |
| 1161 | 104× | let content = match blob_cache.get(&sha) { |
| 1162 | 32× | Some(c) => c.clone(), |
| 1163 | | None => { |
| 1164 | 72× | let c = cat.read(&sha)?; |
| 1165 | 72× | if cache_bytes + c.len() > 64 * 1024 * 1024 { |
| 1166 | 0× | blob_cache.clear(); |
| 1167 | 0× | cache_bytes = 0; |
| 1168 | 72× | } |
| 1169 | 72× | cache_bytes += c.len(); |
| 1170 | 72× | blob_cache.insert(sha.clone(), c.clone()); |
| 1171 | 72× | c |
| 1172 | | } |
| 1173 | | }; |
| 1174 | 104× | entries.insert(path, FsEntry::new(kind, exec, content)); |
| 1175 | | } |
| 1176 | |
|
| 1177 | | |
| 1178 | | |
| 1179 | 80× | if !gitlinks.is_empty() { |
| 1180 | 1× | report.submodules += gitlinks.len(); |
| 1181 | 1× | let gm = entries |
| 1182 | 1× | .get(".gitmodules") |
| 1183 | 1× | .map(|e| { |
| 1184 | 1× | crate::subrepo::Modules::from_gitmodules(&String::from_utf8_lossy( |
| 1185 | 1× | &e.content, |
| 1186 | 1× | )) |
| 1187 | 1× | }) |
| 1188 | 1× | .unwrap_or_default(); |
| 1189 | 1× | let mut modules = entries |
| 1190 | 1× | .get(".oxymodules") |
| 1191 | 1× | .map(|e| crate::subrepo::Modules::parse(&String::from_utf8_lossy(&e.content))) |
| 1192 | 1× | .unwrap_or_default(); |
| 1193 | 1× | for (path, sha) in &gitlinks { |
| 1194 | 1× | let m = gm.entries.get(path); |
| 1195 | 1× | let branch = m |
| 1196 | 1× | .and_then(|m| m.bookmark.clone()) |
| 1197 | 1× | .unwrap_or_else(|| "HEAD".into()); |
| 1198 | 1× | entries.insert( |
| 1199 | 1× | path.clone(), |
| 1200 | 1× | FsEntry::new( |
| 1201 | 1× | NodeKind::Subrepo, |
| 1202 | | false, |
| 1203 | 1× | crate::subrepo::Pin::Git { |
| 1204 | 1× | sha: sha.clone(), |
| 1205 | 1× | branch, |
| 1206 | 1× | } |
| 1207 | 1× | .encode(), |
| 1208 | | ), |
| 1209 | | ); |
| 1210 | 1× | if let Some(m) = m { |
| 1211 | 1× | modules.entries.insert(path.clone(), m.clone()); |
| 1212 | 1× | } |
| 1213 | | } |
| 1214 | 1× | if !modules.entries.is_empty() { |
| 1215 | 1× | entries.insert( |
| 1216 | 1× | ".oxymodules".into(), |
| 1217 | 1× | FsEntry::new(NodeKind::File, false, modules.to_text().into_bytes()), |
| 1218 | 1× | ); |
| 1219 | 1× | } |
| 1220 | 79× | } |
| 1221 | 80× | lap(3, &mut clock); |
| 1222 | | |
| 1223 | | |
| 1224 | 80× | let seed = *blake3::hash(format!("oxy git import\0{}", gc.sha).as_bytes()).as_bytes(); |
| 1225 | 80× | let mut built = if partial { |
| 1226 | | |
| 1227 | 42× | let dir_needed = |dir: &str| { |
| 1228 | 10× | let prefix = format!("{dir}/"); |
| 1229 | 10× | tree.range(prefix.clone()..) |
| 1230 | 10× | .next() |
| 1231 | 10× | .is_some_and(|(k, _)| k.starts_with(&prefix)) |
| 1232 | 10× | }; |
| 1233 | 42× | self.build_from_entries_seeded( |
| 1234 | 42× | &base, |
| 1235 | 42× | &base_snapshot, |
| 1236 | 42× | &entries, |
| 1237 | 42× | seed, |
| 1238 | 42× | Some(&dir_needed), |
| 1239 | 0× | )? |
| 1240 | | } else { |
| 1241 | 38× | self.build_from_entries_seeded(&base, &base_snapshot, &entries, seed, None)? |
| 1242 | | }; |
| 1243 | 80× | lap(4, &mut clock); |
| 1244 | | |
| 1245 | | |
| 1246 | | |
| 1247 | | |
| 1248 | 139× | for (path, f) in &base_snapshot.files { |
| 1249 | 139× | let (FileContent::Opaque { blobs }, Some(e)) = (&f.content, entries.get(path)) |
| 1250 | | else { |
| 1251 | 127× | continue; |
| 1252 | | }; |
| 1253 | 12× | if blobs.len() < 2 || f.kind != e.kind { |
| 1254 | 11× | continue; |
| 1255 | 1× | } |
| 1256 | 1× | let chosen = self.store_blob(&e.content)?; |
| 1257 | 2× | for b in blobs { |
| 1258 | 2× | built.edits.push(Edit::Replace { |
| 1259 | 2× | node: f.node, |
| 1260 | 2× | old: Some(*b), |
| 1261 | 2× | new: Some(chosen), |
| 1262 | 2× | }); |
| 1263 | 2× | } |
| 1264 | 1× | built.resolves = true; |
| 1265 | 1× | built |
| 1266 | 1× | .contributors |
| 1267 | 1× | .extend(base.live_replaces(&f.node).into_iter().map(|(c, _)| c)); |
| 1268 | | } |
| 1269 | | |
| 1270 | | |
| 1271 | 80× | drop(base_snapshot); |
| 1272 | 80× | drop(entries); |
| 1273 | 80× | let mut deps: BTreeSet<ChangeHash> = built.contributors.iter().copied().collect(); |
| 1274 | 80× | let mut message = gc.message.clone(); |
| 1275 | 80× | if !message.ends_with('\n') { |
| 1276 | 80× | message.push('\n'); |
| 1277 | 80× | } |
| 1278 | 80× | message.push_str(&format!( |
| 1279 | 80× | "\nGit-Commit: {}\nGit-Author: {}\n", |
| 1280 | 80× | gc.sha, gc.author |
| 1281 | 80× | )); |
| 1282 | 80× | let mut change = Change { |
| 1283 | | version: crate::objects::CHANGE_VERSION, |
| 1284 | 80× | change_id: change_id_for(&gc.sha, &gc.message), |
| 1285 | 80× | deps: vec![], |
| 1286 | | author: ObjectRef::ZERO, |
| 1287 | 80× | hlc: Hlc { |
| 1288 | 80× | wall_ms: gc.author_secs * 1000, |
| 1289 | 80× | logical: 0, |
| 1290 | 80× | }, |
| 1291 | 80× | message, |
| 1292 | 80× | tree_ops: built.tree_ops, |
| 1293 | 80× | edits: built.edits, |
| 1294 | 80× | kind: if built.resolves { |
| 1295 | 12× | ChangeKind::Resolution |
| 1296 | | } else { |
| 1297 | 68× | ChangeKind::Normal |
| 1298 | | }, |
| 1299 | | }; |
| 1300 | 80× | let t = std::time::Instant::now(); |
| 1301 | | |
| 1302 | | |
| 1303 | | |
| 1304 | 80× | let need: Vec<NodeId> = change |
| 1305 | 80× | .edits |
| 1306 | 80× | .iter() |
| 1307 | 89× | .filter(|e| matches!(e, Edit::Delete { .. })) |
| 1308 | 80× | .map(|e| e.node()) |
| 1309 | 80× | .filter(|n| !base.is_built(n)) |
| 1310 | 80× | .collect(); |
| 1311 | 80× | if !need.is_empty() { |
| 1312 | 0× | self.load_graphs_of(&mut base, &need)?; |
| 1313 | 80× | } |
| 1314 | 80× | deps.extend(referenced_changes(&change, &base)); |
| 1315 | 80× | crate::timing::add("store: referenced", t.elapsed()); |
| 1316 | 80× | change.deps = deps.into_iter().collect(); |
| 1317 | 80× | change.normalize(); |
| 1318 | 80× | let hash = self.store.put_change(&change)?; |
| 1319 | 88× | for d in &change.deps { |
| 1320 | 88× | heads_now.remove(d); |
| 1321 | 88× | } |
| 1322 | 80× | heads_now.insert(hash); |
| 1323 | | |
| 1324 | | |
| 1325 | 80× | let t = std::time::Instant::now(); |
| 1326 | 80× | let (skeleton, texts) = self.store.get_change_lazy(&hash)?; |
| 1327 | 80× | base.add_known_mixed(hash, change, skeleton, texts); |
| 1328 | 80× | crate::timing::add("store: add to state", t.elapsed()); |
| 1329 | 80× | known.imported.insert(gc.sha.clone(), hash); |
| 1330 | 80× | if waiting.get(gc.sha.as_str()).is_some_and(|n| *n > 0) { |
| 1331 | | |
| 1332 | | |
| 1333 | | |
| 1334 | | |
| 1335 | | |
| 1336 | 46× | if base.built_count() > KEPT_GRAPHS || base.built_atoms() > kept_atoms { |
| 1337 | 0× | shed += base.shed_graphs(|b| self.store_blob(b))?; |
| 1338 | 46× | } |
| 1339 | 46× | kept.insert(gc.sha.clone(), (base, tree)); |
| 1340 | 46× | kept_order.push_back(gc.sha.clone()); |
| 1341 | 46× | if kept_order.len() > max_kept { |
| 1342 | 0× | if let Some(old) = kept_order.pop_front() { |
| 1343 | 0× | kept.remove(&old); |
| 1344 | 0× | } |
| 1345 | 46× | } |
| 1346 | 34× | } |
| 1347 | 80× | last = Some(gc.sha.clone()); |
| 1348 | 80× | report.commits += 1; |
| 1349 | 80× | lap(5, &mut clock); |
| 1350 | 80× | done += 1; |
| 1351 | | |
| 1352 | | |
| 1353 | | |
| 1354 | 80× | let before_trim = if trace { rss_mb() } else { 0 }; |
| 1355 | 80× | if gc.parents.len() > 1 { |
| 1356 | 23× | crate::alloc_stats::release_freed_memory(); |
| 1357 | 57× | } |
| 1358 | 80× | if trace { |
| 1359 | 0× | let built = kept |
| 1360 | 0× | .get(gc.sha.as_str()) |
| 1361 | 0× | .map(|(st, _)| st.built_count()) |
| 1362 | 0× | .unwrap_or(0); |
| 1363 | 0× | let (edits, most) = kept |
| 1364 | 0× | .get(gc.sha.as_str()) |
| 1365 | 0× | .map(|(st, _)| st.deferred_edit_count()) |
| 1366 | 0× | .unwrap_or((0, 0)); |
| 1367 | 0× | let atoms = kept |
| 1368 | 0× | .get(gc.sha.as_str()) |
| 1369 | 0× | .map(|(st, _)| st.built_atoms()) |
| 1370 | 0× | .unwrap_or(0); |
| 1371 | 0× | eprintln!( |
| 1372 | | "trace {done} {} parents={} base={base_how} merged={merged} built={built} atoms={atoms} kept={} shed={shed} rss_mb={} before_trim_mb={before_trim} deferred_edits={edits} most={most}", |
| 1373 | 0× | &gc.sha[..12.min(gc.sha.len())], |
| 1374 | 0× | gc.parents.len(), |
| 1375 | 0× | kept.len(), |
| 1376 | 0× | rss_mb() |
| 1377 | | ); |
| 1378 | 80× | } |
| 1379 | | } |
| 1380 | 84× | for (name, d) in [ |
| 1381 | 14× | "git import: bases", |
| 1382 | 14× | "git import: tree", |
| 1383 | 14× | "git import: render base", |
| 1384 | 14× | "git import: read blobs", |
| 1385 | 14× | "git import: build change", |
| 1386 | 14× | "git import: store change", |
| 1387 | 14× | ] |
| 1388 | 14× | .iter() |
| 1389 | 14× | .zip(spent) |
| 1390 | 84× | { |
| 1391 | 84× | crate::timing::record(name, d); |
| 1392 | 84× | } |
| 1393 | 14× | crate::timing::report_totals(); |
| 1394 | 14× | if crate::timing::enabled() { |
| 1395 | 0× | eprintln!( |
| 1396 | 0× | "timing git import: {rebuilt} bases rebuilt from history, {shed} graphs shed" |
| 1397 | 0× | ); |
| 1398 | 14× | } |
| 1399 | |
|
| 1400 | | |
| 1401 | 14× | report.heads = old_heads.len(); |
| 1402 | 14× | if last.is_none() { |
| 1403 | 1× | return Ok(report); |
| 1404 | 13× | } |
| 1405 | 13× | let heads: Vec<ChangeHash> = heads_now.into_iter().collect(); |
| 1406 | 13× | report.heads = heads.len(); |
| 1407 | 13× | let (op_ref, op) = self.head_op()?; |
| 1408 | 13× | let mut view = op.view.clone(); |
| 1409 | 13× | let old_state_ref = view.bookmarks.get(&self.config.bookmark).copied(); |
| 1410 | 13× | let state_ref = self.store.put_state(&StateObject::new(heads.clone()))?; |
| 1411 | 13× | view.bookmarks |
| 1412 | 13× | .insert(self.config.bookmark.clone(), state_ref); |
| 1413 | 13× | self.record_op(&[op_ref], command, view)?; |
| 1414 | | |
| 1415 | | |
| 1416 | 13× | let old_known = old_heads.is_empty() |
| 1417 | 2× | || old_state_ref.is_some_and(|s| known.exported.values().any(|e| *e == s)); |
| 1418 | 13× | if let (Some(tip), true) = (commits.last(), old_known) { |
| 1419 | 13× | self.record_git_state(git_dir, &state_ref, &tip.sha)?; |
| 1420 | 0× | } |
| 1421 | | |
| 1422 | 13× | if old_heads.is_empty() { |
| 1423 | 12× | self.checkout(&heads, true, &format!("{command} (checkout)"))?; |
| 1424 | | } else { |
| 1425 | 1× | let snap = self.snapshot(command)?; |
| 1426 | 1× | let clean = snap.wc.tree_ops.is_empty() && snap.wc.edits.is_empty(); |
| 1427 | 1× | let mut base = snap.base.maximal(&snap.wc.deps); |
| 1428 | 1× | base.sort(); |
| 1429 | 1× | let mut sorted_old = old_heads.clone(); |
| 1430 | 1× | sorted_old.sort(); |
| 1431 | 1× | if clean && base == sorted_old { |
| 1432 | 1× | self.checkout(&heads, false, &format!("{command} (checkout)"))?; |
| 1433 | 0× | } |
| 1434 | | } |
| 1435 | 13× | Ok(report) |
| 1436 | 14× | } |
| 1437 | |
|
| 1438 | | |
| 1439 | | |
| 1440 | | |
| 1441 | 1× | fn add_git_ancestors( |
| 1442 | 1× | &self, |
| 1443 | 1× | st: &mut State, |
| 1444 | 1× | git_dir: &Path, |
| 1445 | 1× | args: &[&str], |
| 1446 | 1× | known: &GitKnown, |
| 1447 | 1× | ) -> Result<()> { |
| 1448 | 1× | self.add_git_ancestors_touching(st, git_dir, args, known, &mut HashSet::new()) |
| 1449 | 1× | } |
| 1450 | |
|
| 1451 | | |
| 1452 | | |
| 1453 | 24× | fn add_git_ancestors_touching( |
| 1454 | 24× | &self, |
| 1455 | 24× | st: &mut State, |
| 1456 | 24× | git_dir: &Path, |
| 1457 | 24× | args: &[&str], |
| 1458 | 24× | known: &GitKnown, |
| 1459 | 24× | touched: &mut HashSet<NodeId>, |
| 1460 | 24× | ) -> Result<()> { |
| 1461 | 24× | let mut full = vec!["rev-list"]; |
| 1462 | 24× | full.extend(args); |
| 1463 | 24× | let out = git(git_dir, &full)?; |
| 1464 | 31× | let mut add = |st: &mut State, h: &ChangeHash| -> Result<()> { |
| 1465 | 31× | if st.contains(h) { |
| 1466 | 2× | return Ok(()); |
| 1467 | 29× | } |
| 1468 | 29× | if !st.is_history_only() { |
| 1469 | 0× | let c = self.store.get_change(h)?; |
| 1470 | 0× | touched.extend(c.edits.iter().map(|e| e.node())); |
| 1471 | 0× | touched.extend(c.tree_ops.iter().map(|o| o.node())); |
| 1472 | 0× | st.add_unchecked(c); |
| 1473 | 0× | return Ok(()); |
| 1474 | 29× | } |
| 1475 | | |
| 1476 | | |
| 1477 | 29× | let (skeleton, texts) = self.store.get_change_lazy(h)?; |
| 1478 | 32× | touched.extend(skeleton.edits.iter().map(|e| e.node())); |
| 1479 | 29× | touched.extend(skeleton.tree_ops.iter().map(|o| o.node())); |
| 1480 | 29× | let built = skeleton |
| 1481 | 29× | .edits |
| 1482 | 29× | .iter() |
| 1483 | 32× | .any(|e| !matches!(e, Edit::Replace { .. }) && st.is_built(&e.node())); |
| 1484 | 29× | if built { |
| 1485 | 4× | let full = self.store.get_change(h)?; |
| 1486 | 4× | st.add_known_mixed(*h, full, skeleton, texts); |
| 1487 | 25× | } else { |
| 1488 | 25× | st.add_known(*h, skeleton, texts); |
| 1489 | 25× | } |
| 1490 | 29× | Ok(()) |
| 1491 | 31× | }; |
| 1492 | 29× | for sha in out.lines() { |
| 1493 | 29× | if let Some(h) = known.imported.get(sha) { |
| 1494 | 28× | add(st, h)?; |
| 1495 | 1× | } else if let Some(state_ref) = known.exported.get(sha) { |
| 1496 | 1× | let heads = self.store.get_state(state_ref)?.heads; |
| 1497 | 3× | for h in self.negotiate(&[], &heads)? { |
| 1498 | 3× | add(st, &h)?; |
| 1499 | | } |
| 1500 | 0× | } |
| 1501 | | } |
| 1502 | 24× | Ok(()) |
| 1503 | 24× | } |
| 1504 | |
|
| 1505 | | |
| 1506 | | |
| 1507 | 18× | fn git_known(&self, git_dir: &Path) -> Result<GitKnown> { |
| 1508 | 18× | let imported = self.imported_commits()?; |
| 1509 | 18× | let marks_dir = self.git_marks_dir(git_dir)?; |
| 1510 | 18× | let oxy_marks = Self::read_oxy_marks(&marks_dir.join("oxy-marks"))?; |
| 1511 | 18× | let mut sha_of_mark: HashMap<u64, String> = HashMap::new(); |
| 1512 | 18× | if let Ok(text) = fs::read_to_string(marks_dir.join("git-marks")) { |
| 1513 | 4× | for line in text.lines() { |
| 1514 | 4× | if let Some((m, sha)) = line.split_once(' ') { |
| 1515 | 4× | if let Ok(m) = m.trim_start_matches(':').parse::<u64>() { |
| 1516 | 4× | sha_of_mark.insert(m, sha.trim().to_string()); |
| 1517 | 4× | } |
| 1518 | 0× | } |
| 1519 | | } |
| 1520 | 14× | } |
| 1521 | 18× | let mut exported = HashMap::new(); |
| 1522 | 18× | for (state_ref, m) in oxy_marks { |
| 1523 | 4× | if let Some(sha) = sha_of_mark.get(&m) { |
| 1524 | 4× | exported.insert(sha.clone(), state_ref); |
| 1525 | 4× | } |
| 1526 | | } |
| 1527 | 18× | for (state_ref, sha) in Self::read_git_states(&marks_dir.join("git-states"))? { |
| 1528 | 7× | exported.entry(sha).or_insert(state_ref); |
| 1529 | 7× | } |
| 1530 | 18× | Ok(GitKnown { imported, exported }) |
| 1531 | 18× | } |
| 1532 | |
|
| 1533 | 6× | fn git_author(&self, c: &Change) -> String { |
| 1534 | 6× | match self.store.get_identity(&c.author) { |
| 1535 | 6× | Ok(id) if !id.name.is_empty() => format!( |
| 1536 | | "{} <{}>", |
| 1537 | 6× | id.name.replace(['<', '>', '\n'], " "), |
| 1538 | 6× | id.email.replace(['<', '>', '\n', ' '], "") |
| 1539 | | ), |
| 1540 | 0× | _ => "oxy <oxy@localhost>".to_string(), |
| 1541 | | } |
| 1542 | 6× | } |
| 1543 | |
|
| 1544 | | #[allow(clippy::too_many_arguments)] |
| 1545 | 9× | fn write_commit( |
| 1546 | 9× | &self, |
| 1547 | 9× | out: &mut Vec<u8>, |
| 1548 | 9× | reference: &str, |
| 1549 | 9× | mark: u64, |
| 1550 | 9× | author: &str, |
| 1551 | 9× | secs: u64, |
| 1552 | 9× | message: &str, |
| 1553 | 9× | parents: &[String], |
| 1554 | 9× | snapshot: &Snapshot, |
| 1555 | 9× | ) -> Result<()> { |
| 1556 | 9× | out.extend_from_slice(format!("commit {reference}\nmark :{mark}\nauthor {author} {secs} +0000\ncommitter {author} {secs} +0000\ndata {}\n{message}\n", message.len()).as_bytes()); |
| 1557 | 9× | for (i, p) in parents.iter().enumerate() { |
| 1558 | 5× | out.extend_from_slice( |
| 1559 | 5× | format!("{} {p}\n", if i == 0 { "from" } else { "merge" }).as_bytes(), |
| 1560 | | ); |
| 1561 | | } |
| 1562 | 9× | out.extend_from_slice(b"deleteall\n"); |
| 1563 | 9× | let has_gitmodules = snapshot.files.contains_key(".gitmodules"); |
| 1564 | 38× | for (path, f) in &snapshot.files { |
| 1565 | 38× | if path == ".oxymodules" { |
| 1566 | | |
| 1567 | 1× | if !has_gitmodules { |
| 1568 | 0× | if let FileContent::Text { bytes, .. } = &f.content { |
| 1569 | 0× | let gm = crate::subrepo::Modules::parse(&String::from_utf8_lossy(bytes)) |
| 1570 | 0× | .to_gitmodules(); |
| 1571 | 0× | if !gm.is_empty() { |
| 1572 | 0× | out.extend_from_slice( |
| 1573 | 0× | format!("M 100644 inline .gitmodules\ndata {}\n", gm.len()) |
| 1574 | 0× | .as_bytes(), |
| 1575 | 0× | ); |
| 1576 | 0× | out.extend_from_slice(gm.as_bytes()); |
| 1577 | 0× | out.push(b'\n'); |
| 1578 | 0× | } |
| 1579 | 0× | } |
| 1580 | 1× | } |
| 1581 | 1× | continue; |
| 1582 | 37× | } |
| 1583 | 37× | if f.kind == NodeKind::Subrepo { |
| 1584 | 1× | if let FileContent::Opaque { blobs } = &f.content { |
| 1585 | 1× | if let Some(b) = blobs.first() { |
| 1586 | 1× | match crate::subrepo::Pin::decode(&self.read_blob(b)?)? { |
| 1587 | 1× | crate::subrepo::Pin::Git { sha, .. } => { |
| 1588 | 1× | out.extend_from_slice(format!("M 160000 {sha} {path}\n").as_bytes()) |
| 1589 | | } |
| 1590 | 0× | crate::subrepo::Pin::Oxy { .. } => self |
| 1591 | 0× | .git_export_skipped |
| 1592 | 0× | .set(self.git_export_skipped.get() + 1), |
| 1593 | | } |
| 1594 | 0× | } |
| 1595 | 0× | } |
| 1596 | 1× | continue; |
| 1597 | 36× | } |
| 1598 | 36× | let (mode, bytes): (&str, Vec<u8>) = match (&f.kind, &f.content) { |
| 1599 | 9× | (NodeKind::Dir, _) => continue, |
| 1600 | 0× | (NodeKind::Symlink, FileContent::Opaque { blobs }) => ( |
| 1601 | 0× | "120000", |
| 1602 | 0× | blobs |
| 1603 | 0× | .first() |
| 1604 | 0× | .map(|b| self.read_blob(b)) |
| 1605 | 0× | .transpose()? |
| 1606 | 0× | .unwrap_or_default(), |
| 1607 | | ), |
| 1608 | 24× | (_, FileContent::Text { bytes, .. }) => { |
| 1609 | 24× | (if f.mode.exec { "100755" } else { "100644" }, bytes.clone()) |
| 1610 | | } |
| 1611 | 3× | (_, FileContent::Opaque { blobs }) => ( |
| 1612 | 3× | if f.mode.exec { "100755" } else { "100644" }, |
| 1613 | 3× | blobs |
| 1614 | 3× | .first() |
| 1615 | 3× | .map(|b| self.read_blob(b)) |
| 1616 | 3× | .transpose()? |
| 1617 | 3× | .unwrap_or_default(), |
| 1618 | | ), |
| 1619 | 0× | (_, FileContent::Dir) => continue, |
| 1620 | | }; |
| 1621 | 27× | out.extend_from_slice( |
| 1622 | 27× | format!("M {mode} inline {path}\ndata {}\n", bytes.len()).as_bytes(), |
| 1623 | | ); |
| 1624 | 27× | out.extend_from_slice(&bytes); |
| 1625 | 27× | out.push(b'\n'); |
| 1626 | | } |
| 1627 | 9× | out.push(b'\n'); |
| 1628 | 9× | Ok(()) |
| 1629 | 9× | } |
| 1630 | | } |
| 1631 | |
|
| 1632 | |
|
| 1633 | | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
| 1634 | | pub struct GitVerifyReport { |
| 1635 | | pub commits: usize, |
| 1636 | | |
| 1637 | | pub skipped: usize, |
| 1638 | | pub files_compared: usize, |
| 1639 | | |
| 1640 | | pub mismatches: Vec<(String, String)>, |
| 1641 | | } |
| 1642 | |
|
| 1643 | | impl Repo { |
| 1644 | | |
| 1645 | | |
| 1646 | | |
| 1647 | | |
| 1648 | | |
| 1649 | 8× | pub fn verify_git_import(&self, git_dir: &Path, branch: &str) -> Result<GitVerifyReport> { |
| 1650 | 8× | self.verify_git_import_last(git_dir, branch, None) |
| 1651 | 8× | } |
| 1652 | |
|
| 1653 | | |
| 1654 | | |
| 1655 | | |
| 1656 | 8× | pub fn verify_git_import_last( |
| 1657 | 8× | &self, |
| 1658 | 8× | git_dir: &Path, |
| 1659 | 8× | branch: &str, |
| 1660 | 8× | last: Option<usize>, |
| 1661 | 8× | ) -> Result<GitVerifyReport> { |
| 1662 | 8× | let commits = list_commits(git_dir, branch)?; |
| 1663 | 8× | let imported = self.imported_commits()?; |
| 1664 | 8× | let mut cat = CatFile::start(git_dir)?; |
| 1665 | 8× | let mut rep = GitVerifyReport::default(); |
| 1666 | | |
| 1667 | 8× | let mut closure: HashMap<String, Arc<BTreeSet<ChangeHash>>> = HashMap::new(); |
| 1668 | | |
| 1669 | 8× | let mut verified_graphs: HashMap<[u8; 32], String> = HashMap::new(); |
| 1670 | 8× | let mut verified_blobs: HashMap<ObjectRef, String> = HashMap::new(); |
| 1671 | | |
| 1672 | | |
| 1673 | | |
| 1674 | 8× | let mut waiting: HashMap<&str, usize> = HashMap::new(); |
| 1675 | 55× | for c in &commits { |
| 1676 | 55× | if let Some(p1) = c.parents.first() { |
| 1677 | 45× | *waiting.entry(p1.as_str()).or_default() += 1; |
| 1678 | 45× | } |
| 1679 | | } |
| 1680 | 8× | let mut kept: HashMap<String, State> = HashMap::new(); |
| 1681 | 8× | let mut kept_order: std::collections::VecDeque<String> = std::collections::VecDeque::new(); |
| 1682 | 55× | for c in &commits { |
| 1683 | 55× | rep.commits += 1; |
| 1684 | 55× | let mut set: BTreeSet<ChangeHash> = BTreeSet::new(); |
| 1685 | 62× | for p in &c.parents { |
| 1686 | 62× | if let Some(ps) = closure.get(p) { |
| 1687 | 62× | set.extend(ps.iter().copied()); |
| 1688 | 62× | } |
| 1689 | | } |
| 1690 | 55× | match imported.get(&c.sha) { |
| 1691 | 55× | Some(h) => { |
| 1692 | 55× | set.insert(*h); |
| 1693 | 55× | } |
| 1694 | 0× | None => { |
| 1695 | 0× | rep.mismatches.push(( |
| 1696 | 0× | c.sha.clone(), |
| 1697 | 0× | "no imported change carries this commit".into(), |
| 1698 | 0× | )); |
| 1699 | 0× | } |
| 1700 | | } |
| 1701 | 55× | let set = Arc::new(set); |
| 1702 | 55× | closure.insert(c.sha.clone(), set.clone()); |
| 1703 | 55× | if rep.mismatches.len() >= 50 { |
| 1704 | 0× | break; |
| 1705 | 55× | } |
| 1706 | 55× | if last.is_some_and(|n| rep.commits + n <= commits.len()) { |
| 1707 | 0× | rep.skipped += 1; |
| 1708 | 0× | continue; |
| 1709 | 55× | } |
| 1710 | 55× | let heads: Vec<ChangeHash> = set.iter().copied().collect(); |
| 1711 | | |
| 1712 | | |
| 1713 | | |
| 1714 | 55× | let from_parent = c.parents.first().and_then(|p1| { |
| 1715 | 45× | let left = waiting.get_mut(p1.as_str()).map(|n| { |
| 1716 | 45× | *n -= 1; |
| 1717 | 45× | *n |
| 1718 | 45× | }); |
| 1719 | 45× | if left == Some(0) { |
| 1720 | 47× | kept_order.retain(|k| k != p1); |
| 1721 | 32× | kept.remove(p1.as_str()) |
| 1722 | | } else { |
| 1723 | 13× | kept.get(p1.as_str()).cloned() |
| 1724 | | } |
| 1725 | 45× | }); |
| 1726 | 55× | let state = match from_parent { |
| 1727 | 45× | Some(mut st) => { |
| 1728 | | |
| 1729 | | |
| 1730 | | |
| 1731 | 202× | for h in set.iter() { |
| 1732 | 202× | if !st.contains(h) { |
| 1733 | 65× | let (change, texts) = self.store.get_change_lazy(h)?; |
| 1734 | 65× | st.add_known(*h, change, texts); |
| 1735 | 137× | } |
| 1736 | | } |
| 1737 | 45× | st |
| 1738 | | } |
| 1739 | 10× | None => self.load_state_history(&heads)?, |
| 1740 | | }; |
| 1741 | 55× | let view = state.tree().view(); |
| 1742 | 55× | let tree = list_tree(git_dir, &c.sha)?; |
| 1743 | 55× | let short = &c.sha[..12.min(c.sha.len())]; |
| 1744 | 55× | let mut differ = |what: String| rep.mismatches.push((c.sha.clone(), what)); |
| 1745 | 55× | let mut conflicted: Vec<String> = |
| 1746 | 55× | view.conflicts.iter().map(|c| format!("{c:?}")).collect(); |
| 1747 | 55× | let mut need: Vec<NodeId> = Vec::new(); |
| 1748 | 131× | for (path, (mode, sha)) in &tree { |
| 1749 | 131× | let Some(e) = view.entries.get(path) else { |
| 1750 | 0× | continue; |
| 1751 | | }; |
| 1752 | 131× | if mode != "160000" |
| 1753 | 131× | && mode != "120000" |
| 1754 | 131× | && e.kind == NodeKind::File |
| 1755 | 131× | && !e.mode.opaque |
| 1756 | | { |
| 1757 | 120× | let known = state |
| 1758 | 120× | .graph_key(&e.node) |
| 1759 | 120× | .is_some_and(|k| verified_graphs.get(&k) == Some(sha)); |
| 1760 | 120× | if !known { |
| 1761 | 46× | need.push(e.node); |
| 1762 | 74× | } |
| 1763 | 11× | } |
| 1764 | | } |
| 1765 | | |
| 1766 | 55× | let keys: HashMap<NodeId, [u8; 32]> = need |
| 1767 | 55× | .iter() |
| 1768 | 55× | .filter_map(|n| Some((*n, state.graph_key(n)?))) |
| 1769 | 55× | .collect(); |
| 1770 | 55× | let need_set: HashSet<NodeId> = need.iter().copied().collect(); |
| 1771 | 55× | let graphs = self.build_graphs_detached(&state, &need)?; |
| 1772 | 131× | for (path, (mode, sha)) in &tree { |
| 1773 | 131× | let Some(e) = view.entries.get(path) else { |
| 1774 | 0× | differ(format!("{short}: {path} is missing")); |
| 1775 | 0× | continue; |
| 1776 | | }; |
| 1777 | 131× | rep.files_compared += 1; |
| 1778 | 131× | match mode.as_str() { |
| 1779 | 131× | "160000" => { |
| 1780 | 0× | let blobs = state.live_blobs(&e.node); |
| 1781 | 0× | match (e.kind, blobs.as_slice()) { |
| 1782 | 0× | (NodeKind::Subrepo, [b]) => { |
| 1783 | 0× | let pin = crate::subrepo::Pin::decode(&self.read_blob(b)?)?; |
| 1784 | 0× | if !matches!(&pin, crate::subrepo::Pin::Git { sha: s, .. } if s == sha) |
| 1785 | 0× | { |
| 1786 | 0× | differ(format!("{short}: {path} pins another commit")); |
| 1787 | 0× | } |
| 1788 | | } |
| 1789 | 0× | (kind, _) => differ(format!( |
| 1790 | 0× | "{short}: {path} is not one submodule pin: {kind:?} with {} pins", |
| 1791 | 0× | blobs.len() |
| 1792 | 0× | )), |
| 1793 | | } |
| 1794 | | } |
| 1795 | 131× | "120000" => { |
| 1796 | 0× | let target = cat.read(sha)?; |
| 1797 | 0× | let blobs = state.live_blobs(&e.node); |
| 1798 | 0× | match (e.kind, blobs.as_slice()) { |
| 1799 | 0× | (NodeKind::Symlink, [b]) if self.read_blob(b)? == target => {} |
| 1800 | 0× | _ => differ(format!("{short}: symlink {path} differs")), |
| 1801 | | } |
| 1802 | | } |
| 1803 | | _ => { |
| 1804 | 131× | if e.mode.exec != (mode == "100755") { |
| 1805 | 0× | differ(format!("{short}: {path} executable bit differs")); |
| 1806 | 131× | } |
| 1807 | 131× | if e.kind == NodeKind::File && !e.mode.opaque { |
| 1808 | 120× | if !need_set.contains(&e.node) { |
| 1809 | | |
| 1810 | 74× | continue; |
| 1811 | 46× | } |
| 1812 | 46× | let (have, m) = match graphs.get(&e.node) { |
| 1813 | 46× | Some(g) => state.render_graph(g), |
| 1814 | 0× | None => (Vec::new(), Default::default()), |
| 1815 | | }; |
| 1816 | 46× | if m.is_conflicted() { |
| 1817 | | |
| 1818 | 0× | let mut detail = state.clone(); |
| 1819 | 0× | self.load_graphs_of(&mut detail, &[e.node])?; |
| 1820 | 0× | let who: Vec<String> = detail |
| 1821 | 0× | .conflict_regions(&e.node) |
| 1822 | 0× | .contributors |
| 1823 | 0× | .iter() |
| 1824 | 0× | .filter_map(|h| state.get(h)) |
| 1825 | 0× | .map(|m| { |
| 1826 | 0× | let sha = m |
| 1827 | 0× | .message |
| 1828 | 0× | .lines() |
| 1829 | 0× | .rev() |
| 1830 | 0× | .find_map(|l| l.strip_prefix("Git-Commit: ")) |
| 1831 | 0× | .unwrap_or("?"); |
| 1832 | 0× | format!( |
| 1833 | | "{} {:?}", |
| 1834 | 0× | &sha[..12.min(sha.len())], |
| 1835 | 0× | m.message.lines().next().unwrap_or("") |
| 1836 | | ) |
| 1837 | 0× | }) |
| 1838 | 0× | .collect(); |
| 1839 | 0× | conflicted.push(format!("{path} between {}", who.join(" and "))); |
| 1840 | 46× | } |
| 1841 | 46× | let want = cat.read(sha)?; |
| 1842 | 46× | if have != want { |
| 1843 | 0× | differ(format!( |
| 1844 | 0× | "{short}: {path} differs: {}", |
| 1845 | 0× | first_difference(&have, &want) |
| 1846 | 0× | )); |
| 1847 | 46× | } else if !m.is_conflicted() { |
| 1848 | 46× | if let Some(k) = keys.get(&e.node) { |
| 1849 | 46× | verified_graphs.insert(*k, sha.clone()); |
| 1850 | 46× | } |
| 1851 | 0× | } |
| 1852 | 46× | continue; |
| 1853 | 11× | } |
| 1854 | 11× | let blobs = state.live_blobs(&e.node); |
| 1855 | 11× | let [b] = blobs.as_slice() else { |
| 1856 | 0× | differ(format!("{short}: {path} is not one file")); |
| 1857 | 0× | continue; |
| 1858 | | }; |
| 1859 | 11× | if verified_blobs.get(b) == Some(sha) { |
| 1860 | 6× | continue; |
| 1861 | 5× | } |
| 1862 | 5× | if self.read_blob(b)? != cat.read(sha)? { |
| 1863 | 0× | differ(format!("{short}: {path} differs")); |
| 1864 | 5× | } else { |
| 1865 | 5× | verified_blobs.insert(*b, sha.clone()); |
| 1866 | 5× | } |
| 1867 | | } |
| 1868 | | } |
| 1869 | | } |
| 1870 | 55× | if !conflicted.is_empty() { |
| 1871 | 0× | differ(format!( |
| 1872 | 0× | "{short}: the state is conflicted: {}", |
| 1873 | 0× | conflicted.join("; ") |
| 1874 | 0× | )); |
| 1875 | 55× | } |
| 1876 | | |
| 1877 | | |
| 1878 | 131× | let has_submodules = tree.values().any(|(m, _)| m == "160000"); |
| 1879 | 166× | for (path, e) in view.entries.iter() { |
| 1880 | 166× | if e.kind != NodeKind::Dir |
| 1881 | 131× | && !tree.contains_key(path) |
| 1882 | 0× | && !(has_submodules && path == ".oxymodules") |
| 1883 | 0× | { |
| 1884 | 0× | differ(format!("{short}: {path} is extra")); |
| 1885 | 166× | } |
| 1886 | | } |
| 1887 | 55× | if waiting.get(c.sha.as_str()).is_some_and(|n| *n > 0) { |
| 1888 | 32× | kept.insert(c.sha.clone(), state); |
| 1889 | 32× | kept_order.push_back(c.sha.clone()); |
| 1890 | 32× | if kept_order.len() > 8 { |
| 1891 | 0× | if let Some(old) = kept_order.pop_front() { |
| 1892 | 0× | kept.remove(&old); |
| 1893 | 0× | } |
| 1894 | 32× | } |
| 1895 | 23× | } |
| 1896 | 55× | if rep.mismatches.len() >= 50 { |
| 1897 | 0× | break; |
| 1898 | 55× | } |
| 1899 | | } |
| 1900 | 8× | Ok(rep) |
| 1901 | 8× | } |
| 1902 | | } |
| 1903 | |
|
| 1904 | |
|
| 1905 | 0× | fn first_difference(have: &[u8], want: &[u8]) -> String { |
| 1906 | 0× | let (h, w): (Vec<&[u8]>, Vec<&[u8]>) = ( |
| 1907 | 0× | have.split(|b| *b == b'\n').collect(), |
| 1908 | 0× | want.split(|b| *b == b'\n').collect(), |
| 1909 | | ); |
| 1910 | 0× | let i = h |
| 1911 | 0× | .iter() |
| 1912 | 0× | .zip(&w) |
| 1913 | 0× | .position(|(a, b)| a != b) |
| 1914 | 0× | .unwrap_or(h.len().min(w.len())); |
| 1915 | 0× | let show = |l: Option<&&[u8]>| { |
| 1916 | 0× | l.map(|l| String::from_utf8_lossy(&l[..l.len().min(60)]).into_owned()) |
| 1917 | 0× | .unwrap_or_else(|| "(end)".into()) |
| 1918 | 0× | }; |
| 1919 | 0× | format!( |
| 1920 | | "line {}: has {:?}, Git has {:?} ({} lines, Git has {})", |
| 1921 | 0× | i + 1, |
| 1922 | 0× | show(h.get(i)), |
| 1923 | 0× | show(w.get(i)), |
| 1924 | 0× | h.len(), |
| 1925 | 0× | w.len() |
| 1926 | | ) |
| 1927 | 0× | } |