Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [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 12:35:06 +0200 | [diff] [blame] | 6 | #include "strbuf.h" |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [diff] [blame] | 7 | #include "decorate.h" |
Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [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-17 18:26:18 -0700 | [diff] [blame] | 16 | void *util; |
Linus Torvalds | 23c17d4 | 2007-11-02 13:32:58 -0700 | [diff] [blame] | 17 | unsigned int indegree; |
Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 18 | unsigned long date; |
| 19 | struct commit_list *parents; |
| 20 | struct tree *tree; |
Linus Torvalds | bd1e17e | 2005-05-25 19:26:28 -0700 | [diff] [blame] | 21 | char *buffer; |
Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Linus Torvalds | 60ab26d | 2005-09-15 14:43:17 -0700 | [diff] [blame] | 24 | extern int save_commit_buffer; |
Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 25 | extern const char *commit_type; |
| 26 | |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [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; |
| 31 | char name[1]; |
| 32 | }; |
| 33 | |
Jason McMullan | 5d6ccf5 | 2005-06-03 11:05:39 -0400 | [diff] [blame] | 34 | struct commit *lookup_commit(const unsigned char *sha1); |
| 35 | struct commit *lookup_commit_reference(const unsigned char *sha1); |
Junio C Hamano | f76412e | 2005-08-21 02:51:10 -0700 | [diff] [blame] | 36 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, |
| 37 | int quiet); |
Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 38 | |
Nicolas Pitre | bd2c39f | 2005-05-06 13:48:34 -0400 | [diff] [blame] | 39 | int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); |
| 40 | |
Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 41 | int parse_commit(struct commit *item); |
| 42 | |
Linus Torvalds | ac5155e | 2005-05-30 18:44:02 -0700 | [diff] [blame] | 43 | struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); |
Miklos Vajna | 6531947 | 2008-06-27 18:21:55 +0200 | [diff] [blame] | 44 | unsigned commit_list_count(const struct commit_list *l); |
Linus Torvalds | f755494 | 2005-07-06 09:31:17 -0700 | [diff] [blame] | 45 | struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); |
Daniel Barkalow | dd97f85 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 46 | |
Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 47 | void free_commit_list(struct commit_list *list); |
| 48 | |
Daniel Barkalow | dd97f85 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 49 | void sort_by_date(struct commit_list **list); |
| 50 | |
Linus Torvalds | 000182e | 2005-06-05 09:02:03 -0700 | [diff] [blame] | 51 | /* Commit formats */ |
| 52 | enum cmit_fmt { |
| 53 | CMIT_FMT_RAW, |
| 54 | CMIT_FMT_MEDIUM, |
| 55 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, |
Linus Torvalds | 9b66ec0 | 2005-06-26 17:50:46 -0700 | [diff] [blame] | 56 | CMIT_FMT_SHORT, |
| 57 | CMIT_FMT_FULL, |
Junio C Hamano | ff56fe1 | 2005-11-09 22:15:27 -0800 | [diff] [blame] | 58 | CMIT_FMT_FULLER, |
Junio C Hamano | d87449c | 2005-08-08 22:15:40 -0700 | [diff] [blame] | 59 | CMIT_FMT_ONELINE, |
Junio C Hamano | 3eefc18 | 2006-04-18 16:45:27 -0700 | [diff] [blame] | 60 | CMIT_FMT_EMAIL, |
Johannes Schindelin | e52a5de | 2007-02-23 01:35:03 +0100 | [diff] [blame] | 61 | CMIT_FMT_USERFORMAT, |
Junio C Hamano | 6b9c58f | 2006-04-15 23:46:36 -0700 | [diff] [blame] | 62 | |
| 63 | CMIT_FMT_UNSPECIFIED, |
Linus Torvalds | 000182e | 2005-06-05 09:02:03 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Junio C Hamano | 4593fb8 | 2007-10-31 14:55:17 -0700 | [diff] [blame] | 66 | extern int non_ascii(int); |
Junio C Hamano | 4da45be | 2008-04-07 17:11:34 -0700 | [diff] [blame] | 67 | struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ |
Alexander Gavrilov | 69cd8f6 | 2008-10-22 00:55:57 +0400 | [diff] [blame] | 68 | extern char *reencode_commit_message(const struct commit *commit, |
| 69 | const char **encoding_p); |
Junio C Hamano | 4da45be | 2008-04-07 17:11:34 -0700 | [diff] [blame] | 70 | extern void get_commit_format(const char *arg, struct rev_info *); |
Pierre Habouzit | 674d172 | 2007-09-10 12:35:06 +0200 | [diff] [blame] | 71 | extern void format_commit_message(const struct commit *commit, |
Jeff King | d36f867 | 2008-08-28 20:54:59 -0400 | [diff] [blame] | 72 | const void *format, struct strbuf *sb, |
| 73 | enum date_mode dmode); |
Pierre Habouzit | 674d172 | 2007-09-10 12:35:06 +0200 | [diff] [blame] | 74 | extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*, |
| 75 | struct strbuf *, |
| 76 | int abbrev, const char *subject, |
Junio C Hamano | 4593fb8 | 2007-10-31 14:55:17 -0700 | [diff] [blame] | 77 | const char *after_subject, enum date_mode, |
Junio C Hamano | 6bf4f1b | 2008-03-14 17:10:09 -0700 | [diff] [blame] | 78 | int need_8bit_cte); |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 79 | void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb, |
| 80 | const char *line, enum date_mode dmode, |
| 81 | const char *encoding); |
| 82 | void pp_title_line(enum cmit_fmt fmt, |
| 83 | const char **msg_p, |
| 84 | struct strbuf *sb, |
| 85 | const char *subject, |
| 86 | const char *after_subject, |
| 87 | const char *encoding, |
Junio C Hamano | 267123b | 2008-03-15 00:09:20 -0700 | [diff] [blame] | 88 | int need_8bit_cte); |
Daniel Barkalow | b02bd65 | 2008-02-18 22:56:08 -0500 | [diff] [blame] | 89 | void pp_remainder(enum cmit_fmt fmt, |
| 90 | const char **msg_p, |
| 91 | struct strbuf *sb, |
| 92 | int indent); |
| 93 | |
Linus Torvalds | e3bc7a3 | 2005-06-01 08:34:23 -0700 | [diff] [blame] | 94 | |
Daniel Barkalow | dd97f85 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 95 | /** Removes the first commit from a list sorted by date, and adds all |
| 96 | * of its parents. |
| 97 | **/ |
Junio C Hamano | a6080a0 | 2007-06-07 00:04:01 -0700 | [diff] [blame] | 98 | struct commit *pop_most_recent_commit(struct commit_list **list, |
Daniel Barkalow | 58e28af | 2005-04-23 20:29:22 -0700 | [diff] [blame] | 99 | unsigned int mark); |
Daniel Barkalow | dd97f85 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 100 | |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 101 | struct commit *pop_commit(struct commit_list **stack); |
| 102 | |
Junio C Hamano | f8f9c73 | 2006-01-07 18:52:42 -0800 | [diff] [blame] | 103 | void clear_commit_marks(struct commit *commit, unsigned int mark); |
| 104 | |
Jon Seymour | ab580ac | 2005-07-07 02:39:34 +1000 | [diff] [blame] | 105 | /* |
| 106 | * Performs an in-place topological sort of list supplied. |
| 107 | * |
Jon Seymour | ab580ac | 2005-07-07 02:39:34 +1000 | [diff] [blame] | 108 | * invariant of resulting list is: |
| 109 | * a reachable from b => ord(b) < ord(a) |
Junio C Hamano | 4c8725f | 2006-02-15 22:05:33 -0800 | [diff] [blame] | 110 | * in addition, when lifo == 0, commits on parallel tracks are |
| 111 | * sorted in the dates order. |
Jon Seymour | ab580ac | 2005-07-07 02:39:34 +1000 | [diff] [blame] | 112 | */ |
Junio C Hamano | 4c8725f | 2006-02-15 22:05:33 -0800 | [diff] [blame] | 113 | void sort_in_topological_order(struct commit_list ** list, int lifo); |
Junio C Hamano | 5040f17 | 2006-04-06 23:58:51 -0700 | [diff] [blame] | 114 | |
| 115 | struct commit_graft { |
| 116 | unsigned char sha1[20]; |
Johannes Schindelin | ed09aef | 2006-10-30 20:09:06 +0100 | [diff] [blame] | 117 | int nr_parent; /* < 0 if shallow commit */ |
Junio C Hamano | 5040f17 | 2006-04-06 23:58:51 -0700 | [diff] [blame] | 118 | unsigned char parent[FLEX_ARRAY][20]; /* more */ |
| 119 | }; |
| 120 | |
| 121 | struct commit_graft *read_graft_line(char *buf, int len); |
| 122 | int register_commit_graft(struct commit_graft *, int); |
Martin Koegler | 4516338 | 2008-02-25 22:46:07 +0100 | [diff] [blame] | 123 | struct commit_graft *lookup_commit_graft(const unsigned char *sha1); |
Junio C Hamano | 5040f17 | 2006-04-06 23:58:51 -0700 | [diff] [blame] | 124 | |
Rene Scharfe | c0fa825 | 2006-07-02 11:49:38 +0200 | [diff] [blame] | 125 | extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup); |
Christian Couder | 53eda89 | 2008-07-30 07:04:14 +0200 | [diff] [blame] | 126 | extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup); |
Miklos Vajna | 5240c9d | 2008-06-27 18:22:00 +0200 | [diff] [blame] | 127 | extern struct commit_list *get_octopus_merge_bases(struct commit_list *in); |
Johannes Schindelin | 7c6f8aa | 2006-06-29 15:17:32 +0200 | [diff] [blame] | 128 | |
Johannes Schindelin | ed09aef | 2006-10-30 20:09:06 +0100 | [diff] [blame] | 129 | extern int register_shallow(const unsigned char *sha1); |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 130 | extern int unregister_shallow(const unsigned char *sha1); |
Johannes Schindelin | ed09aef | 2006-10-30 20:09:06 +0100 | [diff] [blame] | 131 | extern int write_shallow_commits(int fd, int use_pack_protocol); |
Junio C Hamano | f43117a | 2007-01-21 22:22:23 -0800 | [diff] [blame] | 132 | extern int is_repository_shallow(void); |
Johannes Schindelin | ed09aef | 2006-10-30 20:09:06 +0100 | [diff] [blame] | 133 | extern struct commit_list *get_shallow_commits(struct object_array *heads, |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 134 | int depth, int shallow_flag, int not_shallow_flag); |
Johannes Schindelin | ed09aef | 2006-10-30 20:09:06 +0100 | [diff] [blame] | 135 | |
Jake Goulding | 7fcdb36 | 2009-01-26 09:13:24 -0500 | [diff] [blame] | 136 | int is_descendant_of(struct commit *, struct commit_list *); |
Junio C Hamano | 03840fc | 2007-01-08 23:22:31 -0800 | [diff] [blame] | 137 | int in_merge_bases(struct commit *, struct commit **, int); |
Kristian Høgsberg | 5868016 | 2007-09-17 20:06:44 -0400 | [diff] [blame] | 138 | |
Junio C Hamano | 3f06188 | 2007-11-25 10:10:10 -0800 | [diff] [blame] | 139 | extern int interactive_add(int argc, const char **argv, const char *prefix); |
Kristian Høgsberg | 5868016 | 2007-09-17 20:06:44 -0400 | [diff] [blame] | 140 | |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 141 | static inline int single_parent(struct commit *commit) |
| 142 | { |
| 143 | return commit->parents && !commit->parents->next; |
| 144 | } |
| 145 | |
Junio C Hamano | 98cf9c3 | 2008-06-27 18:22:03 +0200 | [diff] [blame] | 146 | struct commit_list *reduce_heads(struct commit_list *heads); |
| 147 | |
Daniel Barkalow | 6eb8ae0 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 148 | #endif /* COMMIT_H */ |