Showing the changes to git-ref/src (2 of 4 files). Show all
Unified · Split
| @@ -1,7 +1,7 @@ | |||
| 1 | use crate::{ | 1 | use crate::{ |
| 2 | mutable::Target, | 2 | mutable::Target, |
| 3 | store::file, | 3 | store::file, |
| 4 | transaction::{Change, DeleteMode, RefEdit, RefEditsExt}, | 4 | transaction::{Change, RefEdit, RefEditsExt, RefLogMode}, |
| 5 | }; | 5 | }; |
| 6 | use bstr::BString; | 6 | use bstr::BString; |
| 7 | use std::io::Write; | 7 | use std::io::Write; |
| @@ -198,8 +198,8 @@ impl<'a> Transaction<'a> { · 190 unmodified lines | |||
| 198 | Change::Delete { mode, .. } => { | 198 | Change::Delete { mode, .. } => { |
| 199 | let lock = change.lock.take().expect("each ref is locked, even deletions"); | 199 | let lock = change.lock.take().expect("each ref is locked, even deletions"); |
| 200 | let (rm_reflog, rm_ref) = match mode { | 200 | let (rm_reflog, rm_ref) = match mode { |
| 201 | DeleteMode::RefAndRefLog => (true, true), | 201 | RefLogMode::RefAndRefLog => (true, true), |
| 202 | DeleteMode::RefLogOnly => (true, false), | 202 | RefLogMode::RefLogOnly => (true, false), |
| 203 | }; | 203 | }; |
| 204 | 204 | ||
| 205 | // Reflog deletion happens first in case it fails a ref without log is less terrible than | 205 | // Reflog deletion happens first in case it fails a ref without log is less terrible than |
| @@ -37,12 +37,15 @@ pub enum Change { · 36 unmodified lines | |||
| 37 | /// Otherwise it functions as `create-or-update`. | 37 | /// Otherwise it functions as `create-or-update`. |
| 38 | Update { | 38 | Update { |
| 39 | /// How to treat the reference log. | 39 | /// How to treat the reference log. |
| 40 | mode: UpdateMode, | 40 | mode: RefLogMode, |
| 41 | /// The previous value of the ref, which will be used to assure the ref is still in the known `previous` state before | 41 | /// The previous value of the ref, which will be used to assure the ref is still in the known `previous` state before |
| 42 | /// updating it. It will also be filled in automatically for use in the reflog, if applicable. | 42 | /// updating it. It will also be filled in automatically for use in the reflog, if applicable. |
| 43 | previous: Option<Target>, | 43 | previous: Option<Target>, |
| 44 | /// The new state of the reference, either for updating an existing one or creating a new one. | 44 | /// The new state of the reference, either for updating an existing one or creating a new one. |
| 45 | new: Target, | 45 | new: Target, |
| 46 | /// If set, create a reflog even though it would otherwise not be the case as prohibited by general rules. | ||
| 47 | /// Note that ref-log writing might be prohibited in the entire repository which is when this flag has no effect either. | ||
| 48 | force_create_reflog: bool, | ||
| 46 | }, | 49 | }, |
| 47 | /// Delete a reference and optionally check if `previous` is its content. | 50 | /// Delete a reference and optionally check if `previous` is its content. |
| 48 | Delete { | 51 | Delete { |
| @@ -52,7 +55,7 @@ pub enum Change { · 3 unmodified lines | |||
| 52 | /// If a previous ref existed, this value will be filled in automatically and can be accessed if the transaction was committed successfully. | 55 | /// If a previous ref existed, this value will be filled in automatically and can be accessed if the transaction was committed successfully. |
| 53 | previous: Option<Target>, | 56 | previous: Option<Target>, |
| 54 | /// How to thread the reference log during deletion. | 57 | /// How to thread the reference log during deletion. |
| 55 | mode: DeleteMode, | 58 | mode: RefLogMode, |
| 56 | }, | 59 | }, |
| 57 | } | 60 | } |
| 58 | 61 | ||
| @@ -70,36 +73,16 @@ pub struct RefEdit { · 11 unmodified lines | |||
| 70 | 73 | ||
| 71 | /// The way to deal with the Reflog in deletions. | 74 | /// The way to deal with the Reflog in deletions. |
| 72 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] | 75 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] |
| 73 | pub enum DeleteMode { | 76 | pub enum RefLogMode { |
| 74 | /// Delete the reference and the log | 77 | /// Delete the reference and the log |
| 75 | RefAndRefLog, | 78 | RefAndRefLog, |
| 76 | /// Delete only the reflog | 79 | /// Delete only the reflog |
| 77 | RefLogOnly, | 80 | RefLogOnly, |
| 78 | } | 81 | } |
| 79 | 82 | ||
| 80 | /// The way to deal with the Reflog in a particular edit | ||
| 81 | /// | ||
| 82 | /// If the `create_unconditionally` field is set, create a reflog even if it otherwise wouldn't be created, | ||
| 83 | /// as is the case for tags. | ||
| 84 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] | ||
| 85 | pub enum UpdateMode { | ||
| 86 | /// As symbolic references only ever see this when you want to detach them, we won't try to dereference them | ||
| 87 | /// in this case and apply the change to it directly. | ||
| 88 | RefAndRefLog { | ||
| 89 | /// If set, update the reflog even if it otherwise wouldn't. | ||
| 90 | create_unconditionally: bool, | ||
| 91 | }, | ||
| 92 | /// Only update the reflog but require this to be a symbolic ref so the actual update can be performed on the | ||
| 93 | /// referent. | ||
| 94 | RefLogOnly { | ||
| 95 | /// If set, update the reflog even if it otherwise wouldn't. | ||
| 96 | create_unconditionally: bool, | ||
| 97 | }, | ||
| 98 | } | ||
| 99 | |||
| 100 | mod ext { | 83 | mod ext { |
| 101 | use crate::{ | 84 | use crate::{ |
| 102 | transaction::{Change, DeleteMode, RefEdit, Target, UpdateMode}, | 85 | transaction::{Change, RefEdit, RefLogMode, Target}, |
| 103 | RefStore, | 86 | RefStore, |
| 104 | }; | 87 | }; |
| 105 | use bstr::BString; | 88 | use bstr::BString; |
| @@ -162,12 +145,14 @@ mod ext { · 56 unmodified lines | |||
| 162 | deref: true, | 145 | deref: true, |
| 163 | }, | 146 | }, |
| 164 | )); | 147 | )); |
| 165 | *mode = match *mode { | 148 | *mode = RefLogMode::RefLogOnly; |
| 166 | DeleteMode::RefLogOnly => DeleteMode::RefLogOnly, | ||
| 167 | DeleteMode::RefAndRefLog => DeleteMode::RefLogOnly, | ||
| 168 | } | ||
| 169 | } | 149 | } |
| 170 | Change::Update { mode, previous, new } => { | 150 | Change::Update { |
| 151 | mode, | ||
| 152 | previous, | ||
| 153 | new, | ||
| 154 | force_create_reflog, | ||
| 155 | } => { | ||
| 171 | new_edits.push(make_entry( | 156 | new_edits.push(make_entry( |
| 172 | eid, | 157 | eid, |
| 173 | RefEdit { | 158 | RefEdit { |
| @@ -175,19 +160,13 @@ mod ext { · 1 unmodified line | |||
| 175 | previous: previous.clone(), | 160 | previous: previous.clone(), |
| 176 | new: new.clone(), | 161 | new: new.clone(), |
| 177 | mode: *mode, | 162 | mode: *mode, |
| 163 | force_create_reflog: *force_create_reflog, | ||
| 178 | }, | 164 | }, |
| 179 | name: referent, | 165 | name: referent, |
| 180 | deref: true, | 166 | deref: true, |
| 181 | }, | 167 | }, |
| 182 | )); | 168 | )); |
| 183 | *mode = match *mode { | 169 | *mode = RefLogMode::RefLogOnly; |
| 184 | UpdateMode::RefLogOnly { create_unconditionally } => { | ||
| 185 | UpdateMode::RefLogOnly { create_unconditionally } | ||
| 186 | } | ||
| 187 | UpdateMode::RefAndRefLog { create_unconditionally } => { | ||
| 188 | UpdateMode::RefLogOnly { create_unconditionally } | ||
| 189 | } | ||
| 190 | } | ||
| 191 | } | 170 | } |
| 192 | }; | 171 | }; |
| 193 | edit.deref = false; | 172 | edit.deref = false; |