Skip to content

Commit f0163c9

Browse files
committed
cleanup crate structure (#450)
1 parent 6278966 commit f0163c9

File tree

9 files changed

+98
-89
lines changed

9 files changed

+98
-89
lines changed

git-refspec/src/instruction.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use crate::{parse::Operation, Instruction};
2+
use bstr::BStr;
3+
4+
impl Instruction<'_> {
5+
/// Derive the mode of operation from this instruction.
6+
pub fn operation(&self) -> Operation {
7+
match self {
8+
Instruction::Push(_) => Operation::Push,
9+
Instruction::Fetch(_) => Operation::Fetch,
10+
}
11+
}
12+
}
13+
14+
/// Note that all sources can either be a ref-name, partial or full, or a rev-spec, unless specified otherwise, on the local side.
15+
/// Destinations can only be a partial or full ref names on the remote side.
16+
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
17+
pub enum Push<'a> {
18+
/// Push all local branches to the matching destination on the remote, which has to exist to be updated.
19+
AllMatchingBranches {
20+
/// If true, allow non-fast-forward updates of the matched destination branch.
21+
allow_non_fast_forward: bool,
22+
},
23+
/// Delete the destination ref or glob pattern, with only a single `*` allowed.
24+
Delete {
25+
/// The reference or pattern to delete on the remote.
26+
ref_or_pattern: &'a BStr,
27+
},
28+
/// Push a single ref or refspec to a known destination ref.
29+
Matching {
30+
/// The source ref or refspec to push. If pattern, it contains a single `*`.
31+
src: &'a BStr,
32+
/// The ref to update with the object from `src`. If `src` is a pattern, this is a pattern too.
33+
dst: &'a BStr,
34+
/// If true, allow non-fast-forward updates of `dest`.
35+
allow_non_fast_forward: bool,
36+
},
37+
}
38+
39+
/// Any source can either be a ref name (full or partial) or a fully spelled out hex-sha for an object, on the remote side.
40+
///
41+
/// Destinations can only be a partial or full ref-names on the local side.
42+
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
43+
pub enum Fetch<'a> {
44+
/// Fetch a ref or refs and write the result into the `FETCH_HEAD` without updating local branches.
45+
Only {
46+
/// The ref name to fetch on the remote side, without updating the local side. This will write the result into `FETCH_HEAD`.
47+
src: &'a BStr,
48+
},
49+
/// Exclude a single ref.
50+
Exclude {
51+
/// A single partial or full ref name to exclude on the remote, or a pattern with a single `*`. It cannot be a spelled out object hash.
52+
src: &'a BStr,
53+
},
54+
/// Fetch from `src` and update the corresponding destination branches in `dst` accordingly.
55+
AndUpdate {
56+
/// The ref name to fetch on the remote side, or a pattern with a single `*` to match against.
57+
src: &'a BStr,
58+
/// The local destination to update with what was fetched, or a pattern whose single `*` will be replaced with the matching portion
59+
/// of the `*` from `src`.
60+
dst: &'a BStr,
61+
/// If true, allow non-fast-forward updates of `dest`.
62+
allow_non_fast_forward: bool,
63+
},
64+
}

git-refspec/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
pub mod parse;
77
pub use parse::function::parse;
88

9+
///
10+
pub mod instruction;
11+
912
/// A refspec with references to the memory it was parsed from.
1013
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
1114
pub struct RefSpecRef<'a> {
1215
mode: types::Mode,
13-
op: Operation,
16+
op: parse::Operation,
1417
src: Option<&'a bstr::BStr>,
1518
dst: Option<&'a bstr::BStr>,
1619
}
@@ -19,12 +22,12 @@ pub struct RefSpecRef<'a> {
1922
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
2023
pub struct RefSpec {
2124
mode: types::Mode,
22-
op: Operation,
25+
op: parse::Operation,
2326
src: Option<bstr::BString>,
2427
dst: Option<bstr::BString>,
2528
}
2629

2730
mod spec;
2831

2932
mod types;
30-
pub use types::{Fetch, Instruction, Operation, Push};
33+
pub use types::Instruction;

