threads / patch / 34622

v21/3] Add log_select function to find commit from context in log view

Subject: [[TIG][PATCH v2] 1/3] Add log_select function to find commit from context in log view

## tl;dr

5 messages between Aug 6, 2013 and Aug 6, 2013. Diffs are folded; open one to read it.

replies: 4people: 1as markdown or json

Kumar Appaiah· Aug 6, 2013, 04:58 UTC · lore

[[TIG][PATCH v2] 0/3] Refactoring the log view

This is a second iteration. This handles the following:
- remove unneeded comments
- remove unneeded pager_request calls
- rename update_commit_ref to recalculate_commit_context

Now, the only thing missing is the recalculation of commits when the line number is changed. The trouble there is that using the :<n> approach doesn't call log_request, so we need to come up with a smarter way to communicate the line number change, I guess.

Thanks for all the feedback!
Kumar Appaiah (3):
  Add log_select function to find commit from context in log view
  Display correct diff the context in split log view
  Revert "Scroll diff with arrow keys in log view"
 NEWS  |  1 +
 tig.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 58 insertions(+), 7 deletions(-)
-- 
1.8.3.2
Kumar Appaiah· Aug 6, 2013, 04:58 UTC · re: Kumar Appaiah · lore

This commit introduces and uses the log_select function to find the correct commit in the unsplit log view. In the log view, if one scrolls down across a commit line, the current commit (as displayed in the status bar) gets updated, but not so when scrolling upward across a commit. The log_select function handles this scenario to do the ``right thing''. In addition, it introduces the log_state structure as the private entry of the log view to hold a flag that decides whether to re-evaluate the current commit based on scrolling.

Signed-off-by: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
---
 tig.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 3 deletions(-)
Show changes to tig.c +47 −3
diff --git a/tig.c b/tig.c
index 4759f1d..845153f 100644
--- a/tig.c
+++ b/tig.c
@@ -4383,6 +4383,35 @@ pager_select(struct view *view, struct line *line)
 	}
 }
 
