summaryrefslogtreecommitdiffstats
path: root/commit.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-03-06 20:44:17 -0500
committerJunio C Hamano <junkio@cox.net>2007-03-07 10:47:10 -0800
commit3a55602eeca4ac8670e8698a7187e18b95683344 (patch)
tree625a8af9c4655ace00b275c3e272c2764db3bcb8 /commit.c
parentDon't build external_grep if its not used (diff)
downloadgit-3a55602eeca4ac8670e8698a7187e18b95683344.tar.gz
git-3a55602eeca4ac8670e8698a7187e18b95683344.zip
General const correctness fixes
We shouldn't attempt to assign constant strings into char*, as the string is not writable at runtime. Likewise we should always be treating unsigned values as unsigned values, not as signed values. Most of these are very straightforward. The only exception is the (unnecessary) xstrdup/free in builtin-branch.c for the detached head case. Since this is a user-level interactive type program and that particular code path is executed no more than once, I feel that the extra xstrdup call is well worth the easy elimination of this warning. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/commit.c b/commit.c
index 5552527342..5b9234e12e 100644
--- a/commit.c
+++ b/commit.c
@@ -651,7 +651,7 @@ static char *get_header(const struct commit *commit, const char *key)
}
}
-static char *replace_encoding_header(char *buf, char *encoding)
+static char *replace_encoding_header(char *buf, const char *encoding)
{
char *encoding_header = strstr(buf, "\nencoding ");
char *end_of_encoding_header;
@@ -694,29 +694,26 @@ static char *replace_encoding_header(char *buf, char *encoding)
}
static char *logmsg_reencode(const struct commit *commit,
- char *output_encoding)
+ const char *output_encoding)
{
+ static const char *utf8 = "utf-8";
+ const char *use_encoding;
char *encoding;
char *out;
- char *utf8 = "utf-8";
if (!*output_encoding)
return NULL;
encoding = get_header(commit, "encoding");
- if (!encoding)
- encoding = utf8;
- if (!strcmp(encoding, output_encoding))
+ use_encoding = encoding ? encoding : utf8;
+ if (!strcmp(use_encoding, output_encoding))
out = strdup(commit->buffer);
else
out = reencode_string(commit->buffer,
- output_encoding, encoding);
+ output_encoding, use_encoding);
if (out)
out = replace_encoding_header(out, output_encoding);
- if (encoding != utf8)
- free(encoding);
- if (!out)
- return NULL;
+ free(encoding);
return out;
}
@@ -917,7 +914,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
const char *msg = commit->buffer;
int plain_non_ascii = 0;
char *reencoded;
- char *encoding;
+ const char *encoding;
if (fmt == CMIT_FMT_USERFORMAT)
return format_commit_message(commit, msg, buf, space);
[ALSA] Kconfig: cleanup sound menuJaroslav Kysela1-1/+7 2005-02-14[ALSA] hdsp ghost midi device fixJaroslav Kysela1-5/+8 2005-02-14[ALSA] Fix 32bit calls to snd_pcm_channel_info()Jaroslav Kysela1-10/+16 2005-02-14[ALSA] Fix compile error (due to last suspend/resume fix)Jaroslav Kysela1-2/+2 2005-02-14[ALSA] intel8x0 - fix for broken PCI ID define for ICH6Jaroslav Kysela1-3/+3 2005-02-14[ALSA] intel8x0 - fixed timeout in the 'get current DMA pointer' routineJaroslav Kysela1-3/+5 2005-02-14[ALSA] Fix suspend/resume functionsJaroslav Kysela1-2/+2 2005-02-14[ALSA] Fix inclusion of pm.hJaroslav Kysela1-0/+1 2005-02-14[ALSA] Fix resume callbackJaroslav Kysela2-2/+2 2005-02-14[ALSA] Remove unused variableJaroslav Kysela1-1/+0 2005-02-14[ALSA] Fix descriptions about suspend/resume callbacksJaroslav Kysela2-5/+5 2005-02-14[ALSA] driver model type fixes for ALSAJaroslav Kysela32-91/+85 2005-02-14[ALSA] use cached idVendor/idProduct valuesJaroslav Kysela1-1/+1 2005-02-14[ALSA] Set default index of modem and bt87x drivers to -2Jaroslav Kysela5-4/+16 2005-02-14[ALSA] Interpret negative index as bitmask of permissible indexesJaroslav Kysela2-117/+121 2005-02-14[ALSA] Changes 'Music' to 'Synth' in mixer control namesJaroslav Kysela1-9/+9 2005-02-14[ALSA] HDSP fixesJaroslav Kysela2-278/+235 2005-02-14[ALSA] Remove pm_register/pm_unregisterJaroslav Kysela6-44/+136 2005-02-14[ALSA] Remove descriptions of obsolete optionsJaroslav Kysela1-16/+0 2005-02-14[ALSA] Ascii chars onlyJaroslav Kysela1-1/+1 2005-02-14[ALSA] Add newline to printkJaroslav Kysela1-1/+1 2005-01-27[ALSA] Removed file added by mistakeJaroslav Kysela1-3/+0 2005-01-25[ALSA] replace schedule_timeout() with msleep()Jaroslav Kysela1-2/+2 2005-01-25[ALSA] insert set_current_state() before schedule_timeout()Jaroslav Kysela1-0/+1 2005-01-25[ALSA] replace schedule_timeout() with msleep_interruptible()Jaroslav Kysela1-6/+1 2005-01-25[ALSA] insert set_current_state() before schedule_timeout()Jaroslav Kysela1-0/+1 2005-01-25[ALSA] replace schedule_timeout() with msleep()Jaroslav Kysela1-5/+3 2005-01-25[ALSA] replace schedule_timeout() with msleep()Jaroslav Kysela1-4/+3 2005-01-25[ALSA] Special AC97 patch for ASUS W1000/CMI9739 laptopJaroslav Kysela1-0/+9