Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx> --- builtin-blame.c | 5 +++-- cache.h | 8 +++++++- ident.c | 47 +++++++++++++++++++++-------------------------- 3 files changed, 31 insertions(+), 29 deletions(-) On 7/31/07, Alex Riesen <raa.lkml@xxxxxxxxx> wrote: > Ach, that's why... Junio, how about this then? I'd even suggest adding > the buffer argument to fmt_ident and use it everywhere (ATM there is > only one user outside of ident.c: builtin-blame.c). Something like this (on top of the previous re git_author|committer_info)
From fd728acc96ec35e36b0a8233c9f9c2f0eb78fd1d Mon Sep 17 00:00:00 2001 From: Alex Riesen <raa.lkml@xxxxxxxxx> Date: Tue, 31 Jul 2007 19:13:06 +0200 Subject: [PATCH] Allow fmt_ident to get an arbitrary buffer for the output Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx> --- builtin-blame.c | 5 +++-- cache.h | 8 +++++++- ident.c | 47 +++++++++++++++++++++-------------------------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/builtin-blame.c b/builtin-blame.c index 0519339..2d5e35d 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -1995,7 +1995,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con struct origin *origin; unsigned char head_sha1[20]; char *buf; - const char *ident; + char ident[FMT_IDENT_BUFSIZE]; int fd; time_t now; unsigned long fin_size; @@ -2108,7 +2108,8 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con cache_tree_invalidate_path(active_cache_tree, path); commit->buffer = xmalloc(400); - ident = fmt_ident("Not Committed Yet", "not.committed.yet", NULL, 0); + fmt_ident(ident, sizeof(ident), + "Not Committed Yet", "not.committed.yet", NULL, 0); snprintf(commit->buffer, 400, "tree 0000000000000000000000000000000000000000\n" "parent %s\n" diff --git a/cache.h b/cache.h index 53801b8..d7b2ef6 100644 --- a/cache.h +++ b/cache.h @@ -425,7 +425,13 @@ unsigned long approxidate(const char *); extern const char *git_author_info(int); extern const char *git_committer_info(int); -extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int); +#define FMT_IDENT_BUFSIZE 1000 +extern char *fmt_ident(char *buffer, + int bufsize, + const char *name, + const char *email, + const char *date_str, + int error_on_no_name); struct checkout { const char *base_dir; diff --git a/ident.c b/ident.c index 0d59090..a29d217 100644 --- a/ident.c +++ b/ident.c @@ -192,9 +192,9 @@ static const char *env_hint = "Add --global to set your account\'s default\n" "\n"; -#define FMT_IDENT_BUFSIZE 1000 -static char *fmt_ident_buf(char *buffer, const char *name, const char *email, - const char *date_str, int error_on_no_name) +char *fmt_ident(char *buffer, int size, + const char *name, const char *email, + const char *date_str, int error_on_no_name) { char date[50]; int i; @@ -227,34 +227,28 @@ static char *fmt_ident_buf(char *buffer, const char *name, const char *email, if (date_str) parse_date(date_str, date, sizeof(date)); - i = copy(buffer, FMT_IDENT_BUFSIZE, 0, name); - i = add_raw(buffer, FMT_IDENT_BUFSIZE, i, " <"); - i = copy(buffer, FMT_IDENT_BUFSIZE, i, email); - i = add_raw(buffer, FMT_IDENT_BUFSIZE, i, "> "); - i = copy(buffer, FMT_IDENT_BUFSIZE, i, date); - if (i >= FMT_IDENT_BUFSIZE) + i = copy(buffer, size, 0, name); + i = add_raw(buffer, size, i, " <"); + i = copy(buffer, size, i, email); + i = add_raw(buffer, size, i, "> "); + i = copy(buffer, size, i, date); + if (i >= size) die("Impossibly long personal identifier"); buffer[i] = 0; return buffer; } -const char *fmt_ident(const char *name, const char *email, - const char *date_str, int error_on_no_name) -{ - static char buffer[FMT_IDENT_BUFSIZE]; - return fmt_ident_buf(buffer, name, email, date_str, error_on_no_name); -} - const char *git_author_info(int error_on_no_name) { static char *buffer; if (!buffer) buffer = xmalloc(FMT_IDENT_BUFSIZE); - return fmt_ident_buf(buffer, - getenv("GIT_AUTHOR_NAME"), - getenv("GIT_AUTHOR_EMAIL"), - getenv("GIT_AUTHOR_DATE"), - error_on_no_name); + return fmt_ident(buffer, + FMT_IDENT_BUFSIZE, + getenv("GIT_AUTHOR_NAME"), + getenv("GIT_AUTHOR_EMAIL"), + getenv("GIT_AUTHOR_DATE"), + error_on_no_name); } const char *git_committer_info(int error_on_no_name) @@ -262,9 +256,10 @@ const char *git_committer_info(int error_on_no_name) static char *buffer; if (!buffer) buffer = xmalloc(FMT_IDENT_BUFSIZE); - return fmt_ident_buf(buffer, - getenv("GIT_COMMITTER_NAME"), - getenv("GIT_COMMITTER_EMAIL"), - getenv("GIT_COMMITTER_DATE"), - error_on_no_name); + return fmt_ident(buffer, + FMT_IDENT_BUFSIZE, + getenv("GIT_COMMITTER_NAME"), + getenv("GIT_COMMITTER_EMAIL"), + getenv("GIT_COMMITTER_DATE"), + error_on_no_name); } -- 1.5.3.rc3.132.g39179