@@ -82,6 +82,12 @@ impl ChangeRef<'_, '_> {
8282 /// Return all shared fields among all variants: `(location, index, entry_mode, id)`
8383 ///
8484 /// In case of rewrites, the fields return to the current change.
85+ ///
86+ /// Note that there are also more specific accessors in case you only need to access to one of
87+ /// these fields individually.
88+ ///
89+ /// See [`ChangeRef::location()`], [`ChangeRef::index()`], [`ChangeRef::entry_mode()`] and
90+ /// [`ChangeRef::id()`].
8591 pub fn fields ( & self ) -> ( & BStr , usize , gix_index:: entry:: Mode , & gix_hash:: oid ) {
8692 match self {
8793 ChangeRef :: Addition {
@@ -114,6 +120,46 @@ impl ChangeRef<'_, '_> {
114120 } => ( location. as_ref ( ) , * index, * entry_mode, id) ,
115121 }
116122 }
123+
124+ /// Return the `location`, in the case of rewrites referring to the current change.
125+ pub fn location ( & self ) -> & BStr {
126+ match self {
127+ ChangeRef :: Addition { location, .. }
128+ | ChangeRef :: Deletion { location, .. }
129+ | ChangeRef :: Modification { location, .. }
130+ | ChangeRef :: Rewrite { location, .. } => location. as_ref ( ) ,
131+ }
132+ }
133+
134+ /// Return the `index`, in the case of rewrites referring to the current change.
135+ pub fn index ( & self ) -> usize {
136+ match self {
137+ ChangeRef :: Addition { index, .. }
138+ | ChangeRef :: Deletion { index, .. }
139+ | ChangeRef :: Modification { index, .. }
140+ | ChangeRef :: Rewrite { index, .. } => * index,
141+ }
142+ }
143+
144+ /// Return the `entry_mode`, in the case of rewrites referring to the current change.
145+ pub fn entry_mode ( & self ) -> gix_index:: entry:: Mode {
146+ match self {
147+ ChangeRef :: Addition { entry_mode, .. }
148+ | ChangeRef :: Deletion { entry_mode, .. }
149+ | ChangeRef :: Modification { entry_mode, .. }
150+ | ChangeRef :: Rewrite { entry_mode, .. } => * entry_mode,
151+ }
152+ }
153+
154+ /// Return the `id`, in the case of rewrites referring to the current change.
155+ pub fn id ( & self ) -> & gix_hash:: oid {
156+ match self {
157+ ChangeRef :: Addition { id, .. }
158+ | ChangeRef :: Deletion { id, .. }
159+ | ChangeRef :: Modification { id, .. }
160+ | ChangeRef :: Rewrite { id, .. } => id,
161+ }
162+ }
117163}
118164
119165impl rewrites:: tracker:: Change for ChangeRef < ' _ , ' _ > {
0 commit comments