From: Junio C Hamano Date: Mon, 20 Feb 2012 08:15:11 +0000 (-0800) Subject: Merge branch 'zj/decimal-width' X-Git-Tag: v1.7.10-rc0~70 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4d9e079e826c9b51b610260564111fa8385f7581;p=git.git Merge branch 'zj/decimal-width' * zj/decimal-width: make lineno_width() from blame reusable for others Conflicts: cache.h pager.c --- 4d9e079e826c9b51b610260564111fa8385f7581 diff --cc cache.h index 3a8e1258e,24732e6ca..422c5cfcb --- a/cache.h +++ b/cache.h @@@ -1177,7 -1176,7 +1177,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 b7909678f,96c07babb..05584dead --- a/pager.c +++ b/pager.c @@@ -117,33 -111,14 +117,45 @@@ int pager_in_use(void 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; + }