Skip to content

Commit c7a1207

Browse files
ttaylorrgitster
authored andcommitted
repack: introduce new compilation unit
Over the years, builtin/repack.c has turned into a grab-bag of functionality powering the 'git repack' builtin. Among its many capabilities, it: - can build and spawn 'git pack-objects' commands, which in turn generate new packs - has infrastructure to manage the set of existing packs in a repository - has infrastructure to split a sequence of packs into a geometric progression based on object size - can manage both generating and combining cruft packs together - can write new MIDXs to name a few. As a result, this builtin has accumulated a lot of code, making adding new functionality difficult. In the future, 'repack' will learn how to manage a chain of incremental MIDXs, adding yet more functionality into the builtin. As a prerequisite step, let's first move some of the functionality in the builtin into its own repack.[ch]. This will be done over the course of many steps, since there are many individual components, some of which will end up in other, yet-to-exist compilation units of their own. Some of the code movement here is also non-trivial, so performing it in individual steps will make it easier to verify. Let's start by migrating 'struct pack_objects_args' (and the related corresponding pack_objects_args_release() function) into repack.h, and teach both the Makefile and Meson how to build the new compilation unit. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8a5d4bd commit c7a1207

5 files changed

Lines changed: 37 additions & 24 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ LIB_OBJS += refs/packed-backend.o
11361136
LIB_OBJS += refs/ref-cache.o
11371137
LIB_OBJS += refspec.o
11381138
LIB_OBJS += remote.o
1139+
LIB_OBJS += repack.o
11391140
LIB_OBJS += replace-object.o
11401141
LIB_OBJS += repo-settings.o
11411142
LIB_OBJS += repository.o

builtin/repack.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "prune-packed.h"
2020
#include "odb.h"
2121
#include "promisor-remote.h"
22+
#include "repack.h"
2223
#include "shallow.h"
2324
#include "pack.h"
2425
#include "pack-bitmap.h"
@@ -53,21 +54,6 @@ static const char incremental_bitmap_conflict_error[] = N_(
5354
"--no-write-bitmap-index or disable the pack.writeBitmaps configuration."
5455
);
5556

56-
struct pack_objects_args {
57-
char *window;
58-
char *window_memory;
59-
char *depth;
60-
char *threads;
61-
unsigned long max_pack_size;
62-
int no_reuse_delta;
63-
int no_reuse_object;
64-
int quiet;
65-
int local;
66-
int name_hash_version;
67-
int path_walk;
68-
struct list_objects_filter_options filter_options;
69-
};
70-
7157
static int repack_config(const char *var, const char *value,
7258
const struct config_context *ctx, void *cb)
7359
{
@@ -116,15 +102,6 @@ static int repack_config(const char *var, const char *value,
116102
return git_default_config(var, value, ctx, cb);
117103
}
118104

119-
static void pack_objects_args_release(struct pack_objects_args *args)
120-
{
121-
free(args->window);
122-
free(args->window_memory);
123-
free(args->depth);
124-
free(args->threads);
125-
list_objects_filter_release(&args->filter_options);
126-
}
127-
128105
struct existing_packs {
129106
struct repository *repo;
130107
struct string_list kept_packs;

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ libgit_sources = [
462462
'reftable/tree.c',
463463
'reftable/writer.c',
464464
'remote.c',
465+
'repack.c',
465466
'replace-object.c',
466467
'repo-settings.c',
467468
'repository.c',

repack.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "git-compat-util.h"
2+
#include "repack.h"
3+
4+
void pack_objects_args_release(struct pack_objects_args *args)
5+
{
6+
free(args->window);
7+
free(args->window_memory);
8+
free(args->depth);
9+
free(args->threads);
10+
list_objects_filter_release(&args->filter_options);
11+
}

repack.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef REPACK_H
2+
#define REPACK_H
3+
4+
#include "list-objects-filter-options.h"
5+
6+
struct pack_objects_args {
7+
char *window;
8+
char *window_memory;
9+
char *depth;
10+
char *threads;
11+
unsigned long max_pack_size;
12+
int no_reuse_delta;
13+
int no_reuse_object;
14+
int quiet;
15+
int local;
16+
int name_hash_version;
17+
int path_walk;
18+
struct list_objects_filter_options filter_options;
19+
};
20+
21+
void pack_objects_args_release(struct pack_objects_args *args);
22+
23+
#endif /* REPACK_H */

0 commit comments

Comments
 (0)