🌐 AI搜索 & 代理 主页
blob: 2c0742b721fe1d4d78a7a63ed1c2ee1cf9c96ab8 [file] [log] [blame]
Daniel Barkalow6eb8ae02005-04-18 18:39:481#ifndef COMMIT_H
2#define COMMIT_H
3
4#include "object.h"
5#include "tree.h"
Pierre Habouzit674d1722007-09-10 10:35:066#include "strbuf.h"
Linus Torvaldsca135e72007-04-16 23:05:107#include "decorate.h"
Daniel Barkalow6eb8ae02005-04-18 18:39:488
9struct commit_list {
10 struct commit *item;
11 struct commit_list *next;
12};
13
14struct commit {
15 struct object object;
Linus Torvaldsd3ff6f52006-06-18 01:26:1816 void *util;
Linus Torvalds23c17d42007-11-02 20:32:5817 unsigned int indegree;
Daniel Barkalow6eb8ae02005-04-18 18:39:4818 unsigned long date;
19 struct commit_list *parents;
20 struct tree *tree;
Linus Torvaldsbd1e17e2005-05-26 02:26:2821 char *buffer;
Daniel Barkalow6eb8ae02005-04-18 18:39:4822};
23
Linus Torvalds60ab26d2005-09-15 21:43:1724extern int save_commit_buffer;
Daniel Barkalow6eb8ae02005-04-18 18:39:4825extern const char *commit_type;
26
Linus Torvaldsca135e72007-04-16 23:05:1027/* 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 15:05:3934struct commit *lookup_commit(const unsigned char *sha1);
35struct commit *lookup_commit_reference(const unsigned char *sha1);
Junio C Hamanof76412e2005-08-21 09:51:1036struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
37 int quiet);
Daniel Barkalow6eb8ae02005-04-18 18:39:4838
Nicolas Pitrebd2c39f2005-05-06 17:48:3439int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
40
Daniel Barkalow6eb8ae02005-04-18 18:39:4841int parse_commit(struct commit *item);
42
Linus Torvaldsac5155e2005-05-31 01:44:0243struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
Miklos Vajna65319472008-06-27 16:21:5544unsigned commit_list_count(const struct commit_list *l);
Linus Torvaldsf7554942005-07-06 16:31:1745struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);
Daniel Barkalowdd97f852005-04-24 01:47:2346
Daniel Barkalow6eb8ae02005-04-18 18:39:4847void free_commit_list(struct commit_list *list);
48
Daniel Barkalowdd97f852005-04-24 01:47:2349void sort_by_date(struct commit_list **list);
50
Linus Torvalds000182e2005-06-05 16:02:0351/* Commit formats */
52enum cmit_fmt {
53 CMIT_FMT_RAW,
54 CMIT_FMT_MEDIUM,
55 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
Linus Torvalds9b66ec02005-06-27 00:50:4656 CMIT_FMT_SHORT,
57 CMIT_FMT_FULL,
Junio C Hamanoff56fe12005-11-10 06:15:2758 CMIT_FMT_FULLER,
Junio C Hamanod87449c2005-08-09 05:15:4059 CMIT_FMT_ONELINE,
Junio C Hamano3eefc182006-04-18 23:45:2760 CMIT_FMT_EMAIL,
Johannes Schindeline52a5de2007-02-23 00:35:0361 CMIT_FMT_USERFORMAT,
Junio C Hamano6b9c58f2006-04-16 06:46:3662
63 CMIT_FMT_UNSPECIFIED,
Linus Torvalds000182e2005-06-05 16:02:0364};
65
Thomas Rastdd2e7942009-10-19 15:48:0866struct 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 21:59:3673 int show_notes;
Thomas Rast8f8f5472009-10-19 15:48:1074 struct reflog_walk_info *reflog_info;
Thomas Rastdd2e7942009-10-19 15:48:0875};
76
Junio C Hamano4593fb82007-10-31 21:55:1777extern int non_ascii(int);
Johannes Schindelin28e9cf62009-08-10 16:22:1878extern int has_non_ascii(const char *text);
Junio C Hamano4da45be2008-04-08 00:11:3479struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
Alexander Gavrilov69cd8f62008-10-21 20:55:5780extern char *reencode_commit_message(const struct commit *commit,
81 const char **encoding_p);
Junio C Hamano4da45be2008-04-08 00:11:3482extern void get_commit_format(const char *arg, struct rev_info *);
Pierre Habouzit674d1722007-09-10 10:35:0683extern void format_commit_message(const struct commit *commit,
Junio C Hamano7f98ebc2009-10-16 05:59:4184 const char *format, struct strbuf *sb,
Thomas Rastdd2e7942009-10-19 15:48:0885 const struct pretty_print_context *context);
86extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
87 struct strbuf *sb,
88 const struct pretty_print_context *context);
Daniel Barkalowb02bd652008-02-19 03:56:0889void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
90 const char *line, enum date_mode dmode,
91 const char *encoding);
92void pp_title_line(enum cmit_fmt fmt,
93 const char **msg_p,
94 struct strbuf *sb,
95 const char *subject,
96 const char *after_subject,
97 const char *encoding,
Junio C Hamano267123b2008-03-15 07:09:2098 int need_8bit_cte);
Daniel Barkalowb02bd652008-02-19 03:56:0899void pp_remainder(enum cmit_fmt fmt,
100 const char **msg_p,
101 struct strbuf *sb,
102 int indent);
103
Linus Torvaldse3bc7a32005-06-01 15:34:23104
Daniel Barkalowdd97f852005-04-24 01:47:23105/** Removes the first commit from a list sorted by date, and adds all
106 * of its parents.
107 **/
Junio C Hamanoa6080a02007-06-07 07:04:01108struct commit *pop_most_recent_commit(struct commit_list **list,
Daniel Barkalow58e28af2005-04-24 03:29:22109 unsigned int mark);
Daniel Barkalowdd97f852005-04-24 01:47:23110
jon@blackcubes.dyndns.orga3437b82005-06-06 15:39:40111struct commit *pop_commit(struct commit_list **stack);
112
Junio C Hamanof8f9c732006-01-08 02:52:42113void clear_commit_marks(struct commit *commit, unsigned int mark);
114
Jon Seymourab580ac2005-07-06 16:39:34115/*
116 * Performs an in-place topological sort of list supplied.
117 *
Jon Seymourab580ac2005-07-06 16:39:34118 * invariant of resulting list is:
119 * a reachable from b => ord(b) < ord(a)
Junio C Hamano4c8725f2006-02-16 06:05:33120 * in addition, when lifo == 0, commits on parallel tracks are
121 * sorted in the dates order.
Jon Seymourab580ac2005-07-06 16:39:34122 */
Junio C Hamano4c8725f2006-02-16 06:05:33123void sort_in_topological_order(struct commit_list ** list, int lifo);
Junio C Hamano5040f172006-04-07 06:58:51124
125struct commit_graft {
126 unsigned char sha1[20];
Johannes Schindelined09aef2006-10-30 19:09:06127 int nr_parent; /* < 0 if shallow commit */
Junio C Hamano5040f172006-04-07 06:58:51128 unsigned char parent[FLEX_ARRAY][20]; /* more */
129};
130
131struct commit_graft *read_graft_line(char *buf, int len);
132int register_commit_graft(struct commit_graft *, int);
Martin Koegler45163382008-02-25 21:46:07133struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
Junio C Hamano5040f172006-04-07 06:58:51134
Christian Couder68095572009-01-23 09:06:53135const unsigned char *lookup_replace_object(const unsigned char *sha1);
136
Rene Scharfec0fa8252006-07-02 09:49:38137extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
Christian Couder53eda892008-07-30 05:04:14138extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
Miklos Vajna5240c9d2008-06-27 16:22:00139extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
Johannes Schindelin7c6f8aa2006-06-29 13:17:32140
Johannes Schindelined09aef2006-10-30 19:09:06141extern int register_shallow(const unsigned char *sha1);
Johannes Schindelinf53514b2006-10-30 19:09:53142extern int unregister_shallow(const unsigned char *sha1);
Shawn O. Pearceedace6f2009-10-31 00:47:23143extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
Junio C Hamanof43117a2007-01-22 06:22:23144extern int is_repository_shallow(void);
Johannes Schindelined09aef2006-10-30 19:09:06145extern struct commit_list *get_shallow_commits(struct object_array *heads,
Johannes Schindelinf53514b2006-10-30 19:09:53146 int depth, int shallow_flag, int not_shallow_flag);
Johannes Schindelined09aef2006-10-30 19:09:06147
Jake Goulding7fcdb362009-01-26 14:13:24148int is_descendant_of(struct commit *, struct commit_list *);
Junio C Hamano03840fc2007-01-09 07:22:31149int in_merge_bases(struct commit *, struct commit **, int);
Kristian Høgsberg58680162007-09-18 00:06:44150
Junio C Hamano3f061882007-11-25 18:10:10151extern int interactive_add(int argc, const char **argv, const char *prefix);
Thomas Rast46b51392009-08-13 12:29:41152extern int run_add_interactive(const char *revision, const char *patch_mode,
153 const char **pathspec);
Kristian Høgsberg58680162007-09-18 00:06:44154
Linus Torvalds53b2c822007-11-05 21:22:34155static inline int single_parent(struct commit *commit)
156{
157 return commit->parents && !commit->parents->next;
158}
159
Junio C Hamano98cf9c32008-06-27 16:22:03160struct commit_list *reduce_heads(struct commit_list *heads);
161
Daniel Barkalow6eb8ae02005-04-18 18:39:48162#endif /* COMMIT_H */