Skip to content

Commit

Permalink
fixup tr/stash-format merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Junio C Hamano committed Oct 31, 2009
2 parents d39d667 + b7b1038 commit 5f809ff
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 79 deletions.
3 changes: 1 addition & 2 deletions Documentation/git-stash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ stash@{1}: On master: 9cc0589... Add git-stash
----------------------------------------------------------------
+
The command takes options applicable to the 'git-log'
command to control what is shown and how. If no options are set, the
default is `-n 10`. See linkgit:git-log[1].
command to control what is shown and how. See linkgit:git-log[1].

show [<stash>]::

Expand Down
9 changes: 9 additions & 0 deletions Documentation/pretty-formats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ The placeholders are:
- '%s': subject
- '%f': sanitized subject line, suitable for a filename
- '%b': body
- '%gD': reflog selector, e.g., `refs/stash@\{1\}`
- '%gd': shortened reflog selector, e.g., `stash@\{1\}`
- '%gs': reflog subject
- '%Cred': switch color to red
- '%Cgreen': switch color to green
- '%Cblue': switch color to blue
Expand All @@ -132,6 +135,12 @@ The placeholders are:
- '%n': newline
- '%x00': print a byte from a hex code

NOTE: Some placeholders may depend on other options given to the
revision traversal engine. For example, the `%g*` reflog options will
insert an empty string unless we are traversing reflog entries (e.g., by
`git log -g`). The `%d` placeholder will use the "short" decoration
format if `--decorate` was not already provided on the command line.

* 'tformat:'
+
The 'tformat:' format works exactly like 'format:', except that it
Expand Down
4 changes: 3 additions & 1 deletion archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static void format_subst(const struct commit *commit,
{
char *to_free = NULL;
struct strbuf fmt = STRBUF_INIT;
struct pretty_print_context ctx = {0};
ctx.date_mode = DATE_NORMAL;

if (src == buf->buf)
to_free = strbuf_detach(buf, NULL);
Expand All @@ -48,7 +50,7 @@ static void format_subst(const struct commit *commit,
strbuf_add(&fmt, b + 8, c - b - 8);

strbuf_add(buf, src, b - src);
format_commit_message(commit, fmt.buf, buf, DATE_NORMAL);
format_commit_message(commit, fmt.buf, buf, &ctx);
len -= c + 1 - src;
src = c + 1;
}
Expand Down
3 changes: 2 additions & 1 deletion builtin-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,9 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,

commit = item->commit;
if (commit && !parse_commit(commit)) {
struct pretty_print_context ctx = {0};
pretty_print_commit(CMIT_FMT_ONELINE, commit,
&subject, 0, NULL, NULL, 0, 0);
&subject, &ctx);
sub = subject.buf;
}

Expand Down
3 changes: 2 additions & 1 deletion builtin-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@ static void show_local_changes(struct object *head)
static void describe_detached_head(char *msg, struct commit *commit)
{
struct strbuf sb = STRBUF_INIT;
struct pretty_print_context ctx = {0};
parse_commit(commit);
pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, 0, NULL, NULL, 0, 0);
pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, &ctx);
fprintf(stderr, "%s %s... %s\n", msg,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
strbuf_release(&sb);
Expand Down
8 changes: 6 additions & 2 deletions builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,10 @@ static const char *find_author_by_nickname(const char *name)
prepare_revision_walk(&revs);
commit = get_revision(&revs);
if (commit) {
struct pretty_print_context ctx = {0};
ctx.date_mode = DATE_NORMAL;
strbuf_release(&buf);
format_commit_message(commit, "%an <%ae>", &buf, DATE_NORMAL);
format_commit_message(commit, "%an <%ae>", &buf, &ctx);
return strbuf_detach(&buf, NULL);
}
die("No existing author found with '%s'", name);
Expand Down Expand Up @@ -983,8 +985,10 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
initial_commit ? " (root-commit)" : "");

if (!log_tree_commit(&rev, commit)) {
struct pretty_print_context ctx = {0};
struct strbuf buf = STRBUF_INIT;
format_commit_message(commit, format + 7, &buf, DATE_NORMAL);
ctx.date_mode = DATE_NORMAL;
format_commit_message(commit, format + 7, &buf, &ctx);
printf("%s\n", buf.buf);
strbuf_release(&buf);
}
Expand Down
3 changes: 2 additions & 1 deletion builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)

if (verbose) {
struct strbuf buf = STRBUF_INIT;
struct pretty_print_context ctx = {0};
pretty_print_commit(CMIT_FMT_ONELINE, commit,
&buf, 0, NULL, NULL, 0, 0);
&buf, &ctx);
printf("%c %s %s\n", sign,
sha1_to_hex(commit->object.sha1), buf.buf);
strbuf_release(&buf);
Expand Down
7 changes: 5 additions & 2 deletions builtin-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ static void squash_message(void)
struct strbuf out = STRBUF_INIT;
struct commit_list *j;
int fd;
struct pretty_print_context ctx = {0};

printf("Squash commit -- not updating HEAD\n");
fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666);
Expand All @@ -285,13 +286,15 @@ static void squash_message(void)
if (prepare_revision_walk(&rev))
die("revision walk setup failed");

ctx.abbrev = rev.abbrev;
ctx.date_mode = rev.date_mode;

strbuf_addstr(&out, "Squashed commit of the following:\n");
while ((commit = get_revision(&rev)) != NULL) {
strbuf_addch(&out, '\n');
strbuf_addf(&out, "commit %s\n",
sha1_to_hex(commit->object.sha1));
pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
NULL, NULL, rev.date_mode, 0);
pretty_print_commit(rev.commit_format, commit, &out, &ctx);
}
if (write(fd, out.buf, out.len) < 0)
die_errno("Writing SQUASH_MSG");
Expand Down
7 changes: 4 additions & 3 deletions builtin-rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ static void show_commit(struct commit *commit, void *data)

