55#include "object-store.h"
66#include "repository.h"
77
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+
850static const char * notnull (const char * arg , const char * name )
951{
1052 if (!arg )
1153 die ("%s required" , name );
1254 return arg ;
1355}
1456
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 )
1659{
17- return atoi (notnull (arg , name ));
60+ return parse_flags (notnull (arg , name ), defs );
1861}
1962
2063static 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)
64107 return argv + 1 ;
65108}
66109
110+ static struct flag_definition pack_flags [] = { FLAG_DEF (PACK_REFS_PRUNE ),
111+ FLAG_DEF (PACK_REFS_ALL ),
112+ { NULL , 0 } };
67113
68114static int cmd_pack_refs (struct ref_store * refs , const char * * argv )
69115{
70- unsigned int flags = arg_flags (* argv ++ , "flags" );
116+ unsigned int flags = arg_flags (* argv ++ , "flags" , pack_flags );
71117
72118 return refs_pack_refs (refs , flags );
73119}
@@ -81,9 +127,15 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
81127 return refs_create_symref (refs , refname , target , logmsg );
82128}
83129
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+
84136static int cmd_delete_refs (struct ref_store * refs , const char * * argv )
85137{
86- unsigned int flags = arg_flags (* argv ++ , "flags" );
138+ unsigned int flags = arg_flags (* argv ++ , "flags" , transaction_flags );
87139 const char * msg = * argv ++ ;
88140 struct string_list refnames = STRING_LIST_INIT_NODUP ;
89141
@@ -120,7 +172,7 @@ static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
120172{
121173 struct object_id oid = * null_oid ();
122174 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 );
124176 int flags ;
125177 const char * ref ;
126178 int ignore_errno ;
@@ -209,7 +261,7 @@ static int cmd_delete_ref(struct ref_store *refs, const char **argv)
209261 const char * msg = notnull (* argv ++ , "msg" );
210262 const char * refname = notnull (* argv ++ , "refname" );
211263 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 );
213265 struct object_id old_oid ;
214266
215267 if (get_oid_hex (sha1_buf , & old_oid ))
@@ -224,7 +276,7 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv)
224276 const char * refname = notnull (* argv ++ , "refname" );
225277 const char * new_sha1_buf = notnull (* argv ++ , "new-sha1" );
226278 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 );
228280 struct object_id old_oid ;
229281 struct object_id new_oid ;
230282
0 commit comments