summaryrefslogtreecommitdiff
path: root/server-info.c
diff options
context:
space:
mode:
Diffstat (limited to 'server-info.c')
-rw-r--r--server-info.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/server-info.c b/server-info.c
index e2b2d6a27a..41274d098b 100644
--- a/server-info.c
+++ b/server-info.c
@@ -78,7 +78,7 @@ static int generate_info_refs(FILE *fp)
return for_each_ref(add_info_ref, fp);
}
-static int update_info_refs(int force)
+static int update_info_refs(void)
{
char *path = git_pathdup("info/refs");
int ret = update_info_file(path, generate_info_refs);
@@ -91,19 +91,15 @@ static struct pack_info {
struct packed_git *p;
int old_num;
int new_num;
- int nr_alloc;
} **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;
@@ -112,9 +108,9 @@ static struct pack_info *find_pack_by_name(const char *name)
/* Returns non-zero when we detect that the info in the
* old file is useless.
*/
-static int parse_pack_def(const char *line, int old_cnt)
+static int parse_pack_def(const char *packname, int old_cnt)
{
- struct pack_info *i = find_pack_by_name(line + 2);
+ struct pack_info *i = find_pack_by_name(packname);
if (i) {
i->old_num = old_cnt;
return 0;
@@ -131,39 +127,40 @@ static int parse_pack_def(const char *line, int old_cnt)
static int read_pack_info_file(const char *infofile)
{
FILE *fp;
- char line[1000];
+ struct strbuf line = STRBUF_INIT;
int old_cnt = 0;
+ int stale = 1;
fp = fopen_or_warn(infofile, "r");
if (!fp)
return 1; /* nonexistent is not an error. */
- while (fgets(line, sizeof(line), fp)) {
- int len = strlen(line);
- if (len && line[len-1] == '\n')
- line[--len] = 0;
+ while (strbuf_getline(&line, fp) != EOF) {
+ const char *arg;
- if (!len)
+ if (!line.len)
continue;
- switch (line[0]) {
- case 'P': /* P name */
- if (parse_pack_def(line, old_cnt++))
+ if (skip_prefix(line.buf, "P ", &arg)) {
+ /* P name */
+ if (parse_pack_def(arg, old_cnt++))
goto out_stale;
- break;
- case 'D': /* we used to emit D but that was misguided. */
- case 'T': /* we used to emit T but nobody uses it. */
+ } else if (line.buf[0] == 'D') {
+ /* we used to emit D but that was misguided. */
goto out_stale;
- default:
- error("unrecognized: %s", line);
- break;
+ } else if (line.buf[0] == 'T') {
+ /* we used to emit T but nobody uses it. */
+ goto out_stale;
+ } else {
+ error("unrecognized: %s", line.buf);
}
}
- fclose(fp);
- return 0;
+ stale = 0;
+
out_stale:
+ strbuf_release(&line);
fclose(fp);
- return 1;
+ return stale;
}
static int compare_info(const void *a_, const void *b_)
@@ -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.
@@ -212,6 +206,7 @@ static void init_pack_info(const char *infofile, int force)
for (i = 0, p = get_all_packs(the_repository); p; p = p->next) {
if (!p->pack_local)
continue;
+ assert(i < num_pack);
info[i] = xcalloc(1, sizeof(struct pack_info));
info[i]->p = p;
info[i]->old_num = -1;
@@ -245,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)
@@ -274,7 +269,7 @@ int update_server_info(int force)
*/
int errs = 0;
- errs = errs | update_info_refs(force);
+ errs = errs | update_info_refs();
errs = errs | update_info_packs(force);
/* remove leftover rev-cache file if there is any */