Merge commit

923bf36c4644352c26a8770513c32bde8053ff5d

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

The mechanism to generate a packfile corresponding to the result of
a fetch/push has been made pluggable through a set of object
database callback functions, removing hardcoded references to
'pack-objects' and enabling alternative ODBs to serve packfiles
themselves.

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