Skip to content

Commit e247cbb

Browse files
committed
Merge branch 'ps/for-each-ref-in-fixes' into jch
A handful of places used refs_for_each_ref_in() API incorrectly, which has been corrected. * ps/for-each-ref-in-fixes: bisect: simplify string_list memory handling bisect: fix misuse of `refs_for_each_ref_in()` pack-bitmap: fix bug with exact ref match in "pack.preferBitmapTips" pack-bitmap: deduplicate logic to iterate over preferred bitmap tips
2 parents 774c2b9 + df8304c commit e247cbb

8 files changed

Lines changed: 111 additions & 43 deletions

File tree

Documentation/config/pack.adoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,10 @@ pack.usePathWalk::
161161

162162
pack.preferBitmapTips::
163163
When selecting which commits will receive bitmaps, prefer a
164-
commit at the tip of any reference that is a suffix of any value
165-
of this configuration over any other commits in the "selection
166-
window".
164+
commmit at the tip of a reference that matches any of the
165+
configured prefixes.
167166
+
168-
Note that setting this configuration to `refs/foo` does not mean that
167+
Note that setting this configuration to `refs/foo/` does not mean that
169168
the commits at the tips of `refs/foo/bar` and `refs/foo/baz` will
170169
necessarily be selected. This is because commits are selected for
171170
bitmaps from within a series of windows of variable length.

bisect.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,8 +1180,7 @@ int estimate_bisect_steps(int all)
11801180
static int mark_for_removal(const struct reference *ref, void *cb_data)
11811181
{
11821182
struct string_list *refs = cb_data;
1183-
char *bisect_ref = xstrfmt("refs/bisect%s", ref->name);
1184-
string_list_append(refs, bisect_ref);
1183+
string_list_append(refs, ref->name);
11851184
return 0;
11861185
}
11871186

@@ -1190,16 +1189,15 @@ int bisect_clean_state(void)
11901189
int result = 0;
11911190

11921191
/* There may be some refs packed during bisection */
1193-
struct string_list refs_for_removal = STRING_LIST_INIT_NODUP;
1194-
refs_for_each_ref_in(get_main_ref_store(the_repository),
1195-
"refs/bisect", mark_for_removal,
1196-
(void *) &refs_for_removal);
1197-
string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
1198-
string_list_append(&refs_for_removal, xstrdup("BISECT_EXPECTED_REV"));
1192+
struct string_list refs_for_removal = STRING_LIST_INIT_DUP;
1193+
refs_for_each_fullref_in(get_main_ref_store(the_repository),
1194+
"refs/bisect/", NULL, mark_for_removal,
1195+
&refs_for_removal);
1196+
string_list_append(&refs_for_removal, "BISECT_HEAD");
1197+
string_list_append(&refs_for_removal, "BISECT_EXPECTED_REV");
11991198
result = refs_delete_refs(get_main_ref_store(the_repository),
12001199
"bisect: remove", &refs_for_removal,
12011200
REF_NO_DEREF);
1202-
refs_for_removal.strdup_strings = 1;
12031201
string_list_clear(&refs_for_removal, 0);
12041202
unlink_or_warn(git_path_bisect_ancestors_ok());
12051203
unlink_or_warn(git_path_bisect_log());

builtin/pack-objects.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,22 +4550,6 @@ static int mark_bitmap_preferred_tip(const struct reference *ref, void *data UNU
45504550
return 0;
45514551
}
45524552

