Skip to content

Commit

Permalink
Pass terminal dimensions to git by setting COLUMNS and LINES
Browse files Browse the repository at this point in the history
This partially reverts "Show diff stats as wide as the terminal" (commit
a7eb305) which passed the terminal
width to git-diff using `--stat=%(width)`. This feature was introduced
in Git version 1.7.10 released 2013-04-06 and causes problems for older
versions of Git.

It turns out that Git will automatically read $COLUMNS when showing diff
stats, so the same effect can be achieved by passing the terminal
dimensions using environment variables.

Fixes GH-151, "Broken commit rendering on Ubuntu 10.04" since
incompatibilitis with older versions of Git is no longer an issue.
Tested using `tig 1f384f3`.
  • Loading branch information
jonas committed May 20, 2013
1 parent 4dd65a9 commit f0ad1f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 0 additions & 1 deletion manual.txt
Expand Up @@ -162,7 +162,6 @@ following variables.
|%(fileargs) |The file arguments passed on the command line.
|%(diffargs) |The diff options passed on the command line.
|%(prompt) |Prompt for the argument value.
|%(width) |The view width.
|=============================================================================

Example user-defined commands:
Expand Down
19 changes: 15 additions & 4 deletions tig.c
Expand Up @@ -22,6 +22,9 @@ static void warn(const char *msg, ...) PRINTF_LIKE(1, 2);
static void report(const char *msg, ...) PRINTF_LIKE(1, 2);
#define report_clear() report("%s", "")

static bool set_environment_variable(const char *name, const char *value);
static bool set_int_environment_variable(const char *name, int value);


enum input_status {
INPUT_OK,
Expand Down Expand Up @@ -2496,6 +2499,8 @@ resize_display(void)
/* Setup window dimensions */

getmaxyx(stdscr, base->height, base->width);
set_int_environment_variable("COLUMNS", base->width);
set_int_environment_variable("LINES", base->height);

This comment has been minimized.

Copy link
@eMPee584

eMPee584 Jun 28, 2013

Setting the LINES/COLUMNS environment variables to a constant number breaks ncurses' getmaxyx() logic, so dynamic resizing doesn't work. But git doesn't need them anyways as it does its own magic..

This comment has been minimized.

Copy link
@jonas

jonas Jul 16, 2013

Author Owner

Yes, I found out that git does its own magic, but this magic doesn't seem to work when git is run within tig. A possible workaround would be to only set LINES and COLUMNS when forking.


/* Make room for the status window. */
base->height -= 1;
Expand Down Expand Up @@ -3077,9 +3082,6 @@ format_expand_arg(struct format_context *format, const char *name)
return string_format_from(format->buf, &format->bufpos, "%s", value);
}

if (!prefixcmp(name, "%(width)"))
return string_format_from(format->buf, &format->bufpos, "%d", format->view->width);

for (i = 0; i < ARRAY_SIZE(vars); i++) {
const char *value;

Expand Down Expand Up @@ -4443,7 +4445,7 @@ diff_open(struct view *view, enum open_flags flags)
{
static const char *diff_argv[] = {
"git", "show", opt_encoding_arg, "--pretty=fuller", "--no-color", "--root",
"--patch", "--stat=%(width)",
"--patch-with-stat",
opt_notes_arg, opt_diff_context_arg, opt_ignore_space_arg,
"%(diffargs)", "%(commit)", "--", "%(fileargs)", NULL
};
Expand Down Expand Up @@ -8184,6 +8186,15 @@ set_environment_variable(const char *name, const char *value)
return FALSE;
}

static bool
set_int_environment_variable(const char *name, int value)
{
char buf[SIZEOF_STR];

return string_format(buf, "%d", value)
&& set_environment_variable(name, buf);
}

static void
set_work_tree(const char *value)
{
Expand Down
1 change: 0 additions & 1 deletion tigrc.5.txt
Expand Up @@ -392,7 +392,6 @@ is run. Valid variable names are:
|%(fileargs) |The file arguments passed on the command line.
|%(diffargs) |The diff options passed on the command line.
|%(prompt) |Prompt for the argument value.
|%(width) |The view width.
|=============================================================================

As an example, the following external command will save the current commit as
Expand Down

0 comments on commit f0ad1f7

Please sign in to comment.