Skip to content

Commit cf39471

Browse files
telezhnayagitster
authored andcommitted
format: create pretty.h file
Create header for pretty.c to make formatting interface more structured. This is a middle point, this file would be merged further with other files which contain formatting stuff. Signed-off-by: Olga Telezhnaia <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3013dff commit cf39471

File tree

6 files changed

+92
-84
lines changed

6 files changed

+92
-84
lines changed

builtin/notes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "builtin.h"
1313
#include "notes.h"
1414
#include "blob.h"
15-
#include "commit.h"
15+
#include "pretty.h"
1616
#include "refs.h"
1717
#include "exec_cmd.h"
1818
#include "run-command.h"

builtin/reset.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "lockfile.h"
1313
#include "tag.h"
1414
#include "object.h"
15-
#include "commit.h"
15+
#include "pretty.h"
1616
#include "run-command.h"
1717
#include "refs.h"
1818
#include "diff.h"

builtin/show-branch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "cache.h"
22
#include "config.h"
3-
#include "commit.h"
3+
#include "pretty.h"
44
#include "refs.h"
55
#include "builtin.h"
66
#include "color.h"

commit.h

+1-80
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "decorate.h"
88
#include "gpg-interface.h"
99
#include "string-list.h"
10+
#include "pretty.h"
1011

1112
struct commit_list {
1213
struct commit *item;
@@ -121,93 +122,13 @@ struct commit_list *copy_commit_list(struct commit_list *list);
121122

122123
void free_commit_list(struct commit_list *list);
123124

124-
/* Commit formats */
125-
enum cmit_fmt {
126-
CMIT_FMT_RAW,
127-
CMIT_FMT_MEDIUM,
128-
CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
129-
CMIT_FMT_SHORT,
130-
CMIT_FMT_FULL,
131-
CMIT_FMT_FULLER,
132-
CMIT_FMT_ONELINE,
133-
CMIT_FMT_EMAIL,
134-
CMIT_FMT_MBOXRD,
135-
CMIT_FMT_USERFORMAT,
136-
137-
CMIT_FMT_UNSPECIFIED
138-
};
139-
140-
static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
141-
{
142-
return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
143-
}
144-
145125
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
146126

147-
struct pretty_print_context {
148-
/*
149-
* Callers should tweak these to change the behavior of pp_* functions.
150-
*/
151-
enum cmit_fmt fmt;
152-
int abbrev;
153-
const char *after_subject;
154-
int preserve_subject;
155-
struct date_mode date_mode;
156-
unsigned date_mode_explicit:1;
157-
int print_email_subject;
158-
int expand_tabs_in_log;
159-
int need_8bit_cte;
160-
char *notes_message;
161-
struct reflog_walk_info *reflog_info;
162-
struct rev_info *rev;
163-
const char *output_encoding;
164-
struct string_list *mailmap;
165-
int color;
166-
struct ident_split *from_ident;
167-
168-
/*
169-
* Fields below here are manipulated internally by pp_* functions and
170-
* should not be counted on by callers.
171-
*/
172-
struct string_list in_body_headers;
173-
int graph_width;
174-
};
175-
176-
struct userformat_want {
177-
unsigned notes:1;
178-
};
179-
180127
extern int has_non_ascii(const char *text);
181128
extern const char *logmsg_reencode(const struct commit *commit,
182129
char **commit_encoding,
183130
const char *output_encoding);
184-
extern void get_commit_format(const char *arg, struct rev_info *);
185-
extern const char *format_subject(struct strbuf *sb, const char *msg,
186-
const char *line_separator);
187-
extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
188-
extern int commit_format_is_empty(enum cmit_fmt);
189131
extern const char *skip_blank_lines(const char *msg);
190-
extern void format_commit_message(const struct commit *commit,
191-
const char *format, struct strbuf *sb,
192-
const struct pretty_print_context *context);
193-
extern void pretty_print_commit(struct pretty_print_context *pp,
194-
const struct commit *commit,
195-
struct strbuf *sb);
196-
extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
197-
struct strbuf *sb);
198-
void pp_user_info(struct pretty_print_context *pp,
199-
const char *what, struct strbuf *sb,
200-
const char *line, const char *encoding);
201-
void pp_title_line(struct pretty_print_context *pp,
202-
const char **msg_p,
203-
struct strbuf *sb,
204-
const char *encoding,
205-
int need_8bit_cte);
206-
void pp_remainder(struct pretty_print_context *pp,
207-
const char **msg_p,
208-
struct strbuf *sb,
209-
int indent);
210-
211132

