config: add '--name-only' option to list only variable names
[gitweb.git] / pager.c
diff --git a/pager.c b/pager.c
index b7909678f459d90d1c8907c78bb5fcb512fe558d..98b26823c9e0c0bd220a7a41a97675626c8e65ec 100644 (file)
--- a/pager.c
+++ b/pager.c
  * something different on Windows.
  */
 
-#ifndef WIN32
-static void pager_preexec(void)
-{
-       /*
-        * Work around bug in "less" by not starting it until we
-        * have real input
-        */
-       fd_set in;
-
-       FD_ZERO(&in);
-       FD_SET(0, &in);
-       select(1, &in, NULL, &in, NULL);
-}
-#endif
-
 static const char *pager_argv[] = { NULL, NULL };
-static struct child_process pager_process;
+static struct child_process pager_process = CHILD_PROCESS_INIT;
 
 static void wait_for_pager(void)
 {
@@ -63,7 +48,7 @@ const char *git_pager(int stdout_is_tty)
                pager = getenv("PAGER");
        if (!pager)
                pager = DEFAULT_PAGER;
-       else if (!*pager || !strcmp(pager, "cat"))
+       if (!*pager || !strcmp(pager, "cat"))
                pager = NULL;
 
        return pager;
@@ -89,13 +74,10 @@ void setup_pager(void)
        pager_process.use_shell = 1;
        pager_process.argv = pager_argv;
        pager_process.in = -1;
-       if (!getenv("LESS")) {
-               static const char *env[] = { "LESS=FRSX", NULL };
-               pager_process.env = env;
-       }
-#ifndef WIN32
-       pager_process.preexec_cb = pager_preexec;
-#endif
+       if (!getenv("LESS"))
+               argv_array_push(&pager_process.env_array, "LESS=FRX");
+       if (!getenv("LV"))
+               argv_array_push(&pager_process.env_array, "LV=-c");
        if (start_command(&pager_process))
                return;
 
@@ -147,3 +129,35 @@ int term_columns(void)
 
        return term_columns_at_startup;
 }
+
+/*
+ * How many columns do we need to show this number in decimal?
+ */
+int decimal_width(uintmax_t number)
+{
+       int width;
+
+       for (width = 1; number >= 10; width++)
+               number /= 10;
+       return width;
+}
+
+/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
+int check_pager_config(const char *cmd)
+{
+       int want = -1;
+       struct strbuf key = STRBUF_INIT;
+       const char *value = NULL;
+       strbuf_addf(&key, "pager.%s", cmd);
+       if (!git_config_get_value(key.buf, &value)) {
+               int b = git_config_maybe_bool(key.buf, value);
+               if (b >= 0)
+                       want = b;
+               else {
+                       want = 1;
+                       pager_program = xstrdup(value);
+               }
+       }
+       strbuf_release(&key);
+       return want;
+}