git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Pat Notz" <patnotz@gmail.com>
To: git@vger.kernel.org
Subject: [PATCHv5 3/8] pretty.c: helper methods for getting output encodings
Date: Thu, 7 Oct 2010 13:10:52 -0600	[thread overview]
Message-ID: <1286478657-61581-4-git-send-email-patnotz@gmail.com> (raw)
In-Reply-To: <1286478657-61581-1-git-send-email-patnotz@gmail.com>

Add helpers get_log_output_encoding() and get_commit_output_encoding()
that eliminate some messy and duplicate if-blocks.

Signed-off-by: Pat Notz <patnotz@gmail.com>
---
 builtin/commit.c |    2 +-
 cache.h          |    3 +++
 environment.c    |   11 +++++++++++
 pretty.c         |    6 +-----
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 9fe4bdc..ea3801d 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -905,7 +905,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
 
 		enc = get_header(commit, "encoding");
 		enc = enc ? enc : utf8;
-		out_enc = git_commit_encoding ? git_commit_encoding : utf8;
+		out_enc = get_commit_output_encoding();
 
 		if (strcmp(out_enc, enc))
 			use_message_buffer =
diff --git a/cache.h b/cache.h
index 3d5ed51..7d49805 100644
--- a/cache.h
+++ b/cache.h
@@ -1003,6 +1003,9 @@ extern int git_env_bool(const char *, int);
 extern int git_config_system(void);
 extern int git_config_global(void);
 extern int config_error_nonbool(const char *);
+extern const char *get_log_output_encoding(void);
+extern const char *get_commit_output_encoding(void);
+
 extern const char *config_exclusive_filename;
 
 #define MAX_GITNAME (1000)
diff --git a/environment.c b/environment.c
index de5581f..a9d44a2 100644
--- a/environment.c
+++ b/environment.c
@@ -192,3 +192,14 @@ int set_git_dir(const char *path)
 	setup_git_env();
 	return 0;
 }
+
+const char *get_log_output_encoding(void)
+{
+	return git_log_output_encoding ? git_log_output_encoding
+		: get_commit_output_encoding();
+}
+
+const char *get_commit_output_encoding(void)
+{
+	return git_commit_encoding ? git_commit_encoding : "UTF-8";
+}
diff --git a/pretty.c b/pretty.c
index 839944c..a607fd6 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1159,11 +1159,7 @@ char *reencode_commit_message(const struct commit *commit, const char **encoding
 {
 	const char *encoding;
 
-	encoding = (git_log_output_encoding
-		    ? git_log_output_encoding
-		    : git_commit_encoding);
-	if (!encoding)
-		encoding = "UTF-8";
+	encoding = get_log_output_encoding();
 	if (encoding_p)
 		*encoding_p = encoding;
 	return logmsg_reencode(commit, encoding);
-- 
1.7.3.1

  parent reply	other threads:[~2010-10-07 19:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-07 19:10 [PATCHv5 0/8] Add commit message options for rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 1/8] commit.c: prefer get_header() to manual searching Pat Notz
2010-10-07 21:11   ` Sverre Rabbelier
2010-10-07 21:12     ` Sverre Rabbelier
2010-10-13 21:59   ` Junio C Hamano
2010-10-07 19:10 ` [PATCHv5 2/8] commit.c: new function for looking up a comit by name Pat Notz
2010-10-13 21:59   ` Junio C Hamano
2010-10-07 19:10 ` Pat Notz [this message]
2010-10-07 19:10 ` [PATCHv5 4/8] pretty.c: teach format_commit_message() to reencode the output Pat Notz
2010-10-13 21:59   ` Junio C Hamano
2010-10-13 22:44     ` Pat Notz
2010-10-07 19:10 ` [PATCHv5 5/8] commit: --fixup option for use with rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 6/8] add tests of commit --fixup Pat Notz
2010-10-07 19:10 ` [PATCHv5 7/8] commit: --squash option for use with rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 8/8] add tests of commit --squash Pat Notz
2010-10-11 21:06 ` [PATCHv5 0/8] Add commit message options for rebase --autosquash Pat Notz
2010-10-12  9:36   ` Sverre Rabbelier

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

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

  git send-email \
    --in-reply-to=1286478657-61581-4-git-send-email-patnotz@gmail.com \
    --to=patnotz@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).