blob: 67bd5091be0b34bfea075cd60281d22cf5b34768 [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"
Sebastian Götteffb6d7d2013-03-31 18:00:14 +02008#include "gpg-interface.h"
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -07009
10struct commit_list {
11 struct commit *item;
12 struct commit_list *next;
13};
14
15struct commit {
16 struct object object;
Linus Torvaldsd3ff6f52006-06-17 18:26:18 -070017 void *util;
Linus Torvalds23c17d42007-11-02 13:32:58 -070018 unsigned int indegree;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070019 unsigned long date;
20 struct commit_list *parents;
21 struct tree *tree;
Linus Torvaldsbd1e17e2005-05-25 19:26:28 -070022 char *buffer;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070023};
24
Linus Torvalds60ab26d2005-09-15 14:43:17 -070025extern int save_commit_buffer;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070026extern const char *commit_type;
27
Linus Torvaldsca135e72007-04-16 16:05:10 -070028/* While we can decorate any object with a name, it's only used for commits.. */
29extern struct decoration name_decoration;
30struct name_decoration {
31 struct name_decoration *next;
Nazri Ramliyeb3005e2010-06-19 09:37:33 +080032 int type;
Linus Torvaldsca135e72007-04-16 16:05:10 -070033 char name[1];
34};
35
Jason McMullan5d6ccf52005-06-03 11:05:39 -040036struct commit *lookup_commit(const unsigned char *sha1);
37struct commit *lookup_commit_reference(const unsigned char *sha1);
Junio C Hamanof76412e2005-08-21 02:51:10 -070038struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
39 int quiet);
Pat Notza6fa5992010-11-02 13:59:07 -060040struct commit *lookup_commit_reference_by_name(const char *name);
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070041
Nguyễn Thái Ngọc Duybaf18fc2011-09-17 21:57:45 +100042/*
43 * Look up object named by "sha1", dereference tag as necessary,
44 * get a commit and return it. If "sha1" does not dereference to
45 * a commit, use ref_name to report an error and die.
46 */
47struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name);
48
Nguyễn Thái Ngọc Duycf7b1ca2011-02-05 17:52:20 +070049int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070050int parse_commit(struct commit *item);
51
Christian Couder11af2aa2010-07-22 15:18:30 +020052/* Find beginning and length of commit subject. */
53int find_commit_subject(const char *commit_buffer, const char **subject);
54
Thiago Farina47e44ed2010-11-26 23:58:14 -020055struct commit_list *commit_list_insert(struct commit *item,
56 struct commit_list **list);
René Scharfe89b5f1d2012-04-25 22:35:27 +020057struct commit_list **commit_list_append(struct commit *commit,
58 struct commit_list **next);
Miklos Vajna65319472008-06-27 18:21:55 +020059unsigned commit_list_count(const struct commit_list *l);
Thiago Farina47e44ed2010-11-26 23:58:14 -020060struct commit_list *commit_list_insert_by_date(struct commit *item,
61 struct commit_list **list);
62void commit_list_sort_by_date(struct commit_list **list);
Daniel Barkalowdd97f852005-04-23 18:47:23 -070063
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070064void free_commit_list(struct commit_list *list);
65
Linus Torvalds000182e2005-06-05 09:02:03 -070066/* Commit formats */
67enum cmit_fmt {
68 CMIT_FMT_RAW,
69 CMIT_FMT_MEDIUM,
70 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
Linus Torvalds9b66ec02005-06-26 17:50:46 -070071 CMIT_FMT_SHORT,
72 CMIT_FMT_FULL,
Junio C Hamanoff56fe12005-11-09 22:15:27 -080073 CMIT_FMT_FULLER,
Junio C Hamanod87449c2005-08-08 22:15:40 -070074 CMIT_FMT_ONELINE,
Junio C Hamano3eefc182006-04-18 16:45:27 -070075 CMIT_FMT_EMAIL,
Johannes Schindeline52a5de2007-02-23 01:35:03 +010076 CMIT_FMT_USERFORMAT,
Junio C Hamano6b9c58f2006-04-15 23:46:36 -070077
Gary V. Vaughan4b055482010-05-14 09:31:35 +000078 CMIT_FMT_UNSPECIFIED
Linus Torvalds000182e2005-06-05 09:02:03 -070079};
80
Jonathan Nieder9cba13c2011-03-16 02:08:34 -050081struct pretty_print_context {
Jeff King6bf13942011-05-26 18:27:49 -040082 enum cmit_fmt fmt;
Thomas Rastdd2e7942009-10-19 17:48:08 +020083 int abbrev;
84 const char *subject;
85 const char *after_subject;
Jeff King9553d2b2011-05-26 18:28:17 -040086 int preserve_subject;
Thomas Rastdd2e7942009-10-19 17:48:08 +020087 enum date_mode date_mode;
Jeff Kingf026c752012-05-04 01:25:18 -040088 unsigned date_mode_explicit:1;
Thomas Rastdd2e7942009-10-19 17:48:08 +020089 int need_8bit_cte;
Junio C Hamanoddf333f2012-10-17 18:51:47 -070090 char *notes_message;
Thomas Rast8f8f5472009-10-19 17:48:10 +020091 struct reflog_walk_info *reflog_info;
Pat Notz177b29d2010-11-02 13:59:08 -060092 const char *output_encoding;
Antoine Pelisse0e2913b2013-01-05 22:26:41 +010093 struct string_list *mailmap;
Junio C Hamano30825172012-12-17 17:56:49 -050094 int color;
Thomas Rastdd2e7942009-10-19 17:48:08 +020095};
96
Johannes Gilger5b163602010-04-13 22:31:12 +020097struct userformat_want {
98 unsigned notes:1;
99};
100
Johannes Schindelin28e9cf62009-08-10 18:22:18 +0200101extern int has_non_ascii(const char *text);
Junio C Hamano4da45be2008-04-07 17:11:34 -0700102struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
Pat Notz177b29d2010-11-02 13:59:08 -0600103extern char *logmsg_reencode(const struct commit *commit,
Nguyễn Thái Ngọc Duy5a10d232013-04-19 09:08:40 +1000104 char **commit_encoding,
Pat Notz177b29d2010-11-02 13:59:08 -0600105 const char *output_encoding);
Jeff Kingdd0d3882013-01-26 04:44:06 -0500106extern void logmsg_free(char *msg, const struct commit *commit);
Junio C Hamano4da45be2008-04-07 17:11:34 -0700107extern void get_commit_format(const char *arg, struct rev_info *);
Ramsay Jonesc8f14442011-04-07 19:26:23 +0100108extern const char *format_subject(struct strbuf *sb, const char *msg,
109 const char *line_separator);
Johannes Gilger5b163602010-04-13 22:31:12 +0200110extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
Pierre Habouzit674d1722007-09-10 12:35:06 +0200111extern void format_commit_message(const struct commit *commit,
Junio C Hamano7f98ebc2009-10-15 22:59:41 -0700112 const char *format, struct strbuf *sb,
Thomas Rastdd2e7942009-10-19 17:48:08 +0200113 const struct pretty_print_context *context);
Jeff King6bf13942011-05-26 18:27:49 -0400114extern void pretty_print_commit(const struct pretty_print_context *pp,
115 const struct commit *commit,
116 struct strbuf *sb);
Jeff King8b8a5372011-05-26 18:27:24 -0400117extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
118 struct strbuf *sb);
Jeff King6bf13942011-05-26 18:27:49 -0400119void pp_user_info(const struct pretty_print_context *pp,
120 const char *what, struct strbuf *sb,
121 const char *line, const char *encoding);
122void pp_title_line(const struct pretty_print_context *pp,
Daniel Barkalowb02bd652008-02-18 22:56:08 -0500123 const char **msg_p,
124 struct strbuf *sb,
Daniel Barkalowb02bd652008-02-18 22:56:08 -0500125 const char *encoding,
Junio C Hamano267123b2008-03-15 00:09:20 -0700126 int need_8bit_cte);
Jeff King6bf13942011-05-26 18:27:49 -0400127void pp_remainder(const struct pretty_print_context *pp,
Daniel Barkalowb02bd652008-02-18 22:56:08 -0500128 const char **msg_p,
129 struct strbuf *sb,
130 int indent);
131
Linus Torvaldse3bc7a32005-06-01 08:34:23 -0700132
Daniel Barkalowdd97f852005-04-23 18:47:23 -0700133/** Removes the first commit from a list sorted by date, and adds all
134 * of its parents.
135 **/
Junio C Hamanoa6080a02007-06-07 00:04:01 -0700136struct commit *pop_most_recent_commit(struct commit_list **list,
Daniel Barkalow58e28af2005-04-23 20:29:22 -0700137 unsigned int mark);
Daniel Barkalowdd97f852005-04-23 18:47:23 -0700138
jon@blackcubes.dyndns.orga3437b82005-06-06 15:39:40 +0000139struct commit *pop_commit(struct commit_list **stack);
140
Junio C Hamanof8f9c732006-01-07 18:52:42 -0800141void clear_commit_marks(struct commit *commit, unsigned int mark);
Junio C Hamanoe895cb52013-03-05 11:42:20 -0800142void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
René Scharfe86a0a402011-10-01 18:16:08 +0200143void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark);
Junio C Hamanof8f9c732006-01-07 18:52:42 -0800144
Jon Seymourab580ac2005-07-07 02:39:34 +1000145/*
146 * Performs an in-place topological sort of list supplied.
147 *
Jon Seymourab580ac2005-07-07 02:39:34 +1000148 * invariant of resulting list is:
149 * a reachable from b => ord(b) < ord(a)
Junio C Hamano4c8725f2006-02-15 22:05:33 -0800150 * in addition, when lifo == 0, commits on parallel tracks are
151 * sorted in the dates order.
Jon Seymourab580ac2005-07-07 02:39:34 +1000152 */
Junio C Hamano4c8725f2006-02-15 22:05:33 -0800153void sort_in_topological_order(struct commit_list ** list, int lifo);
Junio C Hamano5040f172006-04-06 23:58:51 -0700154
155struct commit_graft {
156 unsigned char sha1[20];
Johannes Schindelined09aef2006-10-30 20:09:06 +0100157 int nr_parent; /* < 0 if shallow commit */
Junio C Hamano5040f172006-04-06 23:58:51 -0700158 unsigned char parent[FLEX_ARRAY][20]; /* more */
159};
Nguyễn Thái Ngọc Duy09d46642011-08-18 19:29:35 +0700160typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
Junio C Hamano5040f172006-04-06 23:58:51 -0700161
162struct commit_graft *read_graft_line(char *buf, int len);
163int register_commit_graft(struct commit_graft *, int);
Martin Koegler45163382008-02-25 22:46:07 +0100164struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
Junio C Hamano5040f172006-04-06 23:58:51 -0700165
Rene Scharfec0fa8252006-07-02 11:49:38 +0200166extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
Christian Couder53eda892008-07-30 07:04:14 +0200167extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
Miklos Vajna5240c9d2008-06-27 18:22:00 +0200168extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
Johannes Schindelin7c6f8aa2006-06-29 15:17:32 +0200169
Stefano Lattarini41ccfdd2013-04-12 00:36:10 +0200170/* largest positive number a signed 32-bit integer can contain */
Nguyễn Thái Ngọc Duy4dcb1672013-01-11 16:05:46 +0700171#define INFINITE_DEPTH 0x7fffffff
172
Johannes Schindelined09aef2006-10-30 20:09:06 +0100173extern int register_shallow(const unsigned char *sha1);
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100174extern int unregister_shallow(const unsigned char *sha1);
Nguyễn Thái Ngọc Duy09d46642011-08-18 19:29:35 +0700175extern int for_each_commit_graft(each_commit_graft_fn, void *);
Junio C Hamanof43117a2007-01-21 22:22:23 -0800176extern int is_repository_shallow(void);
Johannes Schindelined09aef2006-10-30 20:09:06 +0100177extern struct commit_list *get_shallow_commits(struct object_array *heads,
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100178 int depth, int shallow_flag, int not_shallow_flag);
Johannes Schindelined09aef2006-10-30 20:09:06 +0100179
Jake Goulding7fcdb362009-01-26 09:13:24 -0500180int is_descendant_of(struct commit *, struct commit_list *);
Junio C Hamanoa20efee2012-08-27 14:46:01 -0700181int in_merge_bases(struct commit *, struct commit *);
Junio C Hamano4c4b27e2013-03-04 10:16:42 -0800182int in_merge_bases_many(struct commit *, int, struct commit **);
Kristian Høgsberg58680162007-09-17 20:06:44 -0400183
Conrad Irwinb4bd4662011-05-07 10:58:07 -0700184extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
Thomas Rast46b51392009-08-13 14:29:41 +0200185extern int run_add_interactive(const char *revision, const char *patch_mode,
186 const char **pathspec);
Kristian Høgsberg58680162007-09-17 20:06:44 -0400187
Linus Torvalds53b2c822007-11-05 13:22:34 -0800188static inline int single_parent(struct commit *commit)
189{
190 return commit->parents && !commit->parents->next;
191}
192
Junio C Hamano98cf9c32008-06-27 18:22:03 +0200193struct commit_list *reduce_heads(struct commit_list *heads);
194
Junio C Hamano5231c632011-11-07 16:21:32 -0800195struct commit_extra_header {
196 struct commit_extra_header *next;
197 char *key;
198 char *value;
199 size_t len;
200};
201
202extern void append_merge_tag_headers(struct commit_list *parents,
203 struct commit_extra_header ***tail);
204
Nguyễn Thái Ngọc Duy13f8b722011-12-15 20:47:22 +0700205extern int commit_tree(const struct strbuf *msg, unsigned char *tree,
Junio C Hamano5231c632011-11-07 16:21:32 -0800206 struct commit_list *parents, unsigned char *ret,
Junio C Hamanoba3c69a2011-10-05 17:23:20 -0700207 const char *author, const char *sign_commit);
Junio C Hamano5231c632011-11-07 16:21:32 -0800208
Junio C Hamanof35ccd92011-12-22 11:27:26 -0800209extern int commit_tree_extended(const struct strbuf *msg, unsigned char *tree,
Junio C Hamano5231c632011-11-07 16:21:32 -0800210 struct commit_list *parents, unsigned char *ret,
Junio C Hamanoba3c69a2011-10-05 17:23:20 -0700211 const char *author, const char *sign_commit,
Junio C Hamano5231c632011-11-07 16:21:32 -0800212 struct commit_extra_header *);
213
Junio C Hamanoc871a1d2012-01-05 10:54:14 -0800214extern struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);
Junio C Hamanoed7a42a2011-11-08 15:38:07 -0800215
Junio C Hamano5231c632011-11-07 16:21:32 -0800216extern void free_commit_extra_headers(struct commit_extra_header *extra);
Jeff King40d52ff2010-04-01 20:05:23 -0400217
Junio C Hamanoae8e4c92011-11-07 13:26:22 -0800218struct merge_remote_desc {
219 struct object *obj; /* the named object, could be a tag */
220 const char *name;
221};
222#define merge_remote_util(commit) ((struct merge_remote_desc *)((commit)->util))
223
224/*
225 * Given "name" from the command line to merge, find the commit object
226 * and return it, while storing merge_remote_desc in its ->util field,
227 * to allow callers to tell if we are told to merge a tag.
228 */
229struct commit *get_merge_parent(const char *name);
230
Junio C Hamano0c37f1f2011-10-18 15:53:23 -0700231extern int parse_signed_commit(const unsigned char *sha1,
232 struct strbuf *message, struct strbuf *signature);
Nguyễn Thái Ngọc Duyefc7df42012-10-26 22:53:51 +0700233extern void print_commit_list(struct commit_list *list,
234 const char *format_cur,
235 const char *format_last);
236
Sebastian Götteffb6d7d2013-03-31 18:00:14 +0200237/*
Sebastian Götteeb307ae2013-03-31 18:02:46 +0200238 * Check the signature of the given commit. The result of the check is stored
239 * in sig->check_result, 'G' for a good signature, 'U' for a good signature
240 * from an untrusted signer, 'B' for a bad signature and 'N' for no signature
241 * at all. This may allocate memory for sig->gpg_output, sig->gpg_status,
242 * sig->signer and sig->key.
Sebastian Götteffb6d7d2013-03-31 18:00:14 +0200243 */
244extern void check_commit_signature(const struct commit* commit, struct signature_check *sigc);
245
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -0700246#endif /* COMMIT_H */