author | Junio C Hamano <gitster@pobox.com> | |
Mon, 20 Feb 2012 08:15:11 +0000 (00:15 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 20 Feb 2012 08:15:11 +0000 (00:15 -0800) |
* zj/decimal-width:
make lineno_width() from blame reusable for others
Conflicts:
cache.h
pager.c
make lineno_width() from blame reusable for others
Conflicts:
cache.h
pager.c
1 | 2 | |||
---|---|---|---|---|
builtin/blame.c | patch | | diff1 | | diff2 | | blob | history |
cache.h | patch | | diff1 | | diff2 | | blob | history |
pager.c | patch | | diff1 | | diff2 | | blob | history |
diff --cc builtin/blame.c
Simple merge
diff --cc cache.h
index 3a8e1258e7a15e5ffba52ad400d9ae23cedb0982,24732e6caf8ba30b44a5aa5f40eb5756d164daf4..422c5cfcb374259b46a7f92fc2a08b726f54f77a
+++ b/cache.h
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 b7909678f459d90d1c8907c78bb5fcb512fe558d,96c07babbd7756a59fb5e891bf78f9c4396fed13..05584dead6728ceff818630fbccaa91bb6c6b686
+++ b/pager.c
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;
+ }