Skip to content

Commit 6713793

Browse files
committed
refactor (#450)
1 parent 0ba1b73 commit 6713793

File tree

2 files changed

+106
-104
lines changed

2 files changed

+106
-104
lines changed

git-refspec/src/lib.rs

Lines changed: 8 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,125 +2,29 @@
22
#![forbid(unsafe_code, rust_2018_idioms)]
33
#![allow(missing_docs)]
44

5-
use bstr::{BStr, BString};
6-
7-
/// The way to interpret a refspec.
8-
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
9-
pub enum Mode {
10-
/// Apply standard rules for refspecs which are including refs with specific rules related to allowing fast forwards of destinations.
11-
Normal,
12-
/// Even though according to normal rules a non-fastforward would be denied, override this and reset a ref forcefully in the destination.
13-
Force,
14-
/// Instead of considering matching refs included, we consider them excluded. This applies only to the source side of a refspec.
15-
Negative,
16-
}
17-
18-
/// What operation to perform with the refspec.
19-
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
20-
pub enum Operation {
21-
/// The `src` side is local and the `dst` side is remote.
22-
Push,
23-
/// The `src` side is remote and the `dst` side is local.
24-
Fetch,
25-
}
26-
27-
pub enum Instruction<'a> {
28-
Push(Push<'a>),
29-
Fetch(Fetch<'a>),
30-
}
31-
32-
pub enum Push<'a> {
33-
/// Push a single ref knowing only one ref name.
34-
SingleMatching {
35-
/// The name of the ref to push from `src` to `dest`.
36-
src_and_dest: &'a BStr,
37-
/// If true, allow non-fast-forward updates of `dest`.
38-
allow_non_fast_forward: bool,
39-
},
40-
/// Exclude a single ref.
41-
ExcludeSingle {
42-
/// A single full ref name to exclude.
43-
src: &'a BStr,
44-
},
45-
/// Exclude multiple refs with single `*` glob.
46-
ExcludeMultipleWithGlob {
47-
/// A ref pattern with a single `*`.
48-
src: &'a BStr,
49-
},
50-
/// Push a single ref or refspec to a known destination ref.
51-
Single {
52-
/// The source ref or refspec to push.
53-
src: &'a BStr,
54-
/// The ref to update with the object from `src`.
55-
dest: &'a BStr,
56-
/// If true, allow non-fast-forward updates of `dest`.
57-
allow_non_fast_forward: bool,
58-
},
59-
/// Push a multiple refs to matching destination refs, with exactly a single glob on both sides.
60-
MultipleWithGlob {
61-
/// The source ref to match against all refs for pushing.
62-
src: &'a BStr,
63-
/// The ref to update with object obtained from `src`, filling in the `*` with the portion that matched in `src`.
64-
dest: &'a BStr,
65-
/// If true, allow non-fast-forward updates of `dest`.
66-
allow_non_fast_forward: bool,
67-
},
68-
}
69-
70-
pub enum Fetch<'a> {
71-
Only {
72-
/// The ref name to fetch on the remote side, without updating the local side.
73-
src: &'a BStr,
74-
},
75-
/// Exclude a single ref.
76-
ExcludeSingle {
77-
/// A single full ref name to exclude.
78-
src: &'a BStr,
79-
},
80-
/// Exclude multiple refs with single `*` glob.
81-
ExcludeMultipleWithGlob {
82-
/// A ref pattern with a single `*`.
83-
src: &'a BStr,
84-
},
85-
AndUpdateSingle {
86-
/// The ref name to fetch on the remote side.
87-
src: &'a BStr,
88-
/// The local destination to update with what was fetched.
89-
dest: &'a BStr,
90-
/// If true, allow non-fast-forward updates of `dest`.
91-
allow_non_fast_forward: bool,
92-
},
93-
/// Similar to `FetchAndUpdate`, but src and destination contain a single glob to fetch and update multiple refs.
94-
AndUpdateMultipleWithGlob {
95-
/// The ref glob to match against all refs on the remote side for fetching.
96-
src: &'a BStr,
97-
/// The local destination to update with what was fetched by replacing the single `*` with the matching portion from `src`.
98-
dest: &'a BStr,
99-
/// If true, allow non-fast-forward updates of `dest`.
100-
allow_non_fast_forward: bool,
101-
},
102-
}
5+
pub mod parse;
6+
pub use parse::function::parse;
1037

