| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 1 | #ifndef COMMIT_H |
| 2 | #define COMMIT_H |
| 3 | |
| 4 | #include "object.h" |
| 5 | #include "tree.h" |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 6 | #include "strbuf.h" |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 7 | #include "decorate.h" |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 8 | |
| 9 | struct commit_list { |
| 10 | struct commit *item; |
| 11 | struct commit_list *next; |
| 12 | }; |
| 13 | |
| 14 | struct commit { |
| 15 | struct object object; |
| Linus Torvalds | d3ff6f5 | 2006-06-18 01:26:18 | [diff] [blame] | 16 | void *util; |
| Linus Torvalds | 23c17d4 | 2007-11-02 20:32:58 | [diff] [blame] | 17 | unsigned int indegree; |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 18 | unsigned long date; |
| 19 | struct commit_list *parents; |
| 20 | struct tree *tree; |
| Linus Torvalds | bd1e17e | 2005-05-26 02:26:28 | [diff] [blame] | 21 | char *buffer; |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 22 | }; |
| 23 | |
| Linus Torvalds | 60ab26d | 2005-09-15 21:43:17 | [diff] [blame] | 24 | extern int save_commit_buffer; |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 25 | extern const char *commit_type; |
| 26 | |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 27 | /* While we can decorate any object with a name, it's only used for commits.. */ |
| 28 | extern struct decoration name_decoration; |
| 29 | struct name_decoration { |
| 30 | struct name_decoration *next; |
| Nazri Ramliy | eb3005e | 2010-06-19 01:37:33 | [diff] [blame] | 31 | int type; |
| Linus Torvalds | ca135e7 | 2007-04-16 23:05:10 | [diff] [blame] | 32 | char name[1]; |
| 33 | }; |
| 34 | |
| Jason McMullan | 5d6ccf5 | 2005-06-03 15:05:39 | [diff] [blame] | 35 | struct commit *lookup_commit(const unsigned char *sha1); |
| 36 | struct commit *lookup_commit_reference(const unsigned char *sha1); |
| Junio C Hamano | f76412e | 2005-08-21 09:51:10 | [diff] [blame] | 37 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, |
| 38 | int quiet); |
| Pat Notz | a6fa599 | 2010-11-02 19:59:07 | [diff] [blame] | 39 | struct commit *lookup_commit_reference_by_name(const char *name); |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 40 | |
| Nguyễn Thái Ngọc Duy | cf7b1ca | 2011-02-05 10:52:20 | [diff] [blame] | 41 | int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size); |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 42 | int parse_commit(struct commit *item); |
| 43 | |
| Christian Couder | 11af2aa | 2010-07-22 13:18:30 | [diff] [blame] | 44 | /* Find beginning and length of commit subject. */ |
| 45 | int find_commit_subject(const char *commit_buffer, const char **subject); |
| 46 | |
| Thiago Farina | 47e44ed | 2010-11-27 01:58:14 | [diff] [blame] | 47 | struct commit_list *commit_list_insert(struct commit *item, |
| 48 | struct commit_list **list); |
| Miklos Vajna | 6531947 | 2008-06-27 16:21:55 | [diff] [blame] | 49 | unsigned commit_list_count(const struct commit_list *l); |
| Thiago Farina | 47e44ed | 2010-11-27 01:58:14 | [diff] [blame] | 50 | struct commit_list *commit_list_insert_by_date(struct commit *item, |
| 51 | struct commit_list **list); |
| 52 | void commit_list_sort_by_date(struct commit_list **list); |
| Daniel Barkalow | dd97f85 | 2005-04-24 01:47:23 | [diff] [blame] | 53 | |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 54 | void free_commit_list(struct commit_list *list); |
| 55 | |
| Linus Torvalds | 000182e | 2005-06-05 16:02:03 | [diff] [blame] | 56 | /* Commit formats */ |
| 57 | enum cmit_fmt { |
| 58 | CMIT_FMT_RAW, |
| 59 | CMIT_FMT_MEDIUM, |
| 60 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, |
| Linus Torvalds | 9b66ec0 | 2005-06-27 00:50:46 | [diff] [blame] | 61 | CMIT_FMT_SHORT, |
| 62 | CMIT_FMT_FULL, |
| Junio C Hamano | ff56fe1 | 2005-11-10 06:15:27 | [diff] [blame] | 63 | CMIT_FMT_FULLER, |
| Junio C Hamano | d87449c | 2005-08-09 05:15:40 | [diff] [blame] | 64 | CMIT_FMT_ONELINE, |
| Junio C Hamano | 3eefc18 | 2006-04-18 23:45:27 | [diff] [blame] | 65 | CMIT_FMT_EMAIL, |
| Johannes Schindelin | e52a5de | 2007-02-23 00:35:03 | [diff] [blame] | 66 | CMIT_FMT_USERFORMAT, |
| Junio C Hamano | 6b9c58f | 2006-04-16 06:46:36 | [diff] [blame] | 67 | |
| Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 | [diff] [blame] | 68 | CMIT_FMT_UNSPECIFIED |
| Linus Torvalds | 000182e | 2005-06-05 16:02:03 | [diff] [blame] | 69 | }; |
| 70 | |
| Jonathan Nieder | 9cba13c | 2011-03-16 07:08:34 | [diff] [blame] | 71 | struct pretty_print_context { |
| Jeff King | 6bf1394 | 2011-05-26 22:27:49 | [diff] [blame] | 72 | enum cmit_fmt fmt; |
| Thomas Rast | dd2e794 | 2009-10-19 15:48:08 | [diff] [blame] | 73 | int abbrev; |
| 74 | const char *subject; |
| 75 | const char *after_subject; |
| Jeff King | 9553d2b | 2011-05-26 22:28:17 | [diff] [blame] | 76 | int preserve_subject; |
| Thomas Rast | dd2e794 | 2009-10-19 15:48:08 | [diff] [blame] | 77 | enum date_mode date_mode; |
| 78 | int need_8bit_cte; |
| Junio C Hamano | 66b2ed0 | 2010-01-20 21:59:36 | [diff] [blame] | 79 | int show_notes; |
| Thomas Rast | 8f8f547 | 2009-10-19 15:48:10 | [diff] [blame] | 80 | struct reflog_walk_info *reflog_info; |
| Pat Notz | 177b29d | 2010-11-02 19:59:08 | [diff] [blame] | 81 | const char *output_encoding; |
| Thomas Rast | dd2e794 | 2009-10-19 15:48:08 | [diff] [blame] | 82 | }; |
| 83 | |
| Johannes Gilger | 5b16360 | 2010-04-13 20:31:12 | [diff] [blame] | 84 | struct userformat_want { |
| 85 | unsigned notes:1; |
| 86 | }; |
| 87 | |
| Johannes Schindelin | 28e9cf6 | 2009-08-10 16:22:18 | [diff] [blame] | 88 | extern int has_non_ascii(const char *text); |
| Junio C Hamano | 4da45be | 2008-04-08 00:11:34 | [diff] [blame] | 89 | struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ |
| Pat Notz | 177b29d | 2010-11-02 19:59:08 | [diff] [blame] | 90 | extern char *logmsg_reencode(const struct commit *commit, |
| 91 | const char *output_encoding); |
| Alexander Gavrilov | 69cd8f6 | 2008-10-21 20:55:57 | [diff] [blame] | 92 | extern char *reencode_commit_message(const struct commit *commit, |
| 93 | const char **encoding_p); |
| Junio C Hamano | 4da45be | 2008-04-08 00:11:34 | [diff] [blame] | 94 | extern void get_commit_format(const char *arg, struct rev_info *); |
| Ramsay Jones | c8f1444 | 2011-04-07 18:26:23 | [diff] [blame] | 95 | extern const char *format_subject(struct strbuf *sb, const char *msg, |
| 96 | const char *line_separator); |
| Johannes Gilger | 5b16360 | 2010-04-13 20:31:12 | [diff] [blame] | 97 | extern void userformat_find_requirements(const char *fmt, struct userformat_want *w); |
| Pierre Habouzit | 674d172 | 2007-09-10 10:35:06 | [diff] [blame] | 98 | extern void format_commit_message(const struct commit *commit, |
| Junio C Hamano | 7f98ebc | 2009-10-16 05:59:41 | [diff] [blame] | 99 | const char *format, struct strbuf *sb, |
| Thomas Rast | dd2e794 | 2009-10-19 15:48:08 | [diff] [blame] | 100 | const struct pretty_print_context *context); |
| Jeff King | 6bf1394 | 2011-05-26 22:27:49 | [diff] [blame] | 101 | extern void pretty_print_commit(const struct pretty_print_context *pp, |
| 102 | const struct commit *commit, |
| 103 | struct strbuf *sb); |
| Jeff King | 8b8a537 | 2011-05-26 22:27:24 | [diff] [blame] | 104 | extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit, |
| 105 | struct strbuf *sb); |
| Jeff King | 6bf1394 | 2011-05-26 22:27:49 | [diff] [blame] | 106 | void pp_user_info(const struct pretty_print_context *pp, |
| 107 | const char *what, struct strbuf *sb, |
| 108 | const char *line, const char *encoding); |
| 109 | void pp_title_line(const struct pretty_print_context *pp, |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 110 | const char **msg_p, |
| 111 | struct strbuf *sb, |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 112 | const char *encoding, |
| Junio C Hamano | 267123b | 2008-03-15 07:09:20 | [diff] [blame] | 113 | int need_8bit_cte); |
| Jeff King | 6bf1394 | 2011-05-26 22:27:49 | [diff] [blame] | 114 | void pp_remainder(const struct pretty_print_context *pp, |
| Daniel Barkalow | b02bd65 | 2008-02-19 03:56:08 | [diff] [blame] | 115 | const char **msg_p, |
| 116 | struct strbuf *sb, |
| 117 | int indent); |
| 118 | |
| Linus Torvalds | e3bc7a3 | 2005-06-01 15:34:23 | [diff] [blame] | 119 | |
| Daniel Barkalow | dd97f85 | 2005-04-24 01:47:23 | [diff] [blame] | 120 | /** Removes the first commit from a list sorted by date, and adds all |
| 121 | * of its parents. |
| 122 | **/ |
| Junio C Hamano | a6080a0 | 2007-06-07 07:04:01 | [diff] [blame] | 123 | struct commit *pop_most_recent_commit(struct commit_list **list, |
| Daniel Barkalow | 58e28af | 2005-04-24 03:29:22 | [diff] [blame] | 124 | unsigned int mark); |
| Daniel Barkalow | dd97f85 | 2005-04-24 01:47:23 | [diff] [blame] | 125 | |
| jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 | [diff] [blame] | 126 | struct commit *pop_commit(struct commit_list **stack); |
| 127 | |
| Junio C Hamano | f8f9c73 | 2006-01-08 02:52:42 | [diff] [blame] | 128 | void clear_commit_marks(struct commit *commit, unsigned int mark); |
| 129 | |
| Jon Seymour | ab580ac | 2005-07-06 16:39:34 | [diff] [blame] | 130 | /* |
| 131 | * Performs an in-place topological sort of list supplied. |
| 132 | * |
| Jon Seymour | ab580ac | 2005-07-06 16:39:34 | [diff] [blame] | 133 | * invariant of resulting list is: |
| 134 | * a reachable from b => ord(b) < ord(a) |
| Junio C Hamano | 4c8725f | 2006-02-16 06:05:33 | [diff] [blame] | 135 | * in addition, when lifo == 0, commits on parallel tracks are |
| 136 | * sorted in the dates order. |
| Jon Seymour | ab580ac | 2005-07-06 16:39:34 | [diff] [blame] | 137 | */ |
| Junio C Hamano | 4c8725f | 2006-02-16 06:05:33 | [diff] [blame] | 138 | void sort_in_topological_order(struct commit_list ** list, int lifo); |
| Junio C Hamano | 5040f17 | 2006-04-07 06:58:51 | [diff] [blame] | 139 | |
| 140 | struct commit_graft { |
| 141 | unsigned char sha1[20]; |
| Johannes Schindelin | ed09aef | 2006-10-30 19:09:06 | [diff] [blame] | 142 | int nr_parent; /* < 0 if shallow commit */ |
| Junio C Hamano | 5040f17 | 2006-04-07 06:58:51 | [diff] [blame] | 143 | unsigned char parent[FLEX_ARRAY][20]; /* more */ |
| 144 | }; |
| Nguyễn Thái Ngọc Duy | 09d4664 | 2011-08-18 12:29:35 | [diff] [blame] | 145 | typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *); |
| Junio C Hamano | 5040f17 | 2006-04-07 06:58:51 | [diff] [blame] | 146 | |
| 147 | struct commit_graft *read_graft_line(char *buf, int len); |
| 148 | int register_commit_graft(struct commit_graft *, int); |
| Martin Koegler | 4516338 | 2008-02-25 21:46:07 | [diff] [blame] | 149 | struct commit_graft *lookup_commit_graft(const unsigned char *sha1); |
| Junio C Hamano | 5040f17 | 2006-04-07 06:58:51 | [diff] [blame] | 150 | |
| Rene Scharfe | c0fa825 | 2006-07-02 09:49:38 | [diff] [blame] | 151 | extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup); |
| Christian Couder | 53eda89 | 2008-07-30 05:04:14 | [diff] [blame] | 152 | extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup); |
| Miklos Vajna | 5240c9d | 2008-06-27 16:22:00 | [diff] [blame] | 153 | extern struct commit_list *get_octopus_merge_bases(struct commit_list *in); |
| Johannes Schindelin | 7c6f8aa | 2006-06-29 13:17:32 | [diff] [blame] | 154 | |
| Johannes Schindelin | ed09aef | 2006-10-30 19:09:06 | [diff] [blame] | 155 | extern int register_shallow(const unsigned char *sha1); |
| Johannes Schindelin | f53514b | 2006-10-30 19:09:53 | [diff] [blame] | 156 | extern int unregister_shallow(const unsigned char *sha1); |
| Nguyễn Thái Ngọc Duy | 09d4664 | 2011-08-18 12:29:35 | [diff] [blame] | 157 | extern int for_each_commit_graft(each_commit_graft_fn, void *); |
| Junio C Hamano | f43117a | 2007-01-22 06:22:23 | [diff] [blame] | 158 | extern int is_repository_shallow(void); |
| Johannes Schindelin | ed09aef | 2006-10-30 19:09:06 | [diff] [blame] | 159 | extern struct commit_list *get_shallow_commits(struct object_array *heads, |
| Johannes Schindelin | f53514b | 2006-10-30 19:09:53 | [diff] [blame] | 160 | int depth, int shallow_flag, int not_shallow_flag); |
| Johannes Schindelin | ed09aef | 2006-10-30 19:09:06 | [diff] [blame] | 161 | |
| Jake Goulding | 7fcdb36 | 2009-01-26 14:13:24 | [diff] [blame] | 162 | int is_descendant_of(struct commit *, struct commit_list *); |
| Junio C Hamano | 03840fc | 2007-01-09 07:22:31 | [diff] [blame] | 163 | int in_merge_bases(struct commit *, struct commit **, int); |
| Kristian Høgsberg | 5868016 | 2007-09-18 00:06:44 | [diff] [blame] | 164 | |
| Conrad Irwin | b4bd466 | 2011-05-07 17:58:07 | [diff] [blame] | 165 | extern int interactive_add(int argc, const char **argv, const char *prefix, int patch); |
| Thomas Rast | 46b5139 | 2009-08-13 12:29:41 | [diff] [blame] | 166 | extern int run_add_interactive(const char *revision, const char *patch_mode, |
| 167 | const char **pathspec); |
| Kristian Høgsberg | 5868016 | 2007-09-18 00:06:44 | [diff] [blame] | 168 | |
| Linus Torvalds | 53b2c82 | 2007-11-05 21:22:34 | [diff] [blame] | 169 | static inline int single_parent(struct commit *commit) |
| 170 | { |
| 171 | return commit->parents && !commit->parents->next; |
| 172 | } |
| 173 | |
| Junio C Hamano | 98cf9c3 | 2008-06-27 16:22:03 | [diff] [blame] | 174 | struct commit_list *reduce_heads(struct commit_list *heads); |
| 175 | |
| Jeff King | 40d52ff | 2010-04-02 00:05:23 | [diff] [blame] | 176 | extern int commit_tree(const char *msg, unsigned char *tree, |
| 177 | struct commit_list *parents, unsigned char *ret, |
| 178 | const char *author); |
| 179 | |
| Daniel Barkalow | 6eb8ae0 | 2005-04-18 18:39:48 | [diff] [blame] | 180 | #endif /* COMMIT_H */ |