Skip to content

Commit c365dbb

Browse files
pks-tgitster
authored andcommitted
server-info: stop using the_repository
Stop using `the_repository` in the "server-info" subsystem by passing in a repository when updating server info and storing the repository in the `update_info_ctx` structure to make it accessible to other functions. Adjust callers accordingly by using `the_repository`. While there may be some callers that have a repository available in their context, this trivial conversion allows for easier verification and bubbles up the use of `the_repository` by one level. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ee907b commit c365dbb

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,7 @@ int cmd_receive_pack(int argc,
26282628
}
26292629
}
26302630
if (auto_update_server_info)
2631-
update_server_info(0);
2631+
update_server_info(the_repository, 0);
26322632
clear_shallow_info(&si);
26332633
}
26342634
if (use_sideband)

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ int cmd_repack(int argc,
15651565
}
15661566

15671567
if (run_update_server_info)
1568-
update_server_info(0);
1568+
update_server_info(the_repository, 0);
15691569

15701570
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) {
15711571
unsigned flags = 0;

builtin/update-server-info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ int cmd_update_server_info(int argc,
2727
if (argc > 0)
2828
usage_with_options(update_server_info_usage, options);
2929

30-
return !!update_server_info(force);
30+
return !!update_server_info(the_repository, force);
3131
}

server-info.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "git-compat-util.h"
@@ -18,6 +17,7 @@
1817
#include "tempfile.h"
1918

2019
struct update_info_ctx {
20+
struct repository *repo;
2121
FILE *cur_fp;
2222
FILE *old_fp; /* becomes NULL if it differs from cur_fp */
2323
struct strbuf cur_sb;
@@ -73,14 +73,15 @@ static int uic_printf(struct update_info_ctx *uic, const char *fmt, ...)
7373
* it into place. The contents of the file come from "generate", which
7474
* should return non-zero if it encounters an error.
7575
*/
76-
static int update_info_file(char *path,
76+
static int update_info_file(struct repository *r, char *path,
7777
int (*generate)(struct update_info_ctx *),
7878
int force)
7979
{
8080
char *tmp = mkpathdup("%s_XXXXXX", path);
8181
struct tempfile *f = NULL;
8282
int ret = -1;
8383
struct update_info_ctx uic = {
84+
.repo = r,
8485
.cur_fp = NULL,
8586
.old_fp = NULL,
8687
.cur_sb = STRBUF_INIT,
@@ -152,15 +153,15 @@ static int add_info_ref(const char *path, const char *referent UNUSED, const str
152153
void *cb_data)
153154
{
154155
struct update_info_ctx *uic = cb_data;
155-
struct object *o = parse_object(the_repository, oid);
156+
struct object *o = parse_object(uic->repo, oid);
156157
if (!o)
157158
return -1;
158159

159160
if (uic_printf(uic, "%s %s\n", oid_to_hex(oid), path) < 0)
160161
return -1;
161162

162163
if (o->type == OBJ_TAG) {
163-
o = deref_tag(the_repository, o, path, 0);
164+
o = deref_tag(uic->repo, o, path, 0);
164165
if (o)
165166
if (uic_printf(uic, "%s %s^{}\n",
166167
oid_to_hex(&o->oid), path) < 0)
@@ -171,14 +172,14 @@ static int add_info_ref(const char *path, const char *referent UNUSED, const str
171172

172173
static int generate_info_refs(struct update_info_ctx *uic)
173174
{
174-
return refs_for_each_ref(get_main_ref_store(the_repository),
175+
return refs_for_each_ref(get_main_ref_store(uic->repo),
175176
add_info_ref, uic);
176177
}
177178

178-
static int update_info_refs(int force)
179+
static int update_info_refs(struct repository *r, int force)
179180
{
180-
char *path = git_pathdup("info/refs");
181-
int ret = update_info_file(path, generate_info_refs, force);
181+
char *path = repo_git_path(r, "info/refs");
182+
int ret = update_info_file(r, path, generate_info_refs, force);
182183
free(path);
183184
return ret;
184185
}
@@ -284,14 +285,14 @@ static int compare_info(const void *a_, const void *b_)
284285
return 1;
285286
}
286287

287-
static void init_pack_info(const char *infofile, int force)
288+
static void init_pack_info(struct repository *r, const char *infofile, int force)
288289
{
289290
struct packed_git *p;
290291
int stale;
291292
int i;
292293
size_t alloc = 0;
293294

294-
for (p = get_all_packs(the_repository); p; p = p->next) {
295+
for (p = get_all_packs(r); p; p = p->next) {
295296
/* we ignore things on alternate path since they are
296297
* not available to the pullers in general.
297298
*/
@@ -340,33 +341,36 @@ static int write_pack_info_file(struct update_info_ctx *uic)
340341
return 0;
341342
}
342343

343-
static int update_info_packs(int force)
344+
static int update_info_packs(struct repository *r, int force)
344345
{
345346
char *infofile = mkpathdup("%s/info/packs",
346-
repo_get_object_directory(the_repository));
347+
repo_get_object_directory(r));
347348
int ret;
348349

349-
init_pack_info(infofile, force);
350-
ret = update_info_file(infofile, write_pack_info_file, force);
350+
init_pack_info(r, infofile, force);
351+
ret = update_info_file(r, infofile, write_pack_info_file, force);
351352
free_pack_info();
352353
free(infofile);
353354
return ret;
354355
}
355356

356357
/* public */
357-
int update_server_info(int force)
358+
int update_server_info(struct repository *r, int force)
358359
{
359360
/* We would add more dumb-server support files later,
360361
* including index of available pack files and their
361362
* intended audiences.
362363
*/
363364
int errs = 0;
365+
char *path;
364366

365-
errs = errs | update_info_refs(force);
366-
errs = errs | update_info_packs(force);
367+
errs = errs | update_info_refs(r, force);
368+
errs = errs | update_info_packs(r, force);
367369

368370
/* remove leftover rev-cache file if there is any */
369-
unlink_or_warn(git_path("info/rev-cache"));
371+
path = repo_git_path(r, "info/rev-cache");
372+
unlink_or_warn(path);
373+
free(path);
370374

371375
return errs;
372376
}

server-info.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#ifndef SERVER_INFO_H
22
#define SERVER_INFO_H
33

4+
struct repository;
5+
46
/* Dumb servers support */
5-
int update_server_info(int);
7+
int update_server_info(struct repository *r, int force);
68

79
#endif /* SERVER_INFO_H */

0 commit comments

Comments
 (0)