1257
unsigned char midx_hash[GIT_MAX_RAWSZ];
1258
uint32_t start_pack;
1259
struct hashfile *f = NULL;
1260
- struct lock_file lk;
1260
+ struct lock_file lk = LOCK_INIT;
1261
struct tempfile *incr;
1262
struct write_midx_context ctx = {
1263
.preferred_pack_idx = NO_PREFERRED_PACK,
1601
}
1602
1603
if (ctx.incremental) {
1604
- struct strbuf lock_name = STRBUF_INIT;
1604
+ if (!(opts->flags & MIDX_WRITE_NO_CHAIN)) {
1605
+ struct strbuf lock_name = STRBUF_INIT;
1606
1606
- get_midx_chain_filename(opts->source, &lock_name);
1607
- hold_lock_file_for_update(&lk, lock_name.buf, LOCK_DIE_ON_ERROR);
1608
- strbuf_release(&lock_name);
1607
+ get_midx_chain_filename(opts->source, &lock_name);
1608
+ hold_lock_file_for_update(&lk, lock_name.buf,
1609
+ LOCK_DIE_ON_ERROR);
1610
+ strbuf_release(&lock_name);
1611
+ }
1612
1613
incr = mks_tempfile_m(midx_name.buf, 0444);
1614
if (!incr) {
1710
if (ctx.num_multi_pack_indexes_before == UINT32_MAX)
1711
die(_("too many multi-pack-indexes"));
1712
1713
+ if (!is_lock_file_locked(&lk))
1714
+ printf("%s\n", hash_to_hex_algop(midx_hash, r->hash_algo));
1715
+ else if (opts->flags & MIDX_WRITE_NO_CHAIN)
1716
+ BUG("lockfile held with MIDX_WRITE_NO_CHAIN set?");
1717
+
1718
if (ctx.incremental) {
1711
- FILE *chainf = fdopen_lock_file(&lk, "w");
1719
struct strbuf final_midx_name = STRBUF_INIT;
1720
struct multi_pack_index *m = ctx.base_midx;
1721
struct multi_pack_index **layers = NULL;
1722
size_t layers_nr = 0, layers_alloc = 0;
1723
1717
- if (!chainf) {
1718
- error_errno(_("unable to open multi-pack-index chain file"));
1719
- goto cleanup;
1724
+ if (is_lock_file_locked(&lk)){
1725
+ FILE *chainf = fdopen_lock_file(&lk, "w");
1726
+ if (!chainf) {
1727
+ error_errno(_("unable to open multi-pack-index chain file"));
1728
+ goto cleanup;
1729
+ }
1730
}
1731
1732
if (link_midx_to_chain(ctx.base_midx) < 0)
1783
1784
free(layers);
1785
1776
- for (size_t i = 0; i < keep_hashes.nr; i++)
1777
- fprintf(get_lock_file_fp(&lk), "%s\n", keep_hashes.v[i]);
1786
+ if (is_lock_file_locked(&lk))
1787
+ for (size_t i = 0; i < keep_hashes.nr; i++)
1788
+ fprintf(get_lock_file_fp(&lk), "%s\n",
1789
+ keep_hashes.v[i]);
1790
} else {
1791
strvec_push(&keep_hashes,
1792
hash_to_hex_algop(midx_hash, r->hash_algo));
1795
if (ctx.m || ctx.base_midx)
1796
odb_close(ctx.repo->objects);
1797
1786
- if (commit_lock_file(&lk) < 0)
1787
- die_errno(_("could not write multi-pack-index"));
1798
+ if (is_lock_file_locked(&lk)) {
1799
+ if (commit_lock_file(&lk) < 0)
1800
+ die_errno(_("could not write multi-pack-index"));
1801
1789
- clear_midx_files(opts->source, &keep_hashes, ctx.incremental);
1802
+ clear_midx_files(opts->source, &keep_hashes, ctx.incremental);
1803
+ }
1804
result = 0;
1805
1806
cleanup: