Skip to content

Commit 364c0ff

Browse files
ttaylorrgitster
authored andcommitted
midx-write.c: extract should_include_pack()
The add_pack_to_midx() callback used via for_each_file_in_pack_dir() is used to add packs with .idx files to the MIDX being written. Within this function, we have a pair of checks that discards packs which: - appear in an existing MIDX, if we successfully read an existing MIDX from disk - or, appear in the "to_include" list, if invoking the MIDX write machinery with the `--stdin-packs` command-line argument. A future commit will want to call a slight variant of these checks from the code that reuses all packs from an existing MIDX, as well as the current location via add_pack_to_midx(). The latter will be modified in subsequent commits to only reuse packs which appear in the to_include list, if one was given. Prepare for that step by extracting these checks as a subroutine that may be called from both places. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33e9218 commit 364c0ff

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

midx-write.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,32 @@ struct write_midx_context {
100100
struct string_list *to_include;
101101
};
102102

103+
static int should_include_pack(const struct write_midx_context *ctx,
104+
const char *file_name)
105+
{
106+
/*
107+
* Note that at most one of ctx->m and ctx->to_include are set,
108+
* so we are testing midx_contains_pack() and
109+
* string_list_has_string() independently (guarded by the
110+
* appropriate NULL checks).
111+
*
112+
* We could support passing to_include while reusing an existing
113+
* MIDX, but don't currently since the reuse process drags
114+
* forward all packs from an existing MIDX (without checking
115+
* whether or not they appear in the to_include list).
116+
*
117+
* If we added support for that, these next two conditional
118+
* should be performed independently (likely checking
119+
* to_include before the existing MIDX).
120+
*/
121+
if (ctx->m && midx_contains_pack(ctx->m, file_name))
122+
return 0;
123+
else if (ctx->to_include &&
124+
!string_list_has_string(ctx->to_include, file_name))
125+
return 0;
126+
return 1;
127+
}
128+
103129
static void add_pack_to_midx(const char *full_path, size_t full_path_len,
104130
const char *file_name, void *data)
105131
{
@@ -108,29 +134,11 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,
108134

109135
if (ends_with(file_name, ".idx")) {
110136
display_progress(ctx->progress, ++ctx->pack_paths_checked);
111-
/*
112-
* Note that at most one of ctx->m and ctx->to_include are set,
113-
* so we are testing midx_contains_pack() and
114-
* string_list_has_string() independently (guarded by the
115-
* appropriate NULL checks).
116-
*
117-
* We could support passing to_include while reusing an existing
118-
* MIDX, but don't currently since the reuse process drags
119-
* forward all packs from an existing MIDX (without checking
120-
* whether or not they appear in the to_include list).
121-
*
122-
* If we added support for that, these next two conditional
123-
* should be performed independently (likely checking
124-
* to_include before the existing MIDX).
125-
*/
126-
if (ctx->m && midx_contains_pack(ctx->m, file_name))
127-
return;
128-
else if (ctx->to_include &&
129-
!string_list_has_string(ctx->to_include, file_name))
137+
138+
if (!should_include_pack(ctx, file_name))
130139
return;
131140

132141
ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
133-
134142
p = add_packed_git(full_path, full_path_len, 0);
135143
if (!p) {
136144
warning(_("failed to add packfile '%s'"),

0 commit comments

Comments
 (0)