History

doc: improve documentation about the `Change` type.

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.

Sebastian Thiel committed 3 years ago

Commit 5f6cf221 parent fadec773 files · +13 −11Browse files

Unified · Split

3 files
  1. gix-ref/src/store/file/transaction/commit.rs +4 −1
  2. gix-ref/src/transaction/mod.rs +1 −2
  3. gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/mod.rs +8 −8
gix-ref/src/store/file/transaction/commit.rs+4−1
@@ -50,7 +50,8 @@ impl<'s, 'p> Transaction<'s, 'p> { · 49 unmodified lines
5050 if update_reflog {
5151 let log_update = match new {
5252 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
5455 // identified by the expectation of what could be there, as is the case when cloning.
5556 match expected {
5657 PreviousValue::ExistingMustMatch(Target::Peeled(oid)) => {
@@ -61,6 +62,8 @@ impl<'s, 'p> Transaction<'s, 'p> { · 4 unmodified lines
6162 }
6263 Target::Peeled(new_oid) => {
6364 let previous = match expected {
65+ // Here, this means that the ref already existed, and that it will receive (even transitively)
66+ // the given value
6467 PreviousValue::MustExistAndMatch(Target::Peeled(oid)) => Some(oid.to_owned()),
6568 _ => None,
6669 }
gix-ref/src/transaction/mod.rs+1−2
@@ -64,7 +64,7 @@ pub enum Change { · 63 unmodified lines
6464 /// The desired change to the reference log.
6565 log: LogChange,
6666 /// 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
6868 /// the transaction was committed successfully.
6969 expected: PreviousValue,
7070 /// 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
9494 /// Return references to values that are in common between all variants and denote the previous observed value.
9595 pub fn previous_value(&self) -> Option<crate::TargetRef<'_>> {
9696 match self {
97− // TODO: use or-patterns once MRV is larger than 1.52 (and this is supported)
9897 Change::Update {
9998 expected: PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous),
10099 ..
gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/mod.rs+8−8
@@ -424,7 +424,8 @@ fn symbolic_reference_writes_reflog_if_previous_value_is_set() -> crate::Result · 423 unmodified lines
424424 );
425425 assert!(
426426 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"
428429 );
429430 assert!(store.try_find_loose(referent)?.is_none(), "referent wasn't created");
430431
@@ -499,11 +500,6 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 68 unmodified lines
499500 mode: RefLog::AndReference,
500501 force_create_reflog: false,
501502 };
502− let log_only = {
503− let mut l = log.clone();
504− l.mode = RefLog::Only;
505− l
506− };
507503 let edits = store
508504 .transaction()
509505 .prepare(
@@ -526,7 +522,11 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 16 unmodified lines
526522 vec![
527523 RefEdit {
528524 change: Change::Update {
529− log: log_only.clone(),
525+ log: {
526+ let mut l = log.clone();
527+ l.mode = RefLog::Only;
528+ l
529+ },
530530 new: new.clone(),
531531 expected: PreviousValue::MustExistAndMatch(new_head_value.clone()),
532532 },
@@ -537,7 +537,7 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 4 unmodified lines
537537 change: Change::Update {
538538 log,
539539 new: new.clone(),
540− expected: PreviousValue::Any,
540+ expected: PreviousValue::Any, // there is no previous value, so we can't put `MustExistAndMatch` here.
541541 },
542542 name: referent.try_into()?,
543543 deref: false,