Further, we update internal logic to decide when to write a reflog for symrefs. Now we will always do it when possible, i.e. there is object ids available.
Unified · Split
| @@ -50,7 +50,8 @@ impl<'s, 'p> Transaction<'s, 'p> { · 49 unmodified lines | ||
| 50 | 50 | if update_reflog { |
| 51 | 51 | let log_update = match new { |
| 52 | 52 | Target::Symbolic(_) => { |
| 53 | − // no reflog for symref changes, unless the ref is new and we can obtain a peeled id | |
| 53 | + // Special HACK: no reflog for symref changes as there is no OID involved which the reflog needs. | |
| 54 | + // Unless, the ref is new and we can obtain a peeled id | |
| 54 | 55 | // identified by the expectation of what could be there, as is the case when cloning. |
| 55 | 56 | match expected { |
| 56 | 57 | PreviousValue::ExistingMustMatch(Target::Peeled(oid)) => { |
| @@ -61,6 +62,8 @@ impl<'s, 'p> Transaction<'s, 'p> { · 4 unmodified lines | ||
| 61 | 62 | } |
| 62 | 63 | Target::Peeled(new_oid) => { |
| 63 | 64 | let previous = match expected { |
| 65 | + // Here, this means that the ref already existed, and that it will receive (even transitively) | |
| 66 | + // the given value | |
| 64 | 67 | PreviousValue::MustExistAndMatch(Target::Peeled(oid)) => Some(oid.to_owned()), |
| 65 | 68 | _ => None, |
| 66 | 69 | } |
| @@ -64,7 +64,7 @@ pub enum Change { · 63 unmodified lines | ||
| 64 | 64 | /// The desired change to the reference log. |
| 65 | 65 | log: LogChange, |
| 66 | 66 | /// The expected value already present in the reference. |
| 67 | − /// If a ref was existing previously it will be overwritten at `MustExistAndMatch(actual_value)` for use after | |
| 67 | + /// If a ref was existing previously this field will be overwritten with `MustExistAndMatch(actual_value)` for use after | |
| 68 | 68 | /// the transaction was committed successfully. |
| 69 | 69 | expected: PreviousValue, |
| 70 | 70 | /// The new state of the reference, either for updating an existing one or creating a new one. |
| @@ -94,7 +94,6 @@ impl Change { · 23 unmodified lines | ||
| 94 | 94 | /// Return references to values that are in common between all variants and denote the previous observed value. |
| 95 | 95 | pub fn previous_value(&self) -> Option<crate::TargetRef<'_>> { |
| 96 | 96 | match self { |
| 97 | − // TODO: use or-patterns once MRV is larger than 1.52 (and this is supported) | |
| 98 | 97 | Change::Update { |
| 99 | 98 | expected: PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous), |
| 100 | 99 | .. |
| @@ -424,7 +424,8 @@ fn symbolic_reference_writes_reflog_if_previous_value_is_set() -> crate::Result · 423 unmodified lines | ||
| 424 | 424 | ); |
| 425 | 425 | assert!( |
| 426 | 426 | head.log_exists(&store), |
| 427 | − "reflog is written for new symbolic ref with information about the peeled target id" | |
| 427 | + "reflog is written for new symbolic ref with information about the peeled target id, \ | |
| 428 | + as special accommodation for the state during clone to allow us to get a peeled id into the log" | |
| 428 | 429 | ); |
| 429 | 430 | assert!(store.try_find_loose(referent)?.is_none(), "referent wasn't created"); |
| 430 | 431 | |
| @@ -499,11 +500,6 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 68 unmodified lines | ||
| 499 | 500 | mode: RefLog::AndReference, |
| 500 | 501 | force_create_reflog: false, |
| 501 | 502 | }; |
| 502 | − let log_only = { | |
| 503 | − let mut l = log.clone(); | |
| 504 | − l.mode = RefLog::Only; | |
| 505 | − l | |
| 506 | − }; | |
| 507 | 503 | let edits = store |
| 508 | 504 | .transaction() |
| 509 | 505 | .prepare( |
| @@ -526,7 +522,11 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 16 unmodified lines | ||
| 526 | 522 | vec![ |
| 527 | 523 | RefEdit { |
| 528 | 524 | change: Change::Update { |
| 529 | − log: log_only.clone(), | |
| 525 | + log: { | |
| 526 | + let mut l = log.clone(); | |
| 527 | + l.mode = RefLog::Only; | |
| 528 | + l | |
| 529 | + }, | |
| 530 | 530 | new: new.clone(), |
| 531 | 531 | expected: PreviousValue::MustExistAndMatch(new_head_value.clone()), |
| 532 | 532 | }, |
| @@ -537,7 +537,7 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 4 unmodified lines | ||
| 537 | 537 | change: Change::Update { |
| 538 | 538 | log, |
| 539 | 539 | new: new.clone(), |
| 540 | − expected: PreviousValue::Any, | |
| 540 | + expected: PreviousValue::Any, // there is no previous value, so we can't put `MustExistAndMatch` here. | |
| 541 | 541 | }, |
| 542 | 542 | name: referent.try_into()?, |
| 543 | 543 | deref: false, |