212133
/** Removes the first commit from a list sorted by date, and adds all
213134
* of its parents.

pretty.h

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#ifndef PRETTY_H
2+
#define PRETTY_H
3+
4+
struct commit;
5+
6+
/* Commit formats */
7+
enum cmit_fmt {
8+
CMIT_FMT_RAW,
9+
CMIT_FMT_MEDIUM,
10+
CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
11+
CMIT_FMT_SHORT,
12+
CMIT_FMT_FULL,
13+
CMIT_FMT_FULLER,
14+
CMIT_FMT_ONELINE,
15+
CMIT_FMT_EMAIL,
16+
CMIT_FMT_MBOXRD,
17+
CMIT_FMT_USERFORMAT,
18+
19+
CMIT_FMT_UNSPECIFIED
20+
};
21+
22+
struct pretty_print_context {
23+
/*
24+
* Callers should tweak these to change the behavior of pp_* functions.
25+
*/
26+
enum cmit_fmt fmt;
27+
int abbrev;
28+
const char *after_subject;
29+
int preserve_subject;
30+
struct date_mode date_mode;
31+
unsigned date_mode_explicit:1;
32+
int print_email_subject;
33+
int expand_tabs_in_log;
34+
int need_8bit_cte;
35+
char *notes_message;
36+
struct reflog_walk_info *reflog_info;
37+
struct rev_info *rev;
38+
const char *output_encoding;
39+
struct string_list *mailmap;
40+
int color;
41+
struct ident_split *from_ident;
42+
43+
/*
44+
* Fields below here are manipulated internally by pp_* functions and
45+
* should not be counted on by callers.
46+
*/
47+
struct string_list in_body_headers;
48+
int graph_width;
49+
};
50+
51+
static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
52+
{
53+
return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
54+
}
55+
56+
struct userformat_want {
57+
unsigned notes:1;
58+
};
59+
60+
void userformat_find_requirements(const char *fmt, struct userformat_want *w);
61+
void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
62+
struct strbuf *sb);
63+
void pp_user_info(struct pretty_print_context *pp, const char *what,
64+
struct strbuf *sb, const char *line,
65+
const char *encoding);
66+
void pp_title_line(struct pretty_print_context *pp, const char **msg_p,
67+
struct strbuf *sb, const char *encoding,
68+
int need_8bit_cte);
69+
void pp_remainder(struct pretty_print_context *pp, const char **msg_p,
70+
struct strbuf *sb, int indent);
71+
72+
void format_commit_message(const struct commit *commit,
73+
const char *format, struct strbuf *sb,
74+
const struct pretty_print_context *context);
75+
76+
void get_commit_format(const char *arg, struct rev_info *);
77+
78+
void pretty_print_commit(struct pretty_print_context *pp,
79+
const struct commit *commit,
80+
struct strbuf *sb);
81+
82+
const char *format_subject(struct strbuf *sb, const char *msg,
83+
const char *line_separator);
84+
85+
int commit_format_is_empty(enum cmit_fmt);
86+
87+
#endif /* PRETTY_H */

revision.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "parse-options.h"
55
#include "grep.h"
66
#include "notes.h"
7-
#include "commit.h"
7+
#include "pretty.h"
88
#include "diff.h"
99

1010
/* Remember to update object flag allocation in object.h */

0 commit comments

Comments
 (0)