Add multiple files to tracking in a single write transaction. This is much faster than calling `add()` in a loop because it avoids opening a separate write transaction (and fsync) for each file. For git import of a commit adding 20 files, this reduces from 20 fsyncs to 1. # Arguments `paths` - Paths to add (relative to repository root) # Returns Number of files actually added (skips already-t
(&self, paths: &[&str])
| 130 | /// |
| 131 | /// Number of files actually added (skips already-tracked files). |
| 132 | pub fn add_batch(&self, paths: &[&str]) -> Result<usize, RepositoryError> { |
| 133 | if paths.is_empty() { |
| 134 | return Ok(0); |
| 135 | } |
| 136 | |
| 137 | let mut txn = self |
| 138 | .pristine |
| 139 | .write_txn() |
| 140 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 141 | |
| 142 | let mut count = 0usize; |
| 143 | for path in paths { |
| 144 | let normalized = normalize_path(Path::new(path)); |
| 145 | if is_tracked(&txn, &normalized) |
| 146 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 147 | { |
| 148 | continue; |
| 149 | } |
| 150 | add_to_tree(&mut txn, &normalized, false) |
| 151 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 152 | count += 1; |
| 153 | } |
| 154 | |
| 155 | txn.commit() |
| 156 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 157 | |
| 158 | Ok(count) |
| 159 | } |
| 160 | |
| 161 | /// Remove multiple files from tracking in a single write transaction. |
| 162 | /// |
no test coverage detected