{"thread":{"id":"32043","subject":"[PATCH] custom log formats for \"diff --submodule=log\"","startedAt":"2012-11-08T20:29:40Z","lastAt":"2012-11-12T22:19:01Z","messageCount":4,"participants":["Jeff King","Ramkumar Ramachandra"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"202667","messageId":"20121108202940.GA7982@sigill.intra.peff.net","threadId":"32043","inReplyTo":null,"subject":"[PATCH] custom log formats for \"diff --submodule=log\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-11-08T20:29:40Z","receivedAt":"2012-11-08T20:29:40Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"An off-list discussion made me wonder if something like this would be\nuseful:\n\n  git log -p --submodule=log:'  %m %an <%ae>: %s'\n\nwhere the format could be whatever you find useful.\n\nI do not use submodules myself, so writing the patch below was just a\nfun exercise. I'm not planning on polishing it for inclusion. But I\nthought I would publish it here in case anybody who is more interested\nfeels like picking it up. It would need documentation and tests at the\nvery least.\n\n---\ndiff --git a/diff.c b/diff.c\nindex 86e5f2a..f2adaca 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2241,7 +2241,7 @@ static void builtin_diff(const char *name_a,\n \t\tconst char *add = diff_get_color_opt(o, DIFF_FILE_NEW);\n \t\tshow_submodule_summary(o->file, one ? one->path : two->path,\n \t\t\t\tone->sha1, two->sha1, two->dirty_submodule,\n-\t\t\t\tdel, add, reset);\n+\t\t\t\tdel, add, reset, o->submodule_log_format);\n \t\treturn;\n \t}\n \n@@ -3654,8 +3654,13 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t} else if (!strcmp(arg, \"--submodule\"))\n \t\tDIFF_OPT_SET(options, SUBMODULE_LOG);\n \telse if (!prefixcmp(arg, \"--submodule=\")) {\n-\t\tif (!strcmp(arg + 12, \"log\"))\n+\t\tconst char *v = arg + 12;\n+\t\tif (!strcmp(v, \"log\"))\n \t\t\tDIFF_OPT_SET(options, SUBMODULE_LOG);\n+\t\telse if (!prefixcmp(v, \"log:\")) {\n+\t\t\tDIFF_OPT_SET(options, SUBMODULE_LOG);\n+\t\t\toptions->submodule_log_format = xstrdup(v + 4);\n+\t\t}\n \t}\n \n \t/* misc options */\ndiff --git a/diff.h b/diff.h\nindex a658f85..9726375 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -132,6 +132,8 @@ struct diff_options {\n \tconst char *stat_sep;\n \tlong xdl_opts;\n \n+\tchar *submodule_log_format;\n+\n \tint stat_width;\n \tint stat_name_width;\n \tint stat_graph_width;\ndiff --git a/submodule.c b/submodule.c\nindex e3e0b45..149bd87 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -217,12 +217,16 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,\n }\n \n static void print_submodule_summary(struct rev_info *rev, FILE *f,\n-\t\tconst char *del, const char *add, const char *reset)\n+\t\tconst char *del, const char *add, const char *reset,\n+\t\tconst char *format)\n {\n-\tstatic const char format[] = \"  %m %s\";\n+\tstatic const char default_format[] = \"  %m %s\";\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct commit *commit;\n \n+\tif (!format)\n+\t\tformat = default_format;\n+\n \twhile ((commit = get_revision(rev))) {\n \t\tstruct pretty_print_context ctx = {0};\n \t\tctx.date_mode = rev->date_mode;\n@@ -259,7 +263,8 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)\n void show_submodule_summary(FILE *f, const char *path,\n \t\tunsigned char one[20], unsigned char two[20],\n \t\tunsigned dirty_submodule,\n-\t\tconst char *del, const char *add, const char *reset)\n+\t\tconst char *del, const char *add, const char *reset,\n+\t\tconst char *format)\n {\n \tstruct rev_info rev;\n \tstruct commit *left = left, *right = right;\n@@ -304,7 +309,7 @@ void show_submodule_summary(FILE *f, const char *path,\n \tfwrite(sb.buf, sb.len, 1, f);\n \n \tif (!message) {\n-\t\tprint_submodule_summary(&rev, f, del, add, reset);\n+\t\tprint_submodule_summary(&rev, f, del, add, reset, format);\n \t\tclear_commit_marks(left, ~0);\n \t\tclear_commit_marks(right, ~0);\n \t}\ndiff --git a/submodule.h b/submodule.h\nindex f2e8271..49a7b75 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -21,7 +21,8 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);\n void show_submodule_summary(FILE *f, const char *path,\n \t\tunsigned char one[20], unsigned char two[20],\n \t\tunsigned dirty_submodule,\n-\t\tconst char *del, const char *add, const char *reset);\n+\t\tconst char *del, const char *add, const char *reset,\n+\t\tconst char *format);\n void set_config_fetch_recurse_submodules(int value);\n void check_for_new_submodule_commits(unsigned char new_sha1[20]);\n int fetch_populated_submodules(const struct argv_array *options,\n"},{"id":"202815","messageId":"CALkWK0mYs7Q1256gY7ZH3Ng3xbYv2+XVHCZ7XYWgWUp2O-VzqQ@mail.gmail.com","threadId":"32043","inReplyTo":"20121108202940.GA7982@sigill.intra.peff.net","subject":"Re: [PATCH] custom log formats for \"diff --submodule=log\"","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2012-11-11T11:26:12Z","receivedAt":"2012-11-11T11:26:12Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Peff,\n\nJeff King wrote:\n> An off-list discussion made me wonder if something like this would be\n> useful:\n>\n>   git log -p --submodule=log:'  %m %an <%ae>: %s'\n>\n> where the format could be whatever you find useful.\n\nInteresting.  Don't you mean `git diff` in place of `git log -p`\nthough?  I don't think `git log --submodule` does anything differently\nfrom `git log`.  Should this respect format.pretty?  Does it?\n\nRam\n"},{"id":"202826","messageId":"CALkWK0nT8RXXUUkLuS8zWVMG=wsm0b740q-qYb3iN3cO7Tb=0A@mail.gmail.com","threadId":"32043","inReplyTo":"CALkWK0mYs7Q1256gY7ZH3Ng3xbYv2+XVHCZ7XYWgWUp2O-VzqQ@mail.gmail.com","subject":"Re: [PATCH] custom log formats for \"diff --submodule=log\"","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2012-11-11T13:05:16Z","receivedAt":"2012-11-11T13:05:16Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi again,\n\nRamkumar Ramachandra wrote:\n> Don't you mean `git diff` in place of `git log -p`\n> though?  I don't think `git log --submodule` does anything differently\n> from `git log`.\n\nSorry for the nonsense.  I just realized that it affects the diffs\nshown by `git log -p`.\n\nRam\n"},{"id":"203009","messageId":"20121112221901.GD10531@sigill.intra.peff.net","threadId":"32043","inReplyTo":"CALkWK0nT8RXXUUkLuS8zWVMG=wsm0b740q-qYb3iN3cO7Tb=0A@mail.gmail.com","subject":"Re: [PATCH] custom log formats for \"diff --submodule=log\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-11-12T22:19:01Z","receivedAt":"2012-11-12T22:19:01Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 11, 2012 at 06:35:16PM +0530, Ramkumar Ramachandra wrote:\n\n> Ramkumar Ramachandra wrote:\n> > Don't you mean `git diff` in place of `git log -p`\n> > though?  I don't think `git log --submodule` does anything differently\n> > from `git log`.\n> \n> Sorry for the nonsense.  I just realized that it affects the diffs\n> shown by `git log -p`.\n\nRight. I don't know if that is a common workflow (I do not really use\nsubmodules), but it was the first thing I tried when I heard about\n--submodule (and it does make sense to me that it would work).\n\nBut the logic could apply equally well to:\n\n  git diff --submodule=log:%an\n\n-Peff\n"}]}