Skip to content

Commit 9590b04

Browse files
author
Junio C Hamano
committed
Builtins: control the use of pager from the command table.
This moves the built-in "always-use-pager" logic for log family to the command dispatch table of git wrapper. This makes it easier to change the default use of pager, and has an added benefit that we fork and exec the pager early before packs are mmapped. Pointed out by Juergen Ruehle <j.ruehle@bmiag.de>. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 3e04228 commit 9590b04

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

builtin-log.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ static int cmd_log_walk(struct rev_info *rev)
3434
struct commit *commit;
3535

3636
prepare_revision_walk(rev);
37-
setup_pager();
3837
while ((commit = get_revision(rev)) != NULL) {
3938
log_tree_commit(rev, commit);
4039
free(commit->buffer);

git.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,21 @@ static int handle_alias(int *argcp, const char ***argv)
211211
const char git_version_string[] = GIT_VERSION;
212212

213213
#define NEEDS_PREFIX 1
214+
#define USE_PAGER 2
214215

215216
static void handle_internal_command(int argc, const char **argv, char **envp)
216217
{
217218
const char *cmd = argv[0];
218219
static struct cmd_struct {
219220
const char *cmd;
220221
int (*fn)(int, const char **, const char *);
221-
int prefix;
222+
int option;
222223
} commands[] = {
223224
{ "version", cmd_version },
224225
{ "help", cmd_help },
225-
{ "log", cmd_log, NEEDS_PREFIX },
226-
{ "whatchanged", cmd_whatchanged, NEEDS_PREFIX },
227-
{ "show", cmd_show, NEEDS_PREFIX },
226+
{ "log", cmd_log, NEEDS_PREFIX | USE_PAGER },
227+
{ "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER },
228+
{ "show", cmd_show, NEEDS_PREFIX | USE_PAGER },
228229
{ "push", cmd_push },
229230
{ "format-patch", cmd_format_patch, NEEDS_PREFIX },
230231
{ "count-objects", cmd_count_objects },
@@ -275,8 +276,10 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
275276
continue;
276277

277278
prefix = NULL;
278-
if (p->prefix)
279+
if (p->option & NEEDS_PREFIX)
279280
prefix = setup_git_directory();
281+
if (p->option & USE_PAGER)
282+
setup_pager();
280283
if (getenv("GIT_TRACE")) {
281284
int i;
282285
fprintf(stderr, "trace: built-in: git");

0 commit comments

Comments
 (0)