Skip to content

Commit 5134ba6

Browse files
committed
Merge branch 'kn/refs-optim-cleanup' into seen
Code clean-up. * kn/refs-optim-cleanup: t/pack-refs-tests: move the 'test_done' to callees refs: rename 'pack_refs_opts' to 'refs_optimize_opts' refs: move to using the '.optimize' functions
2 parents ef26efc + 7f46fe7 commit 5134ba6

File tree

11 files changed

+42
-72
lines changed

11 files changed

+42
-72
lines changed

pack-refs.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ int pack_refs_core(int argc,
1414
{
1515
struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
1616
struct string_list included_refs = STRING_LIST_INIT_NODUP;
17-
struct pack_refs_opts pack_refs_opts = {
17+
struct refs_optimize_opts optimize_opts = {
1818
.exclusions = &excludes,
1919
.includes = &included_refs,
20-
.flags = PACK_REFS_PRUNE,
20+
.flags = REFS_OPTIMIZE_PRUNE,
2121
};
2222
struct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;
2323
struct string_list_item *item;
@@ -26,9 +26,9 @@ int pack_refs_core(int argc,
2626

2727
struct option opts[] = {
2828
OPT_BOOL(0, "all", &pack_all, N_("pack everything")),
29-
OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
30-
OPT_BIT(0, "auto", &pack_refs_opts.flags, N_("auto-pack refs as needed"), PACK_REFS_AUTO),
31-
OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"),
29+
OPT_BIT(0, "prune", &optimize_opts.flags, N_("prune loose refs (default)"), REFS_OPTIMIZE_PRUNE),
30+
OPT_BIT(0, "auto", &optimize_opts.flags, N_("auto-pack refs as needed"), REFS_OPTIMIZE_AUTO),
31+
OPT_STRING_LIST(0, "include", optimize_opts.includes, N_("pattern"),
3232
N_("references to include")),
3333
OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"),
3434
N_("references to exclude")),
@@ -39,15 +39,15 @@ int pack_refs_core(int argc,
3939
usage_with_options(usage_opts, opts);
4040

4141
for_each_string_list_item(item, &option_excluded_refs)
42-
add_ref_exclusion(pack_refs_opts.exclusions, item->string);
42+
add_ref_exclusion(optimize_opts.exclusions, item->string);
4343

4444
if (pack_all)
45-
string_list_append(pack_refs_opts.includes, "*");
45+
string_list_append(optimize_opts.includes, "*");
4646

47-
if (!pack_refs_opts.includes->nr)
48-
string_list_append(pack_refs_opts.includes, "refs/tags/*");
47+
if (!optimize_opts.includes->nr)
48+
string_list_append(optimize_opts.includes, "refs/tags/*");
4949

50-
ret = refs_optimize(get_main_ref_store(repo), &pack_refs_opts);
50+
ret = refs_optimize(get_main_ref_store(repo), &optimize_opts);
5151

5252
clear_ref_exclusions(&excludes);
5353
string_list_clear(&included_refs, 0);

refs.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,13 +2313,7 @@ void base_ref_store_init(struct ref_store *refs, struct repository *repo,
23132313
refs->gitdir = xstrdup(path);
23142314
}
23152315

2316-
/* backend functions */
2317-
int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts)
2318-
{
2319-
return refs->be->pack_refs(refs, opts);
2320-
}
2321-
2322-
int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts)
2316+
int refs_optimize(struct ref_store *refs, struct refs_optimize_opts *opts)
23232317
{
23242318
return refs->be->optimize(refs, opts);
23252319
}

refs.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -499,32 +499,26 @@ void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp,
499499
const struct string_list *refnames);
500500

501501
/*
502-
* Flags for controlling behaviour of pack_refs()
503-
* PACK_REFS_PRUNE: Prune loose refs after packing
504-
* PACK_REFS_AUTO: Pack refs on a best effort basis. The heuristics and end
505-
* result are decided by the ref backend. Backends may ignore
506-
* this flag and fall back to a normal repack.
502+
* Flags for controlling behaviour of refs_optimize()
503+
* REFS_OPTIMIZE_PRUNE: Prune loose refs after packing
504+
* REFS_OPTIMIZE_AUTO: Pack refs on a best effort basis. The heuristics and end
505+
* result are decided by the ref backend. Backends may ignore
506+
* this flag and fall back to a normal repack.
507507
*/
508-
#define PACK_REFS_PRUNE (1 << 0)
509-
#define PACK_REFS_AUTO (1 << 1)
508+
#define REFS_OPTIMIZE_PRUNE (1 << 0)
509+
#define REFS_OPTIMIZE_AUTO (1 << 1)
510510

511-
struct pack_refs_opts {
511+
struct refs_optimize_opts {
512512
unsigned int flags;
513513
struct ref_exclusions *exclusions;
514514
struct string_list *includes;
515515
};
516516

517-
/*
518-
* Write a packed-refs file for the current repository.
519-
* flags: Combination of the above PACK_REFS_* flags.
520-
*/
521-
int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts);
522-
523517
/*
524518
* Optimize the ref store. The exact behavior is up to the backend.
525519
* For the files backend, this is equivalent to packing refs.
526520
*/
527-
int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts);
521+
int refs_optimize(struct ref_store *refs, struct refs_optimize_opts *opts);
528522

529523
/*
530524
* Setup reflog before using. Fill in err and return -1 on failure.

refs/debug.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ static int debug_transaction_abort(struct ref_store *refs,
124124
return res;
125125
}
126126

127-
static int debug_pack_refs(struct ref_store *ref_store, struct pack_refs_opts *opts)
127+
static int debug_optimize(struct ref_store *ref_store, struct refs_optimize_opts *opts)
128128
{
129129
struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
130-
int res = drefs->refs->be->pack_refs(drefs->refs, opts);
131-
trace_printf_key(&trace_refs, "pack_refs: %d\n", res);
130+
int res = drefs->refs->be->optimize(drefs->refs, opts);
131+
trace_printf_key(&trace_refs, "optimize: %d\n", res);
132132
return res;
133133
}
134134

@@ -439,7 +439,7 @@ struct ref_storage_be refs_be_debug = {
439439
.transaction_finish = debug_transaction_finish,
440440
.transaction_abort = debug_transaction_abort,
441441

442-
.pack_refs = debug_pack_refs,
442+
.optimize = debug_optimize,
443443
.rename_ref = debug_rename_ref,
444444
.copy_ref = debug_copy_ref,
445445

refs/files-backend.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_
13551355
*/
13561356
static int should_pack_ref(struct files_ref_store *refs,
13571357
const struct reference *ref,
1358-
struct pack_refs_opts *opts)
1358+
struct refs_optimize_opts *opts)
13591359
{
13601360
struct string_list_item *item;
13611361

@@ -1383,15 +1383,15 @@ static int should_pack_ref(struct files_ref_store *refs,
13831383
}
13841384

13851385
static int should_pack_refs(struct files_ref_store *refs,
1386-
struct pack_refs_opts *opts)
1386+
struct refs_optimize_opts *opts)
13871387
{
13881388
struct ref_iterator *iter;
13891389
size_t packed_size;
13901390
size_t refcount = 0;
13911391
size_t limit;
13921392
int ret;
13931393

1394-
if (!(opts->flags & PACK_REFS_AUTO))
1394+
if (!(opts->flags & REFS_OPTIMIZE_AUTO))
13951395
return 1;
13961396

13971397
ret = packed_refs_size(refs->packed_ref_store, &packed_size);
@@ -1444,8 +1444,8 @@ static int should_pack_refs(struct files_ref_store *refs,
14441444
return 0;
14451445
}
14461446

1447-
static int files_pack_refs(struct ref_store *ref_store,
1448-
struct pack_refs_opts *opts)
1447+
static int files_optimize(struct ref_store *ref_store,
1448+
struct refs_optimize_opts *opts)
14491449
{
14501450
struct files_ref_store *refs =
14511451
files_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB,
@@ -1488,7 +1488,7 @@ static int files_pack_refs(struct ref_store *ref_store,
14881488
iter->ref.name, err.buf);
14891489

14901490
/* Schedule the loose reference for pruning if requested. */
1491-
if ((opts->flags & PACK_REFS_PRUNE)) {
1491+
if ((opts->flags & REFS_OPTIMIZE_PRUNE)) {
14921492
struct ref_to_prune *n;
14931493
FLEX_ALLOC_STR(n, name, iter->ref.name);
14941494
oidcpy(&n->oid, iter->ref.oid);
@@ -1512,15 +1512,6 @@ static int files_pack_refs(struct ref_store *ref_store,
15121512
return 0;
15131513
}
15141514

1515-
static int files_optimize(struct ref_store *ref_store, struct pack_refs_opts *opts)
1516-
{
1517-
/*
1518-
* For the "files" backend, "optimizing" is the same as "packing".
1519-
* So, we just call the existing worker function for packing.
1520-
*/
1521-
return files_pack_refs(ref_store, opts);
1522-
}
1523-
15241515
/*
15251516
* People using contrib's git-new-workdir have .git/logs/refs ->
15261517
* /some/other/path/.git/logs/refs, and that may live on another device.
@@ -3990,7 +3981,6 @@ struct ref_storage_be refs_be_files = {
39903981
.transaction_finish = files_transaction_finish,
39913982
.transaction_abort = files_transaction_abort,
39923983

3993-
.pack_refs = files_pack_refs,
39943984
.optimize = files_optimize,
39953985
.rename_ref = files_rename_ref,
39963986
.copy_ref = files_copy_ref,

refs/packed-backend.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,8 +1773,8 @@ static int packed_transaction_finish(struct ref_store *ref_store,
17731773
return ret;
17741774
}
17751775

1776-
static int packed_pack_refs(struct ref_store *ref_store UNUSED,
1777-
struct pack_refs_opts *pack_opts UNUSED)
1776+
static int packed_optimize(struct ref_store *ref_store UNUSED,
1777+
struct refs_optimize_opts *opts UNUSED)
17781778
{
17791779
/*
17801780
* Packed refs are already packed. It might be that loose refs
@@ -2129,7 +2129,7 @@ struct ref_storage_be refs_be_packed = {
21292129
.transaction_finish = packed_transaction_finish,
21302130
.transaction_abort = packed_transaction_abort,
21312131

2132-
.pack_refs = packed_pack_refs,
2132+
.optimize = packed_optimize,
21332133
.rename_ref = NULL,
21342134
.copy_ref = NULL,
21352135

refs/refs-internal.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,8 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,
422422
struct ref_transaction *transaction,
423423
struct strbuf *err);
424424

425-
typedef int pack_refs_fn(struct ref_store *ref_store,
426-
struct pack_refs_opts *opts);
427425
typedef int optimize_fn(struct ref_store *ref_store,
428-
struct pack_refs_opts *opts);
426+
struct refs_optimize_opts *opts);
429427
typedef int rename_ref_fn(struct ref_store *ref_store,
430428
const char *oldref, const char *newref,
431429
const char *logmsg);
@@ -550,7 +548,6 @@ struct ref_storage_be {
550548
ref_transaction_finish_fn *transaction_finish;
551549
ref_transaction_abort_fn *transaction_abort;
552550

553-
pack_refs_fn *pack_refs;
554551
optimize_fn *optimize;
555552
rename_ref_fn *rename_ref;
556553
copy_ref_fn *copy_ref;

refs/reftable-backend.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,11 +1700,11 @@ static int reftable_be_transaction_finish(struct ref_store *ref_store UNUSED,
17001700
return ret;
17011701
}
17021702

1703-
static int reftable_be_pack_refs(struct ref_store *ref_store,
1704-
struct pack_refs_opts *opts)
1703+
static int reftable_be_optimize(struct ref_store *ref_store,
1704+
struct refs_optimize_opts *opts)
17051705
{
17061706
struct reftable_ref_store *refs =
1707-
reftable_be_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, "pack_refs");
1707+
reftable_be_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, "optimize_refs");
17081708
struct reftable_stack *stack;
17091709
int ret;
17101710

@@ -1715,7 +1715,7 @@ static int reftable_be_pack_refs(struct ref_store *ref_store,
17151715
if (!stack)
17161716
stack = refs->main_backend.stack;
17171717

1718-
if (opts->flags & PACK_REFS_AUTO)
1718+
if (opts->flags & REFS_OPTIMIZE_AUTO)
17191719
ret = reftable_stack_auto_compact(stack);
17201720
else
17211721
ret = reftable_stack_compact_all(stack, NULL);
@@ -1733,12 +1733,6 @@ static int reftable_be_pack_refs(struct ref_store *ref_store,
17331733
return ret;
17341734
}
17351735

1736-
static int reftable_be_optimize(struct ref_store *ref_store,
1737-
struct pack_refs_opts *opts)
1738-
{
1739-
return reftable_be_pack_refs(ref_store, opts);
1740-
}
1741-
17421736
struct write_create_symref_arg {
17431737
struct reftable_ref_store *refs;
17441738
struct reftable_stack *stack;
@@ -2761,7 +2755,6 @@ struct ref_storage_be refs_be_reftable = {
27612755
.transaction_finish = reftable_be_transaction_finish,
27622756
.transaction_abort = reftable_be_transaction_abort,
27632757

2764-
.pack_refs = reftable_be_pack_refs,
27652758
.optimize = reftable_be_optimize,
27662759
.rename_ref = reftable_be_rename_ref,
27672760
.copy_ref = reftable_be_copy_ref,

t/pack-refs-tests.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,5 +459,3 @@ test_expect_success 'pack-refs does not store invalid peeled tag value' '
459459
test_grep ! "^\^" .git/packed-refs
460460
)
461461
'
462-
463-
test_done

t/t0601-reffiles-pack-refs.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ export GIT_TEST_DEFAULT_REF_FORMAT
1818
. ./test-lib.sh
1919

2020
. "$TEST_DIRECTORY"/pack-refs-tests.sh
21+
22+
test_done

0 commit comments

Comments
 (0)