Skip to content

Commit

Permalink
don't expose mode() as it's kind of messy and should be left as imple…
Browse files Browse the repository at this point in the history
…mentation detail (#450)
  • Loading branch information
Byron committed Aug 7, 2022
1 parent c695a7e commit 6278966
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 27 deletions.
6 changes: 3 additions & 3 deletions git-refspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use parse::function::parse;
/// A refspec with references to the memory it was parsed from.
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
pub struct RefSpecRef<'a> {
mode: Mode,
mode: types::Mode,
op: Operation,
src: Option<&'a bstr::BStr>,
dst: Option<&'a bstr::BStr>,
Expand All @@ -18,7 +18,7 @@ pub struct RefSpecRef<'a> {
/// An owned refspec.
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
pub struct RefSpec {
mode: Mode,
mode: types::Mode,
op: Operation,
src: Option<bstr::BString>,
dst: Option<bstr::BString>,
Expand All @@ -27,4 +27,4 @@ pub struct RefSpec {
mod spec;

mod types;
pub use types::{Fetch, Instruction, Mode, Operation, Push};
pub use types::{Fetch, Instruction, Operation, Push};
2 changes: 1 addition & 1 deletion git-refspec/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum Error {

pub(crate) mod function {
use crate::parse::Error;
use crate::{Mode, Operation, RefSpecRef};
use crate::{types::Mode, Operation, RefSpecRef};
use bstr::{BStr, ByteSlice};

/// Parse `spec` for use in `operation` and return it if it is valid.
Expand Down
7 changes: 1 addition & 6 deletions git-refspec/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::types::Push;
use crate::{Fetch, Instruction, Mode, Operation, RefSpec, RefSpecRef};
use crate::{types::Mode, Fetch, Instruction, Operation, RefSpec, RefSpecRef};

/// Conversion. Use the [RefSpecRef][RefSpec::to_ref()] type for more usage options.
impl RefSpec {
Expand All @@ -22,11 +22,6 @@ impl Into<RefSpec> for RefSpecRef<'_> {

/// Access
impl RefSpecRef<'_> {
/// Return the refspec mode.
pub fn mode(&self) -> Mode {
self.mode
}

/// Transform the state of the refspec into an instruction making clear what to do with it.
pub fn instruction(&self) -> Instruction<'_> {
match self.op {
Expand Down
2 changes: 1 addition & 1 deletion git-refspec/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bstr::BStr;

/// The way to interpret a refspec.
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
pub enum Mode {
pub(crate) enum Mode {
/// Apply standard rules for refspecs which are including refs with specific rules related to allowing fast forwards of destinations.
Normal,
/// Even though according to normal rules a non-fastforward would be denied, override this and reset a ref forcefully in the destination.
Expand Down
12 changes: 3 additions & 9 deletions git-refspec/tests/parse/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::parse::{assert_parse, b, try_parse};
use git_refspec::{parse::Error, Fetch, Instruction, Mode, Operation};
use git_refspec::{parse::Error, Fetch, Instruction, Operation};

#[test]
fn revspecs_are_disallowed() {
Expand Down Expand Up @@ -71,12 +71,7 @@ fn ampersand_is_resolved_to_head() {
#[test]
fn lhs_colon_empty_fetches_only() {
assert_parse("src:", Instruction::Fetch(Fetch::Only { src: b("src") }));
let spec = assert_parse("+src:", Instruction::Fetch(Fetch::Only { src: b("src") }));
assert_eq!(
spec.mode(),
Mode::Force,
"force is set, even though it has no effect in the actual instruction"
);
assert_parse("+src:", Instruction::Fetch(Fetch::Only { src: b("src") }));
}

#[test]
Expand Down Expand Up @@ -140,8 +135,7 @@ fn empty_lhs_colon_rhs_fetches_head_to_destination() {
#[test]
fn colon_alone_is_for_fetching_head_into_fetchhead() {
assert_parse(":", Instruction::Fetch(Fetch::Only { src: b("HEAD") }));
let spec = assert_parse("+:", Instruction::Fetch(Fetch::Only { src: b("HEAD") }));
assert_eq!(spec.mode(), Mode::Force, "it's set even though it's not useful");
assert_parse("+:", Instruction::Fetch(Fetch::Only { src: b("HEAD") }));
}

#[test]
Expand Down
9 changes: 2 additions & 7 deletions git-refspec/tests/parse/push.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::parse::{assert_parse, b, try_parse};
use git_refspec::{parse::Error, Instruction, Mode, Operation, Push};
use git_refspec::{parse::Error, Instruction, Operation, Push};

#[test]
fn negative_unsupported() {
Expand Down Expand Up @@ -123,10 +123,5 @@ fn colon_alone_is_for_pushing_matching_refs() {
#[test]
fn delete() {
assert_parse(":a", Instruction::Push(Push::Delete { ref_or_pattern: b("a") }));
let spec = assert_parse("+:a", Instruction::Push(Push::Delete { ref_or_pattern: b("a") }));
assert_eq!(
spec.mode(),
Mode::Force,
"force is set, even though it has no effect in the actual instruction"
);
assert_parse("+:a", Instruction::Push(Push::Delete { ref_or_pattern: b("a") }));
}

0 comments on commit 6278966

Please sign in to comment.