summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2019-04-05 14:14:04 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-04-16 16:58:21 +0900
commitb9fb142eac8053afc43344ef83bca0275d59b438 (patch)
treef1d69124ab03556521285692b3f2d2daa31cdb32
parentserver-info: drop nr_alloc struct member (diff)
downloadtgif-b9fb142eac8053afc43344ef83bca0275d59b438.tar.xz
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>
-rw-r--r--server-info.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/server-info.c b/server-info.c
index c9fbfd3a51..ab03c1b3c2 100644
--- a/server-info.c
+++ b/server-info.c
@@ -93,16 +93,13 @@ static struct pack_info {
int new_num;
} **info;
static int num_pack;
-static const char *objdir;
-static int objdirlen;
static struct pack_info *find_pack_by_name(const char *name)
{
int i;
for (i = 0; i < num_pack; i++) {
struct packed_git *p = info[i]->p;
- /* skip "/pack/" after ".git/objects" */
- if (!strcmp(p->pack_name + objdirlen + 6, name))
+ if (!strcmp(pack_basename(p), name))
return info[i];
}
return NULL;
@@ -196,9 +193,6 @@ static void init_pack_info(const char *infofile, int force)
int stale;
int i = 0;
- objdir = get_object_directory();
- objdirlen = strlen(objdir);
-
for (p = get_all_packs(the_repository); p; p = p->next) {
/* we ignore things on alternate path since they are
* not available to the pullers in general.
@@ -246,7 +240,7 @@ static int write_pack_info_file(FILE *fp)
{
int i;
for (i = 0; i < num_pack; i++) {
- if (fprintf(fp, "P %s\n", info[i]->p->pack_name + objdirlen + 6) < 0)
+ if (fprintf(fp, "P %s\n", pack_basename(info[i]->p)) < 0)
return -1;
}
if (fputc('\n', fp) == EOF)