Skip to content

Commit f7d92bc

Browse files
black-deskgitster
authored andcommitted
config: refactor include_by_gitdir() into include_by_path()
The include_by_gitdir() function matches the realpath of a given path against a glob pattern, but its interface is tightly coupled to the gitdir condition: it takes a struct config_options *opts and extracts opts->git_dir internally. Refactor it into a more generic include_by_path() helper that takes a const char *path parameter directly, and update the gitdir and gitdir/i callers to pass opts->git_dir explicitly. No behavior change, just preparing for the addition of a new worktree condition that will reuse the same path-matching logic with a different path. Signed-off-by: Chen Linxuan <me@black-desk.cn> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2565546 commit f7d92bc

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

config.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,23 +235,20 @@ static int prepare_include_condition_pattern(const struct key_value_info *kvi,
235235
return 0;
236236
}
237237

238-
static int include_by_gitdir(const struct key_value_info *kvi,
239-
const struct config_options *opts,
240-
const char *cond, size_t cond_len, int icase)
238+
static int include_by_path(const struct key_value_info *kvi,
239+
const char *path,
240+
const char *cond, size_t cond_len, int icase)
241241
{
242242
struct strbuf text = STRBUF_INIT;
243243
struct strbuf pattern = STRBUF_INIT;
244244
size_t prefix;
245245
int ret = 0;
246-
const char *git_dir;
247246
int already_tried_absolute = 0;
248247

249-
if (opts->git_dir)
250-
git_dir = opts->git_dir;
251-
else
248+
if (!path)
252249
goto done;
253250

254-
strbuf_realpath(&text, git_dir, 1);
251+
strbuf_realpath(&text, path, 1);
255252
strbuf_add(&pattern, cond, cond_len);
256253
ret = prepare_include_condition_pattern(kvi, &pattern, &prefix);
257254
if (ret < 0)
@@ -284,7 +281,7 @@ static int include_by_gitdir(const struct key_value_info *kvi,
284281
* which'll do the right thing
285282
*/
286283
strbuf_reset(&text);
287-
strbuf_add_absolute_path(&text, git_dir);
284+
strbuf_add_absolute_path(&text, path);
288285
already_tried_absolute = 1;
289286
goto again;
290287
}
@@ -400,9 +397,9 @@ static int include_condition_is_true(const struct key_value_info *kvi,
400397
const struct config_options *opts = inc->opts;
401398

402399
if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
403-
return include_by_gitdir(kvi, opts, cond, cond_len, 0);
400+
return include_by_path(kvi, opts->git_dir, cond, cond_len, 0);
404401
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
405-
return include_by_gitdir(kvi, opts, cond, cond_len, 1);
402+
return include_by_path(kvi, opts->git_dir, cond, cond_len, 1);
406403
else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
407404
return include_by_branch(inc, cond, cond_len);
408405
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,

0 commit comments

Comments
 (0)