Skip to content

Commit

Permalink
pretty.c: drop const-ness from pretty_print_context
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Jul 3, 2013
1 parent 8c4e4ec commit 10f2fbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 12 additions & 4 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ enum cmit_fmt {
};

struct pretty_print_context {
/*
* Callers should tweak these to change the behavior of pp_* functions.
*/
enum cmit_fmt fmt;
int abbrev;
const char *subject;
Expand All @@ -92,6 +95,11 @@ struct pretty_print_context {
const char *output_encoding;
struct string_list *mailmap;
int color;

/*
* Fields below here are manipulated internally by pp_* functions and
* should not be counted on by callers.
*/
};

struct userformat_want {
Expand All @@ -111,20 +119,20 @@ extern void userformat_find_requirements(const char *fmt, struct userformat_want
extern void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *context);
extern void pretty_print_commit(const struct pretty_print_context *pp,
extern void pretty_print_commit(struct pretty_print_context *pp,
const struct commit *commit,
struct strbuf *sb);
extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
struct strbuf *sb);
void pp_user_info(const struct pretty_print_context *pp,
void pp_user_info(struct pretty_print_context *pp,
const char *what, struct strbuf *sb,
const char *line, const char *encoding);
void pp_title_line(const struct pretty_print_context *pp,
void pp_title_line(struct pretty_print_context *pp,
const char **msg_p,
struct strbuf *sb,
const char *encoding,
int need_8bit_cte);
void pp_remainder(const struct pretty_print_context *pp,
void pp_remainder(struct pretty_print_context *pp,
const char **msg_p,
struct strbuf *sb,
int indent);
Expand Down
10 changes: 5 additions & 5 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ static const char *show_ident_date(const struct ident_split *ident,
return show_date(date, tz, mode);
}

void pp_user_info(const struct pretty_print_context *pp,
void pp_user_info(struct pretty_print_context *pp,
const char *what, struct strbuf *sb,
const char *line, const char *encoding)
{
Expand Down Expand Up @@ -1514,7 +1514,7 @@ void format_commit_message(const struct commit *commit,
free(context.signature_check.signer);
}

static void pp_header(const struct pretty_print_context *pp,
static void pp_header(struct pretty_print_context *pp,
const char *encoding,
const struct commit *commit,
const char **msg_p,
Expand Down Expand Up @@ -1575,7 +1575,7 @@ static void pp_header(const struct pretty_print_context *pp,
}
}

void pp_title_line(const struct pretty_print_context *pp,
void pp_title_line(struct pretty_print_context *pp,
const char **msg_p,
struct strbuf *sb,
const char *encoding,
Expand Down Expand Up @@ -1618,7 +1618,7 @@ void pp_title_line(const struct pretty_print_context *pp,
strbuf_release(&title);
}

void pp_remainder(const struct pretty_print_context *pp,
void pp_remainder(struct pretty_print_context *pp,
const char **msg_p,
struct strbuf *sb,
int indent)
Expand Down Expand Up @@ -1650,7 +1650,7 @@ void pp_remainder(const struct pretty_print_context *pp,
}
}

void pretty_print_commit(const struct pretty_print_context *pp,
void pretty_print_commit(struct pretty_print_context *pp,
const struct commit *commit,
struct strbuf *sb)
{
Expand Down

0 comments on commit 10f2fbf

Please sign in to comment.