Skip to content

Commit 773b69b

Browse files
pcloudsgitster
authored andcommitted
shortlog: run setup_git_directory_gently() sooner
shortlog already runs a repository search unconditionally; running such a search earlier is not very risky. Without this change, the “[pager] shortlog” configuration is not respected at all: “git shortlog” unconditionally paginates. The tests are a bit slow. Running the full battery like this for all built-in commands would be counterproductive; the intent is rather to test shortlog as a representative example command using ..._gently(). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ee38dfb commit 773b69b

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

builtin/shortlog.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
249249
{
250250
static struct shortlog log;
251251
static struct rev_info rev;
252-
int nongit;
252+
int nongit = !startup_info->have_repository;
253253

254254
static const struct option options[] = {
255255
OPT_BOOLEAN('n', "numbered", &log.sort_by_number,
@@ -265,7 +265,6 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
265265

266266
struct parse_opt_ctx_t ctx;
267267

268-
prefix = setup_git_directory_gently(&nongit);
269268
git_config(git_default_config, NULL);
270269
shortlog_init(&log);
271270
init_revisions(&rev, prefix);

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static void handle_internal_command(int argc, const char **argv)
384384
{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
385385
{ "rm", cmd_rm, RUN_SETUP },
386386
{ "send-pack", cmd_send_pack, RUN_SETUP },
387-
{ "shortlog", cmd_shortlog, USE_PAGER },
387+
{ "shortlog", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },
388388
{ "show-branch", cmd_show_branch, RUN_SETUP },
389389
{ "show", cmd_show, RUN_SETUP | USE_PAGER },
390390
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },

t/t7006-pager.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,13 @@ test_GIT_PAGER_overrides expect_success test_must_fail 'git -p'
369369

370370
test_doesnt_paginate expect_failure test_must_fail 'git -p nonsense'
371371

372+
test_pager_choices 'git shortlog'
373+
test_expect_success 'setup: configure shortlog not to paginate' '
374+
git config pager.shortlog false
375+
'
376+
test_doesnt_paginate expect_success 'git shortlog'
377+
test_no_local_config_subdir expect_success 'git shortlog'
378+
test_default_pager expect_success 'git -p shortlog'
379+
test_core_pager_subdir expect_success 'git -p shortlog'
380+
372381
test_done

0 commit comments

Comments
 (0)