summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c752e7f)
raw | patch | inline | side by side (parent: c752e7f)
author | Pat Notz <patnotz@gmail.com> | |
Tue, 2 Nov 2010 19:59:07 +0000 (13:59 -0600) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 4 Nov 2010 20:53:34 +0000 (13:53 -0700) |
* builtin/commit.c: Replace block of code with a one-liner call to
logmsg_reencode().
* commit.c: new function for looking up a comit by name
* pretty.c: helper methods for getting output encodings
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
logmsg_reencode().
* commit.c: new function for looking up a comit by name
* pretty.c: helper methods for getting output encodings
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c | patch | blob | history | |
builtin/log.c | patch | blob | history | |
builtin/mailinfo.c | patch | blob | history | |
cache.h | patch | blob | history | |
commit.c | patch | blob | history | |
commit.h | patch | blob | history | |
environment.c | patch | blob | history | |
pretty.c | patch | blob | history |
diff --git a/builtin/commit.c b/builtin/commit.c
index 66fdd2202495b2893c79b4f92b0fc2e715f5b7bb..54fcc6d142e4bb73f9dde1f0658af23d1b1b1272 100644 (file)
--- a/builtin/commit.c
+++ b/builtin/commit.c
if (!use_message && renew_authorship)
die("--reset-author can be used only with -C, -c or --amend.");
if (use_message) {
- unsigned char sha1[20];
- static char utf8[] = "UTF-8";
const char *out_enc;
- char *enc, *end;
struct commit *commit;
- if (get_sha1(use_message, sha1))
+ commit = lookup_commit_reference_by_name(use_message);
+ if (!commit)
die("could not lookup commit %s", use_message);
- commit = lookup_commit_reference(sha1);
- if (!commit || parse_commit(commit))
- die("could not parse commit %s", use_message);
-
- enc = strstr(commit->buffer, "\nencoding");
- if (enc) {
- end = strchr(enc + 10, '\n');
- enc = xstrndup(enc + 10, end - (enc + 10));
- } else {
- enc = utf8;
- }
- out_enc = git_commit_encoding ? git_commit_encoding : utf8;
-
- if (strcmp(out_enc, enc))
- use_message_buffer =
- reencode_string(commit->buffer, out_enc, enc);
+ out_enc = get_commit_output_encoding();
+ use_message_buffer = logmsg_reencode(commit, out_enc);
/*
* If we failed to reencode the buffer, just copy it
*/
if (use_message_buffer == NULL)
use_message_buffer = xstrdup(commit->buffer);
- if (enc != utf8)
- free(enc);
}
if (!!also + !!only + !!all + !!interactive > 1)
diff --git a/builtin/log.c b/builtin/log.c
index 22d12903ac06597979f30d0fd94267fc543afa29..90e05aca9dc0f980f13b8beaf3865cb86c5669a8 100644 (file)
--- a/builtin/log.c
+++ b/builtin/log.c
struct strbuf out = STRBUF_INIT;
pp_user_info("Tagger", rev->commit_format, &out, buf, rev->date_mode,
- git_log_output_encoding ?
- git_log_output_encoding: git_commit_encoding);
+ get_log_output_encoding());
printf("%s", out.buf);
strbuf_release(&out);
}
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index 2320d981ceab220e287e42c21f3c9f3be5b3722f..71e6262a87d883a4a82953db5f742bccf99e5c77 100644 (file)
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
*/
git_config(git_mailinfo_config, NULL);
- def_charset = (git_commit_encoding ? git_commit_encoding : "UTF-8");
+ def_charset = get_commit_output_encoding();
metainfo_charset = def_charset;
while (1 < argc && argv[1][0] == '-') {
index 3d5ed51989d6c118062c0709eae41fcb3cc6543b..7d498056b243afe3f828d178d42821f0667de72d 100644 (file)
--- a/cache.h
+++ b/cache.h
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/commit.c b/commit.c
index 0094ec1c9278332f736d2814c847b272788a7dd3..5ed9ccd723b9992e9d331df8d7ad6122fd661a5f 100644 (file)
--- a/commit.c
+++ b/commit.c
return check_commit(obj, sha1, 0);
}
+struct commit *lookup_commit_reference_by_name(const char *name)
+{
+ unsigned char sha1[20];
+ struct commit *commit;
+
+ if (get_sha1(name, sha1))
+ return NULL;
+ commit = lookup_commit_reference(sha1);
+ if (!commit || parse_commit(commit))
+ return NULL;
+ return commit;
+}
+
static unsigned long parse_commit_date(const char *buf, const char *tail)
{
const char *dateptr;
diff --git a/commit.h b/commit.h
index 9113bbe4889d71e824348edcb920110598db18d2..a0b710f843d81819a84dd7bb44f405d7d04ed89d 100644 (file)
--- a/commit.h
+++ b/commit.h
struct commit *lookup_commit_reference(const unsigned char *sha1);
struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
int quiet);
+struct commit *lookup_commit_reference_by_name(const char *name);
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
diff --git a/environment.c b/environment.c
index de5581fe51d532231b0121bd2ef2e46669015bda..a9d44a28a75cbba39e04561e5ea3ae4f1b9f51d3 100644 (file)
--- a/environment.c
+++ b/environment.c
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 f85444b27d4815547f7cef542291b1f6616f77d5..c253172ef96fcbdfb9171edf3c1d278586ee9bc3 100644 (file)
--- a/pretty.c
+++ b/pretty.c
case 'N':
if (c->pretty_ctx->show_notes) {
format_display_notes(commit->object.sha1, sb,
- git_log_output_encoding ? git_log_output_encoding
- : git_commit_encoding, 0);
+ get_log_output_encoding(), 0);
return 1;
}
return 0;
@@ -1159,11 +1158,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);