Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 4914c96

Browse files
pcloudspeff
authored andcommitted
Move setup_diff_pager to libgit.a
This is used by diff-no-index.c, part of libgit.a while it stays in builtin/diff.c. Move it to diff.c so that we won't get undefined reference if a program that uses libgit.a happens to pull it in. While at it, move check_pager from git.c to pager.c. It makes more sense there and pager.c is also part of libgit.a Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent efc7df4 commit 4914c96

File tree

7 files changed

+52
-53
lines changed

7 files changed

+52
-53
lines changed

builtin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
3737
const unsigned char *from_obj, const unsigned char *to_obj);
3838
void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
3939

40-
extern int check_pager_config(const char *cmd);
41-
struct diff_options;
42-
extern void setup_diff_pager(struct diff_options *);
43-
4440
extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
4541

4642
extern int cmd_add(int argc, const char **argv, const char *prefix);

builtin/diff.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,3 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
418418
refresh_index_quietly();
419419
return result;
420420
}
421-
422-
void setup_diff_pager(struct diff_options *opt)
423-
{
424-
/*
425-
* If the user asked for our exit code, then either they want --quiet
426-
* or --exit-code. We should definitely not bother with a pager in the
427-
* former case, as we will generate no output. Since we still properly
428-
* report our exit code even when a pager is run, we _could_ run a
429-
* pager with --exit-code. But since we have not done so historically,
430-
* and because it is easy to find people oneline advising "git diff
431-
* --exit-code" in hooks and other scripts, we do not do so.
432-
*/
433-
if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
434-
check_pager_config("diff") != 0)
435-
setup_pager();
436-
}

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,7 @@ extern int pager_in_use(void);
11831183
extern int pager_use_color;
11841184
extern int term_columns(void);
11851185
extern int decimal_width(int);
1186+
extern int check_pager_config(const char *cmd);
11861187

11871188
extern const char *editor_program;
11881189
extern const char *askpass_program;

diff.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4878,3 +4878,19 @@ size_t fill_textconv(struct userdiff_driver *driver,
48784878

48794879
return size;
48804880
}
4881+
4882+
void setup_diff_pager(struct diff_options *opt)
4883+
{
4884+
/*
4885+
* If the user asked for our exit code, then either they want --quiet
4886+
* or --exit-code. We should definitely not bother with a pager in the
4887+
* former case, as we will generate no output. Since we still properly
4888+
* report our exit code even when a pager is run, we _could_ run a
4889+
* pager with --exit-code. But since we have not done so historically,
4890+
* and because it is easy to find people oneline advising "git diff
4891+
* --exit-code" in hooks and other scripts, we do not do so.
4892+
*/
4893+
if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
4894+
check_pager_config("diff") != 0)
4895+
setup_pager();
4896+
}

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,6 @@ extern int parse_rename_score(const char **cp_p);
335335

336336
extern int print_stat_summary(FILE *fp, int files,
337337
int insertions, int deletions);
338+
extern void setup_diff_pager(struct diff_options *);
338339

339340
#endif /* DIFF_H */

git.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,6 @@ const char git_more_info_string[] =
1717

1818
static struct startup_info git_startup_info;
1919
static int use_pager = -1;
20-
struct pager_config {
21-
const char *cmd;
22-
int want;
23-
char *value;
24-
};
25-
26-
static int pager_command_config(const char *var, const char *value, void *data)
27-
{
28-
struct pager_config *c = data;
29-
if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) {
30-
int b = git_config_maybe_bool(var, value);
31-
if (b >= 0)
32-
c->want = b;
33-
else {
34-
c->want = 1;
35-
c->value = xstrdup(value);
36-
}
37-
}
38-
return 0;
39-
}
40-
41-
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
42-
int check_pager_config(const char *cmd)
43-
{
44-
struct pager_config c;
45-
c.cmd = cmd;
46-
c.want = -1;
47-
c.value = NULL;
48-
git_config(pager_command_config, &c);
49-
if (c.value)
50-
pager_program = c.value;
51-
return c.want;
52-
}
5320

5421
static void commit_pager_choice(void) {
5522
switch (use_pager) {

pager.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#define DEFAULT_PAGER "less"
77
#endif
88

9+
struct pager_config {
10+
const char *cmd;
11+
int want;
12+
char *value;
13+
};
14+
915
/*
1016
* This is split up from the rest of git so that we can do
1117
* something different on Windows.
@@ -141,3 +147,31 @@ int decimal_width(int number)
141147
i *= 10;
142148
return width;
143149
}
150+
151+
static int pager_command_config(const char *var, const char *value, void *data)
152+
{
153+
struct pager_config *c = data;
154+
if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) {
155+
int b = git_config_maybe_bool(var, value);
156+
if (b >= 0)
157+
c->want = b;
158+
else {
159+
c->want = 1;
160+
c->value = xstrdup(value);
161+
}
162+
}
163+
return 0;
164+
}
165+
166+
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
167+
int check_pager_config(const char *cmd)
168+
{
169+
struct pager_config c;
170+
c.cmd = cmd;
171+
c.want = -1;
172+
c.value = NULL;
173+
git_config(pager_command_config, &c);
174+
if (c.value)
175+
pager_program = c.value;
176+
return c.want;
177+
}

0 commit comments

Comments
 (0)