git-refspec/src/parse.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ pub enum Error {
2626
RevSpec(#[from] git_revision::spec::parse::Error),
2727
}
2828

29+
/// Define how the parsed refspec should be used.
30+
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
31+
pub enum Operation {
32+
/// The `src` side is local and the `dst` side is remote.
33+
Push,
34+
/// The `src` side is remote and the `dst` side is local.
35+
Fetch,
36+
}
37+
2938
pub(crate) mod function {
3039
use crate::parse::Error;
31-
use crate::{types::Mode, Operation, RefSpecRef};
40+
use crate::{parse::Operation, types::Mode, RefSpecRef};
3241
use bstr::{BStr, ByteSlice};
3342

3443
/// Parse `spec` for use in `operation` and return it if it is valid.

git-refspec/src/spec.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::types::Push;
2-
use crate::{types::Mode, Fetch, Instruction, Operation, RefSpec, RefSpecRef};
1+
use crate::instruction::{Fetch, Push};
2+
use crate::{parse::Operation, types::Mode, Instruction, RefSpec, RefSpecRef};
33

44
/// Conversion. Use the [RefSpecRef][RefSpec::to_ref()] type for more usage options.
55
impl RefSpec {
@@ -14,9 +14,13 @@ impl RefSpec {
1414
}
1515
}
1616

17-
impl Into<RefSpec> for RefSpecRef<'_> {
18-
fn into(self) -> RefSpec {
19-
self.to_owned()
17+
mod impls {
18+
use crate::{RefSpec, RefSpecRef};
19+
20+
impl Into<RefSpec> for RefSpecRef<'_> {
21+
fn into(self) -> RefSpec {
22+
self.to_owned()
23+
}
2024
}
2125
}
2226

git-refspec/src/types.rs

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bstr::BStr;
1+
use crate::instruction;
22

33
/// The way to interpret a refspec.
44
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
@@ -11,82 +11,11 @@ pub(crate) enum Mode {
1111
Negative,
1212
}
1313

14-
/// What operation to perform with the refspec.
15-
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
16-
pub enum Operation {
17-
/// The `src` side is local and the `dst` side is remote.
18-
Push,
19-
/// The `src` side is remote and the `dst` side is local.
20-
Fetch,
21-
}
22-
23-
/// Tells what to do and is derived from a [`RefSpec`][RefSpecRef].
14+
/// Tells what to do and is derived from a [`RefSpec`][crate::RefSpecRef].
2415
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
2516
pub enum Instruction<'a> {
2617
/// An instruction for pushing.
27-
Push(Push<'a>),
18+
Push(instruction::Push<'a>),
2819
/// An instruction for fetching.
29-
Fetch(Fetch<'a>),
30-
}
31-
32-
/// Note that all sources can either be a ref-name, partial or full, or a rev-spec, unless specified otherwise, on the local side.
33-
/// Destinations can only be a partial or full ref names on the remote side.
34-
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
35-
pub enum Push<'a> {
36-
/// Push all local branches to the matching destination on the remote, which has to exist to be updated.
37-
AllMatchingBranches {
38-
/// If true, allow non-fast-forward updates of the matched destination branch.
39-
allow_non_fast_forward: bool,
40-
},
41-
/// Delete the destination ref or glob pattern, with only a single `*` allowed.
42-
Delete {
43-
/// The reference or pattern to delete on the remote.
44-
ref_or_pattern: &'a BStr,
45-
},
46-
/// Push a single ref or refspec to a known destination ref.
47-
Matching {
48-
/// The source ref or refspec to push. If pattern, it contains a single `*`.
49-
src: &'a BStr,
50-
/// The ref to update with the object from `src`. If `src` is a pattern, this is a pattern too.
51-
dst: &'a BStr,
52-
/// If true, allow non-fast-forward updates of `dest`.
53-
allow_non_fast_forward: bool,
54-
},
55-
}
56-
57-
/// Note that any source can either be a ref name (full or partial) or a fully spelled out hex-sha for an object, on the remote side.
58-
///
59-
/// Destinations can only be a partial or full ref-names on the local side.
60-
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
61-
pub enum Fetch<'a> {
62-
/// Fetch a ref or refs and write the result into the `FETCH_HEAD` without updating local branches.
63-
Only {
64-
/// The ref name to fetch on the remote side, without updating the local side. This will write the result into `FETCH_HEAD`.
65-
src: &'a BStr,
66-
},
67-
/// Exclude a single ref.
68-
Exclude {
69-
/// A single partial or full ref name to exclude on the remote, or a pattern with a single `*`. It cannot be a spelled out object hash.
70-
src: &'a BStr,
71-
},
72-
/// Fetch from `src` and update the corresponding destination branches in `dst` accordingly.
73-
AndUpdate {
74-
/// The ref name to fetch on the remote side, or a pattern with a single `*` to match against.
75-
src: &'a BStr,
76-
/// The local destination to update with what was fetched, or a pattern whose single `*` will be replaced with the matching portion
77-
/// of the `*` from `src`.
78-
dst: &'a BStr,
79-
/// If true, allow non-fast-forward updates of `dest`.
80-
allow_non_fast_forward: bool,
81-
},
82-
}
83-
84-
impl Instruction<'_> {
85-
/// Derive the mode of operation from this instruction.
86-
pub fn operation(&self) -> Operation {
87-
match self {
88-
Instruction::Push(_) => Operation::Push,
89-
Instruction::Fetch(_) => Operation::Fetch,
90-
}
91-
}
20+
Fetch(instruction::Fetch<'a>),
9221
}

git-refspec/tests/parse/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::parse::{assert_parse, b, try_parse};
2-
use git_refspec::{parse::Error, Fetch, Instruction, Operation};
2+
use git_refspec::{instruction::Fetch, parse::Error, parse::Operation, Instruction};
33

44
#[test]
55
fn revspecs_are_disallowed() {

git-refspec/tests/parse/invalid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::parse::try_parse;
2-
use git_refspec::{parse::Error, Operation};
2+
use git_refspec::{parse::Error, parse::Operation};
33

44
#[test]
55
fn empty() {

git-refspec/tests/parse/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bstr::ByteSlice;
2-
use git_refspec::Operation;
2+
use git_refspec::parse::Operation;
33
use git_testtools::scripted_fixture_repo_read_only;
44
use std::panic::catch_unwind;
55

@@ -61,7 +61,7 @@ mod invalid;
6161
mod push;
6262

6363
mod util {
64-
use git_refspec::{Instruction, Operation, RefSpecRef};
64+
use git_refspec::{parse::Operation, Instruction, RefSpecRef};
6565

6666
pub fn b(input: &str) -> &bstr::BStr {
6767
input.into()

git-refspec/tests/parse/push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::parse::{assert_parse, b, try_parse};
2-
use git_refspec::{parse::Error, Instruction, Operation, Push};
2+
use git_refspec::{instruction::Push, parse::Error, parse::Operation, Instruction};
33

44
#[test]
55
fn negative_unsupported() {

0 commit comments

Comments
 (0)