From: Stephen Boyd <bebarino@gmail.com>
To: git@vger.kernel.org
Cc: Miklos Vajna <vmiklos@frugalware.org>,
Steven Drake <sdrake@xnet.co.nz>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 2/4] format-patch: use a string_list for headers
Date: Sun, 7 Mar 2010 13:33:16 -0800 [thread overview]
Message-ID: <1267997598-20815-3-git-send-email-bebarino@gmail.com> (raw)
In-Reply-To: <7vk4torn8j.fsf@alter.siamese.dyndns.org>
In the next patch we'll need to clear the header lists if the user
specifies --no-add-headers or --no-to or --no-cc. This actually cuts
down on the code a bit too.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
I had a patch like this but using strbuf's instead. I couldn't find it...
builtin-log.c | 70 +++++++++++++++++++++++++-------------------------------
1 files changed, 31 insertions(+), 39 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 5d23a67..dd8369f 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -458,35 +458,28 @@ static int auto_number = 1;
static char *default_attach = NULL;
-static char **extra_hdr;
-static int extra_hdr_nr;
-static int extra_hdr_alloc;
-
-static char **extra_to;
-static int extra_to_nr;
-static int extra_to_alloc;
-
-static char **extra_cc;
-static int extra_cc_nr;
-static int extra_cc_alloc;
+static struct string_list extra_hdr = { .strdup_strings = 1 };
+static struct string_list extra_to = { .strdup_strings = 1 };
+static struct string_list extra_cc = { .strdup_strings = 1 };
static void add_header(const char *value)
{
+ struct string_list_item *i;
int len = strlen(value);
while (len && value[len - 1] == '\n')
len--;
+
if (!strncasecmp(value, "to: ", 4)) {
- ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
- extra_to[extra_to_nr++] = xstrndup(value + 4, len - 4);
- return;
+ i = string_list_append(value + 4, &extra_to);
+ len -= 4;
+ } else if (!strncasecmp(value, "cc: ", 4)) {
+ i = string_list_append(value + 4, &extra_cc);
+ len -= 4;
+ } else {
+ i =string_list_append(value, &extra_hdr);
}
- if (!strncasecmp(value, "cc: ", 4)) {
- ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
- extra_cc[extra_cc_nr++] = xstrndup(value + 4, len - 4);
- return;
- }
- ALLOC_GROW(extra_hdr, extra_hdr_nr + 1, extra_hdr_alloc);
- extra_hdr[extra_hdr_nr++] = xstrndup(value, len);
+
+ i->string[len] = '\0';
}
#define THREAD_SHALLOW 1
@@ -507,15 +500,13 @@ static int git_format_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "format.to")) {
if (!value)
return config_error_nonbool(var);
- ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
- extra_to[extra_to_nr++] = xstrdup(value);
+ string_list_append(value, &extra_to);
return 0;
}
if (!strcmp(var, "format.cc")) {
if (!value)
return config_error_nonbool(var);
- ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
- extra_cc[extra_cc_nr++] = xstrdup(value);
+ string_list_append(value, &extra_cc);
return 0;
}
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
@@ -884,15 +875,13 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
static int to_callback(const struct option *opt, const char *arg, int unset)
{
- ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
- extra_to[extra_to_nr++] = xstrdup(arg);
+ string_list_append(arg, &extra_to);
return 0;
}
static int cc_callback(const struct option *opt, const char *arg, int unset)
{
- ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
- extra_cc[extra_cc_nr++] = xstrdup(arg);
+ string_list_append(arg, &extra_cc);
return 0;
}
@@ -1008,29 +997,29 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
add_signoff = xmemdupz(committer, endpos - committer + 1);
}
- for (i = 0; i < extra_hdr_nr; i++) {
- strbuf_addstr(&buf, extra_hdr[i]);
+ for (i = 0; i < extra_hdr.nr; i++) {
+ strbuf_addstr(&buf, extra_hdr.items[i].string);
strbuf_addch(&buf, '\n');
}
- if (extra_to_nr)
+ if (extra_to.nr)
strbuf_addstr(&buf, "To: ");
- for (i = 0; i < extra_to_nr; i++) {
+ for (i = 0; i < extra_to.nr; i++) {
if (i)
strbuf_addstr(&buf, " ");
- strbuf_addstr(&buf, extra_to[i]);
- if (i + 1 < extra_to_nr)
+ strbuf_addstr(&buf, extra_to.items[i].string);
+ if (i + 1 < extra_to.nr)
strbuf_addch(&buf, ',');
strbuf_addch(&buf, '\n');
}
- if (extra_cc_nr)
+ if (extra_cc.nr)
strbuf_addstr(&buf, "Cc: ");
- for (i = 0; i < extra_cc_nr; i++) {
+ for (i = 0; i < extra_cc.nr; i++) {
if (i)
strbuf_addstr(&buf, " ");
- strbuf_addstr(&buf, extra_cc[i]);
- if (i + 1 < extra_cc_nr)
+ strbuf_addstr(&buf, extra_cc.items[i].string);
+ if (i + 1 < extra_cc.nr)
strbuf_addch(&buf, ',');
strbuf_addch(&buf, '\n');
}
@@ -1239,6 +1228,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
fclose(stdout);
}
free(list);
+ string_list_clear(&extra_to, 0);
+ string_list_clear(&extra_cc, 0);
+ string_list_clear(&extra_hdr, 0);
if (ignore_if_in_upstream)
free_patch_ids(&ids);
return 0;
--
1.7.0.1.171.geb5ee
next prev parent reply other threads:[~2010-03-07 21:33 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-04 0:02 What's cooking in git.git (Mar 2010, #01; Wed, 03) Junio C Hamano
2010-03-04 0:36 ` Adam Simpkins
2010-03-04 8:26 ` Björn Gustavsson
2010-03-04 18:26 ` Junio C Hamano
2010-03-04 12:09 ` Tay Ray Chuan
2010-03-04 18:26 ` Junio C Hamano
2010-03-04 21:42 ` Junio C Hamano
2010-03-05 0:49 ` Junio C Hamano
2010-03-05 16:25 ` git reset --keep (Re: What's cooking in git.git (Mar 2010, #01; Wed, 03)) Jonathan Nieder
2010-03-05 21:08 ` Christian Couder
2010-03-05 17:32 ` What's cooking in git.git (Mar 2010, #01; Wed, 03) Christian Couder
2010-03-04 22:21 ` Thomas Rast
2010-03-05 1:30 ` Mark Lodato
2010-03-05 1:32 ` Mark Lodato
2010-03-05 3:23 ` Junio C Hamano
2010-03-06 0:39 ` [PATCH] Add tests for git format-patch --to and format.to config option Miklos Vajna
2010-03-06 2:21 ` Junio C Hamano
2010-03-06 21:06 ` [PATCH] format-patch --to: overwrite format.to contents, don't append it Miklos Vajna
2010-03-07 0:06 ` [PATCH] Add tests for git format-patch --to and format.to config option Stephen Boyd
2010-03-07 1:20 ` Miklos Vajna
2010-03-07 3:42 ` Junio C Hamano
2010-03-07 9:43 ` Stephen Boyd
2010-03-07 18:38 ` Junio C Hamano
2010-03-07 21:33 ` [PATCH 0/4] format-patch and send-email ignoring config settings Stephen Boyd
2010-03-07 22:46 ` [PATCHv2 0/3] " Stephen Boyd
2010-03-07 22:46 ` [PATCHv2 1/3] format-patch: use a string_list for headers Stephen Boyd
2010-03-07 22:46 ` [PATCHv2 2/3] format-patch: add --no-cc, --no-to, and --no-add-headers Stephen Boyd
2010-03-07 22:46 ` [PATCHv2 3/3] send-email: add --no-cc, --no-to, and --no-bcc Stephen Boyd
2010-03-09 2:44 ` [PATCH 0/4] format-patch and send-email ignoring config settings Junio C Hamano
2010-03-07 21:33 ` [PATCH 1/4] send-email: actually add bcc headers Stephen Boyd
2010-03-07 21:53 ` Stephen Boyd
2010-03-07 21:33 ` Stephen Boyd [this message]
2010-03-07 21:44 ` [PATCH 2/4] format-patch: use a string_list for headers Erik Faye-Lund
2010-03-07 21:54 ` Stephen Boyd
2010-03-07 22:13 ` Johannes Schindelin
2010-03-07 21:33 ` [PATCH 3/4] format-patch: add --no-cc, --no-to, and --no-add-headers Stephen Boyd
2010-03-07 21:33 ` [PATCH 4/4] send-email: add --no-cc, --no-to, and --no-bcc Stephen Boyd
2010-03-10 3:53 ` [PATCH] Add tests for git format-patch --to and format.to config option Steven Drake
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1267997598-20815-3-git-send-email-bebarino@gmail.com \
--to=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sdrake@xnet.co.nz \
--cc=vmiklos@frugalware.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).