blob: 6ef88dcf45d6c5b2cd0f26397db2fc7b8859d581 [file] [log] [blame]
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -07001#ifndef COMMIT_H
2#define COMMIT_H
3
4#include "object.h"
5#include "tree.h"
Pierre Habouzit674d1722007-09-10 12:35:06 +02006#include "strbuf.h"
Linus Torvaldsca135e72007-04-16 16:05:10 -07007#include "decorate.h"
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -07008
9struct commit_list {
10 struct commit *item;
11 struct commit_list *next;
12};
13
14struct commit {
15 struct object object;
Linus Torvaldsd3ff6f52006-06-17 18:26:18 -070016 void *util;
Linus Torvalds23c17d42007-11-02 13:32:58 -070017 unsigned int indegree;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070018 unsigned long date;
19 struct commit_list *parents;
20 struct tree *tree;
Linus Torvaldsbd1e17e2005-05-25 19:26:28 -070021 char *buffer;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070022};
23
Linus Torvalds60ab26d2005-09-15 14:43:17 -070024extern int save_commit_buffer;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070025extern const char *commit_type;
26
Linus Torvaldsca135e72007-04-16 16:05:10 -070027/* While we can decorate any object with a name, it's only used for commits.. */
28extern struct decoration name_decoration;
29struct name_decoration {
30 struct name_decoration *next;
31 char name[1];
32};
33
Jason McMullan5d6ccf52005-06-03 11:05:39 -040034struct commit *lookup_commit(const unsigned char *sha1);
35struct commit *lookup_commit_reference(const unsigned char *sha1);
Junio C Hamanof76412e2005-08-21 02:51:10 -070036struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
37 int quiet);
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070038
Nicolas Pitrebd2c39f2005-05-06 13:48:34 -040039int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
40
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070041int parse_commit(struct commit *item);
42
Linus Torvaldsac5155e2005-05-30 18:44:02 -070043struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
Miklos Vajna65319472008-06-27 18:21:55 +020044unsigned commit_list_count(const struct commit_list *l);
Linus Torvaldsf7554942005-07-06 09:31:17 -070045struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);
Daniel Barkalowdd97f852005-04-23 18:47:23 -070046
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070047void free_commit_list(struct commit_list *list);
48
Daniel Barkalowdd97f852005-04-23 18:47:23 -070049void sort_by_date(struct commit_list **list);
50
Linus Torvalds000182e2005-06-05 09:02:03 -070051/* Commit formats */
52enum cmit_fmt {
53 CMIT_FMT_RAW,
54 CMIT_FMT_MEDIUM,
55 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
Linus Torvalds9b66ec02005-06-26 17:50:46 -070056 CMIT_FMT_SHORT,
57 CMIT_FMT_FULL,
Junio C Hamanoff56fe12005-11-09 22:15:27 -080058 CMIT_FMT_FULLER,
Junio C Hamanod87449c2005-08-08 22:15:40 -070059 CMIT_FMT_ONELINE,
Junio C Hamano3eefc182006-04-18 16:45:27 -070060 CMIT_FMT_EMAIL,
Johannes Schindeline52a5de2007-02-23 01:35:03 +010061 CMIT_FMT_USERFORMAT,
Junio C Hamano6b9c58f2006-04-15 23:46:36 -070062
63 CMIT_FMT_UNSPECIFIED,
Linus Torvalds000182e2005-06-05 09:02:03 -070064};
65
Thomas Rastdd2e7942009-10-19 17:48:08 +020066struct pretty_print_context
67{
68 int abbrev;
69 const char *subject;
70 const char *after_subject;
71 enum date_mode date_mode;
72 int need_8bit_cte;
Junio C Hamano66b2ed02010-01-20 13:59:36 -080073 int show_notes;
Thomas Rast8f8f5472009-10-19 17:48:10 +020074 struct reflog_walk_info *reflog_info;
Thomas Rastdd2e7942009-10-19 17:48:08 +020075};
76
Johannes Gilger5b163602010-04-13 22:31:12 +020077struct userformat_want {
78 unsigned notes:1;
79};
80
Johannes Schindelin28e9cf62009-08-10 18:22:18 +020081extern int has_non_ascii(const char *text);
Junio C Hamano4da45be2008-04-07 17:11:34 -070082struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
Alexander Gavrilov69cd8f62008-10-22 00:55:57 +040083extern char *reencode_commit_message(const struct commit *commit,
84 const char **encoding_p);
Junio C Hamano4da45be2008-04-07 17:11:34 -070085extern void get_commit_format(const char *arg, struct rev_info *);
Johannes Gilger5b163602010-04-13 22:31:12 +020086extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
Pierre Habouzit674d1722007-09-10 12:35:06 +020087extern void format_commit_message(const struct commit *commit,
Junio C Hamano7f98ebc2009-10-15 22:59:41 -070088 const char *format, struct strbuf *sb,
Thomas Rastdd2e7942009-10-19 17:48:08 +020089 const struct pretty_print_context *context);
90extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
91 struct strbuf *sb,
92 const struct pretty_print_context *context);
Daniel Barkalowb02bd652008-02-18 22:56:08 -050093void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
94 const char *line, enum date_mode dmode,
95 const char *encoding);
96void pp_title_line(enum cmit_fmt fmt,
97 const char **msg_p,
98 struct strbuf *sb,
99 const char *subject,
100 const char *after_subject,
101 const char *encoding,
Junio C Hamano267123b2008-03-15 00:09:20 -0700102 int need_8bit_cte);
Daniel Barkalowb02bd652008-02-18 22:56:08 -0500103void pp_remainder(enum cmit_fmt fmt,
104 const char **msg_p,
105 struct strbuf *sb,
106 int indent);
107
Linus Torvaldse3bc7a32005-06-01 08:34:23 -0700108
Daniel Barkalowdd97f852005-04-23 18:47:23 -0700109/** Removes the first commit from a list sorted by date, and adds all
110 * of its parents.
111 **/
Junio C Hamanoa6080a02007-06-07 00:04:01 -0700112struct commit *pop_most_recent_commit(struct commit_list **list,
Daniel Barkalow58e28af2005-04-23 20:29:22 -0700113 unsigned int mark);
Daniel Barkalowdd97f852005-04-23 18:47:23 -0700114
jon@blackcubes.dyndns.orga3437b82005-06-06 15:39:40 +0000115struct commit *pop_commit(struct commit_list **stack);
116
Junio C Hamanof8f9c732006-01-07 18:52:42 -0800117void clear_commit_marks(struct commit *commit, unsigned int mark);
118
Jon Seymourab580ac2005-07-07 02:39:34 +1000119/*
120 * Performs an in-place topological sort of list supplied.
121 *
Jon Seymourab580ac2005-07-07 02:39:34 +1000122 * invariant of resulting list is:
123 * a reachable from b => ord(b) < ord(a)
Junio C Hamano4c8725f2006-02-15 22:05:33 -0800124 * in addition, when lifo == 0, commits on parallel tracks are
125 * sorted in the dates order.
Jon Seymourab580ac2005-07-07 02:39:34 +1000126 */
Junio C Hamano4c8725f2006-02-15 22:05:33 -0800127void sort_in_topological_order(struct commit_list ** list, int lifo);
Junio C Hamano5040f172006-04-06 23:58:51 -0700128
129struct commit_graft {
130 unsigned char sha1[20];
Johannes Schindelined09aef2006-10-30 20:09:06 +0100131 int nr_parent; /* < 0 if shallow commit */
Junio C Hamano5040f172006-04-06 23:58:51 -0700132 unsigned char parent[FLEX_ARRAY][20]; /* more */
133};
134
135struct commit_graft *read_graft_line(char *buf, int len);
136int register_commit_graft(struct commit_graft *, int);
Martin Koegler45163382008-02-25 22:46:07 +0100137struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
Junio C Hamano5040f172006-04-06 23:58:51 -0700138
Christian Couder68095572009-01-23 10:06:53 +0100139const unsigned char *lookup_replace_object(const unsigned char *sha1);
140
Rene Scharfec0fa8252006-07-02 11:49:38 +0200141extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
Christian Couder53eda892008-07-30 07:04:14 +0200142extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
Miklos Vajna5240c9d2008-06-27 18:22:00 +0200143extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
Johannes Schindelin7c6f8aa2006-06-29 15:17:32 +0200144
Johannes Schindelined09aef2006-10-30 20:09:06 +0100145extern int register_shallow(const unsigned char *sha1);
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100146extern int unregister_shallow(const unsigned char *sha1);
Shawn O. Pearceedace6f2009-10-30 17:47:23 -0700147extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
Junio C Hamanof43117a2007-01-21 22:22:23 -0800148extern int is_repository_shallow(void);
Johannes Schindelined09aef2006-10-30 20:09:06 +0100149extern struct commit_list *get_shallow_commits(struct object_array *heads,
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100150 int depth, int shallow_flag, int not_shallow_flag);
Johannes Schindelined09aef2006-10-30 20:09:06 +0100151
Jake Goulding7fcdb362009-01-26 09:13:24 -0500152int is_descendant_of(struct commit *, struct commit_list *);
Junio C Hamano03840fc2007-01-08 23:22:31 -0800153int in_merge_bases(struct commit *, struct commit **, int);
Kristian Høgsberg58680162007-09-17 20:06:44 -0400154
Junio C Hamano3f061882007-11-25 10:10:10 -0800155extern int interactive_add(int argc, const char **argv, const char *prefix);
Thomas Rast46b51392009-08-13 14:29:41 +0200156extern int run_add_interactive(const char *revision, const char *patch_mode,
157 const char **pathspec);
Kristian Høgsberg58680162007-09-17 20:06:44 -0400158
Linus Torvalds53b2c822007-11-05 13:22:34 -0800159static inline int single_parent(struct commit *commit)
160{
161 return commit->parents && !commit->parents->next;
162}
163
Junio C Hamano98cf9c32008-06-27 18:22:03 +0200164struct commit_list *reduce_heads(struct commit_list *heads);
165
Jeff King40d52ff2010-04-01 20:05:23 -0400166extern int commit_tree(const char *msg, unsigned char *tree,
167 struct commit_list *parents, unsigned char *ret,
168 const char *author);
169
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -0700170#endif /* COMMIT_H */