mirror of
https://github.com/git/git
synced 2024-10-06 00:29:28 +00:00
format-patch: use a string_list for headers
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ae6c098f15
commit
ca9e0a1b87
|
@ -458,35 +458,28 @@ static int auto_number = 1;
|
||||||
|
|
||||||
static char *default_attach = NULL;
|
static char *default_attach = NULL;
|
||||||
|
|
||||||
static char **extra_hdr;
|
static struct string_list extra_hdr;
|
||||||
static int extra_hdr_nr;
|
static struct string_list extra_to;
|
||||||
static int extra_hdr_alloc;
|
static struct string_list extra_cc;
|
||||||
|
|
||||||
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 void add_header(const char *value)
|
static void add_header(const char *value)
|
||||||
{
|
{
|
||||||
|
struct string_list_item *item;
|
||||||
int len = strlen(value);
|
int len = strlen(value);
|
||||||
while (len && value[len - 1] == '\n')
|
while (len && value[len - 1] == '\n')
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
if (!strncasecmp(value, "to: ", 4)) {
|
if (!strncasecmp(value, "to: ", 4)) {
|
||||||
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
|
item = string_list_append(value + 4, &extra_to);
|
||||||
extra_to[extra_to_nr++] = xstrndup(value + 4, len - 4);
|
len -= 4;
|
||||||
return;
|
} else if (!strncasecmp(value, "cc: ", 4)) {
|
||||||
|
item = string_list_append(value + 4, &extra_cc);
|
||||||
|
len -= 4;
|
||||||
|
} else {
|
||||||
|
item = string_list_append(value, &extra_hdr);
|
||||||
}
|
}
|
||||||
if (!strncasecmp(value, "cc: ", 4)) {
|
|
||||||
ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
|
item->string[len] = '\0';
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define THREAD_SHALLOW 1
|
#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 (!strcmp(var, "format.to")) {
|
||||||
if (!value)
|
if (!value)
|
||||||
return config_error_nonbool(var);
|
return config_error_nonbool(var);
|
||||||
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
|
string_list_append(value, &extra_to);
|
||||||
extra_to[extra_to_nr++] = xstrdup(value);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strcmp(var, "format.cc")) {
|
if (!strcmp(var, "format.cc")) {
|
||||||
if (!value)
|
if (!value)
|
||||||
return config_error_nonbool(var);
|
return config_error_nonbool(var);
|
||||||
ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
|
string_list_append(value, &extra_cc);
|
||||||
extra_cc[extra_cc_nr++] = xstrdup(value);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
|
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)
|
static int to_callback(const struct option *opt, const char *arg, int unset)
|
||||||
{
|
{
|
||||||
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
|
string_list_append(arg, &extra_to);
|
||||||
extra_to[extra_to_nr++] = xstrdup(arg);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cc_callback(const struct option *opt, const char *arg, int unset)
|
static int cc_callback(const struct option *opt, const char *arg, int unset)
|
||||||
{
|
{
|
||||||
ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
|
string_list_append(arg, &extra_cc);
|
||||||
extra_cc[extra_cc_nr++] = xstrdup(arg);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -972,6 +961,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extra_hdr.strdup_strings = 1;
|
||||||
|
extra_to.strdup_strings = 1;
|
||||||
|
extra_cc.strdup_strings = 1;
|
||||||
git_config(git_format_config, NULL);
|
git_config(git_format_config, NULL);
|
||||||
init_revisions(&rev, prefix);
|
init_revisions(&rev, prefix);
|
||||||
rev.commit_format = CMIT_FMT_EMAIL;
|
rev.commit_format = CMIT_FMT_EMAIL;
|
||||||
|
@ -1008,29 +1000,29 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
||||||
add_signoff = xmemdupz(committer, endpos - committer + 1);
|
add_signoff = xmemdupz(committer, endpos - committer + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < extra_hdr_nr; i++) {
|
for (i = 0; i < extra_hdr.nr; i++) {
|
||||||
strbuf_addstr(&buf, extra_hdr[i]);
|
strbuf_addstr(&buf, extra_hdr.items[i].string);
|
||||||
strbuf_addch(&buf, '\n');
|
strbuf_addch(&buf, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extra_to_nr)
|
if (extra_to.nr)
|
||||||
strbuf_addstr(&buf, "To: ");
|
strbuf_addstr(&buf, "To: ");
|
||||||
for (i = 0; i < extra_to_nr; i++) {
|
for (i = 0; i < extra_to.nr; i++) {
|
||||||
if (i)
|
if (i)
|
||||||
strbuf_addstr(&buf, " ");
|
strbuf_addstr(&buf, " ");
|
||||||
strbuf_addstr(&buf, extra_to[i]);
|
strbuf_addstr(&buf, extra_to.items[i].string);
|
||||||
if (i + 1 < extra_to_nr)
|
if (i + 1 < extra_to.nr)
|
||||||
strbuf_addch(&buf, ',');
|
strbuf_addch(&buf, ',');
|
||||||
strbuf_addch(&buf, '\n');
|
strbuf_addch(&buf, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extra_cc_nr)
|
if (extra_cc.nr)
|
||||||
strbuf_addstr(&buf, "Cc: ");
|
strbuf_addstr(&buf, "Cc: ");
|
||||||
for (i = 0; i < extra_cc_nr; i++) {
|
for (i = 0; i < extra_cc.nr; i++) {
|
||||||
if (i)
|
if (i)
|
||||||
strbuf_addstr(&buf, " ");
|
strbuf_addstr(&buf, " ");
|
||||||
strbuf_addstr(&buf, extra_cc[i]);
|
strbuf_addstr(&buf, extra_cc.items[i].string);
|
||||||
if (i + 1 < extra_cc_nr)
|
if (i + 1 < extra_cc.nr)
|
||||||
strbuf_addch(&buf, ',');
|
strbuf_addch(&buf, ',');
|
||||||
strbuf_addch(&buf, '\n');
|
strbuf_addch(&buf, '\n');
|
||||||
}
|
}
|
||||||
|
@ -1239,6 +1231,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
||||||
fclose(stdout);
|
fclose(stdout);
|
||||||
}
|
}
|
||||||
free(list);
|
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)
|
if (ignore_if_in_upstream)
|
||||||
free_patch_ids(&ids);
|
free_patch_ids(&ids);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue