From: "Alex Riesen" <raa.lkml@gmail.com>
To: "Kristian Høgsberg" <krh@redhat.com>
Cc: "Junio C Hamano" <gitster@pobox.com>, git@vger.kernel.org
Subject: [PATCH] Allow git_author|committer_info be called in the same expression
Date: Tue, 31 Jul 2007 18:57:05 +0200 [thread overview]
Message-ID: <81b0412b0707310957x62ac9d28j60104bffb46a80b7@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1180 bytes --]
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
ident.c | 49 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 32 insertions(+), 17 deletions(-)
On 7/31/07, Kristian Høgsberg <krh@redhat.com> wrote:
> There's number of buffers that don't get freed: the strbuf, the commit
> message buffer, and the strdup'ed author and committer info. All the
> leaks are not critical since the process exits immediately. As for the
> strbuf leak, I was thinking about renaming strbuf_begin to strbuf_reset
> and making it public[1], which will then be used for freeing up strbuf
> memory. The message buffer leak should be fixed by adding a
> strbuf_read_fd() that just reads it straight into the strbuf. The
> xstrdup's are necessary because fmt_ident uses a static buffer (thanks,
> test case :). We could add rotating static buffers for fmt_ident like
> git_path and avoid the strdups, but again, the leaks are not critical.
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).
This one is applicable immediately, though
[-- Attachment #2: 0001-Allow-git_author-committer_info-be-called-in-the-same.txt --]
[-- Type: text/plain, Size: 2862 bytes --]
From 0c86739aa9f5db19ebcd2bc041622c317611c87f Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@gmail.com>
Date: Tue, 31 Jul 2007 18:48:23 +0200
Subject: [PATCH] Allow git_author|committer_info be called in the same expression
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
ident.c | 49 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/ident.c b/ident.c
index 6612d17..0d59090 100644
--- a/ident.c
+++ b/ident.c
@@ -192,10 +192,10 @@ static const char *env_hint =
"Add --global to set your account\'s default\n"
"\n";
-const char *fmt_ident(const char *name, const char *email,
- const char *date_str, int error_on_no_name)
+#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)
{
- static char buffer[1000];
char date[50];
int i;
@@ -227,29 +227,44 @@ const char *fmt_ident(const char *name, const char *email,
if (date_str)
parse_date(date_str, date, sizeof(date));
- i = copy(buffer, sizeof(buffer), 0, name);
- i = add_raw(buffer, sizeof(buffer), i, " <");
- i = copy(buffer, sizeof(buffer), i, email);
- i = add_raw(buffer, sizeof(buffer), i, "> ");
- i = copy(buffer, sizeof(buffer), i, date);
- if (i >= sizeof(buffer))
+ 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)
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)
{
- return fmt_ident(getenv("GIT_AUTHOR_NAME"),
- getenv("GIT_AUTHOR_EMAIL"),
- getenv("GIT_AUTHOR_DATE"),
- 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);
}
const char *git_committer_info(int error_on_no_name)
{
- return fmt_ident(getenv("GIT_COMMITTER_NAME"),
- getenv("GIT_COMMITTER_EMAIL"),
- getenv("GIT_COMMITTER_DATE"),
- 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);
}
--
1.5.3.rc3.132.g39179
next reply other threads:[~2007-07-31 16:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-31 16:57 Alex Riesen [this message]
2007-08-01 9:24 ` [PATCH] Allow git_author|committer_info be called in the same expression Junio C Hamano
2007-08-01 9:35 ` Alex Riesen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81b0412b0707310957x62ac9d28j60104bffb46a80b7@mail.gmail.com \
--to=raa.lkml@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=krh@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).