if (revs->verbose_header && commit->buffer) {
struct strbuf buf = STRBUF_INIT;
pretty_print_commit(revs->commit_format, commit,
&buf, revs->abbrev, NULL, NULL,
revs->date_mode, 0);
struct pretty_print_context ctx = {0};
ctx.abbrev = revs->abbrev;
ctx.date_mode = revs->date_mode;
pretty_print_commit(revs->commit_format, commit, &buf, &ctx);
if (revs->graph) {
if (buf.len) {
if (revs->commit_format != CMIT_FMT_ONELINE)
Expand Down
9 changes: 6 additions & 3 deletions builtin-shortlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
sha1_to_hex(commit->object.sha1));
if (log->user_format) {
struct strbuf buf = STRBUF_INIT;

pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &buf,
DEFAULT_ABBREV, "", "", DATE_NORMAL, 0);
struct pretty_print_context ctx = {0};
ctx.abbrev = DEFAULT_ABBREV;
ctx.subject = "";
ctx.after_subject = "";
ctx.date_mode = DATE_NORMAL;
pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &buf, &ctx);
insert_one_record(log, author, buf.buf);
strbuf_release(&buf);
return;
Expand Down
4 changes: 2 additions & 2 deletions builtin-show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ static void show_one_commit(struct commit *commit, int no_name)
struct commit_name *name = commit->util;

if (commit->object.parsed) {
pretty_print_commit(CMIT_FMT_ONELINE, commit,
&pretty, 0, NULL, NULL, 0, 0);
struct pretty_print_context ctx = {0};
pretty_print_commit(CMIT_FMT_ONELINE, commit, &pretty, &ctx);
pretty_str = pretty.buf;
}
if (!prefixcmp(pretty_str, "[PATCH] "))
Expand Down
20 changes: 14 additions & 6 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ enum cmit_fmt {
CMIT_FMT_UNSPECIFIED,
};

struct pretty_print_context
{
int abbrev;
const char *subject;
const char *after_subject;
enum date_mode date_mode;
int need_8bit_cte;
struct reflog_walk_info *reflog_info;
};

extern int non_ascii(int);
extern int has_non_ascii(const char *text);
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
Expand All @@ -71,12 +81,10 @@ extern char *reencode_commit_message(const struct commit *commit,
extern void get_commit_format(const char *arg, struct rev_info *);
extern void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
enum date_mode dmode);
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,
struct strbuf *,
int abbrev, const char *subject,
const char *after_subject, enum date_mode,
int need_8bit_cte);
const struct pretty_print_context *context);
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
struct strbuf *sb,
const struct pretty_print_context *context);
void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
const char *line, enum date_mode dmode,
const char *encoding);
Expand Down
8 changes: 1 addition & 7 deletions git-stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ have_stash () {

list_stash () {
have_stash || return 0
git log --no-color --pretty=oneline -g "$@" $ref_stash -- |
sed -n -e 's/^[.0-9a-f]* refs\///p'
git log --format="%gd: %gs" -g "$@" $ref_stash --
}

show_stash () {
Expand Down Expand Up @@ -383,11 +382,6 @@ test -n "$seen_non_option" || set "save" "$@"
case "$1" in
list)
shift
if test $# = 0
then
set x -n 10
shift
fi
list_stash "$@"
;;
show)
Expand Down
25 changes: 14 additions & 11 deletions log-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
if (commit) {
int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
struct pretty_print_context ctx = {0};
ctx.date_mode = DATE_NORMAL;

format_commit_message(commit, "%f", buf, DATE_NORMAL);
format_commit_message(commit, "%f", buf, &ctx);
if (max_len < buf->len)
strbuf_setlen(buf, max_len);
strbuf_addstr(buf, suffix);
Expand Down Expand Up @@ -277,10 +279,9 @@ void show_log(struct rev_info *opt)
struct strbuf msgbuf = STRBUF_INIT;
struct log_info *log = opt->loginfo;
struct commit *commit = log->commit, *parent = log->parent;
int abbrev = opt->diffopt.abbrev;
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
const char *subject = NULL, *extra_headers = opt->extra_headers;
int need_8bit_cte = 0;
const char *extra_headers = opt->extra_headers;
struct pretty_print_context ctx = {0};

opt->loginfo = NULL;
if (!opt->verbose_header) {
Expand Down Expand Up @@ -347,8 +348,8 @@ void show_log(struct rev_info *opt)
*/

if (opt->commit_format == CMIT_FMT_EMAIL) {
log_write_email_headers(opt, commit, &subject, &extra_headers,
&need_8bit_cte);
log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
&ctx.need_8bit_cte);
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
if (opt->commit_format != CMIT_FMT_ONELINE)
Expand Down Expand Up @@ -405,11 +406,13 @@ void show_log(struct rev_info *opt)
/*
* And then the pretty-printed message itself
*/
if (need_8bit_cte >= 0)
need_8bit_cte = has_non_ascii(opt->add_signoff);
pretty_print_commit(opt->commit_format, commit, &msgbuf,
abbrev, subject, extra_headers, opt->date_mode,
need_8bit_cte);
if (ctx.need_8bit_cte >= 0)
ctx.need_8bit_cte = has_non_ascii(opt->add_signoff);
ctx.date_mode = opt->date_mode;
ctx.abbrev = opt->diffopt.abbrev;
ctx.after_subject = extra_headers;
ctx.reflog_info = opt->reflog_info;
pretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx);

if (opt->add_signoff)
append_signoff(&msgbuf, opt->add_signoff);
Expand Down
Loading

0 comments on commit 5f809ff

Please sign in to comment.