Browse Source

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>
maint
Junio C Hamano 19 years ago
parent
commit
c7d77dab93
  1. 5
      cache.h
  2. 15
      ident.c
  3. 2
      var.c

5
cache.h

@ -263,9 +263,8 @@ void datestamp(char *buf, int bufsize); @@ -263,9 +263,8 @@ void datestamp(char *buf, int bufsize);
unsigned long approxidate(const char *);

extern int setup_ident(void);
extern char *get_ident(const char *name, const char *email, const char *date_str);
extern char *git_author_info(void);
extern char *git_committer_info(void);
extern const char *git_author_info(void);
extern const char *git_committer_info(void);

static inline void *xmalloc(size_t size)
{

15
ident.c

@ -156,7 +156,8 @@ static int copy(char *buf, int size, int offset, const char *src) @@ -156,7 +156,8 @@ static int copy(char *buf, int size, int offset, const char *src)
return offset;
}

char *get_ident(const char *name, const char *email, const char *date_str)
static const char *get_ident(const char *name, const char *email,
const char *date_str)
{
static char buffer[1000];
char date[50];
@ -181,12 +182,16 @@ char *get_ident(const char *name, const char *email, const char *date_str) @@ -181,12 +182,16 @@ char *get_ident(const char *name, const char *email, const char *date_str)
return buffer;
}

char *git_author_info(void)
const char *git_author_info(void)
{
return get_ident(getenv("GIT_AUTHOR_NAME"), getenv("GIT_AUTHOR_EMAIL"), getenv("GIT_AUTHOR_DATE"));
return get_ident(getenv("GIT_AUTHOR_NAME"),
getenv("GIT_AUTHOR_EMAIL"),
getenv("GIT_AUTHOR_DATE"));
}

char *git_committer_info(void)
const char *git_committer_info(void)
{
return get_ident(getenv("GIT_COMMITTER_NAME"), getenv("GIT_COMMITTER_EMAIL"), getenv("GIT_COMMITTER_DATE"));
return get_ident(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL"),
getenv("GIT_COMMITTER_DATE"));
}

2
var.c

@ -12,7 +12,7 @@ static const char var_usage[] = "git-var [-l | <variable>]"; @@ -12,7 +12,7 @@ static const char var_usage[] = "git-var [-l | <variable>]";

struct git_var {
const char *name;
char *(*read)(void);
const char *(*read)(void);
};
static struct git_var git_vars[] = {
{ "GIT_COMMITTER_IDENT", git_committer_info },

Loading…
Cancel
Save