57
return m->data + m->data_len - the_hash_algo->rawsz;
58
}
59
60
-char *get_midx_filename(const char *object_dir)
60
+void get_midx_filename(struct strbuf *out, const char *object_dir)
61
{
62
- return xstrfmt("%s/pack/multi-pack-index", object_dir);
62
+ strbuf_addf(out, "%s/pack/multi-pack-index", object_dir);
63
}
64
65
-char *get_midx_rev_filename(struct multi_pack_index *m)
65
+void get_midx_rev_filename(struct strbuf *out, struct multi_pack_index *m)
66
{
67
- return xstrfmt("%s/pack/multi-pack-index-%s.rev",
68
- m->object_dir, hash_to_hex(get_midx_checksum(m)));
67
+ get_midx_filename(out, m->object_dir);
68
+ strbuf_addf(out, "-%s.rev", hash_to_hex(get_midx_checksum(m)));
69
}
70
71
static int midx_read_oid_fanout(const unsigned char *chunk_start,
89
size_t midx_size;
90
void *midx_map = NULL;
91
uint32_t hash_version;
92
- char *midx_name = get_midx_filename(object_dir);
92
+ struct strbuf midx_name = STRBUF_INIT;
93
uint32_t i;
94
const char *cur_pack_name;
95
struct chunkfile *cf = NULL;
96
97
- fd = git_open(midx_name);
97
+ get_midx_filename(&midx_name, object_dir);
98
+
99
+ fd = git_open(midx_name.buf);
100
101
if (fd < 0)
102
goto cleanup_fail;
103
if (fstat(fd, &st)) {
102
- error_errno(_("failed to read %s"), midx_name);
104
+ error_errno(_("failed to read %s"), midx_name.buf);
105
goto cleanup_fail;
106
}
107
108
midx_size = xsize_t(st.st_size);
109
110
if (midx_size < MIDX_MIN_SIZE) {
109
- error(_("multi-pack-index file %s is too small"), midx_name);
111
+ error(_("multi-pack-index file %s is too small"), midx_name.buf);
112
goto cleanup_fail;
113
}
114
113
- FREE_AND_NULL(midx_name);
115
+ strbuf_release(&midx_name);
116
117
midx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0);
118
close(fd);
186
187
cleanup_fail:
188
free(m);
187
- free(midx_name);
189
+ strbuf_release(&midx_name);
190
free_chunkfile(cf);
191
if (midx_map)
192
munmap(midx_map, midx_size);
1117
const char *refs_snapshot,
1118
unsigned flags)
1119
{
1118
- char *midx_name;
1120
+ struct strbuf midx_name = STRBUF_INIT;
1121
unsigned char midx_hash[GIT_MAX_RAWSZ];
1122
uint32_t i;
1123
struct hashfile *f = NULL;
1132
/* Ensure the given object_dir is local, or a known alternate. */
1133
find_odb(the_repository, object_dir);
1134
1133
- midx_name = get_midx_filename(object_dir);
1134
- if (safe_create_leading_directories(midx_name))
1135
+ get_midx_filename(&midx_name, object_dir);
1136
+ if (safe_create_leading_directories(midx_name.buf))
1137
die_errno(_("unable to create leading directories of %s"),
1136
- midx_name);
1138
+ midx_name.buf);
1139
1140
if (!packs_to_include) {
1141
/*
1369
pack_name_concat_len += MIDX_CHUNK_ALIGNMENT -
1370
(pack_name_concat_len % MIDX_CHUNK_ALIGNMENT);
1371
1370
- hold_lock_file_for_update(&lk, midx_name, LOCK_DIE_ON_ERROR);
1372
+ hold_lock_file_for_update(&lk, midx_name.buf, LOCK_DIE_ON_ERROR);
1373
f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk));
1374
1375
if (ctx.nr - dropped_packs == 0) {
1406
ctx.pack_order = midx_pack_order(&ctx);
1407
1408
if (flags & MIDX_WRITE_REV_INDEX)
1407
- write_midx_reverse_index(midx_name, midx_hash, &ctx);
1409
+ write_midx_reverse_index(midx_name.buf, midx_hash, &ctx);
1410
if (flags & MIDX_WRITE_BITMAP) {
1409
- if (write_midx_bitmap(midx_name, midx_hash, &ctx,
1411
+ if (write_midx_bitmap(midx_name.buf, midx_hash, &ctx,
1412
refs_snapshot, flags) < 0) {
1413
error(_("could not write multi-pack bitmap"));
1414
result = 1;
1437
free(ctx.entries);
1438
free(ctx.pack_perm);
1439
free(ctx.pack_order);
1438
- free(midx_name);
1440
+ strbuf_release(&midx_name);
1441
1442
return result;
1443
}
1501
1502
void clear_midx_file(struct repository *r)
1503
{
1502
- char *midx = get_midx_filename(r->objects->odb->path);
1504
+ struct strbuf midx = STRBUF_INIT;
1505
+
1506
+ get_midx_filename(&midx, r->objects->odb->path);
1507
1508
if (r->objects && r->objects->multi_pack_index) {
1509
close_midx(r->objects->multi_pack_index);
1510
r->objects->multi_pack_index = NULL;
1511
}
1512
1509
- if (remove_path(midx))
1510
- die(_("failed to clear multi-pack-index at %s"), midx);
1513
+ if (remove_path(midx.buf))
1514
+ die(_("failed to clear multi-pack-index at %s"), midx.buf);
1515
1516
clear_midx_files_ext(r->objects->odb->path, ".bitmap", NULL);
1517
clear_midx_files_ext(r->objects->odb->path, ".rev", NULL);
1518
1515
- free(midx);
1519
+ strbuf_release(&midx);
1520
}
1521
1522
static int verify_midx_error;
1569
if (!m) {
1570
int result = 0;
1571
struct stat sb;
1568
- char *filename = get_midx_filename(object_dir);
1569
- if (!stat(filename, &sb)) {
1572
+ struct strbuf filename = STRBUF_INIT;
1573
+
1574
+ get_midx_filename(&filename, object_dir);
1575
+
1576
+ if (!stat(filename.buf, &sb)) {
1577
error(_("multi-pack-index file exists, but failed to parse"));
1578
result = 1;
1579
}
1573
- free(filename);
1580
+ strbuf_release(&filename);
1581
return result;
1582
}
1583