{"thread":{"id":"34622","subject":"[[TIG][PATCH v2] 1/3] Add log_select function to find commit from context in log view","startedAt":"2013-08-06T04:58:18Z","lastAt":"2013-08-06T23:05:34Z","messageCount":5,"participants":["Kumar Appaiah"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"224645","messageId":"1375765101-31461-1-git-send-email-a.kumar@alumni.iitm.ac.in","threadId":"34622","inReplyTo":null,"subject":"[[TIG][PATCH v2] 0/3] Refactoring the log view","fromName":"Kumar Appaiah","fromEmail":"a.kumar@alumni.iitm.ac.in","sentAt":"2013-08-06T04:58:18Z","receivedAt":"2013-08-06T04:58:18Z","isPatch":true,"sender":{"key":"a.kumar@alumni.iitm.ac.in","avatar":"https://gravatar.com/avatar/7ce299108bfff26792729bde4a1dd0638292f852a042d40a0a1991ff2ae58b0b?d=mp&s=160"},"body":"This is a second iteration. This handles the following:\n\n- remove unneeded comments\n- remove unneeded pager_request calls\n- rename update_commit_ref to recalculate_commit_context\n\nNow, the only thing missing is the recalculation of commits when the\nline number is changed. The trouble there is that using the :<n>\napproach doesn't call log_request, so we need to come up with a\nsmarter way to communicate the line number change, I guess.\n\nThanks for all the feedback!\n\nKumar Appaiah (3):\n  Add log_select function to find commit from context in log view\n  Display correct diff the context in split log view\n  Revert \"Scroll diff with arrow keys in log view\"\n\n NEWS  |  1 +\n tig.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------\n 2 files changed, 58 insertions(+), 7 deletions(-)\n\n-- \n1.8.3.2\n"},{"id":"224643","messageId":"1375765101-31461-2-git-send-email-a.kumar@alumni.iitm.ac.in","threadId":"34622","inReplyTo":"1375765101-31461-1-git-send-email-a.kumar@alumni.iitm.ac.in","subject":"[[TIG][PATCH v2] 1/3] Add log_select function to find commit from context in log view","fromName":"Kumar Appaiah","fromEmail":"a.kumar@alumni.iitm.ac.in","sentAt":"2013-08-06T04:58:19Z","receivedAt":"2013-08-06T04:58:19Z","isPatch":true,"sender":{"key":"a.kumar@alumni.iitm.ac.in","avatar":"https://gravatar.com/avatar/7ce299108bfff26792729bde4a1dd0638292f852a042d40a0a1991ff2ae58b0b?d=mp&s=160"},"body":"This commit introduces and uses the log_select function to find the\ncorrect commit in the unsplit log view. In the log view, if one\nscrolls down across a commit line, the current commit (as displayed in\nthe status bar) gets updated, but not so when scrolling upward across\na commit. The log_select function handles this scenario to do the\n``right thing''. In addition, it introduces the log_state structure as\nthe private entry of the log view to hold a flag that decides whether\nto re-evaluate the current commit based on scrolling.\n\nSigned-off-by: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>\n---\n tig.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 47 insertions(+), 3 deletions(-)\n\ndiff --git a/tig.c b/tig.c\nindex 4759f1d..845153f 100644\n--- a/tig.c\n+++ b/tig.c\n@@ -4383,6 +4383,35 @@ pager_select(struct view *view, struct line *line)\n \t}\n }\n \n+struct log_state {\n+\t/* We need to recalculate the previous commit, when the user\n+\t * scrolls up or uses the page up/down in the log\n+\t * view. recalculate_commit_context is used as a flag to\n+\t * indicate this. */\n+\tbool recalculate_commit_context;\n+};\n+\n+static void\n+log_select(struct view *view, struct line *line)\n+{\n+\tstruct log_state *state = view->private;\n+\n+\tif (state->recalculate_commit_context && line->lineno > 1) {\n+\t\tconst struct line *commit_line = find_prev_line_by_type(view, line, LINE_COMMIT);\n+\n+\t\tif (commit_line)\n+\t\t\tstring_copy_rev(view->ref, (char *) (commit_line->data + STRING_SIZE(\"commit \")));\n+\t}\n+\tif (line->type == LINE_COMMIT) {\n+\t\tchar *text = (char *)line->data + STRING_SIZE(\"commit \");\n+\n+\t\tif (!view_has_flags(view, VIEW_NO_REF))\n+\t\t\tstring_copy_rev(view->ref, text);\n+\t}\n+\tstring_copy_rev(ref_commit, view->ref);\n+\tstate->recalculate_commit_context = FALSE;\n+}\n+\n static bool\n pager_open(struct view *view, enum open_flags flags)\n {\n@@ -4426,11 +4455,26 @@ log_open(struct view *view, enum open_flags flags)\n static enum request\n log_request(struct view *view, enum request request, struct line *line)\n {\n+\tstruct log_state *state = (struct log_state *) view->private;\n+\n \tswitch (request) {\n \tcase REQ_REFRESH:\n \t\tload_refs();\n \t\trefresh_view(view);\n-\t\treturn REQ_NONE;\n+\t\treturn request;\n+\n+\tcase REQ_MOVE_UP:\n+\tcase REQ_PREVIOUS:\n+\t\tif (line->type == LINE_COMMIT && line->lineno > 1) {\n+\t\t\tstate->recalculate_commit_context = TRUE;\n+\t\t}\n+\t\treturn request;\n+\n+\tcase REQ_MOVE_PAGE_UP:\n+\tcase REQ_MOVE_PAGE_DOWN:\n+\t\tstate->recalculate_commit_context = TRUE;\n+\t\treturn request;\n+\n \tdefault:\n \t\treturn pager_request(view, request, line);\n \t}\n@@ -4440,13 +4484,13 @@ static struct view_ops log_ops = {\n \t\"line\",\n \t{ \"log\" },\n \tVIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_NO_PARENT_NAV,\n-\t0,\n+\tsizeof(struct log_state),\n \tlog_open,\n \tpager_read,\n \tpager_draw,\n \tlog_request,\n \tpager_grep,\n-\tpager_select,\n+\tlog_select,\n };\n \n struct diff_state {\n-- \n1.8.3.2\n"},{"id":"224644","messageId":"1375765101-31461-3-git-send-email-a.kumar@alumni.iitm.ac.in","threadId":"34622","inReplyTo":"1375765101-31461-1-git-send-email-a.kumar@alumni.iitm.ac.in","subject":"[[TIG][PATCH v2] 2/3] Display correct diff the context in split log view","fromName":"Kumar Appaiah","fromEmail":"a.kumar@alumni.iitm.ac.in","sentAt":"2013-08-06T04:58:20Z","receivedAt":"2013-08-06T04:58:20Z","isPatch":true,"sender":{"key":"a.kumar@alumni.iitm.ac.in","avatar":"https://gravatar.com/avatar/7ce299108bfff26792729bde4a1dd0638292f852a042d40a0a1991ff2ae58b0b?d=mp&s=160"},"body":"In the log view, when scrolling across a commit, the diff view should\nautomatically switch to the commit whose context the cursor is on in\nthe log view. This commit changes things to catch the REQ_ENTER in the\nlog view and handle recalculation of the commit and diff display from\nlog_request, rather than delegating it to pager_request. In addition,\nit also gets rid of unexpected upward scrolling of the log view.\n\nFixes GH #155\n\nSigned-Off-By: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>\n---\n NEWS  | 1 +\n tig.c | 9 ++++++++-\n 2 files changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/NEWS b/NEWS\nindex 076ac9d..1b0f737 100644\n--- a/NEWS\n+++ b/NEWS\n@@ -49,6 +49,7 @@ Bug fixes:\n  - Ignore unrepresentable characters when transliterating text for rendering.\n  - Transliterate text to output encoding before trimming it to avoid\n    misalignment. (GH #86)\n+ - Introduce a more natural context-sensitive log display. (GH #155)\n \n tig-1.1\n -------\ndiff --git a/tig.c b/tig.c\nindex 845153f..256b589 100644\n--- a/tig.c\n+++ b/tig.c\n@@ -4475,8 +4475,15 @@ log_request(struct view *view, enum request request, struct line *line)\n \t\tstate->recalculate_commit_context = TRUE;\n \t\treturn request;\n \n+\tcase REQ_ENTER:\n+\t\tstate->recalculate_commit_context = TRUE;\n+\t\tif (VIEW(REQ_VIEW_DIFF)->ref != ref_commit)\n+\t\t\topen_view(view, REQ_VIEW_DIFF, OPEN_SPLIT);\n+\t\tupdate_view_title(view);\n+\t\treturn request;\n+\n \tdefault:\n-\t\treturn pager_request(view, request, line);\n+\t\treturn request;\n \t}\n }\n \n-- \n1.8.3.2\n"},{"id":"224646","messageId":"1375765101-31461-4-git-send-email-a.kumar@alumni.iitm.ac.in","threadId":"34622","inReplyTo":"1375765101-31461-1-git-send-email-a.kumar@alumni.iitm.ac.in","subject":"[[TIG][PATCH v2] 3/3] Revert \"Scroll diff with arrow keys in log view\"","fromName":"Kumar Appaiah","fromEmail":"a.kumar@alumni.iitm.ac.in","sentAt":"2013-08-06T04:58:21Z","receivedAt":"2013-08-06T04:58:21Z","isPatch":true,"sender":{"key":"a.kumar@alumni.iitm.ac.in","avatar":"https://gravatar.com/avatar/7ce299108bfff26792729bde4a1dd0638292f852a042d40a0a1991ff2ae58b0b?d=mp&s=160"},"body":"This reverts commit 888611dd5d407775245d574a3dc5c01b5963a5ba. This is\nbecause, in the re-engineered log view, scrolling the log with the\narrows now updates the diff in the diff view when the screen is\nsplit. This resembles the earlier behaviour, and is also what users of\nsoftware like Mutt (which uses the pager view concept) would expect.\n\nSigned-Off-By: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>\n\nConflicts:\n\ttig.c\n---\n tig.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/tig.c b/tig.c\nindex 256b589..5f564a5 100644\n--- a/tig.c\n+++ b/tig.c\n@@ -1905,7 +1905,6 @@ enum view_flag {\n \tVIEW_STDIN\t\t= 1 << 8,\n \tVIEW_SEND_CHILD_ENTER\t= 1 << 9,\n \tVIEW_FILE_FILTER\t= 1 << 10,\n-\tVIEW_NO_PARENT_NAV\t= 1 << 11,\n };\n \n #define view_has_flags(view, flag)\t((view)->ops->flags & (flag))\n@@ -3773,7 +3772,7 @@ view_driver(struct view *view, enum request request)\n \n \tcase REQ_NEXT:\n \tcase REQ_PREVIOUS:\n-\t\tif (view->parent && !view_has_flags(view->parent, VIEW_NO_PARENT_NAV)) {\n+\t\tif (view->parent) {\n \t\t\tint line;\n \n \t\t\tview = view->parent;\n@@ -4490,7 +4489,7 @@ log_request(struct view *view, enum request request, struct line *line)\n static struct view_ops log_ops = {\n \t\"line\",\n \t{ \"log\" },\n-\tVIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_NO_PARENT_NAV,\n+\tVIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER,\n \tsizeof(struct log_state),\n \tlog_open,\n \tpager_read,\n-- \n1.8.3.2\n"},{"id":"224719","messageId":"20130806230534.GA11980@bluemoon.alumni.iitm.ac.in","threadId":"34622","inReplyTo":"1375765101-31461-3-git-send-email-a.kumar@alumni.iitm.ac.in","subject":"Re: [[TIG][PATCH v2] 2/3] Display correct diff the context in split log view","fromName":"Kumar Appaiah","fromEmail":"a.kumar@alumni.iitm.ac.in","sentAt":"2013-08-06T23:05:34Z","receivedAt":"2013-08-06T23:05:34Z","isPatch":true,"sender":{"key":"a.kumar@alumni.iitm.ac.in","avatar":"https://gravatar.com/avatar/7ce299108bfff26792729bde4a1dd0638292f852a042d40a0a1991ff2ae58b0b?d=mp&s=160"},"body":"On Tue, Aug 06, 2013 at 12:58:20AM -0400, Kumar Appaiah wrote:\n>  tig-1.1\n>  -------\n> diff --git a/tig.c b/tig.c\n> index 845153f..256b589 100644\n> --- a/tig.c\n> +++ b/tig.c\n> @@ -4475,8 +4475,15 @@ log_request(struct view *view, enum request request, struct line *line)\n>  \t\tstate->recalculate_commit_context = TRUE;\n>  \t\treturn request;\n>  \n> +\tcase REQ_ENTER:\n> +\t\tstate->recalculate_commit_context = TRUE;\n> +\t\tif (VIEW(REQ_VIEW_DIFF)->ref != ref_commit)\n> +\t\t\topen_view(view, REQ_VIEW_DIFF, OPEN_SPLIT);\n> +\t\tupdate_view_title(view);\n  \t\t^^^^^^^^^^^^^^^^^^^^^^^\n\nI missed removing update_view_title. I've done it locally, though.\n\nThanks.\n\nKumar\n\n> +\t\treturn request;\n> +\n>  \tdefault:\n> -\t\treturn pager_request(view, request, line);\n> +\t\treturn request;\n>  \t}\n>  }\n>  \n> -- \n> 1.8.3.2\n\n-- \nKumar Appaiah\n"}]}