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 <pclouds@gmail.com> Signed-off-by: Jeff King <peff@peff.net>
This commit is contained in:

committed by
Jeff King

parent
efc7df454e
commit
4914c9629c
@ -37,10 +37,6 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
|
|||||||
const unsigned char *from_obj, const unsigned char *to_obj);
|
const unsigned char *from_obj, const unsigned char *to_obj);
|
||||||
void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
|
void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
|
||||||
|
|
||||||
extern int check_pager_config(const char *cmd);
|
|
||||||
struct diff_options;
|
|
||||||
extern void setup_diff_pager(struct diff_options *);
|
|
||||||
|
|
||||||
extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
|
extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
|
||||||
|
|
||||||
extern int cmd_add(int argc, const char **argv, const char *prefix);
|
extern int cmd_add(int argc, const char **argv, const char *prefix);
|
||||||
|
@ -418,19 +418,3 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
|||||||
refresh_index_quietly();
|
refresh_index_quietly();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_diff_pager(struct diff_options *opt)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* If the user asked for our exit code, then either they want --quiet
|
|
||||||
* or --exit-code. We should definitely not bother with a pager in the
|
|
||||||
* former case, as we will generate no output. Since we still properly
|
|
||||||
* report our exit code even when a pager is run, we _could_ run a
|
|
||||||
* pager with --exit-code. But since we have not done so historically,
|
|
||||||
* and because it is easy to find people oneline advising "git diff
|
|
||||||
* --exit-code" in hooks and other scripts, we do not do so.
|
|
||||||
*/
|
|
||||||
if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
|
|
||||||
check_pager_config("diff") != 0)
|
|
||||||
setup_pager();
|
|
||||||
}
|
|
||||||
|
1
cache.h
1
cache.h
@ -1183,6 +1183,7 @@ extern int pager_in_use(void);
|
|||||||
extern int pager_use_color;
|
extern int pager_use_color;
|
||||||
extern int term_columns(void);
|
extern int term_columns(void);
|
||||||
extern int decimal_width(int);
|
extern int decimal_width(int);
|
||||||
|
extern int check_pager_config(const char *cmd);
|
||||||
|
|
||||||
extern const char *editor_program;
|
extern const char *editor_program;
|
||||||
extern const char *askpass_program;
|
extern const char *askpass_program;
|
||||||
|
16
diff.c
16
diff.c
@ -4878,3 +4878,19 @@ size_t fill_textconv(struct userdiff_driver *driver,
|
|||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setup_diff_pager(struct diff_options *opt)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If the user asked for our exit code, then either they want --quiet
|
||||||
|
* or --exit-code. We should definitely not bother with a pager in the
|
||||||
|
* former case, as we will generate no output. Since we still properly
|
||||||
|
* report our exit code even when a pager is run, we _could_ run a
|
||||||
|
* pager with --exit-code. But since we have not done so historically,
|
||||||
|
* and because it is easy to find people oneline advising "git diff
|
||||||
|
* --exit-code" in hooks and other scripts, we do not do so.
|
||||||
|
*/
|
||||||
|
if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
|
||||||
|
check_pager_config("diff") != 0)
|
||||||
|
setup_pager();
|
||||||
|
}
|
||||||
|
1
diff.h
1
diff.h
@ -335,5 +335,6 @@ extern int parse_rename_score(const char **cp_p);
|
|||||||
|
|
||||||
extern int print_stat_summary(FILE *fp, int files,
|
extern int print_stat_summary(FILE *fp, int files,
|
||||||
int insertions, int deletions);
|
int insertions, int deletions);
|
||||||
|
extern void setup_diff_pager(struct diff_options *);
|
||||||
|
|
||||||
#endif /* DIFF_H */
|
#endif /* DIFF_H */
|
||||||
|
33
git.c
33
git.c
@ -17,39 +17,6 @@ const char git_more_info_string[] =
|
|||||||
|
|
||||||
static struct startup_info git_startup_info;
|
static struct startup_info git_startup_info;
|
||||||
static int use_pager = -1;
|
static int use_pager = -1;
|
||||||
struct pager_config {
|
|
||||||
const char *cmd;
|
|
||||||
int want;
|
|
||||||
char *value;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int pager_command_config(const char *var, const char *value, void *data)
|
|
||||||
{
|
|
||||||
struct pager_config *c = data;
|
|
||||||
if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) {
|
|
||||||
int b = git_config_maybe_bool(var, value);
|
|
||||||
if (b >= 0)
|
|
||||||
c->want = b;
|
|
||||||
else {
|
|
||||||
c->want = 1;
|
|
||||||
c->value = xstrdup(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
|
|
||||||
int check_pager_config(const char *cmd)
|
|
||||||
{
|
|
||||||
struct pager_config c;
|
|
||||||
c.cmd = cmd;
|
|
||||||
c.want = -1;
|
|
||||||
c.value = NULL;
|
|
||||||
git_config(pager_command_config, &c);
|
|
||||||
if (c.value)
|
|
||||||
pager_program = c.value;
|
|
||||||
return c.want;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void commit_pager_choice(void) {
|
static void commit_pager_choice(void) {
|
||||||
switch (use_pager) {
|
switch (use_pager) {
|
||||||
|
34
pager.c
34
pager.c
@ -6,6 +6,12 @@
|
|||||||
#define DEFAULT_PAGER "less"
|
#define DEFAULT_PAGER "less"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct pager_config {
|
||||||
|
const char *cmd;
|
||||||
|
int want;
|
||||||
|
char *value;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is split up from the rest of git so that we can do
|
* This is split up from the rest of git so that we can do
|
||||||
* something different on Windows.
|
* something different on Windows.
|
||||||
@ -141,3 +147,31 @@ int decimal_width(int number)
|
|||||||
i *= 10;
|
i *= 10;
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pager_command_config(const char *var, const char *value, void *data)
|
||||||
|
{
|
||||||
|
struct pager_config *c = data;
|
||||||
|
if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) {
|
||||||
|
int b = git_config_maybe_bool(var, value);
|
||||||
|
if (b >= 0)
|
||||||
|
c->want = b;
|
||||||
|
else {
|
||||||
|
c->want = 1;
|
||||||
|
c->value = xstrdup(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
|
||||||
|
int check_pager_config(const char *cmd)
|
||||||
|
{
|
||||||
|
struct pager_config c;
|
||||||
|
c.cmd = cmd;
|
||||||
|
c.want = -1;
|
||||||
|
c.value = NULL;
|
||||||
|
git_config(pager_command_config, &c);
|
||||||
|
if (c.value)
|
||||||
|
pager_program = c.value;
|
||||||
|
return c.want;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user