@@ -3,25 +3,27 @@ use bitflags::bitflags;
33use crate :: entry:: Stage ;
44
55bitflags ! {
6- /// In-memory flags
6+ /// In-memory flags.
7+ ///
8+ /// Notably, not all of these will be persisted but can be used to aid all kinds of operations.
79 #[ derive( Debug , Clone , Copy , Eq , PartialEq ) ]
810 pub struct Flags : u32 {
9- /// The mask to apply to obtain the stage number of an entry.
10- const STAGE_MASK = 0x3000 ;
11- /// If set, additional bits need to be written to storage.
12- const EXTENDED = 0x4000 ;
1311 // TODO: could we use the pathlen ourselves to save 8 bytes? And how to handle longer paths than that? 0 as sentinel maybe?
14- /// The mask to obtain the length of the path associated with this entry.
12+ /// The mask to obtain the length of the path associated with this entry, up to 4095 characters without extension .
1513 const PATH_LEN = 0x0fff ;
14+ /// The mask to apply to obtain the stage number of an entry, encoding three value: 0 = base, 1 = ours, 2 = theirs.
15+ const STAGE_MASK = 1 <<12 | 1 <<13 ;
16+ /// If set, additional bits need to be written to storage.
17+ const EXTENDED = 1 <<14 ;
1618 /// If set, the entry be assumed to match with the version on the working tree, as a way to avoid `lstat()` checks.
1719 const ASSUME_VALID = 1 << 15 ;
1820 /// Indicates that an entry needs to be updated as it's in-memory representation doesn't match what's on disk.
1921 const UPDATE = 1 << 16 ;
2022 /// Indicates an entry should be removed - this typically happens during writing, by simply skipping over them.
2123 const REMOVE = 1 << 17 ;
22- /// Indicates that an entry is known to be uptodate .
24+ /// Indicates that an entry is known to be up-to-date .
2325 const UPTODATE = 1 << 18 ;
24- /// Only temporarily used by unpack_trees() (in C)
26+ /// Only temporarily used by unpack_trees() (in C).
2527 const ADDED = 1 << 19 ;
2628
2729 /// Whether an up-to-date object hash exists for the entry.
@@ -46,8 +48,8 @@ bitflags! {
4648 /// Indicates the entry name is present in the base/shared index, and thus doesn't have to be stored in this one.
4749 const STRIP_NAME = 1 << 28 ;
4850
49- ///
50- /// stored at rest, see at_rest::FlagsExtended
51+ /// Created with `git add --intent-to-add` to mark empty entries that have their counter-part in the worktree, but not
52+ /// yet in the object database.
5153 const INTENT_TO_ADD = 1 << 29 ;
5254 /// Stored at rest
5355 const SKIP_WORKTREE = 1 << 30 ;
@@ -102,7 +104,7 @@ pub(crate) mod at_rest {
102104
103105 bitflags ! {
104106 /// Extended flags - add flags for serialization here and offset them down to u16.
105- #[ derive( Copy , Clone , Debug ) ]
107+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
106108 pub struct FlagsExtended : u16 {
107109 const INTENT_TO_ADD = 1 << ( 29 - 16 ) ;
108110 const SKIP_WORKTREE = 1 << ( 30 - 16 ) ;
@@ -124,6 +126,18 @@ pub(crate) mod at_rest {
124126 mod tests {
125127 use super :: * ;
126128
129+ #[ test]
130+ fn flags_extended_conversion ( ) {
131+ assert_eq ! (
132+ FlagsExtended :: all( ) . to_flags( ) ,
133+ Some ( super :: super :: Flags :: INTENT_TO_ADD | super :: super :: Flags :: SKIP_WORKTREE )
134+ ) ;
135+ assert_eq ! (
136+ FlagsExtended :: from_flags( super :: super :: Flags :: all( ) ) ,
137+ FlagsExtended :: all( )
138+ ) ;
139+ }
140+
127141 #[ test]
128142 fn flags_from_bits_with_conflict ( ) {
129143 let input = 0b1110_0010_1000_1011 ;
0 commit comments