It feels like the better name.
Unified · Split
| @@ -192,7 +192,7 @@ fn edit_git_note(repository: &gix::Repository, args: &Target) -> Result<()> { · 191 unmodified lines | |||
| 192 | let data: Option<&[u8]> = saved.then_some(cleaned.as_ref()); | 192 | let data: Option<&[u8]> = saved.then_some(cleaned.as_ref()); |
| 193 | match data { | 193 | match data { |
| 194 | Some(data) => notes | 194 | Some(data) => notes |
| 195 | .add_to_ref(reference.as_ref(), target, data) | 195 | .replace_at_ref(reference.as_ref(), target, data) |
| 196 | .context("could not save Git note")?, | 196 | .context("could not save Git note")?, |
| 197 | None => notes | 197 | None => notes |
| 198 | .remove(reference.as_ref().as_partial_name().to_owned(), target) | 198 | .remove(reference.as_ref().as_partial_name().to_owned(), target) |
| @@ -3219,7 +3219,7 @@ mod tests { · 3218 unmodified lines | |||
| 3219 | .default_ref() | 3219 | .default_ref() |
| 3220 | .expect("the test repository has a default notes ref") | 3220 | .expect("the test repository has a default notes ref") |
| 3221 | .to_owned(); | 3221 | .to_owned(); |
| 3222 | notes.add_to_ref(reference.as_ref(), id, data)?; | 3222 | notes.replace_at_ref(reference.as_ref(), id, data)?; |
| 3223 | Ok(()) | 3223 | Ok(()) |
| 3224 | } | 3224 | } |
| 3225 | 3225 | ||
| @@ -193,7 +193,7 @@ mod tests { · 192 unmodified lines | |||
| 193 | .default_ref() | 193 | .default_ref() |
| 194 | .expect("the test repository has a default notes ref") | 194 | .expect("the test repository has a default notes ref") |
| 195 | .to_owned(); | 195 | .to_owned(); |
| 196 | notes.add_to_ref(notes_ref.as_ref(), old, b"source Git note")?; | 196 | notes.replace_at_ref(notes_ref.as_ref(), old, b"source Git note")?; |
| 197 | let upper = apply(open(fixture.path())?, &graph, prepared, &edited)?; | 197 | let upper = apply(open(fixture.path())?, &graph, prepared, &edited)?; |
| 198 | let repository = open(fixture.path())?; | 198 | let repository = open(fixture.path())?; |
| 199 | assert_eq!( | 199 | assert_eq!( |
| @@ -1412,10 +1412,10 @@ mod tests { · 1411 unmodified lines | |||
| 1412 | let change_id = crate::change_id::for_commit(&repo, middle)?; | 1412 | let change_id = crate::change_id::for_commit(&repo, middle)?; |
| 1413 | let reference: gix::refs::FullName = crate::enrich::REF_NAME.try_into()?; | 1413 | let reference: gix::refs::FullName = crate::enrich::REF_NAME.try_into()?; |
| 1414 | repo.notes()? | 1414 | repo.notes()? |
| 1415 | .add_to_ref(reference.as_ref(), ObjectId::from(change_id), b"[commit")?; | 1415 | .replace_at_ref(reference.as_ref(), ObjectId::from(change_id), b"[commit")?; |
| 1416 | let tree_id = crate::enrich::tree_id(&repo, middle)?; | 1416 | let tree_id = crate::enrich::tree_id(&repo, middle)?; |
| 1417 | let reference: gix::refs::FullName = crate::enrich::TREE_REF_NAME.try_into()?; | 1417 | let reference: gix::refs::FullName = crate::enrich::TREE_REF_NAME.try_into()?; |
| 1418 | repo.notes()?.add_to_ref(reference.as_ref(), tree_id, b"[tree")?; | 1418 | repo.notes()?.replace_at_ref(reference.as_ref(), tree_id, b"[tree")?; |
| 1419 | 1419 | ||
| 1420 | let prepared = prepare_test(&repo, base, base, &commits, Some(tip))?; | 1420 | let prepared = prepare_test(&repo, base, base, &commits, Some(tip))?; |
| 1421 | let document = String::from_utf8(prepared.document)?; | 1421 | let document = String::from_utf8(prepared.document)?; |
| @@ -182,7 +182,7 @@ pub(crate) fn apply_headers( · 181 unmodified lines | |||
| 182 | }; | 182 | }; |
| 183 | let reference: FullName = REF_NAME.try_into().expect("the tix enrich reference is valid"); | 183 | let reference: FullName = REF_NAME.try_into().expect("the tix enrich reference is valid"); |
| 184 | open(repo)? | 184 | open(repo)? |
| 185 | .add_to_ref(reference.as_ref(), object, data) | 185 | .replace_at_ref(reference.as_ref(), object, data) |
| 186 | .context("could not write the tix enrichment")?; | 186 | .context("could not write the tix enrichment")?; |
| 187 | Ok(Some(desired)) | 187 | Ok(Some(desired)) |
| 188 | } | 188 | } |
| @@ -253,7 +253,7 @@ fn update( · 64 unmodified lines | |||
| 253 | edit(&mut config)?; | 253 | edit(&mut config)?; |
| 254 | let reference: FullName = REF_NAME.try_into().expect("the tix enrich reference is valid"); | 254 | let reference: FullName = REF_NAME.try_into().expect("the tix enrich reference is valid"); |
| 255 | notes | 255 | notes |
| 256 | .add_to_ref(reference.as_ref(), ObjectId::from(change_id), config.to_bstring()) | 256 | .replace_at_ref(reference.as_ref(), ObjectId::from(change_id), config.to_bstring()) |
| 257 | .context("could not write the tix enrichment")?; | 257 | .context("could not write the tix enrichment")?; |
| 258 | load(&mut notes, change_id) | 258 | load(&mut notes, change_id) |
| 259 | } | 259 | } |
| @@ -270,7 +270,7 @@ fn update_tree( · 10 unmodified lines | |||
| 270 | .try_into() | 270 | .try_into() |
| 271 | .expect("the tix tree enrich reference is valid"); | 271 | .expect("the tix tree enrich reference is valid"); |
| 272 | notes | 272 | notes |
| 273 | .add_to_ref(reference.as_ref(), tree_id, config.to_bstring()) | 273 | .replace_at_ref(reference.as_ref(), tree_id, config.to_bstring()) |
| 274 | .context("could not write the tix tree enrichment")?; | 274 | .context("could not write the tix tree enrichment")?; |
| 275 | load_tree(&mut notes, tree_id) | 275 | load_tree(&mut notes, tree_id) |
| 276 | } | 276 | } |
| @@ -291,7 +291,7 @@ mod tests { · 14 unmodified lines | |||
| 291 | let id = repo.head_id()?.detach(); | 291 | let id = repo.head_id()?.detach(); |
| 292 | let change_id = crate::change_id::for_commit(&repo, id)?; | 292 | let change_id = crate::change_id::for_commit(&repo, id)?; |
| 293 | let reference: FullName = REF_NAME.try_into()?; | 293 | let reference: FullName = REF_NAME.try_into()?; |
| 294 | repo.notes()?.add_to_ref( | 294 | repo.notes()?.replace_at_ref( |
| 295 | reference.as_ref(), | 295 | reference.as_ref(), |
| 296 | ObjectId::from(change_id), | 296 | ObjectId::from(change_id), |
| 297 | b"[commit]\n\ttodo = true\n\towner = me\n", | 297 | b"[commit]\n\ttodo = true\n\towner = me\n", |
| @@ -345,7 +345,7 @@ mod tests { · 47 unmodified lines | |||
| 345 | let original = repo.head_id()?.detach(); | 345 | let original = repo.head_id()?.detach(); |
| 346 | let tree = tree_id(&repo, original)?; | 346 | let tree = tree_id(&repo, original)?; |
| 347 | let reference: FullName = TREE_REF_NAME.try_into()?; | 347 | let reference: FullName = TREE_REF_NAME.try_into()?; |
| 348 | repo.notes()?.add_to_ref( | 348 | repo.notes()?.replace_at_ref( |
| 349 | reference.as_ref(), | 349 | reference.as_ref(), |
| 350 | tree, | 350 | tree, |
| 351 | b"[tree]\n\tchecks-pass = false\n\towner = me\n", | 351 | b"[tree]\n\tchecks-pass = false\n\towner = me\n", |
| @@ -457,7 +457,7 @@ mod tests { · 105 unmodified lines | |||
| 457 | let change_id = crate::change_id::for_commit(&repo, id)?; | 457 | let change_id = crate::change_id::for_commit(&repo, id)?; |
| 458 | let reference: FullName = REF_NAME.try_into()?; | 458 | let reference: FullName = REF_NAME.try_into()?; |
| 459 | repo.notes()? | 459 | repo.notes()? |
| 460 | .add_to_ref(reference.as_ref(), ObjectId::from(change_id), b"[commit")?; | 460 | .replace_at_ref(reference.as_ref(), ObjectId::from(change_id), b"[commit")?; |
| 461 | 461 | ||
| 462 | assert!( | 462 | assert!( |
| 463 | load(&mut open(&repo)?, change_id).is_err(), | 463 | load(&mut open(&repo)?, change_id).is_err(), |
| @@ -469,7 +469,7 @@ mod tests { · 5 unmodified lines | |||
| 469 | ); | 469 | ); |
| 470 | let tree = tree_id(&repo, id)?; | 470 | let tree = tree_id(&repo, id)?; |
| 471 | let reference: FullName = TREE_REF_NAME.try_into()?; | 471 | let reference: FullName = TREE_REF_NAME.try_into()?; |
| 472 | repo.notes()?.add_to_ref(reference.as_ref(), tree, b"[tree")?; | 472 | repo.notes()?.replace_at_ref(reference.as_ref(), tree, b"[tree")?; |
| 473 | assert!( | 473 | assert!( |
| 474 | toggle_checks_pass(&repo, id).is_err(), | 474 | toggle_checks_pass(&repo, id).is_err(), |
| 475 | "tree mutation does not replace malformed enrichments" | 475 | "tree mutation does not replace malformed enrichments" |
| @@ -5425,7 +5425,7 @@ fn set_git_note_reporting( · 5424 unmodified lines | |||
| 5425 | match data { | 5425 | match data { |
| 5426 | Some(data) => { | 5426 | Some(data) => { |
| 5427 | notes | 5427 | notes |
| 5428 | .add_to_ref(reference, id, data) | 5428 | .replace_at_ref(reference, id, data) |
| 5429 | .context("could not save Git note")?; | 5429 | .context("could not save Git note")?; |
| 5430 | } | 5430 | } |
| 5431 | None => { | 5431 | None => { |
| @@ -170,14 +170,14 @@ impl<'repo> Platform<'repo> { · 169 unmodified lines | |||
| 170 | .try_into() | 170 | .try_into() |
| 171 | .or_raise(|| message("The notes reference name is invalid"))?; | 171 | .or_raise(|| message("The notes reference name is invalid"))?; |
| 172 | let notes_ref = expand_notes_ref(notes_ref.as_ref())?; | 172 | let notes_ref = expand_notes_ref(notes_ref.as_ref())?; |
| 173 | self.add_to_ref(notes_ref.as_ref(), object, data) | 173 | self.replace_at_ref(notes_ref.as_ref(), object, data) |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | /// Replace a note for `object` with `data` in the fully qualified `notes_ref`, | 176 | /// Replace a note for `object` with `data` in the fully qualified `notes_ref`, |
| 177 | /// or add it if absent, returning the previous note id. | 177 | /// or add it if absent, returning the previous note id. |
| 178 | /// | 178 | /// |
| 179 | /// Unlike [`Self::replace()`], this does not apply `refs/notes/` shorthand expansion. | 179 | /// Unlike [`Self::replace()`], this does not apply `refs/notes/` shorthand expansion. |
| 180 | pub fn add_to_ref( | 180 | pub fn replace_at_ref( |
| 181 | &mut self, | 181 | &mut self, |
| 182 | notes_ref: &gix_ref::FullNameRef, | 182 | notes_ref: &gix_ref::FullNameRef, |
| 183 | object: impl Into<gix_hash::ObjectId>, | 183 | object: impl Into<gix_hash::ObjectId>, |
| @@ -339,7 +339,7 @@ fn add_to_an_exact_fully_qualified_reference() -> crate::Result { · 338 unmodified lines | |||
| 339 | let mut notes = repo.notes()?; | 339 | let mut notes = repo.notes()?; |
| 340 | 340 | ||
| 341 | assert_eq!( | 341 | assert_eq!( |
| 342 | notes.add_to_ref(reference.as_ref(), target, b"[commit]\n\ttodo = true\n")?, | 342 | notes.replace_at_ref(reference.as_ref(), target, b"[commit]\n\ttodo = true\n")?, |
| 343 | None | 343 | None |
| 344 | ); | 344 | ); |
| 345 | let mut exact = repo.notes()?.with_refs([reference.as_bstr()])?; | 345 | let mut exact = repo.notes()?.with_refs([reference.as_bstr()])?; |