4553-
static void mark_bitmap_preferred_tips(void)
4554-
{
4555-
struct string_list_item *item;
4556-
const struct string_list *preferred_tips;
4557-
4558-
preferred_tips = bitmap_preferred_tips(the_repository);
4559-
if (!preferred_tips)
4560-
return;
4561-
4562-
for_each_string_list_item(item, preferred_tips) {
4563-
refs_for_each_ref_in(get_main_ref_store(the_repository),
4564-
item->string, mark_bitmap_preferred_tip,
4565-
NULL);
4566-
}
4567-
}
4568-
45694553
static inline int is_oid_uninteresting(struct repository *repo,
45704554
struct object_id *oid)
45714555
{
@@ -4706,7 +4690,8 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
47064690
load_delta_islands(the_repository, progress);
47074691

47084692
if (write_bitmap_index)
4709-
mark_bitmap_preferred_tips();
4693+
for_each_preferred_bitmap_tip(the_repository, mark_bitmap_preferred_tip,
4694+
NULL);
47104695

47114696
if (!fn_show_object)
47124697
fn_show_object = show_object;

pack-bitmap.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,7 @@ int bitmap_is_midx(struct bitmap_index *bitmap_git)
33143314
return !!bitmap_git->midx;
33153315
}
33163316

3317-
const struct string_list *bitmap_preferred_tips(struct repository *r)
3317+
static const struct string_list *bitmap_preferred_tips(struct repository *r)
33183318
{
33193319
const struct string_list *dest;
33203320

@@ -3323,6 +3323,22 @@ const struct string_list *bitmap_preferred_tips(struct repository *r)
33233323
return NULL;
33243324
}
33253325

