5
5
#include "object-store.h"
6
6
#include "repository.h"
7
7
8
+ struct flag_definition {
9
+ const char * name ;
10
+ uint64_t mask ;
11
+ };
12
+
13
+ #define FLAG_DEF (x ) \
14
+ { \
15
+ #x, (x) \
16
+ }
17
+
18
+ static unsigned int parse_flags (const char * str , struct flag_definition * defs )
19
+ {
20
+ struct string_list masks = STRING_LIST_INIT_DUP ;
21
+ int i = 0 ;
22
+ unsigned int result = 0 ;
23
+
24
+ if (!strcmp (str , "0" ))
25
+ return 0 ;
26
+
27
+ string_list_split (& masks , str , ',' , 64 );
28
+ for (; i < masks .nr ; i ++ ) {
29
+ const char * name = masks .items [i ].string ;
30
+ struct flag_definition * def = defs ;
31
+ int found = 0 ;
32
+ while (def -> name ) {
33
+ if (!strcmp (def -> name , name )) {
34
+ result |= def -> mask ;
35
+ found = 1 ;
36
+ break ;
37
+ }
38
+ def ++ ;
39
+ }
40
+ if (!found )
41
+ die ("unknown flag \"%s\"" , name );
42
+ }
43
+
44
+ string_list_clear (& masks , 0 );
45
+ return result ;
46
+ }
47
+
48
+ static struct flag_definition empty_flags [] = { { NULL , 0 } };
49
+
8
50
static const char * notnull (const char * arg , const char * name )
9
51
{
10
52
if (!arg )
11
53
die ("%s required" , name );
12
54
return arg ;
13
55
}
14
56
15
- static unsigned int arg_flags (const char * arg , const char * name )
57
+ static unsigned int arg_flags (const char * arg , const char * name ,
58
+ struct flag_definition * defs )
16
59
{
17
- return atoi (notnull (arg , name ));
60
+ return parse_flags (notnull (arg , name ), defs );
18
61
}
19
62
20
63
static const char * * get_store (const char * * argv , struct ref_store * * refs )
@@ -64,10 +107,13 @@ static const char **get_store(const char **argv, struct ref_store **refs)
64
107
return argv + 1 ;
65
108
}
66
109
110
+ static struct flag_definition pack_flags [] = { FLAG_DEF (PACK_REFS_PRUNE ),
111
+ FLAG_DEF (PACK_REFS_ALL ),
112
+ { NULL , 0 } };
67
113
68
114
static int cmd_pack_refs (struct ref_store * refs , const char * * argv )
69
115
{
70
- unsigned int flags = arg_flags (* argv ++ , "flags" );
116
+ unsigned int flags = arg_flags (* argv ++ , "flags" , pack_flags );
71
117
72
118
return refs_pack_refs (refs , flags );
73
119
}
@@ -81,9 +127,15 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
81
127
return refs_create_symref (refs , refname , target , logmsg );
82
128
}
83
129
130
+ static struct flag_definition transaction_flags [] = {
131
+ FLAG_DEF (REF_NO_DEREF ),
132
+ FLAG_DEF (REF_FORCE_CREATE_REFLOG ),
133
+ { NULL , 0 }
134
+ };
135
+
84
136
static int cmd_delete_refs (struct ref_store * refs , const char * * argv )
85
137
{
86
- unsigned int flags = arg_flags (* argv ++ , "flags" );
138
+ unsigned int flags = arg_flags (* argv ++ , "flags" , transaction_flags );
87
139
const char * msg = * argv ++ ;
88
140
struct string_list refnames = STRING_LIST_INIT_NODUP ;
89
141
@@ -120,7 +172,7 @@ static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
120
172
{
121
173
struct object_id oid = * null_oid ();
122
174
const char * refname = notnull (* argv ++ , "refname" );
123
- int resolve_flags = arg_flags (* argv ++ , "resolve-flags" );
175
+ int resolve_flags = arg_flags (* argv ++ , "resolve-flags" , empty_flags );
124
176
int flags ;
125
177
const char * ref ;
126
178
int ignore_errno ;
@@ -209,7 +261,7 @@ static int cmd_delete_ref(struct ref_store *refs, const char **argv)
209
261
const char * msg = notnull (* argv ++ , "msg" );
210
262
const char * refname = notnull (* argv ++ , "refname" );
211
263
const char * sha1_buf = notnull (* argv ++ , "old-sha1" );
212
- unsigned int flags = arg_flags (* argv ++ , "flags" );
264
+ unsigned int flags = arg_flags (* argv ++ , "flags" , transaction_flags );
213
265
struct object_id old_oid ;
214
266
215
267
if (get_oid_hex (sha1_buf , & old_oid ))
@@ -224,7 +276,7 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv)
224
276
const char * refname = notnull (* argv ++ , "refname" );
225
277
const char * new_sha1_buf = notnull (* argv ++ , "new-sha1" );
226
278
const char * old_sha1_buf = notnull (* argv ++ , "old-sha1" );
227
- unsigned int flags = arg_flags (* argv ++ , "flags" );
279
+ unsigned int flags = arg_flags (* argv ++ , "flags" , transaction_flags );
228
280
struct object_id old_oid ;
229
281
struct object_id new_oid ;
230
282
0 commit comments