15
#include "promisor-remote.h"
16
#include "shallow.h"
17
#include "pack.h"
18
+#include "pack-bitmap.h"
19
+#include "refs.h"
20
21
static int delta_base_offset = 1;
22
static int pack_kept_objects = -1;
455
geometry->split = 0;
456
}
457
458
+struct midx_snapshot_ref_data {
459
+ struct tempfile *f;
460
+ struct oidset seen;
461
+ int preferred;
462
+};
463
+
464
+static int midx_snapshot_ref_one(const char *refname,
465
+ const struct object_id *oid,
466
+ int flag, void *_data)
467
+{
468
+ struct midx_snapshot_ref_data *data = _data;
469
+ struct object_id peeled;
470
+
471
+ if (!peel_iterated_oid(oid, &peeled))
472
+ oid = &peeled;
473
+
474
+ if (oidset_insert(&data->seen, oid))
475
+ return 0; /* already seen */
476
+
477
+ if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
478
+ return 0;
479
+
480
+ fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
481
+ oid_to_hex(oid));
482
+
483
+ return 0;
484
+}
485
+
486
+static void midx_snapshot_refs(struct tempfile *f)
487
+{
488
+ struct midx_snapshot_ref_data data;
489
+ const struct string_list *preferred = bitmap_preferred_tips(the_repository);
490
+
491
+ data.f = f;
492
+ data.preferred = 0;
493
+ oidset_init(&data.seen, 0);
494
+
495
+ if (!fdopen_tempfile(f, "w"))
496
+ die(_("could not open tempfile %s for writing"),
497
+ get_tempfile_path(f));
498
+
499
+ if (preferred) {
500
+ struct string_list_item *item;
501
+
502
+ data.preferred = 1;
503
+ for_each_string_list_item(item, preferred)
504
+ for_each_ref_in(item->string, midx_snapshot_ref_one, &data);
505
+ data.preferred = 0;
506
+ }
507
+
508
+ for_each_ref(midx_snapshot_ref_one, &data);
509
+
510
+ if (close_tempfile_gently(f)) {
511
+ int save_errno = errno;
512
+ delete_tempfile(&f);
513
+ errno = save_errno;
514
+ die_errno(_("could not close refs snapshot tempfile"));
515
+ }
516
+
517
+ oidset_clear(&data.seen);
518
+}
519
+
520
static void midx_included_packs(struct string_list *include,
521
struct string_list *existing_nonkept_packs,
522
struct string_list *existing_kept_packs,
552
553
static int write_midx_included_packs(struct string_list *include,
554
struct pack_geometry *geometry,
555
+ const char *refs_snapshot,
556
int show_progress, int write_bitmaps)
557
{
558
struct child_process cmd = CHILD_PROCESS_INIT;
582
strvec_pushf(&cmd.args, "--preferred-pack=%s",
583
pack_basename(largest));
584
585
+ if (refs_snapshot)
586
+ strvec_pushf(&cmd.args, "--refs-snapshot=%s", refs_snapshot);
587
+
588
ret = start_command(&cmd);
589
if (ret)
590
return ret;
607
struct string_list existing_kept_packs = STRING_LIST_INIT_DUP;
608
struct pack_geometry *geometry = NULL;
609
struct strbuf line = STRBUF_INIT;
610
+ struct tempfile *refs_snapshot = NULL;
611
int i, ext, ret;
612
FILE *out;
613
int show_progress = isatty(2);
696
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
697
die(_(incremental_bitmap_conflict_error));
698
699
+ if (write_midx && write_bitmaps) {
700
+ struct strbuf path = STRBUF_INIT;
701
+
702
+ strbuf_addf(&path, "%s/%s_XXXXXX", get_object_directory(),
703
+ "bitmap-ref-tips");
704
+
705
+ refs_snapshot = xmks_tempfile(path.buf);
706
+ midx_snapshot_refs(refs_snapshot);
707
+
708
+ strbuf_release(&path);
709
+ }
710
+
711
if (geometric_factor) {
712
if (pack_everything)
713
die(_("--geometric is incompatible with -A, -a"));
890
&existing_kept_packs, &names, geometry);
891
892
ret = write_midx_included_packs(&include, geometry,
893
+ refs_snapshot ? get_tempfile_path(refs_snapshot) : NULL,
894
show_progress, write_bitmaps > 0);
895
896
string_list_clear(&include, 0);