Re: [tig] [PATCHv2 3/3] log: Colour the diff stat

2014-04-16 Thread Kumar Appaiah

On Wed, Apr 16, 2014 at 08:44:41PM -0400, Jonas Fonseca wrote:
 On Sun, Apr 13, 2014 at 5:54 PM, Kumar Appaiah
 a.ku...@alumni.iitm.ac.in wrote:
 
  This commit adds custom log_read and log_draw functions that utilize
  the diff stat drawing functions from the diff module. The absence of
  the triple hyphen separator prevents direct usage of the diff drawing
  functions directly.
 
 See my comments below.

Hi Jonas.

  +static bool
  +log_draw(struct view *view, struct line *line, unsigned int lineno)
  +{
  +   char *text = line-data;
  +   enum line_type type = line-type;
  +
 
 This is missing a call to draw_lineno(...)

Noted.

  +   if (type == LINE_DIFF_STAT) {
  +   diff_common_draw_diff_stat(view, type, text);
  +   draw_text(view, type, text);
 
 I had to #include tig/draw.h for this to compile.

I'll take care of this.

I'll send you a pull request eventually. You can handle it after your
refactor is complete.

Thanks!

Kumar
-- 
Kumar Appaiah
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[tig] [PATCHv2 0/3] log: colour the diffstat

2014-04-13 Thread Kumar Appaiah
These patches add colourization to the log view. They reuse the diff
stat drawing functions from the diff module directly.

This version just includes some code reformatting and minor
fixes. Please comment on what other fixes could help.

Thanks.

Kumar Appaiah (3):
  diff: Move diff stat addition to a common function
  diff: Move diff stat drawing to a common function
  log: Colour the diff stat

 include/tig/diff.h |  2 ++
 src/diff.c | 57 ++
 src/log.c  | 55 ++--
 3 files changed, 91 insertions(+), 23 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[tig] [PATCHv2 1/3] diff: Move diff stat addition to a common function

2014-04-13 Thread Kumar Appaiah
Signed-off-by: Kumar Appaiah a.ku...@alumni.iitm.ac.in
---
 include/tig/diff.h |  1 +
 src/diff.c | 27 ++-
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/include/tig/diff.h b/include/tig/diff.h
index be325c4..ba40386 100644
--- a/include/tig/diff.h
+++ b/include/tig/diff.h
@@ -27,6 +27,7 @@ enum request diff_common_edit(struct view *view, enum request 
request, struct li
 bool diff_common_read(struct view *view, const char *data, struct diff_state 
*state);
 bool diff_common_draw(struct view *view, struct line *line, unsigned int 
lineno);
 enum request diff_common_enter(struct view *view, enum request request, struct 
line *line);
+bool diff_common_add_diff_stat(struct view *view, const char *data);
 
 unsigned int diff_get_lineno(struct view *view, struct line *line);
 const char *diff_get_pathname(struct view *view, struct line *line);
diff --git a/src/diff.c b/src/diff.c
index 4b30068..1daf8fa 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -38,6 +38,21 @@ diff_open(struct view *view, enum open_flags flags)
 }
 
 bool
+diff_common_add_diff_stat(struct view *view, const char *data)
+{
+   size_t len = strlen(data);
+   char *pipe = strchr(data, '|');
+   bool has_histogram = data[len - 1] == '-' || data[len - 1] == '+';
+   bool has_bin_diff = pipe  strstr(pipe, Bin)  strstr(pipe, -);
+   bool has_rename = data[len - 1] == '0'  (strstr(data, =) || 
!strncmp(data,  ..., 4));
+   bool has_no_change = pipe  strstr(pipe,  0);
+
+   if (pipe  (has_histogram || has_bin_diff || has_rename || 
has_no_change))
+   return add_line_text(view, data, LINE_DIFF_STAT) != NULL;
+   return FALSE;
+}
+
+bool
 diff_common_read(struct view *view, const char *data, struct diff_state *state)
 {
enum line_type type = get_line_type(data);
@@ -49,15 +64,9 @@ diff_common_read(struct view *view, const char *data, struct 
diff_state *state)
state-reading_diff_stat = TRUE;
 
if (state-reading_diff_stat) {
-   size_t len = strlen(data);
-   char *pipe = strchr(data, '|');
-   bool has_histogram = data[len - 1] == '-' || data[len - 1] == 
'+';
-   bool has_bin_diff = pipe  strstr(pipe, Bin)  strstr(pipe, 
-);
-   bool has_rename = data[len - 1] == '0'  (strstr(data, =) 
|| !strncmp(data,  ..., 4));
-   bool has_no_change = pipe  strstr(pipe,  0);
-
-   if (pipe  (has_histogram || has_bin_diff || has_rename || 
has_no_change)) {
-   return add_line_text(view, data, LINE_DIFF_STAT) != 
NULL;
+   bool ret = diff_common_add_diff_stat(view, data);
+   if (ret) {
+   return TRUE;
} else {
state-reading_diff_stat = FALSE;
}
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[tig] [PATCHv2 2/3] diff: Move diff stat drawing to a common function

2014-04-13 Thread Kumar Appaiah
Signed-off-by: Kumar Appaiah a.ku...@alumni.iitm.ac.in
---
 include/tig/diff.h |  1 +
 src/diff.c | 30 ++
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/include/tig/diff.h b/include/tig/diff.h
index ba40386..16299fe 100644
--- a/include/tig/diff.h
+++ b/include/tig/diff.h
@@ -28,6 +28,7 @@ bool diff_common_read(struct view *view, const char *data, 
struct diff_state *st
 bool diff_common_draw(struct view *view, struct line *line, unsigned int 
lineno);
 enum request diff_common_enter(struct view *view, enum request request, struct 
line *line);
 bool diff_common_add_diff_stat(struct view *view, const char *data);
+void diff_common_draw_diff_stat(struct view *view, enum line_type *type, char 
**text);
 
 unsigned int diff_get_lineno(struct view *view, struct line *line);
 const char *diff_get_pathname(struct view *view, struct line *line);
diff --git a/src/diff.c b/src/diff.c
index 1daf8fa..b204bab 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -167,6 +167,23 @@ diff_common_draw_part(struct view *view, enum line_type 
*type, char **text, char
return sep != NULL;
 }
 
+void
+diff_common_draw_diff_stat(struct view *view, enum line_type *type, char 
**text)
+{
+   diff_common_draw_part(view, type, text, '|', LINE_DEFAULT);
+   if (diff_common_draw_part(view, type, text, 'B', LINE_DEFAULT)) 
{
+   /* Handle binary diffstat: Bin deleted - added 
bytes */
+   diff_common_draw_part(view, type, text, ' ', 
LINE_DIFF_DEL);
+   diff_common_draw_part(view, type, text, '-', 
LINE_DEFAULT);
+   diff_common_draw_part(view, type, text, ' ', 
LINE_DIFF_ADD);
+   diff_common_draw_part(view, type, text, 'b', 
LINE_DEFAULT);
+
+   } else {
+   diff_common_draw_part(view, type, text, '+', 
LINE_DIFF_ADD);
+   diff_common_draw_part(view, type, text, '-', 
LINE_DIFF_DEL);
+   }
+}
+
 bool
 diff_common_draw(struct view *view, struct line *line, unsigned int lineno)
 {
@@ -180,18 +197,7 @@ diff_common_draw(struct view *view, struct line *line, 
unsigned int lineno)
return TRUE;
 
if (type == LINE_DIFF_STAT) {
-   diff_common_draw_part(view, type, text, '|', LINE_DEFAULT);
-   if (diff_common_draw_part(view, type, text, 'B', 
LINE_DEFAULT)) {
-   /* Handle binary diffstat: Bin deleted - added 
bytes */
-   diff_common_draw_part(view, type, text, ' ', 
LINE_DIFF_DEL);
-   diff_common_draw_part(view, type, text, '-', 
LINE_DEFAULT);
-   diff_common_draw_part(view, type, text, ' ', 
LINE_DIFF_ADD);
-   diff_common_draw_part(view, type, text, 'b', 
LINE_DEFAULT);
-
-   } else {
-   diff_common_draw_part(view, type, text, '+', 
LINE_DIFF_ADD);
-   diff_common_draw_part(view, type, text, '-', 
LINE_DIFF_DEL);
-   }
+   diff_common_draw_diff_stat(view, type, text);
}
 
if (line-user_flags  DIFF_LINE_COMMIT_TITLE)
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[tig] [PATCHv2 3/3] log: Colour the diff stat

2014-04-13 Thread Kumar Appaiah
This commit adds custom log_read and log_draw functions that utilize
the diff stat drawing functions from the diff module. The absence of
the triple hyphen separator prevents direct usage of the diff drawing
functions directly.

Signed-Off-By: Kumar Appaiah a.ku...@alumni.iitm.ac.in
---
 src/log.c | 55 +--
 1 file changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/log.c b/src/log.c
index 40c9a21..468f7c3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -23,6 +23,9 @@ struct log_state {
 * up/down in the log view. */
int last_lineno;
enum line_type last_type;
+   bool commit_title_read;
+   bool after_commit_header;
+   bool reading_diff_stat;
 };
 
 static void
@@ -78,14 +81,62 @@ log_request(struct view *view, enum request request, struct 
line *line)
}
 }
 
+static bool
+log_read(struct view *view, char *data)
+{
+   enum line_type type;
+   struct log_state *state = view-private;
+   size_t len;
+
+   if (!data)
+   return TRUE;
+
+   type = get_line_type(data);
+   len = strlen(data);
+
+   if (type == LINE_COMMIT)
+   state-commit_title_read = TRUE;
+   else if (state-commit_title_read  len  1) {
+   state-commit_title_read = FALSE;
+   state-after_commit_header = TRUE;
+   } else if (state-after_commit_header  len  1) {
+   state-after_commit_header = FALSE;
+   state-reading_diff_stat = TRUE;
+   } else if (state-reading_diff_stat) {
+   bool ret = diff_common_add_diff_stat(view, data);
+   if (ret) {
+   return TRUE;
+   } else {
+   state-reading_diff_stat = FALSE;
+   }
+   }
+
+   return pager_common_read(view, data, type);
+}
+
+static bool
+log_draw(struct view *view, struct line *line, unsigned int lineno)
+{
+   char *text = line-data;
+   enum line_type type = line-type;
+
+   if (type == LINE_DIFF_STAT) {
+   diff_common_draw_diff_stat(view, type, text);
+   draw_text(view, type, text);
+   return TRUE;
+   }
+
+   return pager_draw(view, line, lineno);
+}
+
 static struct view_ops log_ops = {
line,
argv_env.head,
VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | 
VIEW_LOG_LIKE | VIEW_REFRESH,
sizeof(struct log_state),
log_open,
-   pager_read,
-   pager_draw,
+   log_read,
+   log_draw,
log_request,
pager_grep,
log_select,
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[tig] [PATCH 0/3] log: colour the diffstat.

2014-04-11 Thread Kumar Appaiah
These patches add colourization to the log view. They reuse the diff
stat drawing functions from the diff module directly.

Kumar Appaiah (3):
  diff: Move diff stat addition to a common function
  diff: Move diff stat drawing to a common function
  log: Colour the diff stat

 include/tig/diff.h |  2 ++
 src/diff.c | 57 +++--
 src/log.c  | 62 --
 3 files changed, 98 insertions(+), 23 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[tig] [PATCH 2/3] diff: Move diff stat drawing to a common function

2014-04-11 Thread Kumar Appaiah
Signed-off-by: Kumar Appaiah a.ku...@alumni.iitm.ac.in
---
 include/tig/diff.h |  1 +
 src/diff.c | 30 ++
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/include/tig/diff.h b/include/tig/diff.h
index ba40386..16299fe 100644
--- a/include/tig/diff.h
+++ b/include/tig/diff.h
@@ -28,6 +28,7 @@ bool diff_common_read(struct view *view, const char *data, 
struct diff_state *st
 bool diff_common_draw(struct view *view, struct line *line, unsigned int 
lineno);
 enum request diff_common_enter(struct view *view, enum request request, struct 
line *line);
 bool diff_common_add_diff_stat(struct view *view, const char *data);
+void diff_common_draw_diff_stat(struct view *view, enum line_type *type, char 
**text);
 
 unsigned int diff_get_lineno(struct view *view, struct line *line);
 const char *diff_get_pathname(struct view *view, struct line *line);
diff --git a/src/diff.c b/src/diff.c
index 1daf8fa..b204bab 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -167,6 +167,23 @@ diff_common_draw_part(struct view *view, enum line_type 
*type, char **text, char
return sep != NULL;
 }
 
+void
+diff_common_draw_diff_stat(struct view *view, enum line_type *type, char 
**text)
+{
+   diff_common_draw_part(view, type, text, '|', LINE_DEFAULT);
+   if (diff_common_draw_part(view, type, text, 'B', LINE_DEFAULT)) 
{
+   /* Handle binary diffstat: Bin deleted - added 
bytes */
+   diff_common_draw_part(view, type, text, ' ', 
LINE_DIFF_DEL);
+   diff_common_draw_part(view, type, text, '-', 
LINE_DEFAULT);
+   diff_common_draw_part(view, type, text, ' ', 
LINE_DIFF_ADD);
+   diff_common_draw_part(view, type, text, 'b', 
LINE_DEFAULT);
+
+   } else {
+   diff_common_draw_part(view, type, text, '+', 
LINE_DIFF_ADD);
+   diff_common_draw_part(view, type, text, '-', 
LINE_DIFF_DEL);
+   }
+}
+
 bool
 diff_common_draw(struct view *view, struct line *line, unsigned int lineno)
 {
@@ -180,18 +197,7 @@ diff_common_draw(struct view *view, struct line *line, 
unsigned int lineno)
return TRUE;
 
if (type == LINE_DIFF_STAT) {
-   diff_common_draw_part(view, type, text, '|', LINE_DEFAULT);
-   if (diff_common_draw_part(view, type, text, 'B', 
LINE_DEFAULT)) {
-   /* Handle binary diffstat: Bin deleted - added 
bytes */
-   diff_common_draw_part(view, type, text, ' ', 
LINE_DIFF_DEL);
-   diff_common_draw_part(view, type, text, '-', 
LINE_DEFAULT);
-   diff_common_draw_part(view, type, text, ' ', 
LINE_DIFF_ADD);
-   diff_common_draw_part(view, type, text, 'b', 
LINE_DEFAULT);
-
-   } else {
-   diff_common_draw_part(view, type, text, '+', 
LINE_DIFF_ADD);
-   diff_common_draw_part(view, type, text, '-', 
LINE_DIFF_DEL);
-   }
+   diff_common_draw_diff_stat(view, type, text);
}
 
if (line-user_flags  DIFF_LINE_COMMIT_TITLE)
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[tig] [PATCH 1/3] diff: Move diff stat addition to a common function

2014-04-11 Thread Kumar Appaiah
Signed-off-by: Kumar Appaiah a.ku...@alumni.iitm.ac.in
---
 include/tig/diff.h |  1 +
 src/diff.c | 27 ++-
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/include/tig/diff.h b/include/tig/diff.h
index be325c4..ba40386 100644
--- a/include/tig/diff.h
+++ b/include/tig/diff.h
@@ -27,6 +27,7 @@ enum request diff_common_edit(struct view *view, enum request 
request, struct li
 bool diff_common_read(struct view *view, const char *data, struct diff_state 
*state);
 bool diff_common_draw(struct view *view, struct line *line, unsigned int 
lineno);
 enum request diff_common_enter(struct view *view, enum request request, struct 
line *line);
+bool diff_common_add_diff_stat(struct view *view, const char *data);
 
 unsigned int diff_get_lineno(struct view *view, struct line *line);
 const char *diff_get_pathname(struct view *view, struct line *line);
diff --git a/src/diff.c b/src/diff.c
index 4b30068..1daf8fa 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -38,6 +38,21 @@ diff_open(struct view *view, enum open_flags flags)
 }
 
 bool
+diff_common_add_diff_stat(struct view *view, const char *data)
+{
+   size_t len = strlen(data);
+   char *pipe = strchr(data, '|');
+   bool has_histogram = data[len - 1] == '-' || data[len - 1] == '+';
+   bool has_bin_diff = pipe  strstr(pipe, Bin)  strstr(pipe, -);
+   bool has_rename = data[len - 1] == '0'  (strstr(data, =) || 
!strncmp(data,  ..., 4));
+   bool has_no_change = pipe  strstr(pipe,  0);
+
+   if (pipe  (has_histogram || has_bin_diff || has_rename || 
has_no_change))
+   return add_line_text(view, data, LINE_DIFF_STAT) != NULL;
+   return FALSE;
+}
+
+bool
 diff_common_read(struct view *view, const char *data, struct diff_state *state)
 {
enum line_type type = get_line_type(data);
@@ -49,15 +64,9 @@ diff_common_read(struct view *view, const char *data, struct 
diff_state *state)
state-reading_diff_stat = TRUE;
 
if (state-reading_diff_stat) {
-   size_t len = strlen(data);
-   char *pipe = strchr(data, '|');
-   bool has_histogram = data[len - 1] == '-' || data[len - 1] == 
'+';
-   bool has_bin_diff = pipe  strstr(pipe, Bin)  strstr(pipe, 
-);
-   bool has_rename = data[len - 1] == '0'  (strstr(data, =) 
|| !strncmp(data,  ..., 4));
-   bool has_no_change = pipe  strstr(pipe,  0);
-
-   if (pipe  (has_histogram || has_bin_diff || has_rename || 
has_no_change)) {
-   return add_line_text(view, data, LINE_DIFF_STAT) != 
NULL;
+   bool ret = diff_common_add_diff_stat(view, data);
+   if (ret) {
+   return TRUE;
} else {
state-reading_diff_stat = FALSE;
}
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[tig] [PATCH 3/3] log: Colour the diff stat

2014-04-11 Thread Kumar Appaiah
This commit adds custom log_read and log_draw functions that utilize
the diff stat drawing functions from the diff module. The absence of
the triple hyphen separator prevents direct usage of the diff drawing
functions directly.

Signed-Off-By: Kumar Appaiah a.ku...@alumni.iitm.ac.in
---
 src/log.c | 62 --
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/log.c b/src/log.c
index eef61dc..e6f2a82 100644
--- a/src/log.c
+++ b/src/log.c
@@ -23,6 +23,9 @@ struct log_state {
 * up/down in the log view. */
int last_lineno;
enum line_type last_type;
+   bool commit_title_read;
+   bool after_commit_header;
+   bool reading_diff_stat;
 };
 
 static void
@@ -76,14 +79,69 @@ log_request(struct view *view, enum request request, struct 
line *line)
}
 }
 
+static bool
+log_read(struct view *view, char *data)
+{
+   enum line_type type;
+   struct log_state *state = view-private;
+   size_t len;
+
+   if (!data)
+   return TRUE;
+
+   type = get_line_type(data);
+
+   len = strlen(data);
+
+   if (type == LINE_COMMIT)
+   state-commit_title_read = TRUE;
+   else if (state-commit_title_read  len  1) {
+   state-commit_title_read = FALSE;
+   state-after_commit_header = TRUE;
+   } else if (state-after_commit_header  len  1) {
+   state-after_commit_header = FALSE;
+   state-reading_diff_stat = TRUE;
+   } else if (state-reading_diff_stat) {
+   bool ret = diff_common_add_diff_stat(view, data);
+   if (ret) {
+   return TRUE;
+   } else {
+   state-reading_diff_stat = FALSE;
+   }
+   }
+
+   return pager_common_read(view, data, type);
+}
+
+static bool
+log_draw(struct view *view, struct line *line, unsigned int lineno)
+{
+   char *text = line-data;
+   enum line_type type = line-type;
+
+   if (draw_lineno(view, lineno))
+   return TRUE;
+
+   if (line-wrapped  draw_text(view, LINE_DELIMITER, +))
+   return TRUE;
+
+   if (type == LINE_DIFF_STAT) {
+   diff_common_draw_diff_stat(view, type, text);
+   draw_text(view, type, text);
+   return TRUE;
+   }
+
+   return pager_draw(view, line, lineno);
+}
+
 static struct view_ops log_ops = {
line,
argv_env.head,
VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | 
VIEW_LOG_LIKE | VIEW_REFRESH,
sizeof(struct log_state),
log_open,
-   pager_read,
-   pager_draw,
+   log_read,
+   log_draw,
log_request,
pager_grep,
log_select,
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-06 Thread Kumar Appaiah
On Tue, Aug 06, 2013 at 12:58:20AM -0400, Kumar Appaiah wrote:
  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

 + return request;
 +
   default:
 - return pager_request(view, request, line);
 + return request;
   }
  }
  
 -- 
 1.8.3.2

-- 
Kumar Appaiah
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-05 Thread Kumar Appaiah
Dear Jonas,

Thanks for the patient review.
On Mon, Aug 05, 2013 at 11:27:44PM -0400, Jonas Fonseca wrote:
 On Fri, Aug 2, 2013 at 8:23 PM, Kumar Appaiah a.ku...@alumni.iitm.ac.in 
 wrote:
  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 to the
 
 s/to to/to do/

Done.

  ``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.ku...@alumni.iitm.ac.in
  ---
   tig.c | 50 --
   1 file changed, 48 insertions(+), 2 deletions(-)
 
  diff --git a/tig.c b/tig.c
  index 72f132a..dd4b0f4 100644
  --- a/tig.c
  +++ b/tig.c
  @@ -4384,6 +4384,33 @@ pager_select(struct view *view, struct line *line)
  }
   }
 
  +struct log_state {
  +   bool update_commit_ref;
  +};
  +
  +static void
  +log_select(struct view *view, struct line *line)
  +{
  +   struct log_state *state = (struct log_state *) view-private;
  +
  +   if (state-update_commit_ref  line-lineno  1) {
  +   /* We need to recalculate the previous commit,
  +  since the user has likely scrolled up. */
 
 I'd prefer that state-update_commit_ref is given another name so it
 won't be necessary to have these comments everywhere the field is
 used, for example recalculate_commit_context. The comment could be
 moved to the declaration in struct log_state to explain its use.

Done.

 Multi-line comments should start with '*' for each additonal line, e.g.
 
   /* bla bla
* bla bla */

Done.

  +   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 )));
 
 You mentioned elsewhere that this looked funny, and I guess you are
 right. I will extract this into a utility method so you can simply
 call: string_copy_rev_from_line(view-ref, commit_line); ...

I will wait on this. The next iteration of the patch will still have
this problem.

  +   }
  +   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);
 
 ... and: string_copy_rev_from_line(view-ref, line);

I understand.

  +   }
  +   string_copy_rev(ref_commit, view-ref);
  +   state-update_commit_ref = FALSE;
  +}
  +
   static bool
   pager_open(struct view *view, enum open_flags flags)
   {
  @@ -4427,11 +4454,30 @@ 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;
 
 There's no need to cast view-private here.

Done.

  +
  switch (request) {
  case REQ_REFRESH:
  load_refs();
  refresh_view(view);
  return REQ_NONE;
  +
  +   case REQ_MOVE_UP:
  +   case REQ_PREVIOUS:
  +   if (line-type == LINE_COMMIT  line-lineno  1) {
  +   /* We are at a commit, and heading upward. We
  +  force log_select to find the previous
  +  commit above, from the context. */
 
 Please delete this comment.

Done.

  +   state-update_commit_ref = TRUE;
  +   }
  +   return pager_request(view, request, line);
 
 There's not really any reason to call pager_request here, since it
 only handles REQ_ENTER.

Done.

  +
  +   case REQ_MOVE_PAGE_UP:
  +   case REQ_MOVE_PAGE_DOWN:
  +   /* We need to figure out the right commit again. */
 
 Please delete this this comment.

Done.

  +   state-update_commit_ref = TRUE;
  +   return pager_request(view, request, line);
 
 Calling pager_request again.

Done.

I will send in another patch to review shortly.

Thanks!

Kumar
-- 
Kumar Appaiah
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-05 Thread Kumar Appaiah
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

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-05 Thread Kumar Appaiah
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.ku...@alumni.iitm.ac.in
---
 tig.c | 50 +++---
 1 file changed, 47 insertions(+), 3 deletions(-)

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

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-05 Thread Kumar Appaiah
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.ku...@alumni.iitm.ac.in
---
 NEWS  | 1 +
 tig.c | 9 -
 2 files changed, 9 insertions(+), 1 deletion(-)

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

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-05 Thread Kumar Appaiah
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.ku...@alumni.iitm.ac.in

Conflicts:
tig.c
---
 tig.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

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

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-02 Thread Kumar Appaiah
Hi.

These set of patches refactor the log view to provide a behaviour that
is quite similar to, say, e-mail with Mutt. The key improvements are:

- The current commit is inferred based on the context. For example, if
  you focus on the commit message of a particular commit, the correct
  commit is inferred automagically.

- Scrolling the log view when the diff is open shows the correct
  commit on the screen, rather than have to scroll up and cross the
  commit line to display the screen.

I have decided to revert 888611dd5d407775245d574a3dc5c01b5963a5ba,
since the behaviour with the updated scrolling pattern is much more
consistent.

As always, I will gladly alter the patch based on comments on coding
style and all other aspects.

Thanks!

Kumar

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 | 67 ++-
 2 files changed, 63 insertions(+), 5 deletions(-)

-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-02 Thread Kumar Appaiah
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.ku...@alumni.iitm.ac.in

Conflicts:
tig.c
---
 tig.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tig.c b/tig.c
index 53947b7..65c91a0 100644
--- a/tig.c
+++ b/tig.c
@@ -1901,7 +1901,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))
@@ -3774,7 +3773,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;
@@ -4498,7 +4497,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

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-02 Thread Kumar Appaiah
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.ku...@alumni.iitm.ac.in
---
 NEWS  |  1 +
 tig.c | 12 
 2 files changed, 13 insertions(+)

diff --git a/NEWS b/NEWS
index 0394407..f59e517 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,7 @@ Bug fixes:
  - Fix rendering glitch for branch names.
  - Do not apply diff styling to untracked files in the stage view. (GH #153)
  - Fix tree indentation for entries containing combining characters. (GH #170)
+ - Introduce a more natural context-sensitive log display. (GH #155)
 
 tig-1.1
 ---
diff --git a/tig.c b/tig.c
index dd4b0f4..53947b7 100644
--- a/tig.c
+++ b/tig.c
@@ -4478,6 +4478,18 @@ log_request(struct view *view, enum request request, 
struct line *line)
state-update_commit_ref = TRUE;
return pager_request(view, request, line);
 
+   case REQ_ENTER:
+   /* Recalculate the correct commit for the context. */
+   state-update_commit_ref = TRUE;
+
+   open_view(view, REQ_VIEW_DIFF, OPEN_SPLIT);
+   update_view_title(view);
+
+   /* We don't want to delegate this to pager_request,
+  since we don't want the extra scrolling of the log
+  view. */
+   return REQ_NONE;
+
default:
return pager_request(view, request, line);
}
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-08-02 Thread Kumar Appaiah
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 to 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.ku...@alumni.iitm.ac.in
---
 tig.c | 50 --
 1 file changed, 48 insertions(+), 2 deletions(-)

diff --git a/tig.c b/tig.c
index 72f132a..dd4b0f4 100644
--- a/tig.c
+++ b/tig.c
@@ -4384,6 +4384,33 @@ pager_select(struct view *view, struct line *line)
}
 }
 
+struct log_state {
+   bool update_commit_ref;
+};
+
+static void
+log_select(struct view *view, struct line *line)
+{
+   struct log_state *state = (struct log_state *) view-private;
+
+   if (state-update_commit_ref  line-lineno  1) {
+   /* We need to recalculate the previous commit,
+  since the user has likely scrolled up. */
+   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-update_commit_ref = FALSE;
+}
+
 static bool
 pager_open(struct view *view, enum open_flags flags)
 {
@@ -4427,11 +4454,30 @@ 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;
+
+   case REQ_MOVE_UP:
+   case REQ_PREVIOUS:
+   if (line-type == LINE_COMMIT  line-lineno  1) {
+   /* We are at a commit, and heading upward. We
+  force log_select to find the previous
+  commit above, from the context. */
+   state-update_commit_ref = TRUE;
+   }
+   return pager_request(view, request, line);
+
+   case REQ_MOVE_PAGE_UP:
+   case REQ_MOVE_PAGE_DOWN:
+   /* We need to figure out the right commit again. */
+   state-update_commit_ref = TRUE;
+   return pager_request(view, request, line);
+
default:
return pager_request(view, request, line);
}
@@ -4441,13 +4487,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

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [TIG][PATCH] Scroll diff with arrow keys in log view

2013-08-01 Thread Kumar Appaiah
On Thu, Aug 01, 2013 at 10:01:58PM -0400, Jonas Fonseca wrote:
 On Wed, Jul 31, 2013 at 11:11 PM, Kumar Appaiah
 a.ku...@alumni.iitm.ac.in wrote:
  This commit introduces the VIEW_NO_PARENT_NAV flag and adds it to the
  log view. This allows the scrolling commands to fall through from the
  pager to the diff when the diff is viewed in the log mode.
 
 Thanks, works like a charm.
 
 BTW, please remember to label tig related patches by adding '[TIG]' or
 something similar in the subject so people on this list won't get
 confused.

Noted, and thanks!

Kumar
-- 
Kumar Appaiah
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Scroll diff with arrow keys in log view

2013-07-31 Thread Kumar Appaiah
This commit introduces the VIEW_NO_PARENT_NAV flag and adds it to the
log view. This allows the scrolling commands to fall through from the
pager to the diff when the diff is viewed in the log mode.

Signed-Off-By: Kumar Appaiah a.ku...@alumni.iitm.ac.in
---
 tig.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tig.c b/tig.c
index 8301295..52831fd 100644
--- a/tig.c
+++ b/tig.c
@@ -1895,6 +1895,7 @@ 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))
@@ -3765,7 +3766,7 @@ view_driver(struct view *view, enum request request)
 
case REQ_NEXT:
case REQ_PREVIOUS:
-   if (view-parent) {
+   if (view-parent  !view_has_flags(view-parent, 
VIEW_NO_PARENT_NAV)) {
int line;
 
view = view-parent;
@@ -4431,7 +4432,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_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | 
VIEW_NO_PARENT_NAV,
0,
log_open,
pager_read,
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html