@@ -82,6 +82,7 @@ Datum git_fdw_validator(PG_FUNCTION_ARGS) {
82
82
Oid catalog = PG_GETARG_OID (1 );
83
83
char * path = NULL ;
84
84
char * branch = NULL ;
85
+ char * git_search_path = NULL ;
85
86
List * other_options = NIL ;
86
87
ListCell * cell ;
87
88
@@ -105,7 +106,7 @@ Datum git_fdw_validator(PG_FUNCTION_ARGS) {
105
106
opt -> optname );
106
107
}
107
108
108
- ereport (ERROR ,
109
+ ereport (WARNING ,
109
110
(errcode (ERRCODE_FDW_INVALID_OPTION_NAME ),
110
111
errmsg ("invalid option \"%s\"" , def -> defname ),
111
112
buf .len > 0
@@ -130,6 +131,14 @@ Datum git_fdw_validator(PG_FUNCTION_ARGS) {
130
131
errmsg ("conflicting or redundant options" )));
131
132
branch = defGetString (def );
132
133
}
134
+ else if (strcmp (def -> defname , "git_search_path" ) == 0 )
135
+ {
136
+ if (git_search_path )
137
+ ereport (ERROR ,
138
+ (errcode (ERRCODE_SYNTAX_ERROR ),
139
+ errmsg ("conflicting or redundant options" )));
140
+ git_search_path = defGetString (def );
141
+ }
133
142
else
134
143
other_options = lappend (other_options , def );
135
144
}
@@ -145,6 +154,7 @@ Datum git_fdw_validator(PG_FUNCTION_ARGS) {
145
154
// TODO: Find where this variable should go (Plan or Path?)
146
155
char * repository_path ;
147
156
char * repository_branch ;
157
+ char * repository_git_search_path ;
148
158
149
159
static bool is_valid_option (const char * option , Oid context ) {
150
160
const struct GitFdwOption * opt ;
@@ -160,29 +170,27 @@ static bool is_valid_option(const char *option, Oid context) {
160
170
static void gitGetOptions (Oid foreigntableid , GitFdwPlanState * state , List * * other_options ) {
161
171
ForeignTable * table ;
162
172
List * options ;
163
- ListCell * lc ,
164
- * prev ;
173
+ ListCell * lc ;
165
174
166
175
table = GetForeignTable (foreigntableid );
167
176
168
177
options = NIL ;
169
178
options = list_concat (options , table -> options );
170
179
171
- prev = NULL ;
172
180
foreach (lc , options ) {
173
181
DefElem * def = (DefElem * ) lfirst (lc );
174
182
175
183
if (strcmp (def -> defname , "path" ) == 0 ) {
176
184
state -> path = defGetString (def );
177
- options = list_delete_cell (options , lc , prev );
178
185
}
179
186
180
187
if (strcmp (def -> defname , "branch" ) == 0 ) {
181
188
state -> branch = defGetString (def );
182
- options = list_delete_cell (options , lc , prev );
183
189
}
184
190
185
- prev = lc ;
191
+ if (strcmp (def -> defname , "git_search_path" ) == 0 ) {
192
+ state -> git_search_path = defGetString (def );
193
+ }
186
194
}
187
195
188
196
if (state -> path == NULL ) {
@@ -260,8 +268,9 @@ static ForeignScan * gitGetForeignPlan(PlannerInfo *root, RelOptInfo *baserel, O
260
268
#endif
261
269
); // Assuming outer_plan is null
262
270
263
- repository_path = ((GitFdwPlanState * )scan -> fdw_private )-> path ;
264
- repository_branch = ((GitFdwPlanState * )scan -> fdw_private )-> branch ;
271
+ repository_path = ((GitFdwPlanState * )scan -> fdw_private )-> path ;
272
+ repository_branch = ((GitFdwPlanState * )scan -> fdw_private )-> branch ;
273
+ repository_git_search_path = ((GitFdwPlanState * )scan -> fdw_private )-> git_search_path ;
265
274
return scan ;
266
275
}
267
276
@@ -280,13 +289,22 @@ static void gitBeginForeignScan(ForeignScanState *node, int eflags) {
280
289
git_libgit2_init ();
281
290
282
291
festate = (GitFdwExecutionState * ) palloc (sizeof (GitFdwExecutionState ));
283
- festate -> path = repository_path ;
284
- festate -> branch = repository_branch ;
285
- festate -> repo = NULL ;
286
- festate -> walker = NULL ;
292
+ festate -> path = repository_path ;
293
+ festate -> branch = repository_branch ;
294
+ festate -> git_search_path = repository_git_search_path ;
295
+ festate -> repo = NULL ;
296
+ festate -> walker = NULL ;
287
297
288
298
node -> fdw_state = (void * ) festate ;
289
299
300
+ if (festate -> git_search_path != NULL ){
301
+ git_libgit2_opts (
302
+ GIT_OPT_SET_SEARCH_PATH ,
303
+ GIT_CONFIG_LEVEL_GLOBAL ,
304
+ festate -> git_search_path
305
+ );
306
+ }
307
+
290
308
if (festate -> repo == NULL ) {
291
309
int repo_opened = -1 ;
292
310
if ((repo_opened = git_repository_open (& festate -> repo , festate -> path )) != GIT_OK ){
0 commit comments