@matheusbsbs / matheus-bagliano / commits / c7d77dab93
Fork 0

git-var: constness and globalness cleanup.

var.c::git_var read function did not have to return writable strings; make it and the functions it points at return const char * instead. ident.c::get_ident() did not need to be global, so make it static. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 21, 2005 at 23:44 UTC c7d77dab9333112cfce8cce51e56005b5e8b4076
3 files changed +13 -9
cache.h
+2 -3
@@ -263,9 +263,8 @@ void datestamp(char *buf, int bufsize);
263 unsigned long approxidate(const char *);
264
265 extern int setup_ident(void);
266 -extern char *get_ident(const char *name, const char *email, const char *date_str);
267 -extern char *git_author_info(void);
268 -extern char *git_committer_info(void);
266 +extern const char *git_author_info(void);
267 +extern const char *git_committer_info(void);
268
269 static inline void *xmalloc(size_t size)
270 {
ident.c
+10 -5
@@ -156,7 +156,8 @@ static int copy(char *buf, int size, int offset, const char *src)
156 return offset;
157 }
158
159 -char *get_ident(const char *name, const char *email, const char *date_str)
159 +static const char *get_ident(const char *name, const char *email,
160 + const char *date_str)
161 {
162 static char buffer[1000];
163 char date[50];
@@ -181,12 +182,16 @@ char *get_ident(const char *name, const char *email, const char *date_str)
182 return buffer;
183 }
184
184 -char *git_author_info(void)
185 +const char *git_author_info(void)
186 {
186 - return get_ident(getenv("GIT_AUTHOR_NAME"), getenv("GIT_AUTHOR_EMAIL"), getenv("GIT_AUTHOR_DATE"));
187 + return get_ident(getenv("GIT_AUTHOR_NAME"),
188 + getenv("GIT_AUTHOR_EMAIL"),
189 + getenv("GIT_AUTHOR_DATE"));
190 }
191
189 -char *git_committer_info(void)
192 +const char *git_committer_info(void)
193 {
191 - return get_ident(getenv("GIT_COMMITTER_NAME"), getenv("GIT_COMMITTER_EMAIL"), getenv("GIT_COMMITTER_DATE"));
194 + return get_ident(getenv("GIT_COMMITTER_NAME"),
195 + getenv("GIT_COMMITTER_EMAIL"),
196 + getenv("GIT_COMMITTER_DATE"));
197 }
var.c
+1 -1
@@ -12,7 +12,7 @@ static const char var_usage[] = "git-var [-l | <variable>]";
12
13 struct git_var {
14 const char *name;
15 - char *(*read)(void);
15 + const char *(*read)(void);
16 };
17 static struct git_var git_vars[] = {
18 { "GIT_COMMITTER_IDENT", git_committer_info },