Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
c365dbb4 5ee907bb

+28 -22
+1 -1
builtin/receive-pack.c
··· 2628 } 2629 } 2630 if (auto_update_server_info) 2631 - update_server_info(0); 2632 clear_shallow_info(&si); 2633 } 2634 if (use_sideband)
··· 2628 } 2629 } 2630 if (auto_update_server_info) 2631 + update_server_info(the_repository, 0); 2632 clear_shallow_info(&si); 2633 } 2634 if (use_sideband)
+1 -1
builtin/repack.c
··· 1565 } 1566 1567 if (run_update_server_info) 1568 - update_server_info(0); 1569 1570 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) { 1571 unsigned flags = 0;
··· 1565 } 1566 1567 if (run_update_server_info) 1568 + update_server_info(the_repository, 0); 1569 1570 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) { 1571 unsigned flags = 0;
+1 -1
builtin/update-server-info.c
··· 27 if (argc > 0) 28 usage_with_options(update_server_info_usage, options); 29 30 - return !!update_server_info(force); 31 }
··· 27 if (argc > 0) 28 usage_with_options(update_server_info_usage, options); 29 30 + return !!update_server_info(the_repository, force); 31 }
+22 -18
server-info.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 #define DISABLE_SIGN_COMPARE_WARNINGS 3 4 #include "git-compat-util.h" ··· 18 #include "tempfile.h" 19 20 struct update_info_ctx { 21 FILE *cur_fp; 22 FILE *old_fp; /* becomes NULL if it differs from cur_fp */ 23 struct strbuf cur_sb; ··· 73 * it into place. The contents of the file come from "generate", which 74 * should return non-zero if it encounters an error. 75 */ 76 - static int update_info_file(char *path, 77 int (*generate)(struct update_info_ctx *), 78 int force) 79 { ··· 81 struct tempfile *f = NULL; 82 int ret = -1; 83 struct update_info_ctx uic = { 84 .cur_fp = NULL, 85 .old_fp = NULL, 86 .cur_sb = STRBUF_INIT, ··· 152 void *cb_data) 153 { 154 struct update_info_ctx *uic = cb_data; 155 - struct object *o = parse_object(the_repository, oid); 156 if (!o) 157 return -1; 158 ··· 160 return -1; 161 162 if (o->type == OBJ_TAG) { 163 - o = deref_tag(the_repository, o, path, 0); 164 if (o) 165 if (uic_printf(uic, "%s %s^{}\n", 166 oid_to_hex(&o->oid), path) < 0) ··· 171 172 static int generate_info_refs(struct update_info_ctx *uic) 173 { 174 - return refs_for_each_ref(get_main_ref_store(the_repository), 175 add_info_ref, uic); 176 } 177 178 - static int update_info_refs(int force) 179 { 180 - char *path = git_pathdup("info/refs"); 181 - int ret = update_info_file(path, generate_info_refs, force); 182 free(path); 183 return ret; 184 } ··· 284 return 1; 285 } 286 287 - static void init_pack_info(const char *infofile, int force) 288 { 289 struct packed_git *p; 290 int stale; 291 int i; 292 size_t alloc = 0; 293 294 - for (p = get_all_packs(the_repository); p; p = p->next) { 295 /* we ignore things on alternate path since they are 296 * not available to the pullers in general. 297 */ ··· 340 return 0; 341 } 342 343 - static int update_info_packs(int force) 344 { 345 char *infofile = mkpathdup("%s/info/packs", 346 - repo_get_object_directory(the_repository)); 347 int ret; 348 349 - init_pack_info(infofile, force); 350 - ret = update_info_file(infofile, write_pack_info_file, force); 351 free_pack_info(); 352 free(infofile); 353 return ret; 354 } 355 356 /* public */ 357 - int update_server_info(int force) 358 { 359 /* We would add more dumb-server support files later, 360 * including index of available pack files and their 361 * intended audiences. 362 */ 363 int errs = 0; 364 365 - errs = errs | update_info_refs(force); 366 - errs = errs | update_info_packs(force); 367 368 /* remove leftover rev-cache file if there is any */ 369 - unlink_or_warn(git_path("info/rev-cache")); 370 371 return errs; 372 }
··· 1 #define DISABLE_SIGN_COMPARE_WARNINGS 2 3 #include "git-compat-util.h" ··· 17 #include "tempfile.h" 18 19 struct update_info_ctx { 20 + struct repository *repo; 21 FILE *cur_fp; 22 FILE *old_fp; /* becomes NULL if it differs from cur_fp */ 23 struct strbuf cur_sb; ··· 73 * it into place. The contents of the file come from "generate", which 74 * should return non-zero if it encounters an error. 75 */ 76 + static int update_info_file(struct repository *r, char *path, 77 int (*generate)(struct update_info_ctx *), 78 int force) 79 { ··· 81 struct tempfile *f = NULL; 82 int ret = -1; 83 struct update_info_ctx uic = { 84 + .repo = r, 85 .cur_fp = NULL, 86 .old_fp = NULL, 87 .cur_sb = STRBUF_INIT, ··· 153 void *cb_data) 154 { 155 struct update_info_ctx *uic = cb_data; 156 + struct object *o = parse_object(uic->repo, oid); 157 if (!o) 158 return -1; 159 ··· 161 return -1; 162 163 if (o->type == OBJ_TAG) { 164 + o = deref_tag(uic->repo, o, path, 0); 165 if (o) 166 if (uic_printf(uic, "%s %s^{}\n", 167 oid_to_hex(&o->oid), path) < 0) ··· 172 173 static int generate_info_refs(struct update_info_ctx *uic) 174 { 175 + return refs_for_each_ref(get_main_ref_store(uic->repo), 176 add_info_ref, uic); 177 } 178 179 + static int update_info_refs(struct repository *r, int force) 180 { 181 + char *path = repo_git_path(r, "info/refs"); 182 + int ret = update_info_file(r, path, generate_info_refs, force); 183 free(path); 184 return ret; 185 } ··· 285 return 1; 286 } 287 288 + static void init_pack_info(struct repository *r, const char *infofile, int force) 289 { 290 struct packed_git *p; 291 int stale; 292 int i; 293 size_t alloc = 0; 294 295 + for (p = get_all_packs(r); p; p = p->next) { 296 /* we ignore things on alternate path since they are 297 * not available to the pullers in general. 298 */ ··· 341 return 0; 342 } 343 344 + static int update_info_packs(struct repository *r, int force) 345 { 346 char *infofile = mkpathdup("%s/info/packs", 347 + repo_get_object_directory(r)); 348 int ret; 349 350 + init_pack_info(r, infofile, force); 351 + ret = update_info_file(r, infofile, write_pack_info_file, force); 352 free_pack_info(); 353 free(infofile); 354 return ret; 355 } 356 357 /* public */ 358 + int update_server_info(struct repository *r, int force) 359 { 360 /* We would add more dumb-server support files later, 361 * including index of available pack files and their 362 * intended audiences. 363 */ 364 int errs = 0; 365 + char *path; 366 367 + errs = errs | update_info_refs(r, force); 368 + errs = errs | update_info_packs(r, force); 369 370 /* remove leftover rev-cache file if there is any */ 371 + path = repo_git_path(r, "info/rev-cache"); 372 + unlink_or_warn(path); 373 + free(path); 374 375 return errs; 376 }
+3 -1
server-info.h
··· 1 #ifndef SERVER_INFO_H 2 #define SERVER_INFO_H 3 4 /* Dumb servers support */ 5 - int update_server_info(int); 6 7 #endif /* SERVER_INFO_H */
··· 1 #ifndef SERVER_INFO_H 2 #define SERVER_INFO_H 3 4 + struct repository; 5 + 6 /* Dumb servers support */ 7 + int update_server_info(struct repository *r, int force); 8 9 #endif /* SERVER_INFO_H */