Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/odb/transaction.h # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / odb / transaction.h` 181 lines ยท 6070 bytes Raw Blame History 1 #ifndef ODB_TRANSACTION_H 2 #define ODB_TRANSACTION_H 3 4 #include "gettext.h" 5 #include "odb.h" 6 7 /* 8 * Options controlling how odb_transaction_write_pack() ingests a packfile. 9 */ 10 struct odb_transaction_write_pack_opts { 11 /* 12 * Optional fsck severity configuration to apply when incoming objects 13 * are verified. 14 */ 15 const char *fsck_msg_types; 16 17 /* 18 * Path to an alternative shallow file describing the shallow boundaries 19 * to honor while ingesting the pack. 20 */ 21 const char *shallow_file; 22 23 /* 24 * The max size in bytes of the incoming packfile allowed. No limit is 25 * enforced when set to 0. 26 */ 27 off_t max_input_size; 28 29 /* 30 * Whether the validity of incoming objects should be verified. 31 */ 32 int fsck_objects; 33 34 /* 35 * Whether to reject an incoming packfile if it is "thin". 36 */ 37 int reject_thin; 38 39 /* 40 * Optional file descriptor for reporting progress and errors. Set to 0 41 * for none. 42 */ 43 int err_fd; 44 45 /* 46 * Suppresses progress reporting. 47 */ 48 int quiet; 49 }; 50 51 /* 52 * A transaction may be started for an object database prior to writing new 53 * objects via odb_transaction_begin(). These objects are not committed until 54 * odb_transaction_commit() is invoked. Only a single transaction may be pending 55 * at a time. 56 * 57 * Each ODB source is expected to implement its own transaction handling. 58 */ 59 struct odb_transaction { 60 /* The ODB source the transaction is opened against. */ 61 struct odb_source *source; 62 63 /* 64 * The ODB source specific callback invoked to commit a transaction. 65 * Returns 0 on success, a negative error code otherwise. 66 */ 67 int (*commit)(struct odb_transaction *transaction); 68 69 /* 70 * Optional ODB source specific callback invoked when the transaction 71 * needs to perform any deferred cleanup after objects have been 72 * committed. Returns 0 on success, a negative error code otherwise. 73 */ 74 int (*finalize)(struct odb_transaction *transaction); 75 76 /* 77 * This callback is expected to write the given object stream into 78 * the ODB transaction. 79 * 80 * The resulting object ID shall be written into the out pointer. The 81 * callback is expected to return 0 on success, a negative error code 82 * otherwise. 83 */ 84 int (*write_object_stream)(struct odb_transaction *transaction, 85 struct odb_stream *stream, 86 struct object_id *oid); 87 /* 88 * This callback is expected to ingest the packfile readable via 89 * `pack_fd` into the transaction. Returns 0 on success, a negative 90 * error code otherwise. On failure, a human-readable description is 91 * appended to `err_msg`. 92 */ 93 int (*write_pack)(struct odb_transaction *transaction, int pack_fd, 94 struct strbuf *err_msg, 95 const struct odb_transaction_write_pack_opts *opts); 96 97 /* 98 * This callback is expected to populate the provided strvec with the 99 * environment variables that a child process should inherit so that its 100 * object writes participate in the transaction. Returns 0 on success, a 101 * negative error code otherwise. 102 */ 103 int (*env)(struct odb_transaction *transaction, struct strvec *env); 104 }; 105 106 /* Flags used to configure an ODB transaction. */ 107 enum odb_transaction_flags { 108 /* Configures the transaction for use with git-receive-pack(1). */ 109 ODB_TRANSACTION_RECEIVE = (1 << 0), 110 }; 111 112 /* 113 * Starts an ODB transaction and returns it via `out`. Subsequent objects are 114 * written to the transaction and not committed until odb_transaction_commit() 115 * is invoked on the transaction. Returns 0 on success and a negative value on 116 * error. Note that it is considered an error to start a new transaction if the 117 * ODB already has an inflight transaction pending. 118 */ 119 int odb_transaction_begin(struct object_database *odb, 120 struct odb_transaction **out, 121 enum odb_transaction_flags flags); 122 123 static inline void odb_transaction_begin_or_die(struct object_database *odb, 124 struct odb_transaction **out, 125 enum odb_transaction_flags flags) 126 { 127 if (odb_transaction_begin(odb, out, flags)) 128 die(_("failed to start ODB transaction")); 129 } 130 131 /* 132 * Commits an ODB transaction making the written objects visible. Returns 0 on 133 * success, a negative error code otherwise. Note that, if the specified 134 * transaction is NULL, the function is a no-op and no error is returned. 135 */ 136 int odb_transaction_commit(struct odb_transaction *transaction); 137 138 /* 139 * Finalizes an ODB transaction, performing any deferred cleanup and freeing it. 140 * Must be called for every successfully started transaction. Note that, if the 141 * specified transaction is NULL, the function is a no-op. Returns 0 on success, 142 * a negative error code otherwise. 143 */ 144 int odb_transaction_finalize(struct odb_transaction *transaction); 145 146 static inline void odb_transaction_commit_and_finalize_or_die(struct odb_transaction *transaction) 147 { 148 if (odb_transaction_commit(transaction)) 149 die(_("failed to commit ODB transaction")); 150 if (odb_transaction_finalize(transaction)) 151 die(_("failed to finalize ODB transaction")); 152 } 153 154 /* 155 * Writes the object in the provided stream into the transaction. The resulting 156 * object ID is written into the out pointer. Returns 0 on success, a negative 157 * error code otherwise. 158 */ 159 int odb_transaction_write_object_stream(struct odb_transaction *transaction, 160 struct odb_stream *stream, 161 struct object_id *oid); 162 163 /* 164 * Ingests the packfile readable via `pack_fd` into the transaction. Returns 0 165 * on success, a negative error code otherwise. On failure, a human-readable 166 * description is appended to `err_msg`. 167 */ 168 int odb_transaction_write_pack(struct odb_transaction *transaction, int pack_fd, 169 struct strbuf *err_msg, 170 const struct odb_transaction_write_pack_opts *opts); 171 172 /* 173 * Populates the provided strvec with the environment variables that a child 174 * process should inherit so that its object writes participate in the 175 * transaction, suitable for using via child_process.env. Returns 0 on success, 176 * a negative error code otherwise. Note that, if the specified transaction is 177 * NULL, the function is a no-op and no error is returned. 178 */ 179 int odb_transaction_env(struct odb_transaction *transaction, struct strvec *env); 180 181 #endif