| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 1 | #ifndef COMMIT_H |
| 2 | #define COMMIT_H |
| 3 | |
| 4 | #include "object.h" |
| Leon Michalak | 2b3ae04 | 2025-07-29 07:01:51 | [diff] [blame] | 5 | #include "add-interactive.h" |
| Elijah Newren | d4a4f92 | 2023-04-22 20:17:26 | [diff] [blame] | 6 | |
| 7 | struct signature_check; |
| 8 | struct strbuf; |
| 9 | struct tree; |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 10 | |
| Derrick Stolee | 177722b | 2018-04-10 12:56:05 | [diff] [blame] | 11 | #define COMMIT_NOT_FROM_GRAPH 0xFFFFFFFF |
| Abhishek Kumar | d7f9278 | 2021-01-16 18:11:13 | [diff] [blame] | 12 | #define GENERATION_NUMBER_INFINITY ((1ULL << 63) - 1) |
| 13 | #define GENERATION_NUMBER_V1_MAX 0x3FFFFFFF |
| Derrick Stolee | 83073cc | 2018-04-25 14:37:55 | [diff] [blame] | 14 | #define GENERATION_NUMBER_ZERO 0 |
| Abhishek Kumar | e8b6300 | 2021-01-16 18:11:15 | [diff] [blame] | 15 | #define GENERATION_NUMBER_V2_OFFSET_MAX ((1ULL << 31) - 1) |
| Derrick Stolee | 177722b | 2018-04-10 12:56:05 | [diff] [blame] | 16 | |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 17 | struct commit_list { |
| 18 | struct commit *item; |
| 19 | struct commit_list *next; |
| 20 | }; |
| 21 | |
| Nguyễn Thái Ngọc Duy | 9d2c970 | 2018-05-19 05:28:31 | [diff] [blame] | 22 | /* |
| 23 | * The size of this struct matters in full repo walk operations like |
| 24 | * 'git clone' or 'git gc'. Consider using commit-slab to attach data |
| 25 | * to a commit instead of adding new fields here. |
| 26 | */ |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 27 | struct commit { |
| 28 | struct object object; |
| Johannes Schindelin | dddbad7 | 2017-04-26 19:29:31 | [diff] [blame] | 29 | timestamp_t date; |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 30 | struct commit_list *parents; |
| Derrick Stolee | 7b8a21d | 2018-04-06 19:09:46 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * If the commit is loaded from the commit-graph file, then this |
| Nguyễn Thái Ngọc Duy | 301b8c7 | 2019-04-16 09:33:19 | [diff] [blame] | 34 | * member may be NULL. Only access it through repo_get_commit_tree() |
| Derrick Stolee | 7b8a21d | 2018-04-06 19:09:46 | [diff] [blame] | 35 | * or get_commit_tree_oid(). |
| 36 | */ |
| Derrick Stolee | 891435d | 2018-04-06 19:09:32 | [diff] [blame] | 37 | struct tree *maybe_tree; |
| Nguyễn Thái Ngọc Duy | 25f859f | 2018-05-11 17:20:54 | [diff] [blame] | 38 | unsigned int index; |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 39 | }; |
| 40 | |
| Linus Torvalds | 60ab26d | 2005-09-15 21:43:17 | [diff] [blame] | 41 | extern int save_commit_buffer; |
| Ævar Arnfjörð Bjarmason | ab62858 | 2021-08-23 10:44:02 | [diff] [blame] | 42 | extern int no_graft_file_deprecated_advice; |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 43 | extern const char *commit_type; |
| 44 | |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 45 | /* While we can decorate any object with a name, it's only used for commits.. */ |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 46 | struct name_decoration { |
| 47 | struct name_decoration *next; |
| Nazri Ramliy | eb3005e | 2010-06-19 01:37:33 | [diff] [blame] | 48 | int type; |
| Jeff King | 2e3dfb2 | 2014-08-26 10:24:20 | [diff] [blame] | 49 | char name[FLEX_ARRAY]; |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 50 | }; |
| 51 | |
| Jeff King | 662174d | 2014-08-26 10:23:36 | [diff] [blame] | 52 | enum decoration_type { |
| 53 | DECORATION_NONE = 0, |
| 54 | DECORATION_REF_LOCAL, |
| 55 | DECORATION_REF_REMOTE, |
| 56 | DECORATION_REF_TAG, |
| 57 | DECORATION_REF_STASH, |
| 58 | DECORATION_REF_HEAD, |
| 59 | DECORATION_GRAFTED, |
| 60 | }; |
| 61 | |
| 62 | void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); |
| Jeff King | 2608c24 | 2014-08-26 10:23:54 | [diff] [blame] | 63 | const struct name_decoration *get_name_decoration(const struct object *obj); |
| Jeff King | 662174d | 2014-08-26 10:23:36 | [diff] [blame] | 64 | |
| Phillip Wood | b8dbfd0 | 2022-10-17 13:17:40 | [diff] [blame] | 65 | /* |
| 66 | * Look up commit named by "oid" respecting replacement objects. |
| 67 | * Returns NULL if "oid" is not a commit or does not exist. |
| 68 | */ |
| 69 | struct commit *lookup_commit_object(struct repository *r, const struct object_id *oid); |
| 70 | |
| 71 | /* |
| 72 | * Look up commit named by "oid" without replacement objects or |
| 73 | * checking for object existence. Returns the requested commit if it |
| 74 | * is found in the object cache, NULL if "oid" is in the object cache |
| 75 | * but is not a commit and a newly allocated unparsed commit object if |
| 76 | * "oid" is not in the object cache. |
| 77 | */ |
| Stefan Beller | bacf168 | 2018-06-29 01:22:10 | [diff] [blame] | 78 | struct commit *lookup_commit(struct repository *r, const struct object_id *oid); |
| Stefan Beller | 1f6c72f | 2018-06-29 01:22:22 | [diff] [blame] | 79 | struct commit *lookup_commit_reference(struct repository *r, |
| 80 | const struct object_id *oid); |
| Stefan Beller | d9a05e7 | 2018-06-29 01:22:21 | [diff] [blame] | 81 | struct commit *lookup_commit_reference_gently(struct repository *r, |
| Stefan Beller | 21e1ee8 | 2018-06-29 01:21:57 | [diff] [blame] | 82 | const struct object_id *oid, |
| Junio C Hamano | f76412e | 2005-08-21 09:51:10 | [diff] [blame] | 83 | int quiet); |
| Pat Notz | a6fa599 | 2010-11-02 19:59:07 | [diff] [blame] | 84 | struct commit *lookup_commit_reference_by_name(const char *name); |
| Derrick Stolee | 69020d0 | 2024-08-14 10:31:28 | [diff] [blame] | 85 | struct commit *lookup_commit_reference_by_name_gently(const char *name, |
| 86 | int quiet); |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 87 | |
| Nguyễn Thái Ngọc Duy | baf18fc | 2011-09-17 11:57:45 | [diff] [blame] | 88 | /* |
| brian m. carlson | bc83266 | 2017-05-06 22:10:10 | [diff] [blame] | 89 | * Look up object named by "oid", dereference tag as necessary, |
| 90 | * get a commit and return it. If "oid" does not dereference to |
| Nguyễn Thái Ngọc Duy | baf18fc | 2011-09-17 11:57:45 | [diff] [blame] | 91 | * a commit, use ref_name to report an error and die. |
| 92 | */ |
| brian m. carlson | bc83266 | 2017-05-06 22:10:10 | [diff] [blame] | 93 | struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name); |
| Nguyễn Thái Ngọc Duy | baf18fc | 2011-09-17 11:57:45 | [diff] [blame] | 94 | |
| Stefan Beller | fd8030c | 2018-06-29 01:22:13 | [diff] [blame] | 95 | int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph); |
| Stefan Beller | 9e5252a | 2018-11-14 00:12:50 | [diff] [blame] | 96 | int repo_parse_commit_internal(struct repository *r, struct commit *item, |
| 97 | int quiet_on_missing, int use_commit_graph); |
| 98 | int repo_parse_commit_gently(struct repository *r, |
| 99 | struct commit *item, |
| 100 | int quiet_on_missing); |
| 101 | static inline int repo_parse_commit(struct repository *r, struct commit *item) |
| Jeff King | 9cc2b07 | 2015-06-01 09:56:26 | [diff] [blame] | 102 | { |
| Stefan Beller | 9e5252a | 2018-11-14 00:12:50 | [diff] [blame] | 103 | return repo_parse_commit_gently(r, item, 0); |
| Jeff King | 9cc2b07 | 2015-06-01 09:56:26 | [diff] [blame] | 104 | } |
| Ævar Arnfjörð Bjarmason | 43d3561 | 2019-03-25 12:08:33 | [diff] [blame] | 105 | |
| Derrick Stolee | c4cc083 | 2021-02-01 17:15:03 | [diff] [blame] | 106 | static inline int repo_parse_commit_no_graph(struct repository *r, |
| 107 | struct commit *commit) |
| Ævar Arnfjörð Bjarmason | 43d3561 | 2019-03-25 12:08:33 | [diff] [blame] | 108 | { |
| Derrick Stolee | c4cc083 | 2021-02-01 17:15:03 | [diff] [blame] | 109 | return repo_parse_commit_internal(r, commit, 0, 0); |
| Ævar Arnfjörð Bjarmason | 43d3561 | 2019-03-25 12:08:33 | [diff] [blame] | 110 | } |
| 111 | |
| Jeff King | 7059dcc | 2013-10-24 08:52:36 | [diff] [blame] | 112 | void parse_commit_or_die(struct commit *item); |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 113 | |
| Patrick Steinhardt | 0d1d22f | 2024-09-05 10:09:12 | [diff] [blame] | 114 | void unparse_commit(struct repository *r, const struct object_id *oid); |
| 115 | |
| Stefan Beller | 65ea9d4 | 2018-06-29 01:22:15 | [diff] [blame] | 116 | struct buffer_slab; |
| 117 | struct buffer_slab *allocate_commit_buffer_slab(void); |
| 118 | void free_commit_buffer_slab(struct buffer_slab *bs); |
| 119 | |
| Jeff King | 0fb370d | 2014-06-12 22:05:37 | [diff] [blame] | 120 | /* |
| Jeff King | 66c2827 | 2014-06-10 21:40:14 | [diff] [blame] | 121 | * Associate an object buffer with the commit. The ownership of the |
| 122 | * memory is handed over to the commit, and must be free()-able. |
| 123 | */ |
| Stefan Beller | 1a40fc4 | 2018-06-29 01:22:16 | [diff] [blame] | 124 | void set_commit_buffer(struct repository *r, struct commit *, void *buffer, unsigned long size); |
| Jeff King | 66c2827 | 2014-06-10 21:40:14 | [diff] [blame] | 125 | |
| 126 | /* |
| Jeff King | 152ff1c | 2014-06-10 21:40:39 | [diff] [blame] | 127 | * Get any cached object buffer associated with the commit. Returns NULL |
| 128 | * if none. The resulting memory should not be freed. |
| 129 | */ |
| Stefan Beller | 4ff7e5c | 2018-06-29 01:22:17 | [diff] [blame] | 130 | const void *get_cached_commit_buffer(struct repository *, const struct commit *, unsigned long *size); |
| Jeff King | 152ff1c | 2014-06-10 21:40:39 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Get the commit's object contents, either from cache or by reading the object |
| 134 | * from disk. The resulting memory should not be modified, and must be given |
| Ævar Arnfjörð Bjarmason | c7c33f5 | 2023-03-28 13:58:57 | [diff] [blame] | 135 | * to repo_unuse_commit_buffer when the caller is done. |
| Jeff King | 152ff1c | 2014-06-10 21:40:39 | [diff] [blame] | 136 | */ |
| Stefan Beller | 07de3fd | 2018-11-14 00:12:57 | [diff] [blame] | 137 | const void *repo_get_commit_buffer(struct repository *r, |
| 138 | const struct commit *, |
| 139 | unsigned long *size); |
| Jeff King | 152ff1c | 2014-06-10 21:40:39 | [diff] [blame] | 140 | |
| 141 | /* |
| Elijah Newren | 15beaaa | 2019-11-05 17:07:23 | [diff] [blame] | 142 | * Tell the commit subsystem that we are done with a particular commit buffer. |
| Jeff King | 152ff1c | 2014-06-10 21:40:39 | [diff] [blame] | 143 | * The commit and buffer should be the input and return value, respectively, |
| Ævar Arnfjörð Bjarmason | c7c33f5 | 2023-03-28 13:58:57 | [diff] [blame] | 144 | * from an earlier call to repo_get_commit_buffer. The buffer may or may not be |
| Jeff King | 152ff1c | 2014-06-10 21:40:39 | [diff] [blame] | 145 | * freed by this call; callers should not access the memory afterwards. |
| 146 | */ |
| Stefan Beller | 7031537 | 2018-11-14 00:12:58 | [diff] [blame] | 147 | void repo_unuse_commit_buffer(struct repository *r, |
| 148 | const struct commit *, |
| 149 | const void *buffer); |
| Jeff King | 152ff1c | 2014-06-10 21:40:39 | [diff] [blame] | 150 | |
| 151 | /* |
| Jeff King | 0fb370d | 2014-06-12 22:05:37 | [diff] [blame] | 152 | * Free any cached object buffer associated with the commit. |
| 153 | */ |
| Stefan Beller | 6a7895f | 2018-12-15 00:09:40 | [diff] [blame] | 154 | void free_commit_buffer(struct parsed_object_pool *pool, struct commit *); |
| Jeff King | 0fb370d | 2014-06-12 22:05:37 | [diff] [blame] | 155 | |
| Nguyễn Thái Ngọc Duy | 301b8c7 | 2019-04-16 09:33:19 | [diff] [blame] | 156 | struct tree *repo_get_commit_tree(struct repository *, const struct commit *); |
| Derrick Stolee | 5bb03de | 2018-04-06 19:09:34 | [diff] [blame] | 157 | struct object_id *get_commit_tree_oid(const struct commit *); |
| 158 | |
| Jeff King | 0fb370d | 2014-06-12 22:05:37 | [diff] [blame] | 159 | /* |
| Stefan Beller | 14ba97f | 2018-05-15 21:48:42 | [diff] [blame] | 160 | * Release memory related to a commit, including the parent list and |
| 161 | * any cached object buffer. |
| 162 | */ |
| Stefan Beller | 6a7895f | 2018-12-15 00:09:40 | [diff] [blame] | 163 | void release_commit_memory(struct parsed_object_pool *pool, struct commit *c); |
| Stefan Beller | 14ba97f | 2018-05-15 21:48:42 | [diff] [blame] | 164 | |
| 165 | /* |
| Jeff King | 0fb370d | 2014-06-12 22:05:37 | [diff] [blame] | 166 | * Disassociate any cached object buffer from the commit, but do not free it. |
| 167 | * The buffer (or NULL, if none) is returned. |
| 168 | */ |
| Jeff King | 8597ea3 | 2014-06-10 21:44:13 | [diff] [blame] | 169 | const void *detach_commit_buffer(struct commit *, unsigned long *sizep); |
| Jeff King | 0fb370d | 2014-06-12 22:05:37 | [diff] [blame] | 170 | |
| Christian Couder | 11af2aa | 2010-07-22 13:18:30 | [diff] [blame] | 171 | /* Find beginning and length of commit subject. */ |
| 172 | int find_commit_subject(const char *commit_buffer, const char **subject); |
| 173 | |
| Charvi Mendiratta | 6e0e288 | 2021-03-15 07:54:31 | [diff] [blame] | 174 | /* Return length of the commit subject from commit log message. */ |
| 175 | size_t commit_subject_length(const char *body); |
| 176 | |
| Thiago Farina | 47e44ed | 2010-11-27 01:58:14 | [diff] [blame] | 177 | struct commit_list *commit_list_insert(struct commit *item, |
| 178 | struct commit_list **list); |
| Derrick Stolee | 597b2c3 | 2020-12-08 22:04:13 | [diff] [blame] | 179 | int commit_list_contains(struct commit *item, |
| 180 | struct commit_list *list); |
| René Scharfe | 89b5f1d | 2012-04-25 20:35:27 | [diff] [blame] | 181 | struct commit_list **commit_list_append(struct commit *commit, |
| 182 | struct commit_list **next); |
| Miklos Vajna | 6531947 | 2008-06-27 16:21:55 | [diff] [blame] | 183 | unsigned commit_list_count(const struct commit_list *l); |
| Thiago Farina | 47e44ed | 2010-11-27 01:58:14 | [diff] [blame] | 184 | struct commit_list *commit_list_insert_by_date(struct commit *item, |
| 185 | struct commit_list **list); |
| 186 | void commit_list_sort_by_date(struct commit_list **list); |
| Daniel Barkalow | dd97f85 | 2005-04-24 01:47:23 | [diff] [blame] | 187 | |
| Thomas Rast | 53d00b3 | 2013-07-31 20:13:20 | [diff] [blame] | 188 | /* Shallow copy of the input list */ |
| Patrick Steinhardt | 44ec7c5 | 2024-06-11 09:21:11 | [diff] [blame] | 189 | struct commit_list *copy_commit_list(const struct commit_list *list); |
| Thomas Rast | 53d00b3 | 2013-07-31 20:13:20 | [diff] [blame] | 190 | |
| Elijah Newren | b0ca120 | 2020-12-16 22:27:59 | [diff] [blame] | 191 | /* Modify list in-place to reverse it, returning new head; list will be tail */ |
| 192 | struct commit_list *reverse_commit_list(struct commit_list *list); |
| 193 | |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 194 | void free_commit_list(struct commit_list *list); |
| 195 | |
| René Scharfe | 6d167fd | 2017-03-01 11:37:07 | [diff] [blame] | 196 | struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ |
| 197 | |
| Stefan Beller | 424510e | 2018-11-14 00:12:59 | [diff] [blame] | 198 | const char *repo_logmsg_reencode(struct repository *r, |
| 199 | const struct commit *commit, |
| 200 | char **commit_encoding, |
| 201 | const char *output_encoding); |
| Stefan Beller | 424510e | 2018-11-14 00:12:59 | [diff] [blame] | 202 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 203 | const char *skip_blank_lines(const char *msg); |
| Linus Torvalds | e3bc7a3 | 2005-06-01 15:34:23 | [diff] [blame] | 204 | |
| René Scharfe | d6ec087 | 2025-07-18 09:39:06 | [diff] [blame] | 205 | struct prio_queue; |
| 206 | |
| 207 | /* Removes the first commit from a prio_queue and adds its parents. */ |
| 208 | struct commit *pop_most_recent_commit(struct prio_queue *queue, |
| Daniel Barkalow | 58e28af | 2005-04-24 03:29:22 | [diff] [blame] | 209 | unsigned int mark); |
| Daniel Barkalow | dd97f85 | 2005-04-24 01:47:23 | [diff] [blame] | 210 | |
| jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 | [diff] [blame] | 211 | struct commit *pop_commit(struct commit_list **stack); |
| 212 | |
| Junio C Hamano | f8f9c73 | 2006-01-08 02:52:42 | [diff] [blame] | 213 | void clear_commit_marks(struct commit *commit, unsigned int mark); |
| Patrick Steinhardt | 85ee068 | 2024-12-27 10:46:25 | [diff] [blame] | 214 | void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark); |
| Junio C Hamano | f8f9c73 | 2006-01-08 02:52:42 | [diff] [blame] | 215 | |
| Junio C Hamano | 08f704f | 2013-06-06 23:07:14 | [diff] [blame] | 216 | |
| 217 | enum rev_sort_order { |
| 218 | REV_SORT_IN_GRAPH_ORDER = 0, |
| Junio C Hamano | 81c6b38 | 2013-06-07 17:35:54 | [diff] [blame] | 219 | REV_SORT_BY_COMMIT_DATE, |
| 220 | REV_SORT_BY_AUTHOR_DATE |
| Junio C Hamano | 08f704f | 2013-06-06 23:07:14 | [diff] [blame] | 221 | }; |
| 222 | |
| Jon Seymour | ab580ac | 2005-07-06 16:39:34 | [diff] [blame] | 223 | /* |
| 224 | * Performs an in-place topological sort of list supplied. |
| 225 | * |
| Jon Seymour | ab580ac | 2005-07-06 16:39:34 | [diff] [blame] | 226 | * invariant of resulting list is: |
| 227 | * a reachable from b => ord(b) < ord(a) |
| Junio C Hamano | 08f704f | 2013-06-06 23:07:14 | [diff] [blame] | 228 | * sort_order further specifies: |
| 229 | * REV_SORT_IN_GRAPH_ORDER: try to show a commit on a single-parent |
| 230 | * chain together. |
| 231 | * REV_SORT_BY_COMMIT_DATE: show eligible commits in committer-date order. |
| Jon Seymour | ab580ac | 2005-07-06 16:39:34 | [diff] [blame] | 232 | */ |
| Junio C Hamano | 08f704f | 2013-06-06 23:07:14 | [diff] [blame] | 233 | void sort_in_topological_order(struct commit_list **, enum rev_sort_order); |
| Junio C Hamano | 5040f17 | 2006-04-07 06:58:51 | [diff] [blame] | 234 | |
| 235 | struct commit_graft { |
| brian m. carlson | 7683e2e | 2015-03-13 23:39:34 | [diff] [blame] | 236 | struct object_id oid; |
| Johannes Schindelin | ed09aef | 2006-10-30 19:09:06 | [diff] [blame] | 237 | int nr_parent; /* < 0 if shallow commit */ |
| brian m. carlson | 7683e2e | 2015-03-13 23:39:34 | [diff] [blame] | 238 | struct object_id parent[FLEX_ARRAY]; /* more */ |
| Junio C Hamano | 5040f17 | 2006-04-07 06:58:51 | [diff] [blame] | 239 | }; |
| Nguyễn Thái Ngọc Duy | 09d4664 | 2011-08-18 12:29:35 | [diff] [blame] | 240 | typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *); |
| Junio C Hamano | 5040f17 | 2006-04-07 06:58:51 | [diff] [blame] | 241 | |
| Patryk Obara | 9a93403 | 2017-08-18 18:33:12 | [diff] [blame] | 242 | struct commit_graft *read_graft_line(struct strbuf *line); |
| Taylor Blau | 183df64 | 2020-04-30 21:11:28 | [diff] [blame] | 243 | /* commit_graft_pos returns an index into r->parsed_objects->grafts. */ |
| Jeff King | 98c431b | 2021-01-28 06:12:35 | [diff] [blame] | 244 | int commit_graft_pos(struct repository *r, const struct object_id *oid); |
| Brandon Williams | a3b78e8 | 2018-05-17 22:51:48 | [diff] [blame] | 245 | int register_commit_graft(struct repository *r, struct commit_graft *, int); |
| Derrick Stolee | 20fd6d5 | 2018-08-20 18:24:30 | [diff] [blame] | 246 | void prepare_commit_graft(struct repository *r); |
| Stefan Beller | b9dbddf | 2018-05-17 22:51:54 | [diff] [blame] | 247 | struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid); |
| Junio C Hamano | 5040f17 | 2006-04-07 06:58:51 | [diff] [blame] | 248 | |
| Pratik Karki | 103148a | 2018-09-04 22:00:08 | [diff] [blame] | 249 | struct commit *get_fork_point(const char *refname, struct commit *commit); |
| 250 | |
| Stefano Lattarini | 41ccfdd | 2013-04-11 22:36:10 | [diff] [blame] | 251 | /* largest positive number a signed 32-bit integer can contain */ |
| Nguyễn Thái Ngọc Duy | 4dcb167 | 2013-01-11 09:05:46 | [diff] [blame] | 252 | #define INFINITE_DEPTH 0x7fffffff |
| 253 | |
| brian m. carlson | 910650d | 2017-03-31 01:40:00 | [diff] [blame] | 254 | struct oid_array; |
| Nguyễn Thái Ngọc Duy | 58babff | 2013-12-05 13:02:35 | [diff] [blame] | 255 | struct ref; |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 256 | int for_each_commit_graft(each_commit_graft_fn, void *); |
| Johannes Schindelin | ed09aef | 2006-10-30 19:09:06 | [diff] [blame] | 257 | |
| John Cai | 8364745 | 2024-09-13 21:16:17 | [diff] [blame] | 258 | int interactive_add(struct repository *repo, |
| 259 | const char **argv, |
| 260 | const char *prefix, |
| Leon Michalak | 2b3ae04 | 2025-07-29 07:01:51 | [diff] [blame] | 261 | int patch, struct add_p_opt *add_p_opt); |
| Kristian Høgsberg | 5868016 | 2007-09-18 00:06:44 | [diff] [blame] | 262 | |
| Junio C Hamano | 5231c63 | 2011-11-08 00:21:32 | [diff] [blame] | 263 | struct commit_extra_header { |
| 264 | struct commit_extra_header *next; |
| 265 | char *key; |
| 266 | char *value; |
| 267 | size_t len; |
| 268 | }; |
| 269 | |
| Patrick Steinhardt | 63c9bd3 | 2024-06-11 09:20:42 | [diff] [blame] | 270 | void append_merge_tag_headers(const struct commit_list *parents, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 271 | struct commit_extra_header ***tail); |
| Junio C Hamano | 5231c63 | 2011-11-08 00:21:32 | [diff] [blame] | 272 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 273 | int commit_tree(const char *msg, size_t msg_len, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 274 | const struct object_id *tree, |
| Patrick Steinhardt | 63c9bd3 | 2024-06-11 09:20:42 | [diff] [blame] | 275 | const struct commit_list *parents, struct object_id *ret, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 276 | const char *author, const char *sign_commit); |
| Junio C Hamano | 5231c63 | 2011-11-08 00:21:32 | [diff] [blame] | 277 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 278 | int commit_tree_extended(const char *msg, size_t msg_len, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 279 | const struct object_id *tree, |
| Patrick Steinhardt | 63c9bd3 | 2024-06-11 09:20:42 | [diff] [blame] | 280 | const struct commit_list *parents, struct object_id *ret, |
| Phillip Wood | e8cbe21 | 2020-08-17 17:40:01 | [diff] [blame] | 281 | const char *author, const char *committer, |
| Patrick Steinhardt | 63c9bd3 | 2024-06-11 09:20:42 | [diff] [blame] | 282 | const char *sign_commit, const struct commit_extra_header *); |
| Junio C Hamano | 5231c63 | 2011-11-08 00:21:32 | [diff] [blame] | 283 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 284 | struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **); |
| Junio C Hamano | ed7a42a | 2011-11-08 23:38:07 | [diff] [blame] | 285 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 286 | void free_commit_extra_headers(struct commit_extra_header *extra); |
| Jeff King | 40d52ff | 2010-04-02 00:05:23 | [diff] [blame] | 287 | |
| Jeff King | fe6eb7f | 2014-08-27 07:56:01 | [diff] [blame] | 288 | /* |
| 289 | * Search the commit object contents given by "msg" for the header "key". |
| Jeff King | fe6eb7f | 2014-08-27 07:56:01 | [diff] [blame] | 290 | * Returns a pointer to the start of the header contents, or NULL. The length |
| 291 | * of the header, up to the first newline, is returned via out_len. |
| 292 | * |
| 293 | * Note that some headers (like mergetag) may be multi-line. It is the caller's |
| 294 | * responsibility to parse further in this case! |
| 295 | */ |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 296 | const char *find_commit_header(const char *msg, const char *key, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 297 | size_t *out_len); |
| Jeff King | fe6eb7f | 2014-08-27 07:56:01 | [diff] [blame] | 298 | |
| Linus Arver | 7cb26a1 | 2023-10-20 19:01:33 | [diff] [blame] | 299 | /* Find the number of bytes to ignore from the end of a log message. */ |
| 300 | size_t ignored_log_message_bytes(const char *buf, size_t len); |
| Christian Couder | 8c38458 | 2014-11-09 09:23:41 | [diff] [blame] | 301 | |
| Johannes Schindelin | fef461e | 2018-04-25 09:54:04 | [diff] [blame] | 302 | typedef int (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 303 | void *cb_data); |
| Christian Couder | 063da62 | 2014-07-07 06:35:37 | [diff] [blame] | 304 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 305 | int for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *data); |
| Christian Couder | 063da62 | 2014-07-07 06:35:37 | [diff] [blame] | 306 | |
| Junio C Hamano | ae8e4c9 | 2011-11-07 21:26:22 | [diff] [blame] | 307 | struct merge_remote_desc { |
| 308 | struct object *obj; /* the named object, could be a tag */ |
| René Scharfe | 5447a76 | 2016-08-13 12:21:27 | [diff] [blame] | 309 | char name[FLEX_ARRAY]; |
| Junio C Hamano | ae8e4c9 | 2011-11-07 21:26:22 | [diff] [blame] | 310 | }; |
| Patrick Steinhardt | 63c9bd3 | 2024-06-11 09:20:42 | [diff] [blame] | 311 | struct merge_remote_desc *merge_remote_util(const struct commit *); |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 312 | void set_merge_remote_desc(struct commit *commit, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 313 | const char *name, struct object *obj); |
| Junio C Hamano | ae8e4c9 | 2011-11-07 21:26:22 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * Given "name" from the command line to merge, find the commit object |
| 317 | * and return it, while storing merge_remote_desc in its ->util field, |
| 318 | * to allow callers to tell if we are told to merge a tag. |
| 319 | */ |
| 320 | struct commit *get_merge_parent(const char *name); |
| 321 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 322 | int parse_signed_commit(const struct commit *commit, |
| brian m. carlson | 1fb5cf0 | 2021-01-18 23:49:11 | [diff] [blame] | 323 | struct strbuf *message, struct strbuf *signature, |
| 324 | const struct git_hash_algo *algop); |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 325 | int remove_signature(struct strbuf *buf); |
| Christian Couder | 0b05ab6 | 2014-07-19 15:01:12 | [diff] [blame] | 326 | |
| Sebastian Götte | ffb6d7d | 2013-03-31 16:00:14 | [diff] [blame] | 327 | /* |
| Sebastian Götte | eb307ae | 2013-03-31 16:02:46 | [diff] [blame] | 328 | * Check the signature of the given commit. The result of the check is stored |
| 329 | * in sig->check_result, 'G' for a good signature, 'U' for a good signature |
| 330 | * from an untrusted signer, 'B' for a bad signature and 'N' for no signature |
| 331 | * at all. This may allocate memory for sig->gpg_output, sig->gpg_status, |
| 332 | * sig->signer and sig->key. |
| Sebastian Götte | ffb6d7d | 2013-03-31 16:00:14 | [diff] [blame] | 333 | */ |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 334 | int check_commit_signature(const struct commit *commit, struct signature_check *sigc); |
| Sebastian Götte | ffb6d7d | 2013-03-31 16:00:14 | [diff] [blame] | 335 | |
| Derrick Stolee | 5284fc5 | 2018-11-01 13:46:21 | [diff] [blame] | 336 | /* record author-date for each commit object */ |
| 337 | struct author_date_slab; |
| 338 | void record_author_date(struct author_date_slab *author_date, |
| 339 | struct commit *commit); |
| 340 | |
| 341 | int compare_commits_by_author_date(const void *a_, const void *b_, void *unused); |
| Junio C Hamano | 6d2035e | 2018-11-18 09:23:54 | [diff] [blame] | 342 | |
| Jeff King | edc4d47 | 2018-11-06 07:50:17 | [diff] [blame] | 343 | /* |
| 344 | * Verify a single commit with check_commit_signature() and die() if it is not |
| 345 | * a good signature. This isn't really suitable for general use, but is a |
| 346 | * helper to implement consistent logic for pull/merge --verify-signatures. |
| Hans Jerry Illikainen | 54887b4 | 2019-12-27 13:55:57 | [diff] [blame] | 347 | * |
| 348 | * The check_trust parameter is meant for backward-compatibility. The GPG |
| 349 | * interface verifies key trust with a default trust level that is below the |
| 350 | * default trust level for merge operations. Its value should be non-zero if |
| 351 | * the user hasn't set a minimum trust level explicitly in their configuration. |
| 352 | * |
| 353 | * If the user has set a minimum trust level, then that value should be obeyed |
| 354 | * and check_trust should be zero, even if the configured trust level is below |
| 355 | * the default trust level for merges. |
| Jeff King | edc4d47 | 2018-11-06 07:50:17 | [diff] [blame] | 356 | */ |
| Hans Jerry Illikainen | 54887b4 | 2019-12-27 13:55:57 | [diff] [blame] | 357 | void verify_merge_signature(struct commit *commit, int verbose, |
| 358 | int check_trust); |
| Jeff King | edc4d47 | 2018-11-06 07:50:17 | [diff] [blame] | 359 | |
| Jeff King | 727377f | 2013-07-02 06:21:48 | [diff] [blame] | 360 | int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused); |
| Derrick Stolee | 3afc679 | 2018-05-01 12:47:11 | [diff] [blame] | 361 | int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused); |
| Jeff King | 727377f | 2013-07-02 06:21:48 | [diff] [blame] | 362 | |
| Benoit Pierre | 15048f8 | 2014-03-18 10:00:53 | [diff] [blame] | 363 | LAST_ARG_MUST_BE_NULL |
| Ævar Arnfjörð Bjarmason | a8cc594 | 2022-03-07 12:33:46 | [diff] [blame] | 364 | int run_commit_hook(int editor_is_used, const char *index_file, |
| 365 | int *invoked_hook, const char *name, ...); |
| Benoit Pierre | 15048f8 | 2014-03-18 10:00:53 | [diff] [blame] | 366 | |
| brian m. carlson | 937032e | 2021-02-11 02:08:04 | [diff] [blame] | 367 | /* Sign a commit or tag buffer, storing the result in a header. */ |
| 368 | int sign_with_header(struct strbuf *buf, const char *keyid); |
| 369 | /* Parse the signature out of a header. */ |
| 370 | int parse_buffer_signed_by_header(const char *buffer, |
| 371 | unsigned long size, |
| 372 | struct strbuf *payload, |
| 373 | struct strbuf *signature, |
| 374 | const struct git_hash_algo *algop); |
| Eric W. Biederman | 6bcc5fa | 2023-10-02 02:40:15 | [diff] [blame] | 375 | int add_header_signature(struct strbuf *buf, struct strbuf *sig, const struct git_hash_algo *algo); |
| brian m. carlson | 937032e | 2021-02-11 02:08:04 | [diff] [blame] | 376 | |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 377 | #endif /* COMMIT_H */ |