blob: b897b5730d9b9c220362b0b6a9df7be5d6803df3 [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"
Linus Torvaldsca135e72007-04-16 16:05:10 -07006#include "decorate.h"
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -07007
8struct commit_list {
9 struct commit *item;
10 struct commit_list *next;
11};
12
13struct commit {
14 struct object object;
Linus Torvaldsd3ff6f52006-06-17 18:26:18 -070015 void *util;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070016 unsigned long date;
17 struct commit_list *parents;
18 struct tree *tree;
Linus Torvaldsbd1e17e2005-05-25 19:26:28 -070019 char *buffer;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070020};
21
Linus Torvalds60ab26d2005-09-15 14:43:17 -070022extern int save_commit_buffer;
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070023extern const char *commit_type;
24
Linus Torvaldsca135e72007-04-16 16:05:10 -070025/* While we can decorate any object with a name, it's only used for commits.. */
26extern struct decoration name_decoration;
27struct name_decoration {
28 struct name_decoration *next;
29 char name[1];
30};
31
Jason McMullan5d6ccf52005-06-03 11:05:39 -040032struct commit *lookup_commit(const unsigned char *sha1);
33struct commit *lookup_commit_reference(const unsigned char *sha1);
Junio C Hamanof76412e2005-08-21 02:51:10 -070034struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
35 int quiet);
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070036
Nicolas Pitrebd2c39f2005-05-06 13:48:34 -040037int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
38
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070039int parse_commit(struct commit *item);
40
Linus Torvaldsac5155e2005-05-30 18:44:02 -070041struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
Linus Torvaldsf7554942005-07-06 09:31:17 -070042struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);
Daniel Barkalowdd97f852005-04-23 18:47:23 -070043
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -070044void free_commit_list(struct commit_list *list);
45
Daniel Barkalowdd97f852005-04-23 18:47:23 -070046void sort_by_date(struct commit_list **list);
47
Linus Torvalds000182e2005-06-05 09:02:03 -070048/* Commit formats */
49enum cmit_fmt {
50 CMIT_FMT_RAW,
51 CMIT_FMT_MEDIUM,
52 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
Linus Torvalds9b66ec02005-06-26 17:50:46 -070053 CMIT_FMT_SHORT,
54 CMIT_FMT_FULL,
Junio C Hamanoff56fe12005-11-09 22:15:27 -080055 CMIT_FMT_FULLER,
Junio C Hamanod87449c2005-08-08 22:15:40 -070056 CMIT_FMT_ONELINE,
Junio C Hamano3eefc182006-04-18 16:45:27 -070057 CMIT_FMT_EMAIL,
Johannes Schindeline52a5de2007-02-23 01:35:03 +010058 CMIT_FMT_USERFORMAT,
Junio C Hamano6b9c58f2006-04-15 23:46:36 -070059
60 CMIT_FMT_UNSPECIFIED,
Linus Torvalds000182e2005-06-05 09:02:03 -070061};
62
Junio C Hamanoacef41c2007-10-31 14:55:17 -070063extern int non_ascii(int);
Linus Torvalds9b66ec02005-06-26 17:50:46 -070064extern enum cmit_fmt get_commit_format(const char *arg);
Junio C Hamanoacef41c2007-10-31 14:55:17 -070065extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char **buf_p, unsigned long *space_p, int abbrev, const char *subject, const char *after_subject, enum date_mode dmode, int non_ascii_present);
Linus Torvaldse3bc7a32005-06-01 08:34:23 -070066
Daniel Barkalowdd97f852005-04-23 18:47:23 -070067/** Removes the first commit from a list sorted by date, and adds all
68 * of its parents.
69 **/
Junio C Hamanoa6080a02007-06-07 00:04:01 -070070struct commit *pop_most_recent_commit(struct commit_list **list,
Daniel Barkalow58e28af2005-04-23 20:29:22 -070071 unsigned int mark);
Daniel Barkalowdd97f852005-04-23 18:47:23 -070072
jon@blackcubes.dyndns.orga3437b82005-06-06 15:39:40 +000073struct commit *pop_commit(struct commit_list **stack);
74
Junio C Hamanof8f9c732006-01-07 18:52:42 -080075void clear_commit_marks(struct commit *commit, unsigned int mark);
76
Jon Seymourab580ac2005-07-07 02:39:34 +100077/*
78 * Performs an in-place topological sort of list supplied.
79 *
Fredrik Kuivinen6b6dcfc2006-03-10 10:21:37 +010080 * Pre-conditions for sort_in_topological_order:
Jon Seymourab580ac2005-07-07 02:39:34 +100081 * all commits in input list and all parents of those
82 * commits must have object.util == NULL
Fredrik Kuivinen6b6dcfc2006-03-10 10:21:37 +010083 *
84 * Pre-conditions for sort_in_topological_order_fn:
85 * all commits in input list and all parents of those
86 * commits must have getter(commit) == NULL
87 *
88 * Post-conditions:
Jon Seymourab580ac2005-07-07 02:39:34 +100089 * invariant of resulting list is:
90 * a reachable from b => ord(b) < ord(a)
Junio C Hamano4c8725f2006-02-15 22:05:33 -080091 * in addition, when lifo == 0, commits on parallel tracks are
92 * sorted in the dates order.
Jon Seymourab580ac2005-07-07 02:39:34 +100093 */
Fredrik Kuivinen6b6dcfc2006-03-10 10:21:37 +010094
95typedef void (*topo_sort_set_fn_t)(struct commit*, void *data);
96typedef void* (*topo_sort_get_fn_t)(struct commit*);
97
98void topo_sort_default_setter(struct commit *c, void *data);
99void *topo_sort_default_getter(struct commit *c);
100
Junio C Hamano4c8725f2006-02-15 22:05:33 -0800101void sort_in_topological_order(struct commit_list ** list, int lifo);
Fredrik Kuivinen6b6dcfc2006-03-10 10:21:37 +0100102void sort_in_topological_order_fn(struct commit_list ** list, int lifo,
103 topo_sort_set_fn_t setter,
104 topo_sort_get_fn_t getter);
Junio C Hamano5040f172006-04-06 23:58:51 -0700105
106struct commit_graft {
107 unsigned char sha1[20];
Johannes Schindelined09aef2006-10-30 20:09:06 +0100108 int nr_parent; /* < 0 if shallow commit */
Junio C Hamano5040f172006-04-06 23:58:51 -0700109 unsigned char parent[FLEX_ARRAY][20]; /* more */
110};
111
112struct commit_graft *read_graft_line(char *buf, int len);
113int register_commit_graft(struct commit_graft *, int);
114int read_graft_file(const char *graft_file);
115
Rene Scharfec0fa8252006-07-02 11:49:38 +0200116extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
Johannes Schindelin7c6f8aa2006-06-29 15:17:32 +0200117
Johannes Schindelined09aef2006-10-30 20:09:06 +0100118extern int register_shallow(const unsigned char *sha1);
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100119extern int unregister_shallow(const unsigned char *sha1);
Johannes Schindelined09aef2006-10-30 20:09:06 +0100120extern int write_shallow_commits(int fd, int use_pack_protocol);
Junio C Hamanof43117a2007-01-21 22:22:23 -0800121extern int is_repository_shallow(void);
Johannes Schindelined09aef2006-10-30 20:09:06 +0100122extern struct commit_list *get_shallow_commits(struct object_array *heads,
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100123 int depth, int shallow_flag, int not_shallow_flag);
Johannes Schindelined09aef2006-10-30 20:09:06 +0100124
Junio C Hamano03840fc2007-01-08 23:22:31 -0800125int in_merge_bases(struct commit *, struct commit **, int);
Daniel Barkalow6eb8ae02005-04-18 11:39:48 -0700126#endif /* COMMIT_H */