@@ -3,25 +3,27 @@ use bitflags::bitflags;
3
3
use crate :: entry:: Stage ;
4
4
5
5
bitflags ! {
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.
7
9
#[ derive( Debug , Clone , Copy , Eq , PartialEq ) ]
8
10
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 ;
13
11
// 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 .
15
13
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 ;
16
18
/// If set, the entry be assumed to match with the version on the working tree, as a way to avoid `lstat()` checks.
17
19
const ASSUME_VALID = 1 << 15 ;
18
20
/// Indicates that an entry needs to be updated as it's in-memory representation doesn't match what's on disk.
19
21
const UPDATE = 1 << 16 ;
20
22
/// Indicates an entry should be removed - this typically happens during writing, by simply skipping over them.
21
23
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 .
23
25
const UPTODATE = 1 << 18 ;
24
- /// Only temporarily used by unpack_trees() (in C)
26
+ /// Only temporarily used by unpack_trees() (in C).
25
27
const ADDED = 1 << 19 ;
26
28
27
29
/// Whether an up-to-date object hash exists for the entry.
@@ -46,8 +48,8 @@ bitflags! {
46
48
/// Indicates the entry name is present in the base/shared index, and thus doesn't have to be stored in this one.
47
49
const STRIP_NAME = 1 << 28 ;
48
50
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.
51
53
const INTENT_TO_ADD = 1 << 29 ;
52
54
/// Stored at rest
53
55
const SKIP_WORKTREE = 1 << 30 ;
@@ -102,7 +104,7 @@ pub(crate) mod at_rest {
102
104
103
105
bitflags ! {
104
106
/// Extended flags - add flags for serialization here and offset them down to u16.
105
- #[ derive( Copy , Clone , Debug ) ]
107
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
106
108
pub struct FlagsExtended : u16 {
107
109
const INTENT_TO_ADD = 1 << ( 29 - 16 ) ;
108
110
const SKIP_WORKTREE = 1 << ( 30 - 16 ) ;
@@ -124,6 +126,18 @@ pub(crate) mod at_rest {
124
126
mod tests {
125
127
use super :: * ;
126
128
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
+
127
141
#[ test]
128
142
fn flags_from_bits_with_conflict ( ) {
129
143
let input = 0b1110_0010_1000_1011 ;
0 commit comments