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
50 if update_reflog {50 if update_reflog {
51 let log_update = match new {51 let log_update = match new {
52 Target::Symbolic(_) => {52 Target::Symbolic(_) => {
53 // no reflog for symref changes, unless the ref is new and we can obtain a peeled id53 // 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 // identified by the expectation of what could be there, as is the case when cloning.55 // identified by the expectation of what could be there, as is the case when cloning.
55 match expected {56 match expected {
56 PreviousValue::ExistingMustMatch(Target::Peeled(oid)) => {57 PreviousValue::ExistingMustMatch(Target::Peeled(oid)) => {
@@ -61,6 +62,8 @@ impl<'s, 'p> Transaction<'s, 'p> { · 4 unmodified lines
61 }62 }
62 Target::Peeled(new_oid) => {63 Target::Peeled(new_oid) => {
63 let previous = match expected {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 PreviousValue::MustExistAndMatch(Target::Peeled(oid)) => Some(oid.to_owned()),67 PreviousValue::MustExistAndMatch(Target::Peeled(oid)) => Some(oid.to_owned()),
65 _ => None,68 _ => None,
66 }69 }
gix-ref/src/transaction/mod.rs+1−2
@@ -64,7 +64,7 @@ pub enum Change { · 63 unmodified lines
64 /// The desired change to the reference log.64 /// The desired change to the reference log.
65 log: LogChange,65 log: LogChange,
66 /// The expected value already present in the reference.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 after67 /// If a ref was existing previously this field will be overwritten with `MustExistAndMatch(actual_value)` for use after
68 /// the transaction was committed successfully.68 /// the transaction was committed successfully.
69 expected: PreviousValue,69 expected: PreviousValue,
70 /// The new state of the reference, either for updating an existing one or creating a new one.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 /// Return references to values that are in common between all variants and denote the previous observed value.94 /// Return references to values that are in common between all variants and denote the previous observed value.
95 pub fn previous_value(&self) -> Option<crate::TargetRef<'_>> {95 pub fn previous_value(&self) -> Option<crate::TargetRef<'_>> {
96 match self {96 match self {
97 // TODO: use or-patterns once MRV is larger than 1.52 (and this is supported)
98 Change::Update {97 Change::Update {
99 expected: PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous),98 expected: PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous),
100 ..99 ..
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
424 );424 );
425 assert!(425 assert!(
426 head.log_exists(&store),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 assert!(store.try_find_loose(referent)?.is_none(), "referent wasn't created");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 mode: RefLog::AndReference,500 mode: RefLog::AndReference,
500 force_create_reflog: false,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 let edits = store503 let edits = store
508 .transaction()504 .transaction()
509 .prepare(505 .prepare(
@@ -526,7 +522,11 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 16 unmodified lines
526 vec![522 vec![
527 RefEdit {523 RefEdit {
528 change: Change::Update {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 new: new.clone(),530 new: new.clone(),
531 expected: PreviousValue::MustExistAndMatch(new_head_value.clone()),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 change: Change::Update {537 change: Change::Update {
538 log,538 log,
539 new: new.clone(),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 name: referent.try_into()?,542 name: referent.try_into()?,
543 deref: false,543 deref: false,