3326+
void for_each_preferred_bitmap_tip(struct repository *repo,
3327+
each_ref_fn cb, void *cb_data)
3328+
{
3329+
struct string_list_item *item;
3330+
const struct string_list *preferred_tips;
3331+
3332+
preferred_tips = bitmap_preferred_tips(repo);
3333+
if (!preferred_tips)
3334+
return;
3335+
3336+
for_each_string_list_item(item, preferred_tips) {
3337+
refs_for_each_fullref_in(get_main_ref_store(repo),
3338+
item->string, NULL, cb, cb_data);
3339+
}
3340+
}
3341+
33263342
int bitmap_is_preferred_refname(struct repository *r, const char *refname)
33273343
{
33283344
const struct string_list *preferred_tips = bitmap_preferred_tips(r);

pack-bitmap.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "khash.h"
66
#include "pack.h"
77
#include "pack-objects.h"
8+
#include "refs.h"
89
#include "string-list.h"
910

1011
struct commit;
@@ -99,6 +100,13 @@ int for_each_bitmapped_object(struct bitmap_index *bitmap_git,
99100
show_reachable_fn show_reach,
100101
void *payload);
101102

103+
/*
104+
* Iterate over all references that are configured as preferred bitmap tips via
105+
* "pack.preferBitmapTips" and invoke the callback on each function.
106+
*/
107+
void for_each_preferred_bitmap_tip(struct repository *repo,
108+
each_ref_fn cb, void *cb_data);
109+
102110
#define GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL \
103111
"GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL"
104112

@@ -182,7 +190,6 @@ char *pack_bitmap_filename(struct packed_git *p);
182190

183191
int bitmap_is_midx(struct bitmap_index *bitmap_git);
184192

185-
const struct string_list *bitmap_preferred_tips(struct repository *r);
186193
int bitmap_is_preferred_refname(struct repository *r, const char *refname);
187194

188195
int verify_bitmap_files(struct repository *r);

repack-midx.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static int midx_snapshot_ref_one(const struct reference *ref, void *_data)
4040
void midx_snapshot_refs(struct repository *repo, struct tempfile *f)
4141
{
4242
struct midx_snapshot_ref_data data;
43-
const struct string_list *preferred = bitmap_preferred_tips(repo);
4443

4544
data.repo = repo;
4645
data.f = f;
@@ -51,16 +50,9 @@ void midx_snapshot_refs(struct repository *repo, struct tempfile *f)
5150
die(_("could not open tempfile %s for writing"),
5251
get_tempfile_path(f));
5352

54-
if (preferred) {
55-
struct string_list_item *item;
56-
57-
data.preferred = 1;
58-
for_each_string_list_item(item, preferred)
59-
refs_for_each_ref_in(get_main_ref_store(repo),
60-
item->string,
61-
midx_snapshot_ref_one, &data);
62-
data.preferred = 0;
63-
}
53+
data.preferred = 1;
54+
for_each_preferred_bitmap_tip(repo, midx_snapshot_ref_one, &data);
55+
data.preferred = 0;
6456

6557
refs_for_each_ref(get_main_ref_store(repo),
6658
midx_snapshot_ref_one, &data);

t/t5310-pack-bitmaps.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,41 @@ test_bitmap_cases () {
466466
)
467467
'
468468

469+
test_expect_success 'pack.preferBitmapTips can use direct refname' '
470+
git init repo &&
471+
test_when_finished "rm -fr repo" &&
472+
(
473+
cd repo &&
474+
475+
# Create enough commits that not all will receive bitmap
476+
# coverage even if they are all at the tip of some reference.
477+
test_commit_bulk --message="%s" 103 &&
478+
git log --format="create refs/tags/%s %H" HEAD >refs &&
479+
git update-ref --stdin <refs &&
480+
481+
# Create the bitmap.
482+
git repack -adb &&
483+
test-tool bitmap list-commits | sort >commits-with-bitmap &&
484+
485+
# Verify that we have at least one commit that did not
486+
# receive a bitmap.
487+
git rev-list HEAD >commits.raw &&
488+
sort <commits.raw >commits &&
489+
comm -13 commits-with-bitmap commits >commits-wo-bitmap &&
490+
test_file_not_empty commits-wo-bitmap &&
491+
commit_id=$(head commits-wo-bitmap) &&
492+
493+
# We now create a reference for this commit and repack
494+
# with "preferBitmapTips" pointing to that exact
495+
# reference. The expectation is that it will now be
496+
# covered by a bitmap.
497+
git update-ref refs/heads/cover-me "$commit_id" &&
498+
git -c pack.preferBitmapTips=refs/heads/cover-me repack -adb &&
499+
test-tool bitmap list-commits >after &&
500+
test_grep "$commit_id" after
501+
)
502+
'
503+
469504
test_expect_success 'complains about multiple pack bitmaps' '
470505
rm -fr repo &&
471506
git init repo &&

t/t5319-multi-pack-index.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,4 +1345,40 @@ test_expect_success 'bitmapped packs are stored via the BTMP chunk' '
13451345
)
13461346
'
13471347

1348+
test_expect_success 'pack.preferBitmapTips can use direct refname' '
1349+
git init repo &&
1350+
test_when_finished "rm -fr repo" &&
1351+
(
1352+
cd repo &&
1353+
1354+
# Create enough commits that not all will receive bitmap
1355+
# coverage even if they are all at the tip of some reference.
1356+
test_commit_bulk --message="%s" 103 &&
1357+
git log --format="create refs/tags/%s %H" HEAD >refs &&
1358+
git update-ref --stdin <refs &&
1359+
1360+
# Create the bitmap via the MIDX.
1361+
git repack -adb --write-midx &&
1362+
test-tool bitmap list-commits | sort >commits-with-bitmap &&
1363+
1364+
# Verify that we have at least one commit that did not
1365+
# receive a bitmap.
1366+
git rev-list HEAD >commits.raw &&
1367+
sort <commits.raw >commits &&
1368+
comm -13 commits-with-bitmap commits >commits-wo-bitmap &&
1369+
test_file_not_empty commits-wo-bitmap &&
1370+
commit_id=$(head commits-wo-bitmap) &&
1371+
1372+
# We now create a reference for this commit and repack
1373+
# with "preferBitmapTips" pointing to that exact
1374+
# reference. The expectation is that it will now be
1375+
# covered by a bitmap.
1376+
git update-ref refs/heads/cover-me "$commit_id" &&
1377+
rm .git/objects/pack/multi-pack-index* &&
1378+
git -c pack.preferBitmapTips=refs/heads/cover-me repack -adb --write-midx &&
1379+
test-tool bitmap list-commits >after &&
1380+
test_grep "$commit_id" after
1381+
)
1382+
'
1383+
13481384
test_done

0 commit comments

Comments
 (0)