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 --combined builtin/blame.c
index 01956c80815a4f330ae27b77b4d21d263a887d1b,f028e8aec82d0936951418f936123041c3b516ad..b35bd6249de66d02b7f33eb7aae4866193447156
--- 1/builtin/blame.c
--- 2/builtin/blame.c
+++ b/builtin/blame.c
return 0;
}
- /*
- * How many columns do we need to show line numbers in decimal?
- */
- static int lineno_width(int lines)
- {
- int i, width;
-
- for (width = 1, i = 10; i <= lines; width++)
- i *= 10;
- return width;
- }
-
/*
* How many columns do we need to show line numbers, authors,
* and filenames?
if (largest_score < ent_score(sb, e))
largest_score = ent_score(sb, e);
}
- max_orig_digits = lineno_width(longest_src_lines);
- max_digits = lineno_width(longest_dst_lines);
- max_score_digits = lineno_width(largest_score);
+ max_orig_digits = decimal_width(longest_src_lines);
+ max_digits = decimal_width(longest_dst_lines);
+ max_score_digits = decimal_width(largest_score);
}
/*
return 0;
}
- switch (userdiff_config(var, value)) {
- case 0:
- break;
- case -1:
+ if (userdiff_config(var, value) < 0)
return -1;
- default:
- return 0;
- }
return git_default_config(var, value, cb);
}
diff --combined cache.h
index 3a8e1258e7a15e5ffba52ad400d9ae23cedb0982,24732e6caf8ba30b44a5aa5f40eb5756d164daf4..422c5cfcb374259b46a7f92fc2a08b726f54f77a
+++ b/cache.h
extern int is_inside_work_tree(void);
extern int have_git_dir(void);
extern const char *get_git_dir(void);
+extern int is_git_directory(const char *path);
extern char *get_object_directory(void);
extern char *get_index_file(void);
extern char *get_graft_file(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 --combined pager.c
index b7909678f459d90d1c8907c78bb5fcb512fe558d,96c07babbd7756a59fb5e891bf78f9c4396fed13..05584dead6728ceff818630fbccaa91bb6c6b686
+++ b/pager.c
if (!pager)
return;
+ /*
+ * force computing the width of the terminal before we redirect
+ * the standard output to the pager.
+ */
+ (void) term_columns();
+
setenv("GIT_PAGER_IN_USE", "true", 1);
/* spawn the pager */
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;
+ }