git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 4/7] Move setup_diff_pager to libgit.a
Date: Fri, 26 Oct 2012 22:53:52 +0700	[thread overview]
Message-ID: <1351266835-22610-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1351266835-22610-1-git-send-email-pclouds@gmail.com>

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>
---
 builtin.h      |  4 ----
 builtin/diff.c | 16 ----------------
 cache.h        |  1 +
 diff.c         | 16 ++++++++++++++++
 diff.h         |  1 +
 git.c          | 33 ---------------------------------
 pager.c        | 34 ++++++++++++++++++++++++++++++++++
 7 files changed, 52 insertions(+), 53 deletions(-)

diff --git a/builtin.h b/builtin.h
index 95116b8..3faf9d6 100644
--- a/builtin.h
+++ b/builtin.h
@@ -37,10 +37,6 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
 			  const unsigned char *from_obj, const unsigned char *to_obj);
 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 cmd_add(int argc, const char **argv, const char *prefix);
diff --git a/builtin/diff.c b/builtin/diff.c
index 9650be2..9c70e40 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -418,19 +418,3 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 		refresh_index_quietly();
 	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();
-}
diff --git a/cache.h b/cache.h
index 2dc4dec..dbd8018 100644
--- a/cache.h
+++ b/cache.h
@@ -1183,6 +1183,7 @@ extern int pager_in_use(void);
 extern int pager_use_color;
 extern int term_columns(void);
 extern int decimal_width(int);
+extern int check_pager_config(const char *cmd);
 
 extern const char *editor_program;
 extern const char *askpass_program;
diff --git a/diff.c b/diff.c
index 35d3f07..1b5727d 100644
--- a/diff.c
+++ b/diff.c
@@ -4871,3 +4871,19 @@ size_t fill_textconv(struct userdiff_driver *driver,
 
 	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();
+}
diff --git a/diff.h b/diff.h
index a658f85..a47bae4 100644
--- a/diff.h
+++ b/diff.h
@@ -335,5 +335,6 @@ extern int parse_rename_score(const char **cp_p);
 
 extern int print_stat_summary(FILE *fp, int files,
 			      int insertions, int deletions);
+extern void setup_diff_pager(struct diff_options *);
 
 #endif /* DIFF_H */
diff --git a/git.c b/git.c
index 8788b32..d33f9b3 100644
--- a/git.c
+++ b/git.c
@@ -17,39 +17,6 @@ const char git_more_info_string[] =
 
 static struct startup_info git_startup_info;
 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) {
 	switch (use_pager) {
diff --git a/pager.c b/pager.c
index 4dcb08d..060fa88 100644
--- a/pager.c
+++ b/pager.c
@@ -6,6 +6,12 @@
 #define DEFAULT_PAGER "less"
 #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
  * something different on Windows.
@@ -159,3 +165,31 @@ int decimal_width(int number)
 		i *= 10;
 	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;
+}
-- 
1.8.0.rc2.23.g1fb49df

  parent reply	other threads:[~2012-10-26 15:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23  2:24 [PATCH] Move try_merge_command and checkout_fast_forward to libgit.a Nguyễn Thái Ngọc Duy
2012-10-25  9:45 ` Jeff King
2012-10-25 12:50   ` Nguyen Thai Ngoc Duy
2012-10-26 12:02     ` Jeff King
2012-10-26 15:53       ` [PATCH 0/7] Move code from builtin " Nguyễn Thái Ngọc Duy
2012-10-26 15:53         ` [PATCH 1/7] Move try_merge_command and checkout_fast_forward " Nguyễn Thái Ngọc Duy
2012-10-26 15:53         ` [PATCH 2/7] Move estimate_bisect_steps " Nguyễn Thái Ngọc Duy
2012-10-26 15:53         ` [PATCH 3/7] Move print_commit_list " Nguyễn Thái Ngọc Duy
2012-10-26 15:53         ` Nguyễn Thái Ngọc Duy [this message]
2012-10-26 15:53         ` [PATCH 5/7] send-pack: move core code " Nguyễn Thái Ngọc Duy
2012-10-26 15:53         ` [PATCH 6/7] fetch-pack: remove global (static) configuration variable "args" Nguyễn Thái Ngọc Duy
2012-10-26 15:53         ` [PATCH 7/7] fetch-pack: move core code to libgit.a Nguyễn Thái Ngọc Duy
2012-10-29  7:43         ` [PATCH 0/7] Move code from builtin " Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351266835-22610-5-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).