pretty.c: drop const-ness from pretty_print_context
In the current code, callers are expected to fill in the pretty_print_context, and then the pretty.c functions simply read from it. This leaves no room for the pretty.c functions to communicate with each other by manipulating the context (e.g., data seen while printing the header may impact how we print the body). Rather than introduce a new struct to hold modifiable data, let's just drop the const-ness of the existing context struct. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 3, 2013 at 03:07 UTC
10f2fbff6859a22327d04f9eb0c1a38995ff48b1
2 files changed
+17
-9
commit.h
+12
-4
@@ -79,6 +79,9 @@ enum cmit_fmt {
79
};
80
81
struct pretty_print_context {
82
+ /*
83
+ * Callers should tweak these to change the behavior of pp_* functions.
84
+ */
85
enum cmit_fmt fmt;
86
int abbrev;
87
const char *subject;
@@ -92,6 +95,11 @@ struct pretty_print_context {
95
const char *output_encoding;
96
struct string_list *mailmap;
97
int color;
98
+
99
+ /*
100
+ * Fields below here are manipulated internally by pp_* functions and
101
+ * should not be counted on by callers.
102
+ */
103
};
104
105
struct userformat_want {
@@ -111,20 +119,20 @@ extern void userformat_find_requirements(const char *fmt, struct userformat_want
119
extern void format_commit_message(const struct commit *commit,
120
const char *format, struct strbuf *sb,
121
const struct pretty_print_context *context);
114
-extern void pretty_print_commit(const struct pretty_print_context *pp,
122
+extern void pretty_print_commit(struct pretty_print_context *pp,
123
const struct commit *commit,
124
struct strbuf *sb);
125
extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
126
struct strbuf *sb);
119
-void pp_user_info(const struct pretty_print_context *pp,
127
+void pp_user_info(struct pretty_print_context *pp,
128
const char *what, struct strbuf *sb,
129
const char *line, const char *encoding);
122
-void pp_title_line(const struct pretty_print_context *pp,
130
+void pp_title_line(struct pretty_print_context *pp,
131
const char **msg_p,
132
struct strbuf *sb,
133
const char *encoding,
134
int need_8bit_cte);
127
-void pp_remainder(const struct pretty_print_context *pp,
135
+void pp_remainder(struct pretty_print_context *pp,
136
const char **msg_p,
137
struct strbuf *sb,
138
int indent);
pretty.c
+5
-5
@@ -406,7 +406,7 @@ static const char *show_ident_date(const struct ident_split *ident,
406
return show_date(date, tz, mode);
407
}
408
409
-void pp_user_info(const struct pretty_print_context *pp,
409
+void pp_user_info(struct pretty_print_context *pp,
410
const char *what, struct strbuf *sb,
411
const char *line, const char *encoding)
412
{
@@ -1514,7 +1514,7 @@ void format_commit_message(const struct commit *commit,
1514
free(context.signature_check.signer);
1515
}
1516
1517
-static void pp_header(const struct pretty_print_context *pp,
1517
+static void pp_header(struct pretty_print_context *pp,
1518
const char *encoding,
1519
const struct commit *commit,
1520
const char **msg_p,
@@ -1575,7 +1575,7 @@ static void pp_header(const struct pretty_print_context *pp,
1575
}
1576
}
1577
1578
-void pp_title_line(const struct pretty_print_context *pp,
1578
+void pp_title_line(struct pretty_print_context *pp,
1579
const char **msg_p,
1580
struct strbuf *sb,
1581
const char *encoding,
@@ -1618,7 +1618,7 @@ void pp_title_line(const struct pretty_print_context *pp,
1618
strbuf_release(&title);
1619
}
1620
1621
-void pp_remainder(const struct pretty_print_context *pp,
1621
+void pp_remainder(struct pretty_print_context *pp,
1622
const char **msg_p,
1623
struct strbuf *sb,
1624
int indent)
@@ -1650,7 +1650,7 @@ void pp_remainder(const struct pretty_print_context *pp,
1650
}
1651
}
1652
1653
-void pretty_print_commit(const struct pretty_print_context *pp,
1653
+void pretty_print_commit(struct pretty_print_context *pp,
1654
const struct commit *commit,
1655
struct strbuf *sb)
1656
{