+struct log_state {
+	/* We need to recalculate the previous commit, when the user
+	 * scrolls up or uses the page up/down in the log
+	 * view. recalculate_commit_context is used as a flag to
+	 * indicate this. */
+	bool recalculate_commit_context;
+};
+
+static void
+log_select(struct view *view, struct line *line)
+{
+	struct log_state *state = view->private;
+
+	if (state->recalculate_commit_context && line->lineno > 1) {
+		const struct line *commit_line = find_prev_line_by_type(view, line, LINE_COMMIT);
+
+		if (commit_line)
+			string_copy_rev(view->ref, (char *) (commit_line->data + STRING_SIZE("commit ")));
+	}
+	if (line->type == LINE_COMMIT) {
+		char *text = (char *)line->data + STRING_SIZE("commit ");
+
+		if (!view_has_flags(view, VIEW_NO_REF))
+			string_copy_rev(view->ref, text);
+	}
+	string_copy_rev(ref_commit, view->ref);
+	state->recalculate_commit_context = FALSE;
+}
+
 static bool
 pager_open(struct view *view, enum open_flags flags)
 {
@@ -4426,11 +4455,26 @@ log_open(struct view *view, enum open_flags flags)
 static enum request
 log_request(struct view *view, enum request request, struct line *line)
 {
+	struct log_state *state = (struct log_state *) view->private;
+
 	switch (request) {
 	case REQ_REFRESH:
 		load_refs();
 		refresh_view(view);
-		return REQ_NONE;
+		return request;
+
+	case REQ_MOVE_UP:
+	case REQ_PREVIOUS:
+		if (line->type == LINE_COMMIT && line->lineno > 1) {
+			state->recalculate_commit_context = TRUE;
+		}
+		return request;
+
+	case REQ_MOVE_PAGE_UP:
+	case REQ_MOVE_PAGE_DOWN:
+		state->recalculate_commit_context = TRUE;
+		return request;
+
 	default:
 		return pager_request(view, request, line);
 	}
@@ -4440,13 +4484,13 @@ static struct view_ops log_ops = {
 	"line",
 	{ "log" },
 	VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_NO_PARENT_NAV,
-	0,
+	sizeof(struct log_state),
 	log_open,
 	pager_read,
 	pager_draw,
 	log_request,
 	pager_grep,
-	pager_select,
+	log_select,
 };
 
 struct diff_state {
-- 
1.8.3.2
Kumar Appaiah· Aug 6, 2013, 04:58 UTC · re: Kumar Appaiah · lore

[[TIG][PATCH v2] 2/3] Display correct diff the context in split log view

In the log view, when scrolling across a commit, the diff view should automatically switch to the commit whose context the cursor is on in the log view. This commit changes things to catch the REQ_ENTER in the log view and handle recalculation of the commit and diff display from log_request, rather than delegating it to pager_request. In addition, it also gets rid of unexpected upward scrolling of the log view.

Fixes GH #155
Signed-Off-By: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
---
 NEWS  | 1 +
 tig.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
Show changes to 2 files +9 −1

NEWS, tig.c

diff --git a/NEWS b/NEWS
index 076ac9d..1b0f737 100644
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,7 @@ Bug fixes:
  - Ignore unrepresentable characters when transliterating text for rendering.
  - Transliterate text to output encoding before trimming it to avoid
    misalignment. (GH #86)
+ - Introduce a more natural context-sensitive log display. (GH #155)
 
 tig-1.1
 -------
diff --git a/tig.c b/tig.c
index 845153f..256b589 100644
--- a/tig.c
+++ b/tig.c
@@ -4475,8 +4475,15 @@ log_request(struct view *view, enum request request, struct line *line)
 		state->recalculate_commit_context = TRUE;
 		return request;
 
+	case REQ_ENTER:
+		state->recalculate_commit_context = TRUE;
+		if (VIEW(REQ_VIEW_DIFF)->ref != ref_commit)
+			open_view(view, REQ_VIEW_DIFF, OPEN_SPLIT);
+		update_view_title(view);
+		return request;
+
 	default:
-		return pager_request(view, request, line);
+		return request;
 	}
 }
 
-- 
1.8.3.2
Kumar Appaiah· Aug 6, 2013, 23:05 UTC · re: Kumar Appaiah · lore

Re: [[TIG][PATCH v2] 2/3] Display correct diff the context in split log view

On Tue, Aug 06, 2013 at 12:58:20AM -0400, Kumar Appaiah wrote:
Show 15 quoted lines
>  tig-1.1
>  -------
> diff --git a/tig.c b/tig.c
> index 845153f..256b589 100644
> --- a/tig.c
> +++ b/tig.c
> @@ -4475,8 +4475,15 @@ log_request(struct view *view, enum request request, struct line *line)
>  		state->recalculate_commit_context = TRUE;
>  		return request;
>  
> +	case REQ_ENTER:
> +		state->recalculate_commit_context = TRUE;
> +		if (VIEW(REQ_VIEW_DIFF)->ref != ref_commit)
> +			open_view(view, REQ_VIEW_DIFF, OPEN_SPLIT);
> +		update_view_title(view);
  		^^^^^^^^^^^^^^^^^^^^^^^
I missed removing update_view_title. I've done it locally, though.
Thanks.
Kumar
Show 10 quoted lines
> +		return request;
> +
>  	default:
> -		return pager_request(view, request, line);
> +		return request;
>  	}
>  }
>  
> -- 
> 1.8.3.2
-- 
Kumar Appaiah
Kumar Appaiah· Aug 6, 2013, 04:58 UTC · re: Kumar Appaiah · lore

[[TIG][PATCH v2] 3/3] Revert "Scroll diff with arrow keys in log view"

This reverts commit 888611dd5d407775245d574a3dc5c01b5963a5ba. This is because, in the re-engineered log view, scrolling the log with the arrows now updates the diff in the diff view when the screen is split. This resembles the earlier behaviour, and is also what users of software like Mutt (which uses the pager view concept) would expect.

Signed-Off-By: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
Conflicts:
	tig.c
---
 tig.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Show changes to tig.c +2 −3
diff --git a/tig.c b/tig.c
index 256b589..5f564a5 100644
--- a/tig.c
+++ b/tig.c
@@ -1905,7 +1905,6 @@ enum view_flag {
 	VIEW_STDIN		= 1 << 8,
 	VIEW_SEND_CHILD_ENTER	= 1 << 9,
 	VIEW_FILE_FILTER	= 1 << 10,
-	VIEW_NO_PARENT_NAV	= 1 << 11,
 };
 
 #define view_has_flags(view, flag)	((view)->ops->flags & (flag))
@@ -3773,7 +3772,7 @@ view_driver(struct view *view, enum request request)
 
 	case REQ_NEXT:
 	case REQ_PREVIOUS:
-		if (view->parent && !view_has_flags(view->parent, VIEW_NO_PARENT_NAV)) {
+		if (view->parent) {
 			int line;
 
 			view = view->parent;
@@ -4490,7 +4489,7 @@ log_request(struct view *view, enum request request, struct line *line)
 static struct view_ops log_ops = {
 	"line",
 	{ "log" },
-	VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_NO_PARENT_NAV,
+	VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER,
 	sizeof(struct log_state),
 	log_open,
 	pager_read,
-- 
1.8.3.2

← back to recent threads