{"thread":{"id":"23594","subject":"[PATCH 0/3] pretty: format aliases","startedAt":"2010-04-25T15:42:52Z","lastAt":"2010-04-27T01:25:55Z","messageCount":16,"participants":["Will Palmer","Jeff King","Jonathan Nieder","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"140339","messageId":"1272210175-20484-1-git-send-email-wmpalmer@gmail.com","threadId":"23594","inReplyTo":null,"subject":"[PATCH 0/3] pretty: format aliases","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-04-25T15:42:52Z","receivedAt":"2010-04-25T15:42:52Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"The following patch series adds the ability to configure aliases for\nuser-defined formats. The first two patches define new placeholders and\nmodify the output of existing placeholders to allow aliases to be more\nconsistent with the way builtin formats are handled. The final patch\nadds support for the aliases themselves.\n\nThere were a couple of places where I wasn't entirely sure about which\ncolor setting I should be following, but I've tried to be consistent\nthroughout. It may be that I could have simply followed diffopt's color\noption in all cases, in which case various modifications to show_log()\nwere entirely unnecessary. I'll await judgement at the hands of one who\ngroks those sections more than I do, but I think what I've done feels\ncorrect.\n\nMy original goal was to make it possible to define all of the builtin\nformats as builtin aliases to format strings, but complications\nregarding how --parents and --decorate would be handled require further\nthought and discussion. For example, we could simply make\n\"--format=%H --decorate\" synonymous with \"--format=%H%d\", but I'm not\nsure if that feels clean enough.\n\nFor now, I think this is at a point where its good-enough to submit, if\nonly as a starting point for some discussion as to where to head next.\n\nWill Palmer (3):\n  pretty: add conditional %C?colorname placeholders\n  pretty: make %H/%h dependent on --abbrev[-commit]\n  pretty: add aliases for pretty formats\n\n Documentation/config.txt         |    8 ++\n Documentation/pretty-formats.txt |    1 +\n builtin/log.c                    |    2 +-\n builtin/rev-list.c               |    2 +\n builtin/shortlog.c               |    7 +-\n builtin/show-branch.c            |    1 +\n combine-diff.c                   |   11 +-\n commit.h                         |    2 +\n log-tree.c                       |   11 ++-\n log-tree.h                       |    2 +-\n pretty.c                         |  248 ++++++++++++++++++++++++++++++--------\n shortlog.h                       |    2 +-\n t/t4205-log-pretty-formats.sh    |   87 +++++++++++++\n 13 files changed, 321 insertions(+), 63 deletions(-)\n create mode 100755 t/t4205-log-pretty-formats.sh\n"},{"id":"140340","messageId":"1272210175-20484-2-git-send-email-wmpalmer@gmail.com","threadId":"23594","inReplyTo":"1272210175-20484-1-git-send-email-wmpalmer@gmail.com","subject":"[PATCH 1/3] pretty: add conditional %C?colorname placeholders","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-04-25T15:42:53Z","receivedAt":"2010-04-25T15:42:53Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"Many commands are able to colorize, or not, depending on a user's\nconfiguration and whether output is being sent to a terminal. However,\nif a user explicitly specifies a --pretty format, color will always be\noutput, regardless of the destination. This would generally be okay, in\na \"do what I tell you, whether or not I should tell you to\" sense, but\nthe assumption fell apart when an alias was defined which may be run in\nvarious contexts: there was no way to specify \"use this color, but only\nif you normally would display color at all\"\n\nHere we add the %C?colorname placeholders which act just as the\n%Ccolorname placeholders, with the exception that the pretty_context is\nchecked to see if color should be used according to configuration\n\nSigned-off-by: Will Palmer <wmpalmer@gmail.com>\n---\n Documentation/pretty-formats.txt |    1 +\n builtin/log.c                    |    2 +-\n builtin/rev-list.c               |    1 +\n builtin/shortlog.c               |    5 ++-\n builtin/show-branch.c            |    1 +\n combine-diff.c                   |   11 +++++---\n commit.h                         |    1 +\n log-tree.c                       |    9 ++++--\n log-tree.h                       |    2 +-\n pretty.c                         |   49 ++++++++++++++++++++++++-------------\n shortlog.h                       |    2 +-\n t/t4205-log-pretty-formats.sh    |   44 ++++++++++++++++++++++++++++++++++\n 12 files changed, 99 insertions(+), 29 deletions(-)\n create mode 100755 t/t4205-log-pretty-formats.sh\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex 1686a54..53eb903 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -132,6 +132,7 @@ The placeholders are:\n - '%Cblue': switch color to blue\n - '%Creset': reset color\n - '%C(...)': color specification, as described in color.branch.* config option\n+- '%C?...: switch to specified color, if relevant color.* config option specifies that color is ok\n - '%m': left, right or boundary mark\n - '%n': newline\n - '%%': a raw '%'\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 6208703..a9fc6ea 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -740,7 +740,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \tlog.in1 = 2;\n \tlog.in2 = 4;\n \tfor (i = 0; i < nr; i++)\n-\t\tshortlog_add_commit(&log, list[i]);\n+\t\tshortlog_add_commit(&log, list[i], rev);\n \n \tshortlog_output(&log);\n \ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 51ceb19..5a53862 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -99,6 +99,7 @@ static void show_commit(struct commit *commit, void *data)\n \t\tstruct pretty_print_context ctx = {0};\n \t\tctx.abbrev = revs->abbrev;\n \t\tctx.date_mode = revs->date_mode;\n+\t\tctx.use_color = DIFF_OPT_TST(&revs->diffopt, COLOR_DIFF);\n \t\tpretty_print_commit(revs->commit_format, commit, &buf, &ctx);\n \t\tif (revs->graph) {\n \t\t\tif (buf.len) {\ndiff --git a/builtin/shortlog.c b/builtin/shortlog.c\nindex 06320f5..7aee491 100644\n--- a/builtin/shortlog.c\n+++ b/builtin/shortlog.c\n@@ -136,13 +136,14 @@ static void read_from_stdin(struct shortlog *log)\n \t}\n }\n \n-void shortlog_add_commit(struct shortlog *log, struct commit *commit)\n+void shortlog_add_commit(struct shortlog *log, struct commit *commit, struct rev_info *rev)\n {\n \tconst char *author = NULL, *buffer;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct strbuf ufbuf = STRBUF_INIT;\n \tstruct pretty_print_context ctx = {0};\n \n+\tctx.use_color = DIFF_OPT_TST(&rev->diffopt, COLOR_DIFF);\n \tpretty_print_commit(CMIT_FMT_RAW, commit, &buf, &ctx);\n \tbuffer = buf.buf;\n \twhile (*buffer && *buffer != '\\n') {\n@@ -183,7 +184,7 @@ static void get_from_rev(struct rev_info *rev, struct shortlog *log)\n \tif (prepare_revision_walk(rev))\n \t\tdie(\"revision walk setup failed\");\n \twhile ((commit = get_revision(rev)) != NULL)\n-\t\tshortlog_add_commit(log, commit);\n+\t\tshortlog_add_commit(log, commit, rev);\n }\n \n static int parse_uint(char const **arg, int comma, int defval)\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex e20fcf3..e324336 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -294,6 +294,7 @@ static void show_one_commit(struct commit *commit, int no_name)\n \n \tif (commit->object.parsed) {\n \t\tstruct pretty_print_context ctx = {0};\n+\t\tctx.use_color = showbranch_use_color;\n \t\tpretty_print_commit(CMIT_FMT_ONELINE, commit, &pretty, &ctx);\n \t\tpretty_str = pretty.buf;\n \t}\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 3480dae..5157c62 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -841,7 +841,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\tint deleted = 0;\n \n \t\tif (rev->loginfo && !rev->no_commit_id)\n-\t\t\tshow_log(rev);\n+\t\t\tshow_log(rev, use_color);\n \t\tdump_quoted_path(dense ? \"diff --cc \" : \"diff --combined \",\n \t\t\t\t \"\", elem->path, c_meta, c_reset);\n \t\tprintf(\"%sindex \", c_meta);\n@@ -923,8 +923,10 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re\n \tif (!line_termination)\n \t\tinter_name_termination = 0;\n \n-\tif (rev->loginfo && !rev->no_commit_id)\n-\t\tshow_log(rev);\n+\tif (rev->loginfo && !rev->no_commit_id) {\n+\t\tint use_color = DIFF_OPT_TST(opt, COLOR_DIFF);\n+\t\tshow_log(rev, use_color);\n+\t}\n \n \tif (opt->output_format & DIFF_FORMAT_RAW) {\n \t\toffset = strlen(COLONS) - num_parent;\n@@ -1005,7 +1007,8 @@ void diff_tree_combined(const unsigned char *sha1,\n \t\tpaths = intersect_paths(paths, i, num_parent);\n \n \t\tif (show_log_first && i == 0) {\n-\t\t\tshow_log(rev);\n+\t\t\tint use_color = DIFF_OPT_TST(opt, COLOR_DIFF);\n+\t\t\tshow_log(rev, use_color);\n \t\t\tif (rev->verbose_header && opt->output_format)\n \t\t\t\tputchar(opt->line_termination);\n \t\t}\ndiff --git a/commit.h b/commit.h\nindex 26ec8c0..b6caf91 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -71,6 +71,7 @@ struct pretty_print_context\n \tenum date_mode date_mode;\n \tint need_8bit_cte;\n \tint show_notes;\n+\tint use_color;\n \tstruct reflog_walk_info *reflog_info;\n };\n \ndiff --git a/log-tree.c b/log-tree.c\nindex d3ae969..b743c43 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -274,7 +274,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n \t*extra_headers_p = extra_headers;\n }\n \n-void show_log(struct rev_info *opt)\n+void show_log(struct rev_info *opt, int use_color)\n {\n \tstruct strbuf msgbuf = STRBUF_INIT;\n \tstruct log_info *log = opt->loginfo;\n@@ -282,6 +282,7 @@ void show_log(struct rev_info *opt)\n \tint abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;\n \tconst char *extra_headers = opt->extra_headers;\n \tstruct pretty_print_context ctx = {0};\n+\tctx.use_color = use_color;\n \n \topt->loginfo = NULL;\n \tctx.show_notes = opt->show_notes;\n@@ -457,12 +458,13 @@ int log_tree_diff_flush(struct rev_info *opt)\n \t}\n \n \tif (opt->loginfo && !opt->no_commit_id) {\n+\t\tint use_color = DIFF_OPT_TST(&opt->diffopt, COLOR_DIFF);\n \t\t/* When showing a verbose header (i.e. log message),\n \t\t * and not in --pretty=oneline format, we would want\n \t\t * an extra newline between the end of log and the\n \t\t * output for readability.\n \t\t */\n-\t\tshow_log(opt);\n+\t\tshow_log(opt, use_color);\n \t\tif ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&\n \t\t    opt->verbose_header &&\n \t\t    opt->commit_format != CMIT_FMT_ONELINE) {\n@@ -559,8 +561,9 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \n \tshown = log_tree_diff(opt, commit, &log);\n \tif (!shown && opt->loginfo && opt->always_show_header) {\n+\t\tint use_color = DIFF_OPT_TST(&opt->diffopt, COLOR_DIFF);\n \t\tlog.parent = NULL;\n-\t\tshow_log(opt);\n+\t\tshow_log(opt, use_color);\n \t\tshown = 1;\n \t}\n \topt->loginfo = NULL;\ndiff --git a/log-tree.h b/log-tree.h\nindex 3f7b400..09f970e 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -11,7 +11,7 @@ void init_log_tree_opt(struct rev_info *);\n int log_tree_diff_flush(struct rev_info *);\n int log_tree_commit(struct rev_info *, struct commit *);\n int log_tree_opt_parse(struct rev_info *, const char **, int);\n-void show_log(struct rev_info *opt);\n+void show_log(struct rev_info *opt, int use_color);\n void show_decorations(struct rev_info *opt, struct commit *commit);\n void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n \t\t\t     const char **subject_p,\ndiff --git a/pretty.c b/pretty.c\nindex 7cb3a2a..fdb5e16 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -634,35 +634,50 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \tstruct format_commit_context *c = context;\n \tconst struct commit *commit = c->commit;\n \tconst char *msg = commit->buffer;\n+\tconst char *color_start;\n \tstruct commit_list *p;\n+\tint use_color = c->pretty_ctx->use_color;\n+\tint conditional_color = 0;\n \tint h1, h2;\n \n \t/* these are independent of the commit */\n \tswitch (placeholder[0]) {\n \tcase 'C':\n-\t\tif (placeholder[1] == '(') {\n+\t\tcolor_start = placeholder;\n+\t\tif (placeholder[1] == '?') {\n+\t\t\tcolor_start++;\n+\t\t\tconditional_color = 1;\n+\t\t}\n+\t\tif (color_start[1] == '(') {\n \t\t\tconst char *end = strchr(placeholder + 2, ')');\n \t\t\tchar color[COLOR_MAXLEN];\n \t\t\tif (!end)\n \t\t\t\treturn 0;\n-\t\t\tcolor_parse_mem(placeholder + 2,\n-\t\t\t\t\tend - (placeholder + 2),\n-\t\t\t\t\t\"--pretty format\", color);\n-\t\t\tstrbuf_addstr(sb, color);\n+\t\t\tif ( !conditional_color || use_color ) {\n+\t\t\t\tcolor_parse_mem(color_start + 2,\n+\t\t\t\t\t\tend - (color_start + 2),\n+\t\t\t\t\t\t\"--pretty format\", color);\n+\t\t\t\tstrbuf_addstr(sb, color);\n+\t\t\t}\n \t\t\treturn end - placeholder + 1;\n \t\t}\n-\t\tif (!prefixcmp(placeholder + 1, \"red\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_RED);\n-\t\t\treturn 4;\n-\t\t} else if (!prefixcmp(placeholder + 1, \"green\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_GREEN);\n-\t\t\treturn 6;\n-\t\t} else if (!prefixcmp(placeholder + 1, \"blue\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_BLUE);\n-\t\t\treturn 5;\n-\t\t} else if (!prefixcmp(placeholder + 1, \"reset\")) {\n-\t\t\tstrbuf_addstr(sb, GIT_COLOR_RESET);\n-\t\t\treturn 6;\n+\n+\t\tif (!prefixcmp(color_start + 1, \"red\")) {\n+\t\t\tif ( !conditional_color || use_color )\n+\t\t\t\tstrbuf_addstr(sb, GIT_COLOR_RED);\n+\t\t\treturn 4 + (conditional_color ? 1 : 0);\n+\t\t} else if (!prefixcmp(color_start + 1, \"green\")) {\n+\t\t\tif ( !conditional_color || use_color )\n+\t\t\t\tstrbuf_addstr(sb, GIT_COLOR_GREEN);\n+\t\t\treturn 6 + (conditional_color ? 1 : 0);\n+\t\t} else if (!prefixcmp(color_start + 1, \"blue\")) {\n+\t\t\tif ( !conditional_color || use_color )\n+\t\t\t\tstrbuf_addstr(sb, GIT_COLOR_BLUE);\n+\t\t\treturn 5 + (conditional_color ? 1 : 0);\n+\t\t} else if (!prefixcmp(color_start + 1, \"reset\")) {\n+\t\t\tif ( !conditional_color || use_color )\n+\t\t\t\tstrbuf_addstr(sb, GIT_COLOR_RESET);\n+\t\t\treturn 6 + (conditional_color ? 1 : 0);\n \t\t} else\n \t\t\treturn 0;\n \tcase 'n':\t\t/* newline */\ndiff --git a/shortlog.h b/shortlog.h\nindex bc02cc2..43498a0 100644\n--- a/shortlog.h\n+++ b/shortlog.h\n@@ -20,7 +20,7 @@ struct shortlog {\n \n void shortlog_init(struct shortlog *log);\n \n-void shortlog_add_commit(struct shortlog *log, struct commit *commit);\n+void shortlog_add_commit(struct shortlog *log, struct commit *commit, struct rev_info *rev);\n \n void shortlog_output(struct shortlog *log);\n \ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nnew file mode 100755\nindex 0000000..28d2948\n--- /dev/null\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -0,0 +1,44 @@\n+#!/bin/sh\n+#\n+# Released into Public Domain by Will Palmer 2010\n+#\n+\n+test_description='Test pretty formats'\n+. ./test-lib.sh\n+\n+test_expect_success \"set up basic repos\" \">foo && git add foo && git commit -m initial\"\n+\n+for flag in false true always; do\n+for color in red green blue reset; do\n+\n+\tmake_expected=\"git config --get-color no.such.slot $color >expected\"\n+\ttest_expect_success \"%C$color with color.ui $flag\" \\\n+\t\t\"$make_expected &&\n+\t\tgit config color.ui $flag &&\n+\t\tgit log -1 --pretty=format:'%C$color' > actual &&\n+\t\tcmp expected actual\"\n+\n+\n+\ttest_expect_success \"%C($color) with color.ui $flag\" \\\n+\t\t\"$make_expected &&\n+\t\tgit config color.ui $flag &&\n+\t\tgit log -1 --pretty=format:'%C($color)' > actual &&\n+\t\tcmp expected actual\"\n+\n+\t[ ! \"$flag\" = \"always\" ] && make_expected=\">expected\"\n+\ttest_expect_success \"%C?$color with color.ui $flag\" \\\n+\t\t\"$make_expected &&\n+\t\tgit config color.ui $flag &&\n+\t\tgit log -1 --pretty=format:'%C?$color' > actual &&\n+\t\tcmp expected actual\"\n+\n+\ttest_expect_success \"%C?($color) with color.ui $flag\" \\\n+\t\t\"$make_expected &&\n+\t\tgit config color.ui $flag &&\n+\t\tgit log -1 --pretty=format:'%C?($color)' > actual &&\n+\t\tcmp expected actual\"\n+\n+done\n+done\n+\n+test_done\n-- \n1.7.1.rc1.13.gbb0a0a.dirty\n"},{"id":"140342","messageId":"1272210175-20484-3-git-send-email-wmpalmer@gmail.com","threadId":"23594","inReplyTo":"1272210175-20484-1-git-send-email-wmpalmer@gmail.com","subject":"[PATCH 2/3] pretty: make %H/%h dependent on --abbrev[-commit]","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-04-25T15:42:54Z","receivedAt":"2010-04-25T15:42:54Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"Prior to this, the output of %H was always 40 characters long, and the\noutput of %h always DEFAULT_ABBREV characters long, without regard to\nwhether --abbrev-commit or --abbrev had been passed.\n\nHere we make \"git log --pretty=%H --abbrev-commit\" synonymous with\n\"git log --pretty=%h\", and make %h/abbreviated-%H respect the length\nspecified for --abbrev.\n\nThe same is applied to other commit-placeholders %P and %p, and\n--abbrev is respected for %t, though %T is not changed.\n\nSigned-off-by: Will Palmer <wmpalmer@gmail.com>\n---\n builtin/rev-list.c |    1 +\n builtin/shortlog.c |    2 ++\n commit.h           |    1 +\n log-tree.c         |    2 ++\n pretty.c           |   30 +++++++++++++++++++-----------\n 5 files changed, 25 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 5a53862..1d1e59c 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -98,6 +98,7 @@ static void show_commit(struct commit *commit, void *data)\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct pretty_print_context ctx = {0};\n \t\tctx.abbrev = revs->abbrev;\n+\t\tctx.abbrev_commit = revs->abbrev_commit;\n \t\tctx.date_mode = revs->date_mode;\n \t\tctx.use_color = DIFF_OPT_TST(&revs->diffopt, COLOR_DIFF);\n \t\tpretty_print_commit(revs->commit_format, commit, &buf, &ctx);\ndiff --git a/builtin/shortlog.c b/builtin/shortlog.c\nindex 7aee491..5c0721c 100644\n--- a/builtin/shortlog.c\n+++ b/builtin/shortlog.c\n@@ -143,6 +143,8 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit, struct rev\n \tstruct strbuf ufbuf = STRBUF_INIT;\n \tstruct pretty_print_context ctx = {0};\n \n+\tctx.abbrev = rev->abbrev;\n+\tctx.abbrev_commit = rev->abbrev_commit;\n \tctx.use_color = DIFF_OPT_TST(&rev->diffopt, COLOR_DIFF);\n \tpretty_print_commit(CMIT_FMT_RAW, commit, &buf, &ctx);\n \tbuffer = buf.buf;\ndiff --git a/commit.h b/commit.h\nindex b6caf91..7a476a0 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -72,6 +72,7 @@ struct pretty_print_context\n \tint need_8bit_cte;\n \tint show_notes;\n \tint use_color;\n+\tint abbrev_commit;\n \tstruct reflog_walk_info *reflog_info;\n };\n \ndiff --git a/log-tree.c b/log-tree.c\nindex b743c43..9bd4f47 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -282,6 +282,8 @@ void show_log(struct rev_info *opt, int use_color)\n \tint abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;\n \tconst char *extra_headers = opt->extra_headers;\n \tstruct pretty_print_context ctx = {0};\n+\tctx.abbrev = opt->abbrev;\n+\tctx.abbrev_commit = opt->abbrev_commit;\n \tctx.use_color = use_color;\n \n \topt->loginfo = NULL;\ndiff --git a/pretty.c b/pretty.c\nindex fdb5e16..f884f48 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -725,13 +725,16 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \n \tswitch (placeholder[0]) {\n \tcase 'H':\t\t/* commit hash */\n-\t\tstrbuf_addstr(sb, sha1_to_hex(commit->object.sha1));\n-\t\treturn 1;\n \tcase 'h':\t\t/* abbreviated commit hash */\n+\t\tif (placeholder[0] != 'h' && !c->pretty_ctx->abbrev_commit) {\n+\t\t\tstrbuf_addstr(sb, sha1_to_hex(commit->object.sha1));\n+\t\t\treturn 1;\n+\t\t}\n+\n \t\tif (add_again(sb, &c->abbrev_commit_hash))\n \t\t\treturn 1;\n \t\tstrbuf_addstr(sb, find_unique_abbrev(commit->object.sha1,\n-\t\t                                     DEFAULT_ABBREV));\n+\t\t\t\t\t\t     c->pretty_ctx->abbrev));\n \t\tc->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;\n \t\treturn 1;\n \tcase 'T':\t\t/* tree hash */\n@@ -741,24 +744,29 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \t\tif (add_again(sb, &c->abbrev_tree_hash))\n \t\t\treturn 1;\n \t\tstrbuf_addstr(sb, find_unique_abbrev(commit->tree->object.sha1,\n-\t\t                                     DEFAULT_ABBREV));\n+\t\t\t\t\t\t     c->pretty_ctx->abbrev));\n \t\tc->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;\n \t\treturn 1;\n \tcase 'P':\t\t/* parent hashes */\n-\t\tfor (p = commit->parents; p; p = p->next) {\n-\t\t\tif (p != commit->parents)\n-\t\t\t\tstrbuf_addch(sb, ' ');\n-\t\t\tstrbuf_addstr(sb, sha1_to_hex(p->item->object.sha1));\n-\t\t}\n-\t\treturn 1;\n \tcase 'p':\t\t/* abbreviated parent hashes */\n+\t\tif (placeholder[0] != 'p' && !c->pretty_ctx->abbrev_commit) {\n+\t\t\tfor (p = commit->parents; p; p = p->next) {\n+\t\t\t\tif (p != commit->parents)\n+\t\t\t\t\tstrbuf_addch(sb, ' ');\n+\t\t\t\tstrbuf_addstr(sb,\n+\t\t\t\t\t      sha1_to_hex(p->item->object.sha1));\n+\t\t\t}\n+\t\t\treturn 1;\n+\t\t}\n+\n \t\tif (add_again(sb, &c->abbrev_parent_hashes))\n \t\t\treturn 1;\n \t\tfor (p = commit->parents; p; p = p->next) {\n \t\t\tif (p != commit->parents)\n \t\t\t\tstrbuf_addch(sb, ' ');\n \t\t\tstrbuf_addstr(sb, find_unique_abbrev(\n-\t\t\t\t\tp->item->object.sha1, DEFAULT_ABBREV));\n+\t\t\t\t      p->item->object.sha1,\n+\t\t\t\t      c->pretty_ctx->abbrev));\n \t\t}\n \t\tc->abbrev_parent_hashes.len = sb->len -\n \t\t                              c->abbrev_parent_hashes.off;\n-- \n1.7.1.rc1.13.gbb0a0a.dirty\n"},{"id":"140341","messageId":"1272210175-20484-4-git-send-email-wmpalmer@gmail.com","threadId":"23594","inReplyTo":"1272210175-20484-1-git-send-email-wmpalmer@gmail.com","subject":"[PATCH 3/3] pretty: add aliases for pretty formats","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-04-25T15:42:55Z","receivedAt":"2010-04-25T15:42:55Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"previously the only ways to alias a --pretty format within git were\neither to set the format as your default format (via the format.pretty\nconfiguration variable), or by using a regular git alias. This left the\ndefinition of more complicated formats to the realm of \"builtin or\nnothing\", with user-defined formats usually being reserved for quick\none-offs.\n\nHere we allow user-defined formats to enjoy more or less the same\nbenefits of builtins. By defining format.pretty.myalias, \"myalias\" can\nbe used in place of whatever would normally come after --pretty=. This\ncan be a format:, tformat:, raw (ie, defaulting to tformat), or the name\nof another builtin or user-defined pretty format.\n\nSigned-off-by: Will Palmer <wmpalmer@gmail.com>\n---\n Documentation/config.txt      |    8 ++\n pretty.c                      |  169 +++++++++++++++++++++++++++++++++++------\n t/t4205-log-pretty-formats.sh |   53 ++++++++++++-\n 3 files changed, 202 insertions(+), 28 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 92f851e..6573d18 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -894,6 +894,14 @@ format.pretty::\n \tSee linkgit:git-log[1], linkgit:git-show[1],\n \tlinkgit:git-whatchanged[1].\n \n+format.pretty.<name>::\n+\tAlias for a --pretty= format string, as specified in\n+\tlinkgit:git-log[1]. Any aliases defined here can be used just\n+\tas the builtin pretty formats could. For example, defining\n+\t\"format.pretty.hash = format:%H\" would cause the invocation\n+\t\"git log --pretty=hash\" to be equivalent to running\n+\t\"git log --pretty=format:%H\".\n+\n format.thread::\n \tThe default threading style for 'git format-patch'.  Can be\n \ta boolean value, or `shallow` or `deep`.  `shallow` threading\ndiff --git a/pretty.c b/pretty.c\nindex f884f48..d49fec7 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -11,6 +11,16 @@\n #include \"reflog-walk.h\"\n \n static char *user_format;\n+static struct cmt_fmt_map {\n+\tconst char *name;\n+\tenum cmit_fmt format;\n+\tconst char *user_format;\n+\tint is_tformat;\n+\tint is_alias;\n+} *commit_formats = NULL;\n+static size_t commit_formats_len = 0;\n+static size_t commit_formats_alloc = 0;\n+static struct cmt_fmt_map *find_commit_format(const char *sought);\n \n static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)\n {\n@@ -21,22 +31,134 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma\n \trev->commit_format = CMIT_FMT_USERFORMAT;\n }\n \n-void get_commit_format(const char *arg, struct rev_info *rev)\n+static int git_pretty_formats_config(const char *var, const char *value, void *cb)\n+{\n+\tif (!prefixcmp(var, \"format.pretty.\")) {\n+\t\tstruct cmt_fmt_map user_format = {0};\n+\t\tconst char *fmt;\n+\n+\t\tuser_format.name = xstrdup(&var[14]);\n+\t\tuser_format.format = CMIT_FMT_USERFORMAT;\n+\t\tgit_config_string(&fmt, var, value);\n+\t\tif (!prefixcmp(fmt, \"format:\") || !prefixcmp(fmt, \"tformat:\")) {\n+\t\t\tuser_format.is_tformat = fmt[0] == 't';\n+\t\t\tfmt = strchr(fmt, ':') + 1;\n+\t\t} else if (strchr(fmt, '%'))\n+\t\t\tuser_format.is_tformat = 1;\n+\t\telse\n+\t\t\tuser_format.is_alias = 1;\n+\t\tuser_format.user_format = fmt;\n+\n+\t\tALLOC_GROW(commit_formats, commit_formats_len+1,\n+\t\t\t   commit_formats_alloc);\n+\t\tmemcpy(&commit_formats[ commit_formats_len ], &user_format,\n+\t\t       sizeof(user_format));\n+\t\tcommit_formats_len++;\n+\t}\n+\treturn 0;\n+}\n+\n+static void setup_commit_formats(void)\n {\n \tint i;\n-\tstatic struct cmt_fmt_map {\n-\t\tconst char *n;\n-\t\tsize_t cmp_len;\n-\t\tenum cmit_fmt v;\n-\t} cmt_fmts[] = {\n-\t\t{ \"raw\",\t1,\tCMIT_FMT_RAW },\n-\t\t{ \"medium\",\t1,\tCMIT_FMT_MEDIUM },\n-\t\t{ \"short\",\t1,\tCMIT_FMT_SHORT },\n-\t\t{ \"email\",\t1,\tCMIT_FMT_EMAIL },\n-\t\t{ \"full\",\t5,\tCMIT_FMT_FULL },\n-\t\t{ \"fuller\",\t5,\tCMIT_FMT_FULLER },\n-\t\t{ \"oneline\",\t1,\tCMIT_FMT_ONELINE },\n+\tconst char **attempted_aliases = NULL;\n+\tsize_t attempted_aliases_alloc = 0;\n+\tsize_t attempted_aliases_len;\n+\tstruct cmt_fmt_map builtin_formats[] = {\n+\t\t{ \"raw\",\tCMIT_FMT_RAW,\t\tNULL,\t0 },\n+\t\t{ \"medium\",\tCMIT_FMT_MEDIUM,\tNULL,\t0 },\n+\t\t{ \"short\",\tCMIT_FMT_SHORT,\t\tNULL,\t0 },\n+\t\t{ \"email\",\tCMIT_FMT_EMAIL,\t\tNULL,\t0 },\n+\t\t{ \"full\",\tCMIT_FMT_FULL,\t\tNULL,\t0 },\n+\t\t{ \"fuller\",\tCMIT_FMT_FULLER,\tNULL,\t0 },\n+\t\t{ \"oneline\",\tCMIT_FMT_ONELINE,\tNULL,\t1 }\n \t};\n+\tcommit_formats_len = ARRAY_SIZE(builtin_formats);\n+\tALLOC_GROW(commit_formats, commit_formats_len, commit_formats_alloc);\n+\tmemcpy(commit_formats, builtin_formats,\n+\t       sizeof(*builtin_formats)*ARRAY_SIZE(builtin_formats));\n+\n+\tgit_config(git_pretty_formats_config, NULL);\n+\n+\tfor (i = ARRAY_SIZE(builtin_formats); i < commit_formats_len; i++) {\n+\t\tattempted_aliases_len = 0;\n+\t\tstruct cmt_fmt_map *aliased_format = &commit_formats[i];\n+\t\tconst char *fmt = commit_formats[i].user_format;\n+\t\tint j;\n+\n+\t\tif (!commit_formats[i].is_alias)\n+\t\t\tcontinue;\n+\n+\t\twhile ((aliased_format = find_commit_format(fmt))) {\n+\t\t\tif (!aliased_format->is_alias)\n+\t\t\t\tbreak;\n+\n+\t\t\tfmt = aliased_format->user_format;\n+\t\t\tfor (j=0; j<attempted_aliases_len; j++) {\n+\t\t\t\tif (!strcmp(fmt, attempted_aliases[j])) {\n+\t\t\t\t\taliased_format = NULL;\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tif (!aliased_format)\n+\t\t\t\tbreak;\n+\n+\t\t\tALLOC_GROW(attempted_aliases, attempted_aliases_len+1,\n+\t\t\t\t   attempted_aliases_alloc);\n+\t\t\tattempted_aliases[attempted_aliases_len] = fmt;\n+\t\t\tattempted_aliases_len++;\n+\t\t}\n+\t\tif (aliased_format) {\n+\t\t\tcommit_formats[i].format = aliased_format->format;\n+\t\t\tcommit_formats[i].user_format = aliased_format->user_format;\n+\t\t\tcommit_formats[i].is_tformat = aliased_format->is_tformat;\n+\t\t\tcommit_formats[i].is_alias = 0;\n+\t\t} else\n+\t\t\tcommit_formats[i].format = CMIT_FMT_UNSPECIFIED;\n+\t}\n+}\n+\n+static struct cmt_fmt_map *find_commit_format(const char *sought)\n+{\n+\tstruct cmt_fmt_map *found = NULL;\n+\tsize_t found_match_len = 0;\n+\n+\tif (!commit_formats)\n+\t\tsetup_commit_formats();\n+\n+\tint i;\n+\tfor (i = 0; i < commit_formats_len; i++) {\n+\t\tconst char *candidate = commit_formats[i].name;\n+\t\tconst char *s = sought;\n+\t\tsize_t match_len = 0;\n+\n+\t\tif (commit_formats[i].format == CMIT_FMT_UNSPECIFIED)\n+\t\t\tcontinue;\n+\n+\t\tfor (; s++, candidate++;) {\n+\t\t\tif (!*candidate && *s) {\n+\t\t\t\tmatch_len = 0;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tif (!*candidate || !*s) {\n+\t\t\t\tmatch_len = s - sought;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tif (*s != *candidate) {\n+\t\t\t\tmatch_len = 0;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tif (match_len > found_match_len) {\n+\t\t\tfound = &commit_formats[i];\n+\t\t}\n+\t}\n+\treturn found;\n+}\n+\n+void get_commit_format(const char *arg, struct rev_info *rev)\n+{\n+\tstruct cmt_fmt_map *commit_format;\n \n \trev->use_terminator = 0;\n \tif (!arg || !*arg) {\n@@ -47,21 +169,22 @@ void get_commit_format(const char *arg, struct rev_info *rev)\n \t\tsave_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');\n \t\treturn;\n \t}\n-\tfor (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {\n-\t\tif (!strncmp(arg, cmt_fmts[i].n, cmt_fmts[i].cmp_len) &&\n-\t\t    !strncmp(arg, cmt_fmts[i].n, strlen(arg))) {\n-\t\t\tif (cmt_fmts[i].v == CMIT_FMT_ONELINE)\n-\t\t\t\trev->use_terminator = 1;\n-\t\t\trev->commit_format = cmt_fmts[i].v;\n-\t\t\treturn;\n-\t\t}\n-\t}\n+\n \tif (strchr(arg, '%')) {\n \t\tsave_user_format(rev, arg, 1);\n \t\treturn;\n \t}\n \n-\tdie(\"invalid --pretty format: %s\", arg);\n+\tcommit_format = find_commit_format(arg);\n+\tif( !commit_format )\n+\t\tdie(\"invalid --pretty format: %s\", arg);\n+\n+\trev->commit_format = commit_format->format;\n+\trev->use_terminator = commit_format->is_tformat;\n+\tif( commit_format->format == CMIT_FMT_USERFORMAT ){\n+\t\tsave_user_format(rev, commit_format->user_format,\n+\t\t\t\t commit_format->is_tformat);\n+\t}\n }\n \n /*\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex 28d2948..ee3e934 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -6,7 +6,15 @@\n test_description='Test pretty formats'\n . ./test-lib.sh\n \n-test_expect_success \"set up basic repos\" \">foo && git add foo && git commit -m initial\"\n+test_expect_success \"set up basic repos\" \\\n+\t\">foo &&\n+\t>bar &&\n+\tgit add foo &&\n+\ttest_tick &&\n+\tgit commit -m initial &&\n+\tgit add bar &&\n+\ttest_tick &&\n+\tgit commit -m 'add bar'\"\n \n for flag in false true always; do\n for color in red green blue reset; do\n@@ -16,29 +24,64 @@ for color in red green blue reset; do\n \t\t\"$make_expected &&\n \t\tgit config color.ui $flag &&\n \t\tgit log -1 --pretty=format:'%C$color' > actual &&\n-\t\tcmp expected actual\"\n+\t\ttest_cmp expected actual\"\n \n \n \ttest_expect_success \"%C($color) with color.ui $flag\" \\\n \t\t\"$make_expected &&\n \t\tgit config color.ui $flag &&\n \t\tgit log -1 --pretty=format:'%C($color)' > actual &&\n-\t\tcmp expected actual\"\n+\t\ttest_cmp expected actual\"\n \n \t[ ! \"$flag\" = \"always\" ] && make_expected=\">expected\"\n \ttest_expect_success \"%C?$color with color.ui $flag\" \\\n \t\t\"$make_expected &&\n \t\tgit config color.ui $flag &&\n \t\tgit log -1 --pretty=format:'%C?$color' > actual &&\n-\t\tcmp expected actual\"\n+\t\ttest_cmp expected actual\"\n \n \ttest_expect_success \"%C?($color) with color.ui $flag\" \\\n \t\t\"$make_expected &&\n \t\tgit config color.ui $flag &&\n \t\tgit log -1 --pretty=format:'%C?($color)' > actual &&\n-\t\tcmp expected actual\"\n+\t\ttest_cmp expected actual\"\n \n done\n done\n+test_expect_success \"reset color flags\" \"git config --unset color.ui\"\n+\n+test_expect_success \"alias builtin format\" \\\n+\t\"git log --pretty=oneline >expected &&\n+\tgit config format.pretty.test-alias oneline &&\n+\tgit log --pretty=test-alias >actual &&\n+\ttest_cmp expected actual\"\n+\n+test_expect_success \"alias user-defined format\" \\\n+\t\"git log --pretty='format:%h' >expected &&\n+\tgit config format.pretty.test-alias 'format:%h' &&\n+\tgit log --pretty=test-alias >actual &&\n+\ttest_cmp expected actual\"\n+\n+test_expect_success \"alias user-defined tformat\" \\\n+\t\"git log --pretty='tformat:%h' >expected &&\n+\tgit config format.pretty.test-alias 'tformat:%h' &&\n+\tgit log --pretty=test-alias >actual &&\n+\ttest_cmp expected actual\"\n+\n+test_expect_code 128 \"alias non-existant format\" \\\n+\t\"git config format.pretty.test-alias format-that-will-never-exist &&\n+\tgit log --pretty=test-alias\"\n+\n+test_expect_success \"alias of an alias\" \\\n+\t\"git log --pretty='tformat:%h' >expected &&\n+\tgit config format.pretty.test-foo 'tformat:%h' &&\n+\tgit config format.pretty.test-bar test-foo &&\n+\tgit log --pretty=test-bar >actual &&\n+\ttest_cmp expected actual\"\n+\n+test_expect_code 128 \"alias loop\" \\\n+\t\"git config format.pretty.test-foo test-bar &&\n+\tgit config format.pretty.test-bar test-foo &&\n+\tgit log --pretty=test-foo\"\n \n test_done\n-- \n1.7.1.rc1.13.gbb0a0a.dirty\n"},{"id":"140361","messageId":"20100425194800.GB14736@coredump.intra.peff.net","threadId":"23594","inReplyTo":"1272210175-20484-1-git-send-email-wmpalmer@gmail.com","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-04-25T19:48:00Z","receivedAt":"2010-04-25T19:48:00Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Apr 25, 2010 at 04:42:52PM +0100, Will Palmer wrote:\n\n> The following patch series adds the ability to configure aliases for\n> user-defined formats. The first two patches define new placeholders and\n> modify the output of existing placeholders to allow aliases to be more\n> consistent with the way builtin formats are handled. The final patch\n> adds support for the aliases themselves.\n\nInteresting idea. I think right now most people just want to use their\nformat with \"log\", so they would do something like:\n\n  git config alias.mylog \"log --format='...'\"\n\nYour method allows the same format to be used with multiple commands,\nwhich is more flexible. But I wonder how many people would find it\nuseful in practice. I can think of only \"log\" and \"show\" that I would\nreally want to share between.\n\nI skimmed your patches and have included a few comments below, as I\ndon't have time at the moment to do a thorough review.\n\n> There were a couple of places where I wasn't entirely sure about which\n> color setting I should be following, but I've tried to be consistent\n> throughout. It may be that I could have simply followed diffopt's color\n> option in all cases, in which case various modifications to show_log()\n> were entirely unnecessary. I'll await judgement at the hands of one who\n> groks those sections more than I do, but I think what I've done feels\n> correct.\n\nI think that makes some sense. The \"diff\" color option was the first,\nand so the commit-coloring in \"git log\" follows that already. So short\nof making a new \"color.log\" variable, that makes the most sense.\n\n> My original goal was to make it possible to define all of the builtin\n> formats as builtin aliases to format strings, but complications\n\nI like that goal. As you found out, it may be harder than you would\nlike. But the pretty-print code is IMHO a bit messy with conditionals,\nand most of it can now be expressed as much simpler user-formats.\n\n>   pretty: add conditional %C?colorname placeholders\n\nThis one seems reasonable overall.\n\n>   pretty: make %H/%h dependent on --abbrev[-commit]\n\nThis is really a variation on the first one. And there are more\nvariations, like %T/%t, %P/%p, etc. I'm a little hesitant to just change\nthe meaning of \"%H\", which has always explicitly meant the full sha1.\nShould we perhaps introduce some universal syntax for \"abbreviate if\n--abbrev was given, otherwise full sha1\". Like \"%?H\" as you did above,\nexcept that \"?\" doesn't really make sense.\n\n>   pretty: add aliases for pretty formats\n\nThe config variables format.* are traditionally about format-patch. I\nsee we have format.pretty these days, too. I'm not sure if that is a\ndeliberate attempt to make format.* more inclusive, or simply an error.\nIf the latter, we should probably not make it worse with\nformat.pretty.name.\n\n-Peff\n\nPS Welcome to the git list. It is nice to see a submission from a\nnewcomer who has clearly read SubmittingPatches, and that even has\nappropriate documentation and test updates. :)\n"},{"id":"140365","messageId":"g2r5b9751661004251340k862172bflc99106ed1cf20921@mail.gmail.com","threadId":"23594","inReplyTo":"20100425194800.GB14736@coredump.intra.peff.net","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-04-25T20:40:23Z","receivedAt":"2010-04-25T20:40:23Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"On Sun, Apr 25, 2010 at 8:48 PM, Jeff King <peff@peff.net> wrote:\n> On Sun, Apr 25, 2010 at 04:42:52PM +0100, Will Palmer wrote:\n> Interesting idea. I think right now most people just want to use their\n> format with \"log\", so they would do something like:\n>\n>  git config alias.mylog \"log --format='...'\"\n>\n> Your method allows the same format to be used with multiple commands,\n> which is more flexible. But I wonder how many people would find it\n> useful in practice. I can think of only \"log\" and \"show\" that I would\n> really want to share between.\n\nIndeed, this is what I do now, and I really wasn't expecting anyone to\nuse it for a command other than log. There are three main\njustifications:\n 1) I hope to eventually have all builtin formats converted to use\nthis mechanism, and this is a good stepping-stone.\n 2) defining a git alias to \"log\" when I really just want a shorter\nway to type a format has always felt horribly clunky to me.\n 3) it's so easy to add it's essentially free.\n\nas you might guess, #2 is what really started the itch, and #3 is what\nencouraged me to scratch it. #1 was more a side-effect when I realized\n(when first trying to implement things) that it's not how things are\ncurrently done.\n\n>\n> I skimmed your patches and have included a few comments below, as I\n> don't have time at the moment to do a thorough review.\n>\nThank you, any input is greatly appreciated.\n\n> I think that makes some sense. The \"diff\" color option was the first,\n> and so the commit-coloring in \"git log\" follows that already. So short\n> of making a new \"color.log\" variable, that makes the most sense.\n>\nfollowing the \"diff\" color seemed to be the right thing in most\nplaces, but for some things it looked as if there may be more-specific\nnot-diff-related color options being passed int, which is why I\nchanged the show_log() calls. Looking back over the patch now, it\nseems that the only place left which doesn't reference a rev_info\nstruct is show-branch.c, which doesn't even have a --format option. So\nI suppose that can all get ripped out and replaced with a single check\nof the diff options in  the next version of the patch.\n\n> This is really a variation on the first one. And there are more\n> variations, like %T/%t, %P/%p, etc. I'm a little hesitant to just change\n> the meaning of \"%H\", which has always explicitly meant the full sha1.\n> Should we perhaps introduce some universal syntax for \"abbreviate if\n> --abbrev was given, otherwise full sha1\". Like \"%?H\" as you did above,\n> except that \"?\" doesn't really make sense.\n>\nThis one I was also a bit iffy on, but in my mind the fact that %H\ncurrently completely ignores the --abbrev-commit option feels like a\nbug to me. One of those \"if it has no effect, there should be a\nwarning\", things.\nWe can at least be assured that as --abbrev[-commit] previously had no\neffect on --format options, that the only people who would have used\nthem together have probably been disappointed at the results, and did\nnot continue to do so.\nThere /are/ a couple of places in-code which use %H to fetch a\ncommit-hash-string, and I made sure to avoid modification of rev_info\nwhen I spotted that, but really that feels like something that should\nbe using a wrapper get_commit_hash_string() function.\n\n> The config variables format.* are traditionally about format-patch. I\n> see we have format.pretty these days, too. I'm not sure if that is a\n> deliberate attempt to make format.* more inclusive, or simply an error.\n> If the latter, we should probably not make it worse with\n> format.pretty.name.\n\nI was writing them as pretty.<name>, until I saw that format.pretty\nwas already there. I'm not sure which is the weirder of the two.\n\n>\n> -Peff\n>\n> PS Welcome to the git list. It is nice to see a submission from a\n> newcomer who has clearly read SubmittingPatches, and that even has\n> appropriate documentation and test updates. :)\n>\n\nNice to be welcome. You may have seen a test-run I did to get my\nconfidence up by submitting a two-line documentation change a week or\nso ago ;)\n-- \nWill Palmer\nwmpalmer@gmail.com\n"},{"id":"140371","messageId":"20100425220955.GA25620@progeny.tock","threadId":"23594","inReplyTo":"20100425194800.GB14736@coredump.intra.peff.net","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-04-25T22:09:55Z","receivedAt":"2010-04-25T22:09:55Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jeff King wrote:\n\n> The config variables format.* are traditionally about format-patch. I\n> see we have format.pretty these days, too.\n\nYes, it as added in commit v1.5.5-rc0~57^2 (log/show/whatchanged:\nintroduce format.pretty configuration, 2008-03-02):\n\n    When running log/show/whatchanged from the command line, the user may want\n    to use a preferred format without having to pass --pretty=<fmt> option\n    every time from the command line.  This teaches these three commands to\n    honor a new configuration variable, format.pretty.\n\n    The --pretty option given from the command line will override the \n    configured format.\n\nI use it to mess with line wrapping; that it’s possible is very nice.\nThanks, Renquan.\n\nJonathan\n"},{"id":"140390","messageId":"z2y81b0412b1004252330m189e68bcv19d7d1cb988820b6@mail.gmail.com","threadId":"23594","inReplyTo":"1272210175-20484-2-git-send-email-wmpalmer@gmail.com","subject":"Re: [PATCH 1/3] pretty: add conditional %C?colorname placeholders","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2010-04-26T06:30:55Z","receivedAt":"2010-04-26T06:30:55Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On Sun, Apr 25, 2010 at 17:42, Will Palmer <wmpalmer@gmail.com> wrote:\n> diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\n> index 1686a54..53eb903 100644\n> --- a/Documentation/pretty-formats.txt\n> +++ b/Documentation/pretty-formats.txt\n> @@ -132,6 +132,7 @@ The placeholders are:\n>  - '%Cblue': switch color to blue\n>  - '%Creset': reset color\n>  - '%C(...)': color specification, as described in color.branch.* config option\n> +- '%C?...: switch to specified color, if relevant color.* config option specifies that color is ok\n\nYou missed the closing quote character. Besides, how do you think to\ndistinguish between \"%C?diff.color\" and \"%C?diff.colorcontinuation text\"?\nThe \"%C(...)\" has a placeholde termination rule (the closing bracket), yours\ndoes not seem to have one (unless something is missing in the documentation).\n\nAh... I see. Definitely something missing. The spec should be: '%C?(...)'.\n"},{"id":"140396","messageId":"x2u5b9751661004260120t46494b18yea74c3f908b5742e@mail.gmail.com","threadId":"23594","inReplyTo":"r2o5b9751661004260113m7b6c387bm8467a063c13e5a0f@mail.gmail.com","subject":"Re: [PATCH 1/3] pretty: add conditional %C?colorname placeholders","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-04-26T08:20:07Z","receivedAt":"2010-04-26T08:20:07Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"On Mon, Apr 26, 2010 at 7:30 AM, Alex Riesen <raa.lkml@gmail.com> wrote:\n> On Sun, Apr 25, 2010 at 17:42, Will Palmer <wmpalmer@gmail.com> wrote:\n>> diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\n>> index 1686a54..53eb903 100644\n>> --- a/Documentation/pretty-formats.txt\n>> +++ b/Documentation/pretty-formats.txt\n>> @@ -132,6 +132,7 @@ The placeholders are:\n>>  - '%Cblue': switch color to blue\n>>  - '%Creset': reset color\n>>  - '%C(...)': color specification, as described in color.branch.* config option\n>> +- '%C?...: switch to specified color, if relevant color.* config option specifies that color is ok\n>\n> You missed the closing quote character. Besides, how do you think to\n> distinguish between \"%C?diff.color\" and \"%C?diff.colorcontinuation text\"?\n> The \"%C(...)\" has a placeholde termination rule (the closing bracket), yours\n> does not seem to have one (unless something is missing in the documentation).\n>\n> Ah... I see. Definitely something missing. The spec should be: '%C?(...)'.\n>\n\nIt's meant to handle both %C?green and %C?(green), perhaps I should\nlist those out on separate lines?\nMissing quote noted, thanks.\n"},{"id":"140428","messageId":"20100426172235.GA626@coredump.intra.peff.net","threadId":"23594","inReplyTo":"20100425220955.GA25620@progeny.tock","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-04-26T17:22:35Z","receivedAt":"2010-04-26T17:22:35Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Apr 25, 2010 at 05:09:55PM -0500, Jonathan Nieder wrote:\n\n> Jeff King wrote:\n> \n> > The config variables format.* are traditionally about format-patch. I\n> > see we have format.pretty these days, too.\n> \n> Yes, it as added in commit v1.5.5-rc0~57^2 (log/show/whatchanged:\n> introduce format.pretty configuration, 2008-03-02):\n> \n>     When running log/show/whatchanged from the command line, the user may want\n>     to use a preferred format without having to pass --pretty=<fmt> option\n>     every time from the command line.  This teaches these three commands to\n>     honor a new configuration variable, format.pretty.\n> \n>     The --pretty option given from the command line will override the \n>     configured format.\n> \n> I use it to mess with line wrapping; that it’s possible is very nice.\n> Thanks, Renquan.\n\nTo be clear, I don't have any problem with the _functionality_. I just\nthink it probably should have been log.pretty, or pretty.default or\nsomething. Too late now, though.\n\n-Peff\n"},{"id":"140430","messageId":"20100426175707.GB11022@progeny.tock","threadId":"23594","inReplyTo":"20100426172235.GA626@coredump.intra.peff.net","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-04-26T17:57:08Z","receivedAt":"2010-04-26T17:57:08Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jeff King wrote:\n\n> To be clear, I don't have any problem with the _functionality_. I just\n> think it probably should have been log.pretty, or pretty.default or\n> something. Too late now, though.\n\nAh, sorry to be dense.  Maybe something like the following would work:\n\n [log \"format\"]\n\tchangelog = \"* [%h] %s\"\n\nThis is rev-list’s code, and log is its most noticeable manifestation.\n\nBy the way: I just noticed today that rev-list is not very friendly\nwhen given a --pretty=format: specification:\n\n  $ git rev-list -1 --oneline HEAD\n  651b91e log --format=email: fix confusing variable name\n  $ git rev-list -1 --format='%h %s' HEAD\n  commit 651b91ef7a15a46145d65193c8709670b969161f\n  651b91e log --format=email: fix confusing variable name\n\nIs this deliberate?  I mention it because I seem to remember from the\ndiscussion of --decorate configuration that scripts should be using\nrev-list in preference to log even when a --format option is involved.\n\nJonathan\n"},{"id":"140436","messageId":"20100426180731.GB4012@coredump.intra.peff.net","threadId":"23594","inReplyTo":"20100426175707.GB11022@progeny.tock","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-04-26T18:07:32Z","receivedAt":"2010-04-26T18:07:32Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Apr 26, 2010 at 12:57:08PM -0500, Jonathan Nieder wrote:\n\n> > To be clear, I don't have any problem with the _functionality_. I just\n> > think it probably should have been log.pretty, or pretty.default or\n> > something. Too late now, though.\n> \n> Ah, sorry to be dense.  Maybe something like the following would work:\n> \n>  [log \"format\"]\n> \tchangelog = \"* [%h] %s\"\n\nWe usually reserve the [log \"format\"] for when \"format\" can be an\narbitrary string. I'm not sure if we can use some nicer syntax like\n[log.format]; I'd have to experiment.\n\n> This is rev-list’s code, and log is its most noticeable manifestation.\n\nWe also tend to refer to the log/show/whatchanged as \"the log family of\ncommands\". I think whatchanged is pretty much dead and historical at\nthis point, though.\n\n> By the way: I just noticed today that rev-list is not very friendly\n> when given a --pretty=format: specification:\n> \n>   $ git rev-list -1 --oneline HEAD\n>   651b91e log --format=email: fix confusing variable name\n>   $ git rev-list -1 --format='%h %s' HEAD\n>   commit 651b91ef7a15a46145d65193c8709670b969161f\n>   651b91e log --format=email: fix confusing variable name\n> \n> Is this deliberate?  I mention it because I seem to remember from the\n> discussion of --decorate configuration that scripts should be using\n> rev-list in preference to log even when a --format option is involved.\n\nI'm not sure it's deliberate, as in somebody thought it was a good idea.\nBut it has always been that way, and I think it has been deliberate that\nwe not change it. I agree it is unfriendly.\n\nI think we have accepted that scripts will use log because of its\nenhanced features (gitk does), but we generally suppress extra output\n(like decorations or notes) for at least --pretty=raw and\n--pretty=format.\n\n-Peff\n"},{"id":"140442","messageId":"20100426183755.GC11378@progeny.tock","threadId":"23594","inReplyTo":"20100426180731.GB4012@coredump.intra.peff.net","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-04-26T18:37:55Z","receivedAt":"2010-04-26T18:37:55Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jeff King wrote:\n> On Mon, Apr 26, 2010 at 12:57:08PM -0500, Jonathan Nieder wrote:\n\n>>  [log \"format\"]\n>> \tchangelog = \"* [%h] %s\"\n>\n> We usually reserve the [log \"format\"] for when \"format\" can be an\n> arbitrary string. I'm not sure if we can use some nicer syntax like\n> [log.format]; I'd have to experiment.\n\nAlternatively, we could use\n\n [logformat]\n\tchangelog = ...\n\nwhich is arguably just as clear and may be closer to existing\npractice.  But really, I am happy as long as the configuration exists.\n\nJonathan\n"},{"id":"140452","messageId":"1272316461.5368.4.camel@walleee","threadId":"23594","inReplyTo":"20100426183755.GC11378@progeny.tock","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-04-26T21:14:21Z","receivedAt":"2010-04-26T21:14:21Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"On Mon, 2010-04-26 at 13:37 -0500, Jonathan Nieder wrote:\n> Alternatively, we could use\n> \n>  [logformat]\n> \tchangelog = ...\n> \n> which is arguably just as clear and may be closer to existing\n> practice.  But really, I am happy as long as the configuration exists.\n> \n> Jonathan\n\nI like the one-level-of-hierarchy thing ([format \"pretty\"] is ugly for a\nnumber of reasons), but two problems with that specific name:\n - it says \"log\", while this effects more than the \"log\" command\n - it says \"format\", while this doesn't effect --format.\n\n[pretty]\n    changelog = ...\n\nis not taken, and my only hesitation there is that some other config\noption may want to be there. Still, it's what I'll call it in the next\nversion of the patch, unless there are specific objections. (which I\ncertainly may have already missed, as I've just switched mail clients\ntwice today)\n\n-- Will\n"},{"id":"140454","messageId":"20100426220049.GA15903@progeny.tock","threadId":"23594","inReplyTo":"1272316461.5368.4.camel@walleee","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-04-26T22:00:49Z","receivedAt":"2010-04-26T22:00:49Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Will Palmer wrote:\n\n> [pretty]\n>     changelog = ...\n\nFine by me. :)\n\n> On Mon, 2010-04-26 at 13:37 -0500, Jonathan Nieder wrote:\n\n>>  [logformat]\n>> \tchangelog = ...\n[...]\n> I like the one-level-of-hierarchy thing ([format \"pretty\"] is ugly for a\n> number of reasons), but two problems with that specific name:\n>  - it says \"log\", while this effects more than the \"log\" command\n>  - it says \"format\", while this doesn't effect --format.\n\nAh, but it does affect --format.  When Nanako wrote commit 3a4c1a5\n(Add --format that is a synonym to --pretty, 2009-02-24), the new\noption made me very happy.  And since then it has remained a synonym.\n\nCheers,\nJonathan\n"},{"id":"140466","messageId":"20100427012555.GB1844@coredump.intra.peff.net","threadId":"23594","inReplyTo":"20100426220049.GA15903@progeny.tock","subject":"Re: [PATCH 0/3] pretty: format aliases","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-04-27T01:25:55Z","receivedAt":"2010-04-27T01:25:55Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Apr 26, 2010 at 05:00:49PM -0500, Jonathan Nieder wrote:\n\n> Will Palmer wrote:\n> \n> > [pretty]\n> >     changelog = ...\n> \n> Fine by me. :)\n\nAlso my favorite of the suggestions.\n\n-Peff\n"}]}