Merge commit

286f72ca82975741c861f23a7ee67d73cfb221d4

Merge branch 'ps/odb-pluggable-pack-generation' into ps/odb-pluggable-fsck

* ps/odb-pluggable-pack-generation:
  bundle: generate packfiles via the object database
  bundle: get (mostly) rid of `the_repository`
  builtin/bundle: refactor option handling for progress meter
  send-pack: generate packfiles via the object database
  upload-pack: generate packfiles via the object database
  odb: introduce interface to generate packfiles

Junio C Hamano <gitster@pobox.com> · 2026-08-26 01:07 UTC

Browse files

Combined diff: only what this merge did beyond taking one side. Added lines are colored by the parent they came from; bold lines came from none of them; removed lines are red.

2 files changed, +178 −7
modified odb.c
@@@ -1046,13 -1046,35 +1046,34 @@@ bool odb_optimize_required(struct objec
1046 return odb_source_optimize_required(odb->sources, opts);
1047 }
1048
1049 + void odb_generate_pack_options_release(struct odb_generate_pack_options *opts)
1050 + {
1051 + oid_array_clear(&opts->wants);
1052 + oid_array_clear(&opts->haves);
1053 + oid_array_clear(&opts->shallows);
1054 + }
1055 +
1056 + int odb_generate_pack(struct object_database *odb,
1057 + struct odb_pack_generator **out,
1058 + const struct odb_generate_pack_options *opts)
1059 + {
1060 + if (!odb->sources->generate_pack)
1061 + return error(_("primary object source does not support generating packfiles"));
1062 + return odb_source_generate_pack(odb->sources, out, opts);
1063 + }
1064 +
1065 + int odb_pack_generator_finish(struct odb_pack_generator *generator)
1066 + {
1067 + return generator->finish(generator);
1068 + }
1069 +
1070 struct object_database *odb_new(struct repository *repo,
- const char *primary_source,
- const char *secondary_sources)
1071 + enum odb_new_flags flags)
1072 {
- struct object_database *o = xmalloc(sizeof(*o));
- char *to_free = NULL;
1073 + char *primary_source = NULL, *secondary_sources = NULL;
1074 + struct object_database *o;
1075
- memset(o, 0, sizeof(*o));
1076 + CALLOC_ARRAY(o, 1);
1077 o->repo = repo;
1078 pthread_mutex_init(&o->replace_mutex, NULL);
1079 string_list_init_dup(&o->submodule_source_paths);
modified odb.h
@@@ -684,12 -672,163 +685,163 @@@ static inline int odb_write_object(stru
685 return odb_write_object_ext(odb, buf, len, type, oid, NULL, 0);
686 }
687
- struct odb_write_stream;
688 + struct odb_stream;
689
690 int odb_write_object_stream(struct object_database *odb,
- struct odb_write_stream *stream, size_t len,
691 + struct odb_stream *stream,
692 struct object_id *oid);
693
694 + /*
695 + * Options for generating a packfile via `odb_generate_pack()`.
696 + */
697 + struct odb_generate_pack_options {
698 + /* Tips of the object graph that shall be packed. */
699 + struct oid_array wants;
700 +
701 + /*
702 + * Boundary of the object graph. Objects reachable from any of these
703 + * tips are expected to already be available to whoever consumes the
704 + * pack and shall thus not be packed.
705 + */
706 + struct oid_array haves;
707 +
708 + /*
709 + * The shallow boundary that shall be used when computing object
710 + * reachability. When set, any shallow information of the repository
711 + * itself shall be ignored in favor of these objects.
712 + */
713 + struct oid_array shallows;
714 +
715 + /*
716 + * Pre-expanded object filter specification that limits the set of
717 + * objects that shall be packed. May be `NULL` in case no filter shall
718 + * be applied.
719 + */
720 + const char *filter_spec;
721 +
722 + /*
723 + * Protocols that may be used to offload objects via packfile URIs.
724 + * May be `NULL` in case packfile URIs shall not be used.
725 + */
726 + const struct string_list *uri_protocols;
727 +
728 + /*
729 + * Hook command that shall be executed instead of the internal
730 + * machinery to generate the pack. It is up to the specific backend
731 + * whether or not this hook is supported. May be `NULL` in case no
732 + * hook shall be executed.
733 + */
734 + const char *pack_objects_hook;
735 +
736 + /*
737 + * File descriptor that the generated pack shall be written to. If set
738 + * to `-1`, a pipe will be created and exposed via the pack generator's
739 + * `out` field. If set to `0`, the pack will be written to the standard
740 + * output stream. Otherwise, the provided descriptor will be written to
741 + * and is consumed by the generator.
742 + */
743 + int pack_fd;
744 +
745 + /*
746 + * File descriptor that progress output shall be written to. The same
747 + * semantics as for `pack_fd` apply, except that `0` will cause the
748 + * generator to write to stderr instead of stdout.
749 + */
750 + int progress_fd;
751 +
752 + /* Whether to print progress or not. */
753 + enum {
754 + /* Don't print progress output. */
755 + ODB_GENERATE_PACK_PROGRESS_NONE,
756 +
757 + /*
758 + * Print progress while computing the packfile, but stop
759 + * printing progress once starting to write it.
760 + */
761 + ODB_GENERATE_PACK_PROGRESS_STANDARD,
762 +
763 + /*
764 + * Similar to STANDARD, but also print progress when writing
765 + * the packfile.
766 + */
767 + ODB_GENERATE_PACK_PROGRESS_VERBOSE,
768 + } progress;
769 +
770 + /* Allow the pack to contain deltas against unpacked objects. */
771 + unsigned thin:1;
772 +
773 + /* Use offset deltas instead of reference deltas. */
774 + unsigned ofs_delta:1;
775 +
776 + /* Include unasked-for annotated tags of packed objects. */
777 + unsigned include_tag:1;
778 +
779 + /* The generated pack is destined for a shallow consumer. */
780 + unsigned shallow:1;
781 +
782 + /* Allow objects that may be missing due to a promisor remote. */
783 + unsigned missing_allow_promisor:1;
784 +
785 + /* Do not use bitmap indices when computing reachability. */
786 + unsigned disable_bitmaps:1;
787 + };
788 +
789 + #define ODB_GENERATE_PACK_OPTIONS_INIT { \
790 + .wants = OID_ARRAY_INIT, \
791 + .haves = OID_ARRAY_INIT, \
792 + .shallows = OID_ARRAY_INIT, \
793 + .pack_fd = -1, \
794 + }
795 +
796 + /* Release resources associated with the options. */
797 + void odb_generate_pack_options_release(struct odb_generate_pack_options *opts);
798 +
799 + /*
800 + * A handle for an ongoing packfile generation as started via
801 + * `odb_generate_pack()`.
802 + */
803 + struct odb_pack_generator {
804 + /*
805 + * File descriptor from which the generated pack can be read. Only set
806 + * when the pack generation was started with `pack_fd == -1`. The
807 + * caller is responsible for closing the descriptor.
808 + */
809 + int out;
810 +
811 + /*
812 + * File descriptor from which progress output can be read. Only set
813 + * when the pack generation was started with `progress_fd == -1`. The
814 + * caller is responsible for closing the descriptor.
815 + */
816 + int err;
817 +
818 + /*
819 + * Callback function to finish this generator. This callback is
820 + * expected to wait for the packfile generation to complete and to then
821 + * free the generator itself.
822 + */
823 + int (*finish)(struct odb_pack_generator *);
824 + };
825 +
826 + /*
827 + * Start generating a packfile from the object database with the given
828 + * options. The pack is generated asynchronously; the caller is expected to
829 + * consume the file descriptors exposed via the pack generator and to then
830 + * wait for completion via `odb_pack_generator_finish()`.
831 + *
832 + * Returns 0 on success and populates the `out` pointer with the pack
833 + * generator. Returns a negative error code otherwise.
834 + */
835 + int odb_generate_pack(struct object_database *odb,
836 + struct odb_pack_generator **out,
837 + const struct odb_generate_pack_options *opts);
838 +
839 + /*
840 + * Wait for the packfile generation to complete and free the pack generator.
841 + * Returns 0 on success, a negative error code otherwise.
842 + */
843 + int odb_pack_generator_finish(struct odb_pack_generator *generator);
844 +
845 void parse_alternates(const char *string,
846 int sep,
847 const char *relative_base,