🌐 AI搜索 & 代理 主页
blob: 12d100b8b6fcd092f3a6886a75c720011ef1b7dc [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;
Nazri Ramliyeb3005e2010-06-19 01:37:3331 int type;
Linus Torvaldsca135e72007-04-16 23:05:1032 char name[1];
33};
34
Jason McMullan5d6ccf52005-06-03 15:05:3935struct commit *lookup_commit(const unsigned char *sha1);
36struct commit *lookup_commit_reference(const unsigned char *sha1);
Junio C Hamanof76412e2005-08-21 09:51:1037struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
38 int quiet);
Pat Notza6fa5992010-11-02 19:59:0739struct commit *lookup_commit_reference_by_name(const char *name);
Daniel Barkalow6eb8ae02005-04-18 18:39:4840
Nguyễn Thái Ngọc Duycf7b1ca2011-02-05 10:52:2041int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);
Daniel Barkalow6eb8ae02005-04-18 18:39:4842int parse_commit(struct commit *item);
43
Christian Couder11af2aa2010-07-22 13:18:3044/* Find beginning and length of commit subject. */
45int find_commit_subject(const char *commit_buffer, const char **subject);
46
Thiago Farina47e44ed2010-11-27 01:58:1447struct commit_list *commit_list_insert(struct commit *item,
48 struct commit_list **list);
Miklos Vajna65319472008-06-27 16:21:5549unsigned commit_list_count(const struct commit_list *l);
Thiago Farina47e44ed2010-11-27 01:58:1450struct commit_list *commit_list_insert_by_date(struct commit *item,
51 struct commit_list **list);
52void commit_list_sort_by_date(struct commit_list **list);
Daniel Barkalowdd97f852005-04-24 01:47:2353
Daniel Barkalow6eb8ae02005-04-18 18:39:4854void free_commit_list(struct commit_list *list);
55
Linus Torvalds000182e2005-06-05 16:02:0356/* Commit formats */
57enum cmit_fmt {
58 CMIT_FMT_RAW,
59 CMIT_FMT_MEDIUM,
60 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
Linus Torvalds9b66ec02005-06-27 00:50:4661 CMIT_FMT_SHORT,
62 CMIT_FMT_FULL,
Junio C Hamanoff56fe12005-11-10 06:15:2763 CMIT_FMT_FULLER,
Junio C Hamanod87449c2005-08-09 05:15:4064 CMIT_FMT_ONELINE,
Junio C Hamano3eefc182006-04-18 23:45:2765 CMIT_FMT_EMAIL,
Johannes Schindeline52a5de2007-02-23 00:35:0366 CMIT_FMT_USERFORMAT,
Junio C Hamano6b9c58f2006-04-16 06:46:3667
Gary V. Vaughan4b055482010-05-14 09:31:3568 CMIT_FMT_UNSPECIFIED
Linus Torvalds000182e2005-06-05 16:02:0369};
70
Jonathan Nieder9cba13c2011-03-16 07:08:3471struct pretty_print_context {
Jeff King6bf13942011-05-26 22:27:4972 enum cmit_fmt fmt;
Thomas Rastdd2e7942009-10-19 15:48:0873 int abbrev;
74 const char *subject;
75 const char *after_subject;
Jeff King9553d2b2011-05-26 22:28:1776 int preserve_subject;
Thomas Rastdd2e7942009-10-19 15:48:0877 enum date_mode date_mode;
78 int need_8bit_cte;
Junio C Hamano66b2ed02010-01-20 21:59:3679 int show_notes;
Thomas Rast8f8f5472009-10-19 15:48:1080 struct reflog_walk_info *reflog_info;
Pat Notz177b29d2010-11-02 19:59:0881 const char *output_encoding;
Thomas Rastdd2e7942009-10-19 15:48:0882};
83
Johannes Gilger5b163602010-04-13 20:31:1284struct userformat_want {
85 unsigned notes:1;
86};
87
Johannes Schindelin28e9cf62009-08-10 16:22:1888extern int has_non_ascii(const char *text);
Junio C Hamano4da45be2008-04-08 00:11:3489struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
Pat Notz177b29d2010-11-02 19:59:0890extern char *logmsg_reencode(const struct commit *commit,
91 const char *output_encoding);
Alexander Gavrilov69cd8f62008-10-21 20:55:5792extern char *reencode_commit_message(const struct commit *commit,
93 const char **encoding_p);
Junio C Hamano4da45be2008-04-08 00:11:3494extern void get_commit_format(const char *arg, struct rev_info *);
Ramsay Jonesc8f14442011-04-07 18:26:2395extern const char *format_subject(struct strbuf *sb, const char *msg,
96 const char *line_separator);
Johannes Gilger5b163602010-04-13 20:31:1297extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
Pierre Habouzit674d1722007-09-10 10:35:0698extern void format_commit_message(const struct commit *commit,
Junio C Hamano7f98ebc2009-10-16 05:59:4199 const char *format, struct strbuf *sb,
Thomas Rastdd2e7942009-10-19 15:48:08100 const struct pretty_print_context *context);
Jeff King6bf13942011-05-26 22:27:49101extern void pretty_print_commit(const struct pretty_print_context *pp,
102 const struct commit *commit,
103 struct strbuf *sb);
Jeff King8b8a5372011-05-26 22:27:24104extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
105 struct strbuf *sb);
Jeff King6bf13942011-05-26 22:27:49106void pp_user_info(const struct pretty_print_context *pp,
107 const char *what, struct strbuf *sb,
108 const char *line, const char *encoding);
109void pp_title_line(const struct pretty_print_context *pp,
Daniel Barkalowb02bd652008-02-19 03:56:08110 const char **msg_p,
111 struct strbuf *sb,
Daniel Barkalowb02bd652008-02-19 03:56:08112 const char *encoding,
Junio C Hamano267123b2008-03-15 07:09:20113 int need_8bit_cte);
Jeff King6bf13942011-05-26 22:27:49114void pp_remainder(const struct pretty_print_context *pp,
Daniel Barkalowb02bd652008-02-19 03:56:08115 const char **msg_p,
116 struct strbuf *sb,
117 int indent);
118
Linus Torvaldse3bc7a32005-06-01 15:34:23119
Daniel Barkalowdd97f852005-04-24 01:47:23120/** Removes the first commit from a list sorted by date, and adds all
121 * of its parents.
122 **/
Junio C Hamanoa6080a02007-06-07 07:04:01123struct commit *pop_most_recent_commit(struct commit_list **list,
Daniel Barkalow58e28af2005-04-24 03:29:22124 unsigned int mark);
Daniel Barkalowdd97f852005-04-24 01:47:23125
jon@blackcubes.dyndns.orga3437b82005-06-06 15:39:40126struct commit *pop_commit(struct commit_list **stack);
127
Junio C Hamanof8f9c732006-01-08 02:52:42128void clear_commit_marks(struct commit *commit, unsigned int mark);
129
Jon Seymourab580ac2005-07-06 16:39:34130/*
131 * Performs an in-place topological sort of list supplied.
132 *
Jon Seymourab580ac2005-07-06 16:39:34133 * invariant of resulting list is:
134 * a reachable from b => ord(b) < ord(a)
Junio C Hamano4c8725f2006-02-16 06:05:33135 * in addition, when lifo == 0, commits on parallel tracks are
136 * sorted in the dates order.
Jon Seymourab580ac2005-07-06 16:39:34137 */
Junio C Hamano4c8725f2006-02-16 06:05:33138void sort_in_topological_order(struct commit_list ** list, int lifo);
Junio C Hamano5040f172006-04-07 06:58:51139
140struct commit_graft {
141 unsigned char sha1[20];
Johannes Schindelined09aef2006-10-30 19:09:06142 int nr_parent; /* < 0 if shallow commit */
Junio C Hamano5040f172006-04-07 06:58:51143 unsigned char parent[FLEX_ARRAY][20]; /* more */
144};
Nguyễn Thái Ngọc Duy09d46642011-08-18 12:29:35145typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
Junio C Hamano5040f172006-04-07 06:58:51146
147struct commit_graft *read_graft_line(char *buf, int len);
148int register_commit_graft(struct commit_graft *, int);
Martin Koegler45163382008-02-25 21:46:07149struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
Junio C Hamano5040f172006-04-07 06:58:51150
Rene Scharfec0fa8252006-07-02 09:49:38151extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
Christian Couder53eda892008-07-30 05:04:14152extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
Miklos Vajna5240c9d2008-06-27 16:22:00153extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
Johannes Schindelin7c6f8aa2006-06-29 13:17:32154
Johannes Schindelined09aef2006-10-30 19:09:06155extern int register_shallow(const unsigned char *sha1);
Johannes Schindelinf53514b2006-10-30 19:09:53156extern int unregister_shallow(const unsigned char *sha1);
Nguyễn Thái Ngọc Duy09d46642011-08-18 12:29:35157extern int for_each_commit_graft(each_commit_graft_fn, void *);
Junio C Hamanof43117a2007-01-22 06:22:23158extern int is_repository_shallow(void);
Johannes Schindelined09aef2006-10-30 19:09:06159extern struct commit_list *get_shallow_commits(struct object_array *heads,
Johannes Schindelinf53514b2006-10-30 19:09:53160 int depth, int shallow_flag, int not_shallow_flag);
Johannes Schindelined09aef2006-10-30 19:09:06161
Jake Goulding7fcdb362009-01-26 14:13:24162int is_descendant_of(struct commit *, struct commit_list *);
Junio C Hamano03840fc2007-01-09 07:22:31163int in_merge_bases(struct commit *, struct commit **, int);
Kristian Høgsberg58680162007-09-18 00:06:44164
Conrad Irwinb4bd4662011-05-07 17:58:07165extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
Thomas Rast46b51392009-08-13 12:29:41166extern int run_add_interactive(const char *revision, const char *patch_mode,
167 const char **pathspec);
Kristian Høgsberg58680162007-09-18 00:06:44168
Linus Torvalds53b2c822007-11-05 21:22:34169static inline int single_parent(struct commit *commit)
170{
171 return commit->parents && !commit->parents->next;
172}
173
Junio C Hamano98cf9c32008-06-27 16:22:03174struct commit_list *reduce_heads(struct commit_list *heads);
175
Jeff King40d52ff2010-04-02 00:05:23176extern int commit_tree(const char *msg, unsigned char *tree,
177 struct commit_list *parents, unsigned char *ret,
178 const char *author);
179
Daniel Barkalow6eb8ae02005-04-18 18:39:48180#endif /* COMMIT_H */