gix_revision/spec/mod.rs
1use crate::Spec;
2
3/// How to interpret a revision specification, or `revspec`.
4#[derive(Default, Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum Kind {
7 /// Include commits reachable from this revision, the default when parsing revision `a` for example, i.e. `a` and its ancestors.
8 /// Example: `a`.
9 #[default]
10 IncludeReachable,
11 /// Exclude commits reachable from this revision, i.e. `a` and its ancestors. Example: `^a`.
12 ExcludeReachable,
13 /// Every commit that is reachable from `b` but not from `a`. Example: `a..b`.
14 RangeBetween,
15 /// Every commit reachable through either `a` or `b` but no commit that is reachable by both. Example: `a...b`.
16 ReachableToMergeBase,
17 /// Include every commit of all parents of `a`, but not `a` itself. Example: `a^@`.
18 IncludeReachableFromParents,
19 /// Exclude every commit of all parents of `a`, but not `a` itself. Example: `a^!`.
20 ExcludeReachableFromParents,
21}
22
23impl Spec {
24 /// Return the kind of this specification.
25 pub fn kind(&self) -> Kind {
26 match self {
27 Spec::Include(_) => Kind::IncludeReachable,
28 Spec::Exclude(_) => Kind::ExcludeReachable,
29 Spec::Range { .. } => Kind::RangeBetween,
30 Spec::Merge { .. } => Kind::ReachableToMergeBase,
31 Spec::IncludeOnlyParents { .. } => Kind::IncludeReachableFromParents,
32 Spec::ExcludeParents { .. } => Kind::ExcludeReachableFromParents,
33 }
34 }
35}
36
37mod _impls {
38 use std::fmt::{Display, Formatter};
39
40 use crate::Spec;
41
42 impl Display for Spec {
43 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
44 match self {
45 Spec::Include(oid) => Display::fmt(oid, f),
46 Spec::Exclude(oid) => write!(f, "^{oid}"),
47 Spec::Range { from, to } => write!(f, "{from}..{to}"),
48 Spec::Merge { theirs, ours } => write!(f, "{theirs}...{ours}"),
49 Spec::IncludeOnlyParents(from_exclusive) => write!(f, "{from_exclusive}^@"),
50 Spec::ExcludeParents(oid) => write!(f, "{oid}^!"),
51 }
52 }
53 }
54}
55
56pub(crate) mod types {
57 /// A revision specification without any bindings to a repository, useful for serialization or movement over thread boundaries.
58 ///
59 /// Note that all [object ids][gix_hash::ObjectId] should be a committish, but don't have to be.
60 /// Unless the field name contains `_exclusive`, the respective objects are included in the set.
61 #[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
62 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63 pub enum Spec {
64 /// Include commits reachable from this revision, i.e. `a` and its ancestors.
65 ///
66 /// The equivalent to [crate::spec::Kind::IncludeReachable], but with data.
67 Include(gix_hash::ObjectId),
68 /// Exclude commits reachable from this revision, i.e. `a` and its ancestors. Example: `^a`.
69 ///
70 /// The equivalent to [crate::spec::Kind::ExcludeReachable], but with data.
71 Exclude(gix_hash::ObjectId),
72 /// Every commit that is reachable from `from` to `to`, but not any ancestors of `from`. Example: `from..to`.
73 ///
74 /// The equivalent to [crate::spec::Kind::RangeBetween], but with data.
75 Range {
76 /// The starting point of the range, which is included in the set.
77 from: gix_hash::ObjectId,
78 /// The end point of the range, which is included in the set.
79 to: gix_hash::ObjectId,
80 },
81 /// Every commit reachable through either `theirs` or `ours`, but no commit that is reachable by both. Example: `theirs...ours`.
82 ///
83 /// The equivalent to [crate::spec::Kind::ReachableToMergeBase], but with data.
84 Merge {
85 /// Their side of the merge, which is included in the set.
86 theirs: gix_hash::ObjectId,
87 /// Our side of the merge, which is included in the set.
88 ours: gix_hash::ObjectId,
89 },
90 /// Include every commit of all parents of `a`, but not `a` itself. Example: `a^@`.
91 ///
92 /// The equivalent to [crate::spec::Kind::IncludeReachableFromParents], but with data.
93 IncludeOnlyParents(
94 /// Include only the parents of this object, but not the object itself.
95 gix_hash::ObjectId,
96 ),
97 /// Exclude every commit of all parents of `a`, but not `a` itself. Example: `a^!`.
98 ///
99 /// The equivalent to [crate::spec::Kind::ExcludeReachableFromParents], but with data.
100 ExcludeParents(
101 /// Exclude the parents of this object, but not the object itself.
102 gix_hash::ObjectId,
103 ),
104 }
105}
106
107///
108pub mod parse;
109pub use parse::function::parse;