History

[ref] refactor

Sebastian Thiel committed 5 years ago

Commit 97fc8641 parent f436f184 files · +50 −77Browse files

Showing the changes to git-ref/src (2 of 4 files). Show all

Unified · Split

2 files
  1. git-ref/src/store/file/transaction.rs +3 −3
  2. git-ref/src/transaction.rs +16 −37
git-ref/src/store/file/transaction.rs+3−3
@@ -1,7 +1,7 @@
11 use crate::{
22 mutable::Target,
33 store::file,
4− transaction::{Change, DeleteMode, RefEdit, RefEditsExt},
4+ transaction::{Change, RefEdit, RefEditsExt, RefLogMode},
55 };
66 use bstr::BString;
77 use std::io::Write;
@@ -198,8 +198,8 @@ impl<'a> Transaction<'a> { · 190 unmodified lines
198198 Change::Delete { mode, .. } => {
199199 let lock = change.lock.take().expect("each ref is locked, even deletions");
200200 let (rm_reflog, rm_ref) = match mode {
201− DeleteMode::RefAndRefLog => (true, true),
202− DeleteMode::RefLogOnly => (true, false),
201+ RefLogMode::RefAndRefLog => (true, true),
202+ RefLogMode::RefLogOnly => (true, false),
203203 };
204204
205205 // Reflog deletion happens first in case it fails a ref without log is less terrible than
git-ref/src/transaction.rs+16−37
@@ -37,12 +37,15 @@ pub enum Change { · 36 unmodified lines
3737 /// Otherwise it functions as `create-or-update`.
3838 Update {
3939 /// How to treat the reference log.
40− mode: UpdateMode,
40+ mode: RefLogMode,
4141 /// The previous value of the ref, which will be used to assure the ref is still in the known `previous` state before
4242 /// updating it. It will also be filled in automatically for use in the reflog, if applicable.
4343 previous: Option<Target>,
4444 /// The new state of the reference, either for updating an existing one or creating a new one.
4545 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,
4649 },
4750 /// Delete a reference and optionally check if `previous` is its content.
4851 Delete {
@@ -52,7 +55,7 @@ pub enum Change { · 3 unmodified lines
5255 /// If a previous ref existed, this value will be filled in automatically and can be accessed if the transaction was committed successfully.
5356 previous: Option<Target>,
5457 /// How to thread the reference log during deletion.
55− mode: DeleteMode,
58+ mode: RefLogMode,
5659 },
5760 }
5861
@@ -70,36 +73,16 @@ pub struct RefEdit { · 11 unmodified lines
7073
7174 /// The way to deal with the Reflog in deletions.
7275 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
73−pub enum DeleteMode {
76+pub enum RefLogMode {
7477 /// Delete the reference and the log
7578 RefAndRefLog,
7679 /// Delete only the reflog
7780 RefLogOnly,
7881 }
7982
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−
10083 mod ext {
10184 use crate::{
102− transaction::{Change, DeleteMode, RefEdit, Target, UpdateMode},
85+ transaction::{Change, RefEdit, RefLogMode, Target},
10386 RefStore,
10487 };
10588 use bstr::BString;
@@ -162,12 +145,14 @@ mod ext { · 56 unmodified lines
162145 deref: true,
163146 },
164147 ));
165− *mode = match *mode {
166− DeleteMode::RefLogOnly => DeleteMode::RefLogOnly,
167− DeleteMode::RefAndRefLog => DeleteMode::RefLogOnly,
168− }
148+ *mode = RefLogMode::RefLogOnly;
169149 }
170− Change::Update { mode, previous, new } => {
150+ Change::Update {
151+ mode,
152+ previous,
153+ new,
154+ force_create_reflog,
155+ } => {
171156 new_edits.push(make_entry(
172157 eid,
173158 RefEdit {
@@ -175,19 +160,13 @@ mod ext { · 1 unmodified line
175160 previous: previous.clone(),
176161 new: new.clone(),
177162 mode: *mode,
163+ force_create_reflog: *force_create_reflog,
178164 },
179165 name: referent,
180166 deref: true,
181167 },
182168 ));
183− *mode = match *mode {
184− UpdateMode::RefLogOnly { create_unconditionally } => {
185− UpdateMode::RefLogOnly { create_unconditionally }
186− }
187− UpdateMode::RefAndRefLog { create_unconditionally } => {
188− UpdateMode::RefLogOnly { create_unconditionally }
189− }
190− }
169+ *mode = RefLogMode::RefLogOnly;
191170 }
192171 };
193172 edit.deref = false;