Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 10f2fbf

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c4e4ec commit 10f2fbf

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

commit.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ enum cmit_fmt {
7979
};
8080

8181
struct pretty_print_context {
82+
/*
83+
* Callers should tweak these to change the behavior of pp_* functions.
84+
*/
8285
enum cmit_fmt fmt;
8386
int abbrev;
8487
const char *subject;
@@ -92,6 +95,11 @@ struct pretty_print_context {
9295
const char *output_encoding;
9396
struct string_list *mailmap;
9497
int color;
98+
99+
/*
100+
* Fields below here are manipulated internally by pp_* functions and
101+
* should not be counted on by callers.
102+
*/
95103
};
96104

97105
struct userformat_want {
@@ -111,20 +119,20 @@ extern void userformat_find_requirements(const char *fmt, struct userformat_want
111119
extern void format_commit_message(const struct commit *commit,
112120
const char *format, struct strbuf *sb,
113121
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,
115123
const struct commit *commit,
116124
struct strbuf *sb);
117125
extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
118126
struct strbuf *sb);
119-
void pp_user_info(const struct pretty_print_context *pp,
127+
void pp_user_info(struct pretty_print_context *pp,
120128
const char *what, struct strbuf *sb,
121129
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,
123131
const char **msg_p,
124132
struct strbuf *sb,
125133
const char *encoding,
126134
int need_8bit_cte);
127-
void pp_remainder(const struct pretty_print_context *pp,
135+
void pp_remainder(struct pretty_print_context *pp,
128136
const char **msg_p,
129137
struct strbuf *sb,
130138
int indent);

pretty.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static const char *show_ident_date(const struct ident_split *ident,
406406
return show_date(date, tz, mode);
407407
}
408408

409-
void pp_user_info(const struct pretty_print_context *pp,
409+
void pp_user_info(struct pretty_print_context *pp,
410410
const char *what, struct strbuf *sb,
411411
const char *line, const char *encoding)
412412
{
@@ -1514,7 +1514,7 @@ void format_commit_message(const struct commit *commit,
15141514
free(context.signature_check.signer);
15151515
}
15161516

1517-
static void pp_header(const struct pretty_print_context *pp,
1517+
static void pp_header(struct pretty_print_context *pp,
15181518
const char *encoding,
15191519
const struct commit *commit,
15201520
const char **msg_p,
@@ -1575,7 +1575,7 @@ static void pp_header(const struct pretty_print_context *pp,
15751575
}
15761576
}
15771577

1578-
void pp_title_line(const struct pretty_print_context *pp,
1578+
void pp_title_line(struct pretty_print_context *pp,
15791579
const char **msg_p,
15801580
struct strbuf *sb,
15811581
const char *encoding,
@@ -1618,7 +1618,7 @@ void pp_title_line(const struct pretty_print_context *pp,
16181618
strbuf_release(&title);
16191619
}
16201620

1621-
void pp_remainder(const struct pretty_print_context *pp,
1621+
void pp_remainder(struct pretty_print_context *pp,
16221622
const char **msg_p,
16231623
struct strbuf *sb,
16241624
int indent)
@@ -1650,7 +1650,7 @@ void pp_remainder(const struct pretty_print_context *pp,
16501650
}
16511651
}
16521652

1653-
void pretty_print_commit(const struct pretty_print_context *pp,
1653+
void pretty_print_commit(struct pretty_print_context *pp,
16541654
const struct commit *commit,
16551655
struct strbuf *sb)
16561656
{

0 commit comments

Comments
 (0)