server-info: drop objdirlen pointer arithmetic

When writing objects/info/packs, we use the basename of each pack (i.e., just the "pack-1234abcd.pack" part). We compute that manually by adding "objdirlen + 6" to the name. This _should_ work consistently, as we do not include non-local packs, meaning everything should be in $objdir/pack/. Before f13d7db4af (server-info.c: use pack_local like everybody else., 2005-12-05), this was definitely true, since we computed "local" based on comparing the objdir string. Since then, we're relying on the code on packfile.c to match our expectations of p->pack_name and p->local. I think our expectations do still hold today, but we can be a bit more defensive by just using pack_basename() to get the base. That future-proofs us, and should hopefully be more obviously safe to somebody reading the code. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 5, 2019 at 14:14 UTC b9fb142eac8053afc43344ef83bca0275d59b438
1 file changed +2 -8
server-info.c
+2 -8
@@ -93,16 +93,13 @@ static struct pack_info {
93 int new_num;
94 } **info;
95 static int num_pack;
96 -static const char *objdir;
97 -static int objdirlen;
96
97 static struct pack_info *find_pack_by_name(const char *name)
98 {
99 int i;
100 for (i = 0; i < num_pack; i++) {
101 struct packed_git *p = info[i]->p;
104 - /* skip "/pack/" after ".git/objects" */
105 - if (!strcmp(p->pack_name + objdirlen + 6, name))
102 + if (!strcmp(pack_basename(p), name))
103 return info[i];
104 }
105 return NULL;
@@ -196,9 +193,6 @@ static void init_pack_info(const char *infofile, int force)
193 int stale;
194 int i = 0;
195
199 - objdir = get_object_directory();
200 - objdirlen = strlen(objdir);
201 -
196 for (p = get_all_packs(the_repository); p; p = p->next) {
197 /* we ignore things on alternate path since they are
198 * not available to the pullers in general.
@@ -246,7 +240,7 @@ static int write_pack_info_file(FILE *fp)
240 {
241 int i;
242 for (i = 0; i < num_pack; i++) {
249 - if (fprintf(fp, "P %s\n", info[i]->p->pack_name + objdirlen + 6) < 0)
243 + if (fprintf(fp, "P %s\n", pack_basename(info[i]->p)) < 0)
244 return -1;
245 }
246 if (fputc('\n', fp) == EOF)