1048
/// A refspec with references to the memory it was parsed from.
1059
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
10610
pub struct RefSpecRef<'a> {
10711
mode: Mode,
10812
op: Operation,
109-
src: Option<&'a BStr>,
110-
dest: Option<&'a BStr>,
13+
src: Option<&'a bstr::BStr>,
14+
dest: Option<&'a bstr::BStr>,
11115
}
11216

11317
/// An owned refspec.
11418
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
11519
pub struct RefSpec {
11620
mode: Mode,
11721
op: Operation,
118-
src: Option<BString>,
119-
dest: Option<BString>,
22+
src: Option<bstr::BString>,
23+
dest: Option<bstr::BString>,
12024
}
12125

122-
pub mod parse;
123-
pub use parse::function::parse;
26+
mod types;
27+
pub use types::{Instruction, Mode, Operation};
12428

12529
mod spec {
12630
use crate::{Instruction, Mode, RefSpec, RefSpecRef};

git-refspec/src/types.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
use bstr::BStr;
2+
3+
/// The way to interpret a refspec.
4+
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
5+
pub enum Mode {
6+
/// Apply standard rules for refspecs which are including refs with specific rules related to allowing fast forwards of destinations.
7+
Normal,
8+
/// Even though according to normal rules a non-fastforward would be denied, override this and reset a ref forcefully in the destination.
9+
Force,
10+
/// Instead of considering matching refs included, we consider them excluded. This applies only to the source side of a refspec.
11+
Negative,
12+
}
13+
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+
pub enum Instruction<'a> {
24+
Push(Push<'a>),
25+
Fetch(Fetch<'a>),
26+
}
27+
28+
pub enum Push<'a> {
29+
/// Push a single ref knowing only one ref name.
30+
SingleMatching {
31+
/// The name of the ref to push from `src` to `dest`.
32+
src_and_dest: &'a BStr,
33+
/// If true, allow non-fast-forward updates of `dest`.
34+
allow_non_fast_forward: bool,
35+
},
36+
/// Exclude a single ref.
37+
ExcludeSingle {
38+
/// A single full ref name to exclude.
39+
src: &'a BStr,
40+
},
41+
/// Exclude multiple refs with single `*` glob.
42+
ExcludeMultipleWithGlob {
43+
/// A ref pattern with a single `*`.
44+
src: &'a BStr,
45+
},
46+
/// Push a single ref or refspec to a known destination ref.
47+
Single {
48+
/// The source ref or refspec to push.
49+
src: &'a BStr,
50+
/// The ref to update with the object from `src`.
51+
dest: &'a BStr,
52+
/// If true, allow non-fast-forward updates of `dest`.
53+
allow_non_fast_forward: bool,
54+
},
55+
/// Push a multiple refs to matching destination refs, with exactly a single glob on both sides.
56+
MultipleWithGlob {
57+
/// The source ref to match against all refs for pushing.
58+
src: &'a BStr,
59+
/// The ref to update with object obtained from `src`, filling in the `*` with the portion that matched in `src`.
60+
dest: &'a BStr,
61+
/// If true, allow non-fast-forward updates of `dest`.
62+
allow_non_fast_forward: bool,
63+
},
64+
}
65+
66+
pub enum Fetch<'a> {
67+
Only {
68+
/// The ref name to fetch on the remote side, without updating the local side.
69+
src: &'a BStr,
70+
},
71+
/// Exclude a single ref.
72+
ExcludeSingle {
73+
/// A single full ref name to exclude.
74+
src: &'a BStr,
75+
},
76+
/// Exclude multiple refs with single `*` glob.
77+
ExcludeMultipleWithGlob {
78+
/// A ref pattern with a single `*`.
79+
src: &'a BStr,
80+
},
81+
AndUpdateSingle {
82+
/// The ref name to fetch on the remote side.
83+
src: &'a BStr,
84+
/// The local destination to update with what was fetched.
85+
dest: &'a BStr,
86+
/// If true, allow non-fast-forward updates of `dest`.
87+
allow_non_fast_forward: bool,
88+
},
89+
/// Similar to `FetchAndUpdate`, but src and destination contain a single glob to fetch and update multiple refs.
90+
AndUpdateMultipleWithGlob {
91+
/// The ref glob to match against all refs on the remote side for fetching.
92+
src: &'a BStr,
93+
/// The local destination to update with what was fetched by replacing the single `*` with the matching portion from `src`.
94+
dest: &'a BStr,
95+
/// If true, allow non-fast-forward updates of `dest`.
96+
allow_non_fast_forward: bool,
97+
},
98+
}

0 commit comments

Comments
 (0)