| 143 | } |
| 144 | |
| 145 | void setup_pager(struct repository *r) |
| 146 | { |
| 147 | static int once = 0; |
| 148 | const char *pager = git_pager(r, isatty(1)); |
| 149 | |
| 150 | if (!pager) |
| 151 | return; |
| 152 | |
| 153 | /* |
| 154 | * After we redirect standard output, we won't be able to use an ioctl |
| 155 | * to get the terminal size. Let's grab it now, and then set $COLUMNS |
| 156 | * to communicate it to any sub-processes. |
| 157 | */ |
| 158 | { |
| 159 | char buf[64]; |
| 160 | xsnprintf(buf, sizeof(buf), "%d", term_columns()); |
| 161 | if (!term_columns_guessed) |
| 162 | setenv("COLUMNS", buf, 0); |
| 163 | } |
| 164 | |
| 165 | setenv("GIT_PAGER_IN_USE", "true", 1); |
| 166 | |
| 167 | child_process_init(&pager_process); |
| 168 | |
| 169 | /* spawn the pager */ |
| 170 | prepare_pager_args(&pager_process, pager); |
| 171 | pager_process.in = -1; |
| 172 | strvec_push(&pager_process.env, "GIT_PAGER_IN_USE"); |
| 173 | if (start_command(&pager_process)) |
| 174 | die("unable to execute pager '%s'", pager); |
| 175 | |
| 176 | /* original process continues, but writes to the pipe */ |
| 177 | old_fd1 = dup(1); |
| 178 | dup2(pager_process.in, 1); |
| 179 | if (isatty(2)) { |
| 180 | old_fd2 = dup(2); |
| 181 | dup2(pager_process.in, 2); |
| 182 | } |
| 183 | close(pager_process.in); |
| 184 | |
| 185 | sigchain_push_common(wait_for_pager_signal); |
| 186 | |
| 187 | if (!once) { |
| 188 | once++; |
| 189 | atexit(wait_for_pager_atexit); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | int pager_in_use(void) |
| 194 | { |
no test coverage detected