{"thread":{"id":"18026","subject":"[RFC PATCH 1/4] Expose reflog_info struct in header","startedAt":"2009-02-26T04:44:03Z","lastAt":"2009-02-26T10:55:27Z","messageCount":7,"participants":["Deskin Miller","Johannes Schindelin","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"106287","messageId":"cover.1235622145.git.deskinm@umich.edu","threadId":"18026","inReplyTo":null,"subject":"[RFC PATCH 0/4] git log -g --pretty=format: learns about reflog","fromName":"Deskin Miller","fromEmail":"deskinm@umich.edu","sentAt":"2009-02-26T04:44:03Z","receivedAt":"2009-02-26T04:44:03Z","isPatch":true,"sender":{"key":"deskinm@umich.edu","avatar":"https://gravatar.com/avatar/d340a0e612cdf0a79535c71863c0b4c535e9aba63b42032226ae903e638b64f9?d=mp&s=160"},"body":"This series exposes reflog information to the pretty-printer when using\n--pretty=format: to git log -g and git rev-list --walk-reflogs, through\nsimilar format codes as are used currently.\n\nThomas Rast mentioned almost as an aside that this would be useful in \n\nhttp://article.gmane.org/gmane.comp.version-control.git/108009\n\nand I've wanted to hack this series for a long time, even before that\ncomment, but my first attempts broke stash horribly.  Hopefully this\nversion fares better.\n\nI'm a little leery of using commit->util to carry the reflog info, but I\ndidn't see a much better way, without altering the signature of\npretty_print_commit to take an optional reflog parameter.  The code\nchecks that util is not being used before assigning the reflog to it, so\nit shouldn't break any existing uses of util of which I am unaware.  I\nconfess to having not done an appropriate amount of research into\nwhether my use of util will actually break anything.  For what it's\nworth this patch series doesn't break any existing tests.\n\nOne of the things I was hoping to do in the unsuccessful version was to\nallow the revision walker to use the reflog, but let the commit\nstructures retain their real parents.  That way, one could still obtain\nmeaningful information from %p even when walking reflogs, which would be\ndistinct from %rp.  It is primarily with this in mind that %rp exists at\nall.  However, as I mentioned, my attempt to change the revision walker\nbroke existing tests, and I didn't have the wherewithal to discover how\nto correct it.  It's possible with the current series that one could\nsimply try to re-parse the commit, but I haven't investigated the\nfeasibility of doing that.\n\nI strongly suspect that there's a cleaner way to do this, but don't\nreally know what that would be, so any comments regarding alternate\napproaches would be very appreciated.  Also, I'm more than happy to\nwrite testcases and documentation once there is some agreement about\nwhat the preferred implementation is.\n\nDeskin Miller (4):\n  Expose reflog_info struct in header\n  Add attach_reflog_info\n  Attach reflog to commit prior to pretty-printing\n  Teach pretty-printer new reflog format codes\n\n list-objects.c |    3 +++\n log-tree.c     |    3 +++\n pretty.c       |   38 ++++++++++++++++++++++++++++++++++++++\n reflog-walk.c  |   26 +++++++++++++++++++-------\n reflog-walk.h  |   12 ++++++++++++\n 5 files changed, 75 insertions(+), 7 deletions(-)\n"},{"id":"106285","messageId":"2a946d8679c4f2065bd6965a2417cde74a049791.1235622145.git.deskinm@umich.edu","threadId":"18026","inReplyTo":"cover.1235622145.git.deskinm@umich.edu","subject":"[RFC PATCH 1/4] Expose reflog_info struct in header","fromName":"Deskin Miller","fromEmail":"deskinm@umich.edu","sentAt":"2009-02-26T04:44:04Z","receivedAt":"2009-02-26T04:44:04Z","isPatch":true,"sender":{"key":"deskinm@umich.edu","avatar":"https://gravatar.com/avatar/d340a0e612cdf0a79535c71863c0b4c535e9aba63b42032226ae903e638b64f9?d=mp&s=160"},"body":"The pretty-printing code needs to know this struct in order to print\nfields from it in log output.\n\nSigned-off-by: Deskin Miller <deskinm@umich.edu>\n---\n reflog-walk.c |    8 +-------\n reflog-walk.h |   10 ++++++++++\n 2 files changed, 11 insertions(+), 7 deletions(-)\n\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex f751fdc..dd172ae 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -8,13 +8,7 @@\n \n struct complete_reflogs {\n \tchar *ref;\n-\tstruct reflog_info {\n-\t\tunsigned char osha1[20], nsha1[20];\n-\t\tchar *email;\n-\t\tunsigned long timestamp;\n-\t\tint tz;\n-\t\tchar *message;\n-\t} *items;\n+\tstruct reflog_info *items;\n \tint nr, alloc;\n };\n \ndiff --git a/reflog-walk.h b/reflog-walk.h\nindex 7ca1438..7b00993 100644\n--- a/reflog-walk.h\n+++ b/reflog-walk.h\n@@ -1,6 +1,16 @@\n #ifndef REFLOG_WALK_H\n #define REFLOG_WALK_H\n \n+struct reflog_walk_info;\n+\n+struct reflog_info {\n+\tunsigned char osha1[20], nsha1[20];\n+\tchar *email;\n+\tunsigned long timestamp;\n+\tint tz;\n+\tchar *message;\n+};\n+\n extern void init_reflog_walk(struct reflog_walk_info** info);\n extern int add_reflog_for_walk(struct reflog_walk_info *info,\n \t\tstruct commit *commit, const char *name);\n-- \n1.6.2.rc0.90.g0753\n"},{"id":"106288","messageId":"dde2a04808e6791dafecfab811b6c55ba252c3c5.1235622145.git.deskinm@umich.edu","threadId":"18026","inReplyTo":"cover.1235622145.git.deskinm@umich.edu","subject":"[RFC PATCH 2/4] Add attach_reflog_info","fromName":"Deskin Miller","fromEmail":"deskinm@umich.edu","sentAt":"2009-02-26T04:44:05Z","receivedAt":"2009-02-26T04:44:05Z","isPatch":true,"sender":{"key":"deskinm@umich.edu","avatar":"https://gravatar.com/avatar/d340a0e612cdf0a79535c71863c0b4c535e9aba63b42032226ae903e638b64f9?d=mp&s=160"},"body":"To enable pretty-printing to print reflog information, the commit object\nneeds to carry its associated reflog entry.  This function uses the util\nfield to point to the appropriate struct reflog_info.\n\nSigned-off-by: Deskin Miller <deskinm@umich.edu>\n---\n reflog-walk.c |   18 ++++++++++++++++++\n reflog-walk.h |    2 ++\n 2 files changed, 20 insertions(+), 0 deletions(-)\n\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex dd172ae..3e8457f 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -235,6 +235,24 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)\n \tcommit->object.flags &= ~(ADDED | SEEN | SHOWN);\n }\n \n+void attach_reflog_info(struct reflog_walk_info *info, struct commit *commit)\n+{\n+\tif (info && info->last_commit_reflog) {\n+\t\tstruct commit_reflog *commit_reflog = info->last_commit_reflog;\n+\n+\t\tif (commit->util &&\n+\t\t    (((void *)(commit_reflog->reflogs->items\n+\t\t\t       + commit_reflog->reflogs->nr) < commit->util)\n+\t\t     || ((void *)(commit_reflog->reflogs->items +\n+\t\t\t\t  commit_reflog->recno + 1) > commit->util))) {\n+\t\t\tdie(\"commit->util being used, cannot attach reflog\");\n+\t\t}\n+\n+\t\tcommit->util = &commit_reflog->reflogs->items\n+\t\t\t[commit_reflog->recno+1];\n+\t}\n+}\n+\n void show_reflog_message(struct reflog_walk_info* info, int oneline,\n \tint relative_date)\n {\ndiff --git a/reflog-walk.h b/reflog-walk.h\nindex 7b00993..44f97e1 100644\n--- a/reflog-walk.h\n+++ b/reflog-walk.h\n@@ -16,6 +16,8 @@ extern int add_reflog_for_walk(struct reflog_walk_info *info,\n \t\tstruct commit *commit, const char *name);\n extern void fake_reflog_parent(struct reflog_walk_info *info,\n \t\tstruct commit *commit);\n+extern void attach_reflog_info(struct reflog_walk_info *info,\n+\t\tstruct commit *commit);\n extern void show_reflog_message(struct reflog_walk_info *info, int, int);\n \n #endif\n-- \n1.6.2.rc0.90.g0753\n"},{"id":"106286","messageId":"72f44a4e928e675ad11c6764c3231b0e150cd115.1235622145.git.deskinm@umich.edu","threadId":"18026","inReplyTo":"cover.1235622145.git.deskinm@umich.edu","subject":"[RFC PATCH 3/4] Attach reflog to commit prior to pretty-printing","fromName":"Deskin Miller","fromEmail":"deskinm@umich.edu","sentAt":"2009-02-26T04:44:06Z","receivedAt":"2009-02-26T04:44:06Z","isPatch":true,"sender":{"key":"deskinm@umich.edu","avatar":"https://gravatar.com/avatar/d340a0e612cdf0a79535c71863c0b4c535e9aba63b42032226ae903e638b64f9?d=mp&s=160"},"body":"Use attach_reflog_info just prior to pretty-printing the commit, so the\nreflog info may be printed if desired.\n\nSigned-off-by: Deskin Miller <deskinm@umich.edu>\n---\n list-objects.c |    3 +++\n log-tree.c     |    3 +++\n 2 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/list-objects.c b/list-objects.c\nindex c8b8375..fd9d23e 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -5,6 +5,7 @@\n #include \"blob.h\"\n #include \"diff.h\"\n #include \"tree-walk.h\"\n+#include \"reflog-walk.h\"\n #include \"revision.h\"\n #include \"list-objects.h\"\n \n@@ -146,6 +147,8 @@ void traverse_commit_list(struct rev_info *revs,\n \n \twhile ((commit = get_revision(revs)) != NULL) {\n \t\tprocess_tree(revs, commit->tree, &objects, NULL, \"\");\n+\t\tif (revs->reflog_info)\n+\t\t\tattach_reflog_info(revs->reflog_info, commit);\n \t\tshow_commit(commit);\n \t}\n \tfor (i = 0; i < revs->pending.nr; i++) {\ndiff --git a/log-tree.c b/log-tree.c\nindex 84a74e5..5ccca0e 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -387,6 +387,9 @@ void show_log(struct rev_info *opt)\n \t */\n \tif (need_8bit_cte >= 0)\n \t\tneed_8bit_cte = has_non_ascii(opt->add_signoff);\n+\tif (opt->reflog_info) {\n+\t\tattach_reflog_info(opt->reflog_info, commit);\n+\t}\n \tpretty_print_commit(opt->commit_format, commit, &msgbuf,\n \t\t\t    abbrev, subject, extra_headers, opt->date_mode,\n \t\t\t    need_8bit_cte);\n-- \n1.6.2.rc0.90.g0753\n"},{"id":"106289","messageId":"eee1f8e216d3813a1dce153dae58aeda5412c418.1235622145.git.deskinm@umich.edu","threadId":"18026","inReplyTo":"cover.1235622145.git.deskinm@umich.edu","subject":"[RFC PATCH 4/4] Teach pretty-printer new reflog format codes","fromName":"Deskin Miller","fromEmail":"deskinm@umich.edu","sentAt":"2009-02-26T04:44:07Z","receivedAt":"2009-02-26T04:44:07Z","isPatch":true,"sender":{"key":"deskinm@umich.edu","avatar":"https://gravatar.com/avatar/d340a0e612cdf0a79535c71863c0b4c535e9aba63b42032226ae903e638b64f9?d=mp&s=160"},"body":"By using %r<char>, one may obtain information from the reflog when\nusing --pretty=format in conjunction with git log -g or\ngit rev-list --walk-reflogs.  The following format codes are supported:\n\n%rp, %rP: abbreviated and full old commit hash\n%rm: reflog message\n%rn, %re, %rt, %rd, etc: all the formats that work for committer and\nauthor work with the reflog printer as well.\n\nSigned-off-by: Deskin Miller <deskinm@umich.edu>\n---\n pretty.c |   38 ++++++++++++++++++++++++++++++++++++++\n 1 files changed, 38 insertions(+), 0 deletions(-)\n\ndiff --git a/pretty.c b/pretty.c\nindex 6cd9149..9303958 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -7,6 +7,7 @@\n #include \"mailmap.h\"\n #include \"log-tree.h\"\n #include \"color.h\"\n+#include \"reflog-walk.h\"\n \n static char *user_format;\n \n@@ -544,6 +545,40 @@ static void format_decoration(struct strbuf *sb, const struct commit *commit)\n \t\tstrbuf_addch(sb, ')');\n }\n \n+static size_t format_reflog_item(struct strbuf *sb, void *util, char part,\n+\t\t\t\t enum date_mode dmode)\n+{\n+\tstruct reflog_info *reflog_info = (struct reflog_info *)util;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tssize_t ret;\n+\n+\tif (!util) {\n+\t\treturn 0;\n+\t}\n+\n+\tswitch (part) {\n+\tcase 'P':\n+\t\tstrbuf_addstr(sb, sha1_to_hex(reflog_info->osha1));\n+\t\treturn 2;\n+\tcase 'p':\t\t/* abbreviated commit hash */\n+\t\tstrbuf_addstr(sb, find_unique_abbrev(reflog_info->osha1,\n+\t\t\t\t\t\tDEFAULT_ABBREV));\n+\t\treturn 2;\n+\tcase 'm':\n+\t\t/* don't print trailing newline */\n+\t\tstrbuf_add(sb, reflog_info->message,\n+\t\t\t   strlen(reflog_info->message) - 1);\n+\t\treturn 2;\n+\t}\n+\n+\tstrbuf_addf(&buf, \"%s %lu %+04d\", reflog_info->email,\n+\t\treflog_info->timestamp, reflog_info->tz);\n+\tret = format_person_part(sb, part, buf.buf, buf.len, dmode);\n+\tstrbuf_release(&buf);\n+\treturn ret;\n+\n+}\n+\n static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n                                void *context)\n {\n@@ -650,6 +685,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n \tcase 'd':\n \t\tformat_decoration(sb, commit);\n \t\treturn 1;\n+\tcase 'r':\n+\t\treturn format_reflog_item(sb, commit->util, placeholder[1],\n+\t\t\t\t\tc->dmode);\n \t}\n \n \t/* For the rest we have to parse the commit header. */\n-- \n1.6.2.rc0.90.g0753\n"},{"id":"106312","messageId":"alpine.DEB.1.00.0902261125230.6258@intel-tinevez-2-302","threadId":"18026","inReplyTo":"cover.1235622145.git.deskinm@umich.edu","subject":"Re: [RFC PATCH 0/4] git log -g --pretty=format: learns about reflog","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-26T10:30:01Z","receivedAt":"2009-02-26T10:30:01Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 25 Feb 2009, Deskin Miller wrote:\n\n> I strongly suspect that there's a cleaner way to do this, but don't \n> really know what that would be, so any comments regarding alternate \n> approaches would be very appreciated.  Also, I'm more than happy to \n> write testcases and documentation once there is some agreement about \n> what the preferred implementation is.\n\n>From skimming your mail, I am not quite sure if I understand correctly \nwhat you want to do.  Is it that you want to be able to output the \n\"Reflog:\" and \"Reflog message:\" information that \"git log -g\" prints?\n\nIf so, I suggest expanding the signature of format_commit_message.\n\nEven better: define a \"struct format_commit_options\" a pointer to \nwhich gets passed around, and which should make the code cleaner \nanyway.\n\nYou could then put a pointer to the reflog_info into that struct.\n\nCiao,\nDscho\n"},{"id":"106315","messageId":"20090226105527.GC4226@coredump.intra.peff.net","threadId":"18026","inReplyTo":"cover.1235622145.git.deskinm@umich.edu","subject":"Re: [RFC PATCH 0/4] git log -g --pretty=format: learns about reflog","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-26T10:55:27Z","receivedAt":"2009-02-26T10:55:27Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 25, 2009 at 11:44:03PM -0500, Deskin Miller wrote:\n\n> I'm a little leery of using commit->util to carry the reflog info, but I\n> didn't see a much better way, without altering the signature of\n> pretty_print_commit to take an optional reflog parameter.  The code\n\nPersonally I am not opposed to some refactoring of the pretty_print\ncode. A few months ago I wanted to add a new pretty-printing\nfeature (it was keeping count of the total and printed patches, so you\ncould say something \"Patch %count/%total\"). Passing information around\nthrough all of the functions got quite burdensome, and I started a\nrefactoring to have a \"pretty_print_context\" that could be passed around\nand contain a lot of the pseudo-global variables.\n\nI didn't get very far before giving up and working on something else.\nBut my point is that any refactoring you do may end up helping other\nfeatures in the future.\n\nAs a side note, I also think figuring out what the formats look like by\nreading the pretty-print code is insane, because it is a mass of special\ncases and switch statements on format. I think it would be much more\nmanageable \"inside-out\": each format has its own primary function, and\nthe common stuff is factored out into helpers.\n\nBut that's just based on memory from a few months ago.\n\n-Peff\n"}]}