From: Junio C Hamano Date: Sat, 25 Feb 2012 00:07:04 +0000 (-0800) Subject: Merge branches zj/decimal-width, zj/term-columns and jc/diff-stat-scaler X-Git-Tag: v1.7.10-rc0~9^2~9 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=db65f0fc3b1e16d5cc4ebf00f5af56c91546d839;p=git.git Merge branches zj/decimal-width, zj/term-columns and jc/diff-stat-scaler --- db65f0fc3b1e16d5cc4ebf00f5af56c91546d839 diff --cc cache.h index 24732e6ca,79c612fc2,c7e3b4d49..deaa35a70 --- a/cache.h +++ b/cache.h @@@@ -1176,7 -1172,6 -1172,7 +1176,8 @@@@ extern void setup_pager(void) extern const char *pager_program; extern int pager_in_use(void); extern int pager_use_color; ++ extern int term_columns(void); ++extern int decimal_width(int); extern const char *editor_program; extern const char *askpass_program; diff --cc pager.c index 96c07babb,975955ba8,b7909678f..05584dead --- a/pager.c +++ b/pager.c @@@@ -110,15 -110,3 -116,34 +116,46 @@@@ int pager_in_use(void env = getenv("GIT_PAGER_IN_USE"); return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0; } + ++ /* ++ * Return cached value (if set) or $COLUMNS environment variable (if ++ * set and positive) or ioctl(1, TIOCGWINSZ).ws_col (if positive), ++ * and default to 80 if all else fails. ++ */ ++ int term_columns(void) ++ { ++ static int term_columns_at_startup; ++ ++ char *col_string; ++ int n_cols; ++ ++ if (term_columns_at_startup) ++ return term_columns_at_startup; ++ ++ term_columns_at_startup = 80; ++ ++ col_string = getenv("COLUMNS"); ++ if (col_string && (n_cols = atoi(col_string)) > 0) ++ term_columns_at_startup = n_cols; ++ #ifdef TIOCGWINSZ ++ else { ++ struct winsize ws; ++ if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) ++ term_columns_at_startup = ws.ws_col; ++ } ++ #endif ++ ++ return term_columns_at_startup; ++ } +++ ++/* ++ * How many columns do we need to show this number in decimal? ++ */ ++int decimal_width(int number) ++{ ++ int i, width; ++ ++ for (width = 1, i = 10; i <= number; width++) ++ i *= 10; ++ return width; ++}