@@ -36,16 +36,16 @@ git_attr_value_t git_attr_value(const char *attr)
3636static int collect_attr_files (
3737 git_repository * repo ,
3838 git_attr_session * attr_session ,
39- uint32_t flags ,
39+ git_attr_options * opts ,
4040 const char * path ,
4141 git_vector * files );
4242
4343static void release_attr_files (git_vector * files );
4444
45- int git_attr_get (
45+ int git_attr_get_ext (
4646 const char * * value ,
4747 git_repository * repo ,
48- uint32_t flags ,
48+ git_attr_options * opts ,
4949 const char * pathname ,
5050 const char * name )
5151{
@@ -61,6 +61,7 @@ int git_attr_get(
6161 GIT_ASSERT_ARG (value );
6262 GIT_ASSERT_ARG (repo );
6363 GIT_ASSERT_ARG (name );
64+ GIT_ERROR_CHECK_VERSION (opts , GIT_ATTR_OPTIONS_VERSION , "git_attr_options" );
6465
6566 * value = NULL ;
6667
@@ -70,7 +71,7 @@ int git_attr_get(
7071 if (git_attr_path__init (& path , repo , pathname , git_repository_workdir (repo ), dir_flag ) < 0 )
7172 return -1 ;
7273
73- if ((error = collect_attr_files (repo , NULL , flags , pathname , & files )) < 0 )
74+ if ((error = collect_attr_files (repo , NULL , opts , pathname , & files )) < 0 )
7475 goto cleanup ;
7576
7677 memset (& attr , 0 , sizeof (attr ));
@@ -97,6 +98,20 @@ int git_attr_get(
9798 return error ;
9899}
99100
101+ int git_attr_get (
102+ const char * * value ,
103+ git_repository * repo ,
104+ uint32_t flags ,
105+ const char * pathname ,
106+ const char * name )
107+ {
108+ git_attr_options opts = GIT_ATTR_OPTIONS_INIT ;
109+
110+ opts .flags = flags ;
111+
112+ return git_attr_get_ext (value , repo , & opts , pathname , name );
113+ }
114+
100115
101116typedef struct {
102117 git_attr_name name ;
@@ -107,7 +122,7 @@ int git_attr_get_many_with_session(
107122 const char * * values ,
108123 git_repository * repo ,
109124 git_attr_session * attr_session ,
110- uint32_t flags ,
125+ git_attr_options * opts ,
111126 const char * pathname ,
112127 size_t num_attr ,
113128 const char * * names )
@@ -129,14 +144,15 @@ int git_attr_get_many_with_session(
129144 GIT_ASSERT_ARG (repo );
130145 GIT_ASSERT_ARG (pathname );
131146 GIT_ASSERT_ARG (names );
147+ GIT_ERROR_CHECK_VERSION (opts , GIT_ATTR_OPTIONS_VERSION , "git_attr_options" );
132148
133149 if (git_repository_is_bare (repo ))
134150 dir_flag = GIT_DIR_FLAG_FALSE ;
135151
136152 if (git_attr_path__init (& path , repo , pathname , git_repository_workdir (repo ), dir_flag ) < 0 )
137153 return -1 ;
138154
139- if ((error = collect_attr_files (repo , attr_session , flags , pathname , & files )) < 0 )
155+ if ((error = collect_attr_files (repo , attr_session , opts , pathname , & files )) < 0 )
140156 goto cleanup ;
141157
142158 info = git__calloc (num_attr , sizeof (attr_get_many_info ));
@@ -189,9 +205,25 @@ int git_attr_get_many(
189205 const char * pathname ,
190206 size_t num_attr ,
191207 const char * * names )
208+ {
209+ git_attr_options opts = GIT_ATTR_OPTIONS_INIT ;
210+
211+ opts .flags = flags ;
212+
213+ return git_attr_get_many_with_session (
214+ values , repo , NULL , & opts , pathname , num_attr , names );
215+ }
216+
217+ int git_attr_get_many_ext (
218+ const char * * values ,
219+ git_repository * repo ,
220+ git_attr_options * opts ,
221+ const char * pathname ,
222+ size_t num_attr ,
223+ const char * * names )
192224{
193225 return git_attr_get_many_with_session (
194- values , repo , NULL , flags , pathname , num_attr , names );
226+ values , repo , NULL , opts , pathname , num_attr , names );
195227}
196228
197229int git_attr_foreach (
@@ -200,6 +232,20 @@ int git_attr_foreach(
200232 const char * pathname ,
201233 int (* callback )(const char * name , const char * value , void * payload ),
202234 void * payload )
235+ {
236+ git_attr_options opts = GIT_ATTR_OPTIONS_INIT ;
237+
238+ opts .flags = flags ;
239+
240+ return git_attr_foreach_ext (repo , & opts , pathname , callback , payload );
241+ }
242+
243+ int git_attr_foreach_ext (
244+ git_repository * repo ,
245+ git_attr_options * opts ,
246+ const char * pathname ,
247+ int (* callback )(const char * name , const char * value , void * payload ),
248+ void * payload )
203249{
204250 int error ;
205251 git_attr_path path ;
@@ -213,14 +259,15 @@ int git_attr_foreach(
213259
214260 GIT_ASSERT_ARG (repo );
215261 GIT_ASSERT_ARG (callback );
262+ GIT_ERROR_CHECK_VERSION (opts , GIT_ATTR_OPTIONS_VERSION , "git_attr_options" );
216263
217264 if (git_repository_is_bare (repo ))
218265 dir_flag = GIT_DIR_FLAG_FALSE ;
219266
220267 if (git_attr_path__init (& path , repo , pathname , git_repository_workdir (repo ), dir_flag ) < 0 )
221268 return -1 ;
222269
223- if ((error = collect_attr_files (repo , NULL , flags , pathname , & files )) < 0 ||
270+ if ((error = collect_attr_files (repo , NULL , opts , pathname , & files )) < 0 ||
224271 (error = git_strmap_new (& seen )) < 0 )
225272 goto cleanup ;
226273
@@ -331,7 +378,7 @@ static int system_attr_file(
331378static int attr_setup (
332379 git_repository * repo ,
333380 git_attr_session * attr_session ,
334- uint32_t flags )
381+ git_attr_options * opts )
335382{
336383 git_buf system = GIT_BUF_INIT , info = GIT_BUF_INIT ;
337384 git_attr_file_source index_source = { GIT_ATTR_FILE_SOURCE_INDEX , NULL , GIT_ATTR_FILE };
@@ -379,7 +426,7 @@ static int attr_setup(
379426 (error = preload_attr_source (repo , attr_session , & index_source )) < 0 )
380427 goto out ;
381428
382- if ((flags & GIT_ATTR_CHECK_INCLUDE_HEAD ) != 0 &&
429+ if ((opts && ( opts -> flags & GIT_ATTR_CHECK_INCLUDE_HEAD ) != 0 ) &&
383430 (error = preload_attr_source (repo , attr_session , & head_source )) < 0 )
384431 goto out ;
385432
@@ -545,7 +592,7 @@ static void release_attr_files(git_vector *files)
545592static int collect_attr_files (
546593 git_repository * repo ,
547594 git_attr_session * attr_session ,
548- uint32_t flags ,
595+ git_attr_options * opts ,
549596 const char * path ,
550597 git_vector * files )
551598{
@@ -554,7 +601,7 @@ static int collect_attr_files(
554601 const char * workdir = git_repository_workdir (repo );
555602 attr_walk_up_info info = { NULL };
556603
557- if ((error = attr_setup (repo , attr_session , flags )) < 0 )
604+ if ((error = attr_setup (repo , attr_session , opts )) < 0 )
558605 return error ;
559606
560607 /* Resolve path in a non-bare repo */
@@ -584,7 +631,7 @@ static int collect_attr_files(
584631
585632 info .repo = repo ;
586633 info .attr_session = attr_session ;
587- info .flags = flags ;
634+ info .flags = opts ? opts -> flags : 0 ;
588635 info .workdir = workdir ;
589636 if (git_repository_index__weakptr (& info .index , repo ) < 0 )
590637 git_error_clear (); /* no error even if there is no index */
@@ -604,7 +651,7 @@ static int collect_attr_files(
604651 goto cleanup ;
605652 }
606653
607- if (( flags & GIT_ATTR_CHECK_NO_SYSTEM ) == 0 ) {
654+ if (! opts || ( opts -> flags & GIT_ATTR_CHECK_NO_SYSTEM ) == 0 ) {
608655 error = system_attr_file (& dir , attr_session );
609656
610657 if (!error )
0 commit comments