{"thread":{"id":"19758","subject":"[PATCH] format-patch: add --prefix to prepend a prefix to output file names","startedAt":"2009-06-09T11:33:47Z","lastAt":"2009-06-14T23:32:37Z","messageCount":15,"participants":["Nguyễn Thái Ngọc Duy","Andreas Ericsson","Johannes Sixt","Nguyen Thai Ngoc Duy","Jakub Narebski","Junio C Hamano","Stephen Boyd"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"115899","messageId":"1244547227-6466-1-git-send-email-pclouds@gmail.com","threadId":"19758","inReplyTo":null,"subject":"[PATCH] format-patch: add --prefix to prepend a prefix to output file names","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2009-06-09T11:33:47Z","receivedAt":"2009-06-09T11:33:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"I use git to manages patches in my Gentoo development. In Gentoo,\nall ebuilds (another form of RPM spec) corresponding to different\nversions of the same package are grouped into one directory. So patches\nfor each versions usually have a prefix to separate them from the ones\nfor other versions. With --prefix it comes handy to produce such patches,\nfor example:\n\ngit format-patch --prefix dbus-1.2.3- HEAD~5\n\nwill generate patches for dbus-1.2.3 for me, all starting with \"dbus-1.2.3-\".\n\nThis might be handy for RPM developers as well.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n This reminds me of another handy patch: git init --import. Any chance that patch\n could get in too?\n\n Documentation/git-format-patch.txt                 |    6 ++-\n builtin-log.c                                      |    9 ++-\n log-tree.c                                         |   10 ++-\n log-tree.h                                         |    4 +-\n revision.h                                         |    1 +\n t/t4013-diff-various.sh                            |    1 +\n ...h_--attach_--stdout_--prefix=foo-_initial..side |   61 ++++++++++++++++++++\n 7 files changed, 83 insertions(+), 9 deletions(-)\n create mode 100644 t/t4013/diff.format-patch_--attach_--stdout_--prefix=foo-_initial..side\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 6f1fc80..7423d67 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -15,7 +15,8 @@ SYNOPSIS\n \t\t   [-s | --signoff]\n \t\t   [-n | --numbered | -N | --no-numbered]\n \t\t   [--start-number <n>] [--numbered-files]\n-\t\t   [--in-reply-to=Message-Id] [--suffix=.<sfx>]\n+\t\t   [--in-reply-to=Message-Id]\n+\t\t   [--prefix=<pfx>] [--suffix=.<sfx>]\n \t\t   [--ignore-if-in-upstream]\n \t\t   [--subject-prefix=Subject-Prefix]\n \t\t   [--cc=<email>]\n@@ -168,6 +169,9 @@ if that is not set.\n \tcontaining the shortlog and the overall diffstat.  You can\n \tfill in a description in the file before sending it out.\n \n+--prefix=.<pfx>::\n+\tPrepend specified prefix in front of generated filenames.\n+\n --suffix=.<sfx>::\n \tInstead of using `.patch` as the suffix for generated\n \tfilenames, use specified suffix.  A common alternative is\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 0d34050..dafa628 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -419,6 +419,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)\n \n /* format-patch */\n \n+static const char *fmt_patch_prefix = \"\";\n static const char *fmt_patch_suffix = \".patch\";\n static int numbered = 0;\n static int auto_number = 1;\n@@ -524,18 +525,19 @@ static int outdir_offset;\n static int reopen_stdout(struct commit *commit, struct rev_info *rev)\n {\n \tstruct strbuf filename = STRBUF_INIT;\n+\tint prefix_len = strlen(fmt_patch_prefix);\n \tint suffix_len = strlen(fmt_patch_suffix) + 1;\n \n \tif (output_directory) {\n \t\tstrbuf_addstr(&filename, output_directory);\n \t\tif (filename.len >=\n-\t\t    PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)\n+\t\t    PATH_MAX - FORMAT_PATCH_NAME_MAX - prefix_len - suffix_len)\n \t\t\treturn error(\"name of output directory is too long\");\n \t\tif (filename.buf[filename.len - 1] != '/')\n \t\t\tstrbuf_addch(&filename, '/');\n \t}\n \n-\tget_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);\n+\tget_patch_filename(commit, rev->nr, fmt_patch_prefix, fmt_patch_suffix, &filename);\n \n \tif (!DIFF_OPT_TST(&rev->diffopt, QUIET))\n \t\tfprintf(realstdout, \"%s\\n\", filename.buf + outdir_offset);\n@@ -877,6 +879,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    \"generate a cover letter\"),\n \t\tOPT_BOOLEAN(0, \"numbered-files\", &numbered_files,\n \t\t\t    \"use simple number sequence for output file names\"),\n+\t\tOPT_STRING(0, \"prefix\", &fmt_patch_prefix, \"pfx\",\n+\t\t\t    \"prepend <pfx> to output file names\"),\n \t\tOPT_STRING(0, \"suffix\", &fmt_patch_suffix, \"sfx\",\n \t\t\t    \"use <sfx> instead of '.patch'\"),\n \t\tOPT_INTEGER(0, \"start-number\", &start_number,\n@@ -1093,6 +1097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tstring_list_append(msgid, rev.ref_message_ids);\n \t}\n \trev.numbered_files = numbered_files;\n+\trev.patch_prefix = fmt_patch_prefix;\n \trev.patch_suffix = fmt_patch_suffix;\n \tif (cover_letter) {\n \t\tif (thread)\ndiff --git a/log-tree.c b/log-tree.c\nindex 59d63eb..139c8b5 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -180,12 +180,13 @@ static int has_non_ascii(const char *s)\n \treturn 0;\n }\n \n-void get_patch_filename(struct commit *commit, int nr, const char *suffix,\n-\t\t\tstruct strbuf *buf)\n+void get_patch_filename(struct commit *commit, int nr, const char *prefix,\n+\t\t\tconst char *suffix, struct strbuf *buf)\n {\n \tint suffix_len = strlen(suffix) + 1;\n-\tint start_len = buf->len;\n+\tint start_len = buf->len + strlen(prefix);\n \n+\tstrbuf_addstr(buf, prefix);\n \tstrbuf_addf(buf, commit ? \"%04d-\" : \"%d\", nr);\n \tif (commit) {\n \t\tint max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;\n@@ -263,7 +264,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n \t\textra_headers = subject_buffer;\n \n \t\tget_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,\n-\t\t\t\t    opt->patch_suffix, &filename);\n+\t\t\t\t    opt->patch_prefix, opt->patch_suffix,\n+\t\t\t\t    &filename);\n \t\tsnprintf(buffer, sizeof(buffer) - 1,\n \t\t\t \"\\n--%s%s\\n\"\n \t\t\t \"Content-Type: text/x-patch;\"\ndiff --git a/log-tree.h b/log-tree.h\nindex 20b5caf..566c85d 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -20,7 +20,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n void load_ref_decorations(void);\n \n #define FORMAT_PATCH_NAME_MAX 64\n-void get_patch_filename(struct commit *commit, int nr, const char *suffix,\n-\t\t\tstruct strbuf *buf);\n+void get_patch_filename(struct commit *commit, int nr, const char *prefix,\n+\t\t\tconst char *suffix, struct strbuf *buf);\n \n #endif\ndiff --git a/revision.h b/revision.h\nindex 227164c..b35c038 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -85,6 +85,7 @@ struct rev_info {\n \tstruct log_info *loginfo;\n \tint\t\tnr, total;\n \tconst char\t*mime_boundary;\n+\tconst char\t*patch_prefix;\n \tconst char\t*patch_suffix;\n \tint\t\tnumbered_files;\n \tchar\t\t*message_id;\ndiff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\nindex 8b33321..771b849 100755\n--- a/t/t4013-diff-various.sh\n+++ b/t/t4013-diff-various.sh\n@@ -246,6 +246,7 @@ format-patch --stdout initial..master\n format-patch --stdout --no-numbered initial..master\n format-patch --stdout --numbered initial..master\n format-patch --attach --stdout initial..side\n+format-patch --attach --stdout --prefix=foo- initial..side\n format-patch --attach --stdout --suffix=.diff initial..side\n format-patch --attach --stdout initial..master^\n format-patch --attach --stdout initial..master\ndiff --git a/t/t4013/diff.format-patch_--attach_--stdout_--prefix=foo-_initial..side b/t/t4013/diff.format-patch_--attach_--stdout_--prefix=foo-_initial..side\nnew file mode 100644\nindex 0000000..a5a78d8\n--- /dev/null\n+++ b/t/t4013/diff.format-patch_--attach_--stdout_--prefix=foo-_initial..side\n@@ -0,0 +1,61 @@\n+$ git format-patch --attach --stdout --prefix=foo- initial..side\n+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001\n+From: A U Thor <author@example.com>\n+Date: Mon, 26 Jun 2006 00:03:00 +0000\n+Subject: [PATCH] Side\n+MIME-Version: 1.0\n+Content-Type: multipart/mixed; boundary=\"------------g-i-t--v-e-r-s-i-o-n\"\n+\n+This is a multi-part message in MIME format.\n+--------------g-i-t--v-e-r-s-i-o-n\n+Content-Type: text/plain; charset=UTF-8; format=fixed\n+Content-Transfer-Encoding: 8bit\n+\n+---\n+ dir/sub |    2 ++\n+ file0   |    3 +++\n+ file3   |    4 ++++\n+ 3 files changed, 9 insertions(+), 0 deletions(-)\n+ create mode 100644 file3\n+\n+\n+--------------g-i-t--v-e-r-s-i-o-n\n+Content-Type: text/x-patch; name=\"foo-0001-Side.patch\"\n+Content-Transfer-Encoding: 8bit\n+Content-Disposition: attachment; filename=\"foo-0001-Side.patch\"\n+\n+diff --git a/dir/sub b/dir/sub\n+index 35d242b..7289e35 100644\n+--- a/dir/sub\n++++ b/dir/sub\n+@@ -1,2 +1,4 @@\n+ A\n+ B\n++1\n++2\n+diff --git a/file0 b/file0\n+index 01e79c3..f4615da 100644\n+--- a/file0\n++++ b/file0\n+@@ -1,3 +1,6 @@\n+ 1\n+ 2\n+ 3\n++A\n++B\n++C\n+diff --git a/file3 b/file3\n+new file mode 100644\n+index 0000000..7289e35\n+--- /dev/null\n++++ b/file3\n+@@ -0,0 +1,4 @@\n++A\n++B\n++1\n++2\n+\n+--------------g-i-t--v-e-r-s-i-o-n--\n+\n+\n+$\n-- \n1.6.3.2.318.g2fd57\n"},{"id":"115904","messageId":"4A2E576D.704@op5.se","threadId":"19758","inReplyTo":"1244547227-6466-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] format-patch: add --prefix to prepend a prefix to output file names","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2009-06-09T12:37:01Z","receivedAt":"2009-06-09T12:37:01Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Nguyễn Thái Ngọc Duy wrote:\n> I use git to manages patches in my Gentoo development. In Gentoo,\n> all ebuilds (another form of RPM spec) corresponding to different\n> versions of the same package are grouped into one directory. So patches\n> for each versions usually have a prefix to separate them from the ones\n> for other versions. With --prefix it comes handy to produce such patches,\n> for example:\n> \n> git format-patch --prefix dbus-1.2.3- HEAD~5\n> \n> will generate patches for dbus-1.2.3 for me, all starting with \"dbus-1.2.3-\".\n> \n> This might be handy for RPM developers as well.\n> \n\nI'm thinking this could be confused with '--subject-prefix' which was\ngiven the long option to *not* confuse it with cover-letters and filename\nprefixes. Any chance you could make it --filename-prefix instead? Since\nit already lacks a short option, the extra typing will probably be worth\nit to avoid unnecessary confusion.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n\nConsidering the successes of the wars on alcohol, poverty, drugs and\nterror, I think we should give some serious thought to declaring war\non peace.\n"},{"id":"115905","messageId":"4A2E6407.1010402@viscovery.net","threadId":"19758","inReplyTo":"1244547227-6466-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] format-patch: add --prefix to prepend a prefix to output file names","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-06-09T13:30:47Z","receivedAt":"2009-06-09T13:30:47Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Nguyễn Thái Ngọc Duy schrieb:\n> I use git to manages patches in my Gentoo development. In Gentoo,\n> all ebuilds (another form of RPM spec) corresponding to different\n> versions of the same package are grouped into one directory. So patches\n> for each versions usually have a prefix to separate them from the ones\n> for other versions. With --prefix it comes handy to produce such patches,\n> for example:\n> \n> git format-patch --prefix dbus-1.2.3- HEAD~5\n> \n> will generate patches for dbus-1.2.3 for me, all starting with \"dbus-1.2.3-\".\n\nCan't you use --output-directory/-o? It is not the same, but almost.\n\n-- Hannes\n"},{"id":"115967","messageId":"fcaeb9bf0906091614y7392bfa8p20a4e5c3c37a051b@mail.gmail.com","threadId":"19758","inReplyTo":"4A2E576D.704@op5.se","subject":"Re: [PATCH] format-patch: add --prefix to prepend a prefix to output file names","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2009-06-09T23:14:14Z","receivedAt":"2009-06-09T23:14:14Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2009/6/9 Andreas Ericsson <ae@op5.se>:\n> Nguyễn Thái Ngọc Duy wrote:\n>>\n>> I use git to manages patches in my Gentoo development. In Gentoo,\n>> all ebuilds (another form of RPM spec) corresponding to different\n>> versions of the same package are grouped into one directory. So patches\n>> for each versions usually have a prefix to separate them from the ones\n>> for other versions. With --prefix it comes handy to produce such patches,\n>> for example:\n>>\n>> git format-patch --prefix dbus-1.2.3- HEAD~5\n>>\n>> will generate patches for dbus-1.2.3 for me, all starting with\n>> \"dbus-1.2.3-\".\n>>\n>> This might be handy for RPM developers as well.\n>>\n>\n> I'm thinking this could be confused with '--subject-prefix' which was\n> given the long option to *not* confuse it with cover-letters and filename\n> prefixes. Any chance you could make it --filename-prefix instead? Since\n> it already lacks a short option, the extra typing will probably be worth\n> it to avoid unnecessary confusion.\n\nI made it --prefix because I see --suffix for file names already. Yes\n--filename-prefix may be less confusing than plain --prefix.\n-- \nDuy\n"},{"id":"115968","messageId":"fcaeb9bf0906091618l406116d8k307f6661b451d030@mail.gmail.com","threadId":"19758","inReplyTo":"4A2E6407.1010402@viscovery.net","subject":"Re: [PATCH] format-patch: add --prefix to prepend a prefix to output file names","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2009-06-09T23:18:00Z","receivedAt":"2009-06-09T23:18:00Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2009/6/9 Johannes Sixt <j.sixt@viscovery.net>:\n> Nguyễn Thái Ngọc Duy schrieb:\n>> I use git to manages patches in my Gentoo development. In Gentoo,\n>> all ebuilds (another form of RPM spec) corresponding to different\n>> versions of the same package are grouped into one directory. So patches\n>> for each versions usually have a prefix to separate them from the ones\n>> for other versions. With --prefix it comes handy to produce such patches,\n>> for example:\n>>\n>> git format-patch --prefix dbus-1.2.3- HEAD~5\n>>\n>> will generate patches for dbus-1.2.3 for me, all starting with \"dbus-1.2.3-\".\n>\n> Can't you use --output-directory/-o? It is not the same, but almost.\n\n-o seems to put slash at the end (in reopen_stdout()) but I don't want\nto create another directory.\n-- \nDuy\n"},{"id":"116000","messageId":"1244629715-30444-1-git-send-email-pclouds@gmail.com","threadId":"19758","inReplyTo":"4A2E576D.704@op5.se","subject":"[PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2009-06-10T10:28:35Z","receivedAt":"2009-06-10T10:28:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"I use git to manage patches in my Gentoo development. In Gentoo, all\nebuilds (another form of RPM spec) corresponding to different versions\nof the same package are grouped into one directory. So patches for\neach version usually have a prefix to separate them from ones for\nother versions. With --filename-prefix it comes handy to produce such\npatches, for example:\n\ngit format-patch --filename-prefix dbus-1.2.3- HEAD~5\n\nwill generate patches for dbus-1.2.3 for me, all starting with \"dbus-1.2.3-\".\n\nThis might be handy for RPM developers as well.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Renamed --prefix to --filename-prefix\n\n Documentation/git-format-patch.txt                 |    6 ++-\n builtin-log.c                                      |    9 ++-\n log-tree.c                                         |   10 ++-\n log-tree.h                                         |    4 +-\n revision.h                                         |    1 +\n t/t4013-diff-various.sh                            |    1 +\n ...h_--stdout_--filename-prefix=foo-_initial..side |   61 ++++++++++++++++++++\n 7 files changed, 83 insertions(+), 9 deletions(-)\n create mode 100644 t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 6f1fc80..30815bc 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -15,7 +15,8 @@ SYNOPSIS\n \t\t   [-s | --signoff]\n \t\t   [-n | --numbered | -N | --no-numbered]\n \t\t   [--start-number <n>] [--numbered-files]\n-\t\t   [--in-reply-to=Message-Id] [--suffix=.<sfx>]\n+\t\t   [--in-reply-to=Message-Id]\n+\t\t   [--filename-prefix=<pfx>] [--suffix=.<sfx>]\n \t\t   [--ignore-if-in-upstream]\n \t\t   [--subject-prefix=Subject-Prefix]\n \t\t   [--cc=<email>]\n@@ -168,6 +169,9 @@ if that is not set.\n \tcontaining the shortlog and the overall diffstat.  You can\n \tfill in a description in the file before sending it out.\n \n+--filename-prefix=.<pfx>::\n+\tPrepend specified prefix in front of generated filenames.\n+\n --suffix=.<sfx>::\n \tInstead of using `.patch` as the suffix for generated\n \tfilenames, use specified suffix.  A common alternative is\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 0d34050..d458753 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -419,6 +419,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)\n \n /* format-patch */\n \n+static const char *fmt_patch_prefix = \"\";\n static const char *fmt_patch_suffix = \".patch\";\n static int numbered = 0;\n static int auto_number = 1;\n@@ -524,18 +525,19 @@ static int outdir_offset;\n static int reopen_stdout(struct commit *commit, struct rev_info *rev)\n {\n \tstruct strbuf filename = STRBUF_INIT;\n+\tint prefix_len = strlen(fmt_patch_prefix);\n \tint suffix_len = strlen(fmt_patch_suffix) + 1;\n \n \tif (output_directory) {\n \t\tstrbuf_addstr(&filename, output_directory);\n \t\tif (filename.len >=\n-\t\t    PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)\n+\t\t    PATH_MAX - FORMAT_PATCH_NAME_MAX - prefix_len - suffix_len)\n \t\t\treturn error(\"name of output directory is too long\");\n \t\tif (filename.buf[filename.len - 1] != '/')\n \t\t\tstrbuf_addch(&filename, '/');\n \t}\n \n-\tget_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);\n+\tget_patch_filename(commit, rev->nr, fmt_patch_prefix, fmt_patch_suffix, &filename);\n \n \tif (!DIFF_OPT_TST(&rev->diffopt, QUIET))\n \t\tfprintf(realstdout, \"%s\\n\", filename.buf + outdir_offset);\n@@ -877,6 +879,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    \"generate a cover letter\"),\n \t\tOPT_BOOLEAN(0, \"numbered-files\", &numbered_files,\n \t\t\t    \"use simple number sequence for output file names\"),\n+\t\tOPT_STRING(0, \"filename-prefix\", &fmt_patch_prefix, \"pfx\",\n+\t\t\t    \"prepend <pfx> to output file names\"),\n \t\tOPT_STRING(0, \"suffix\", &fmt_patch_suffix, \"sfx\",\n \t\t\t    \"use <sfx> instead of '.patch'\"),\n \t\tOPT_INTEGER(0, \"start-number\", &start_number,\n@@ -1093,6 +1097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tstring_list_append(msgid, rev.ref_message_ids);\n \t}\n \trev.numbered_files = numbered_files;\n+\trev.patch_prefix = fmt_patch_prefix;\n \trev.patch_suffix = fmt_patch_suffix;\n \tif (cover_letter) {\n \t\tif (thread)\ndiff --git a/log-tree.c b/log-tree.c\nindex 59d63eb..139c8b5 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -180,12 +180,13 @@ static int has_non_ascii(const char *s)\n \treturn 0;\n }\n \n-void get_patch_filename(struct commit *commit, int nr, const char *suffix,\n-\t\t\tstruct strbuf *buf)\n+void get_patch_filename(struct commit *commit, int nr, const char *prefix,\n+\t\t\tconst char *suffix, struct strbuf *buf)\n {\n \tint suffix_len = strlen(suffix) + 1;\n-\tint start_len = buf->len;\n+\tint start_len = buf->len + strlen(prefix);\n \n+\tstrbuf_addstr(buf, prefix);\n \tstrbuf_addf(buf, commit ? \"%04d-\" : \"%d\", nr);\n \tif (commit) {\n \t\tint max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;\n@@ -263,7 +264,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n \t\textra_headers = subject_buffer;\n \n \t\tget_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,\n-\t\t\t\t    opt->patch_suffix, &filename);\n+\t\t\t\t    opt->patch_prefix, opt->patch_suffix,\n+\t\t\t\t    &filename);\n \t\tsnprintf(buffer, sizeof(buffer) - 1,\n \t\t\t \"\\n--%s%s\\n\"\n \t\t\t \"Content-Type: text/x-patch;\"\ndiff --git a/log-tree.h b/log-tree.h\nindex 20b5caf..566c85d 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -20,7 +20,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n void load_ref_decorations(void);\n \n #define FORMAT_PATCH_NAME_MAX 64\n-void get_patch_filename(struct commit *commit, int nr, const char *suffix,\n-\t\t\tstruct strbuf *buf);\n+void get_patch_filename(struct commit *commit, int nr, const char *prefix,\n+\t\t\tconst char *suffix, struct strbuf *buf);\n \n #endif\ndiff --git a/revision.h b/revision.h\nindex 227164c..b35c038 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -85,6 +85,7 @@ struct rev_info {\n \tstruct log_info *loginfo;\n \tint\t\tnr, total;\n \tconst char\t*mime_boundary;\n+\tconst char\t*patch_prefix;\n \tconst char\t*patch_suffix;\n \tint\t\tnumbered_files;\n \tchar\t\t*message_id;\ndiff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\nindex 8b33321..cf16c0a 100755\n--- a/t/t4013-diff-various.sh\n+++ b/t/t4013-diff-various.sh\n@@ -246,6 +246,7 @@ format-patch --stdout initial..master\n format-patch --stdout --no-numbered initial..master\n format-patch --stdout --numbered initial..master\n format-patch --attach --stdout initial..side\n+format-patch --attach --stdout --filename-prefix=foo- initial..side\n format-patch --attach --stdout --suffix=.diff initial..side\n format-patch --attach --stdout initial..master^\n format-patch --attach --stdout initial..master\ndiff --git a/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side b/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side\nnew file mode 100644\nindex 0000000..72127eb\n--- /dev/null\n+++ b/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side\n@@ -0,0 +1,61 @@\n+$ git format-patch --attach --stdout --filename-prefix=foo- initial..side\n+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001\n+From: A U Thor <author@example.com>\n+Date: Mon, 26 Jun 2006 00:03:00 +0000\n+Subject: [PATCH] Side\n+MIME-Version: 1.0\n+Content-Type: multipart/mixed; boundary=\"------------g-i-t--v-e-r-s-i-o-n\"\n+\n+This is a multi-part message in MIME format.\n+--------------g-i-t--v-e-r-s-i-o-n\n+Content-Type: text/plain; charset=UTF-8; format=fixed\n+Content-Transfer-Encoding: 8bit\n+\n+---\n+ dir/sub |    2 ++\n+ file0   |    3 +++\n+ file3   |    4 ++++\n+ 3 files changed, 9 insertions(+), 0 deletions(-)\n+ create mode 100644 file3\n+\n+\n+--------------g-i-t--v-e-r-s-i-o-n\n+Content-Type: text/x-patch; name=\"foo-0001-Side.patch\"\n+Content-Transfer-Encoding: 8bit\n+Content-Disposition: attachment; filename=\"foo-0001-Side.patch\"\n+\n+diff --git a/dir/sub b/dir/sub\n+index 35d242b..7289e35 100644\n+--- a/dir/sub\n++++ b/dir/sub\n+@@ -1,2 +1,4 @@\n+ A\n+ B\n++1\n++2\n+diff --git a/file0 b/file0\n+index 01e79c3..f4615da 100644\n+--- a/file0\n++++ b/file0\n+@@ -1,3 +1,6 @@\n+ 1\n+ 2\n+ 3\n++A\n++B\n++C\n+diff --git a/file3 b/file3\n+new file mode 100644\n+index 0000000..7289e35\n+--- /dev/null\n++++ b/file3\n+@@ -0,0 +1,4 @@\n++A\n++B\n++1\n++2\n+\n+--------------g-i-t--v-e-r-s-i-o-n--\n+\n+\n+$\n-- \n1.6.3.2.318.g2fd57\n"},{"id":"116003","messageId":"h0o36t$7it$1@ger.gmane.org","threadId":"19758","inReplyTo":"1244629715-30444-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-06-10T10:51:09Z","receivedAt":"2009-06-10T10:51:09Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Nguy?n Thái Ng?c Duy wrote:\n\n> +--filename-prefix=.<pfx>::\n> +       Prepend specified prefix in front of generated filenames.\n> +\n>  --suffix=.<sfx>::\n>         Instead of using `.patch` as the suffix for generated\n>         filenames, use specified suffix.  A common alternative is\n\nI think it should be\n\n   --filename-prefix=<pfx>::\n\n(without the dot '.').\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"116004","messageId":"fcaeb9bf0906100356h430f370m88ec2800d3d50865@mail.gmail.com","threadId":"19758","inReplyTo":"h0o36t$7it$1@ger.gmane.org","subject":"Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2009-06-10T10:56:50Z","receivedAt":"2009-06-10T10:56:50Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2009/6/10 Jakub Narebski <jnareb@gmail.com>:\n> Nguy?n Thái Ng?c Duy wrote:\n>\n>> +--filename-prefix=.<pfx>::\n>> +       Prepend specified prefix in front of generated filenames.\n>> +\n>>  --suffix=.<sfx>::\n>>         Instead of using `.patch` as the suffix for generated\n>>         filenames, use specified suffix.  A common alternative is\n>\n> I think it should be\n>\n>   --filename-prefix=<pfx>::\n>\n> (without the dot '.').\n\nRight. I remember I got rid of that dot in the synopis. Obviously I\nmissed another one.\n-- \nDuy\n"},{"id":"116016","messageId":"7vr5xsozcm.fsf@alter.siamese.dyndns.org","threadId":"19758","inReplyTo":"1244629715-30444-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-06-10T15:58:01Z","receivedAt":"2009-06-10T15:58:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> I use git to manage patches in my Gentoo development. In Gentoo, all\n> ebuilds (another form of RPM spec) corresponding to different versions\n> of the same package are grouped into one directory. So patches for\n> each version usually have a prefix to separate them from ones for\n> other versions. With --filename-prefix it comes handy to produce such\n> patches, for example:\n>\n> git format-patch --filename-prefix dbus-1.2.3- HEAD~5\n>\n> will generate patches for dbus-1.2.3 for me, all starting with \"dbus-1.2.3-\".\n>\n> This might be handy for RPM developers as well.\n\nIf this patch needs another round, I would prefer seeing the explanation\ndone in a different order.  When a busy person who is uninterested in\nGentoo starts reading the above paragraph, the patch will (incorrectly) be\ndismissed with an \"Ah, Gentoo specific feature?  Not interesting.\" after\nreading the first two lines.  I.e. \"Add X that does Y.  This is useful in\nsuch and such situations because ...\".\n\n> +--filename-prefix=.<pfx>::\n> +\tPrepend specified prefix in front of generated filenames.\n\nHmm... ;-)\n\nWhat happens when I feed a path with a slash in it with --filename-prefix?\nWe will fail in open/creat if the leading path does not exist?\n\nI am not saying we must allow a slash in the prefix and create necessary\nleading paths ourselves, nor we must check for a slash and fail in the\ninput validation phase, but I am wondering if we can have some clever way\nto internally unify the handling of this new option with --outdir.\n\n> diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\n> index 8b33321..cf16c0a 100755\n> --- a/t/t4013-diff-various.sh\n> +++ b/t/t4013-diff-various.sh\n> @@ -246,6 +246,7 @@ format-patch --stdout initial..master\n>  format-patch --stdout --no-numbered initial..master\n>  format-patch --stdout --numbered initial..master\n>  format-patch --attach --stdout initial..side\n> +format-patch --attach --stdout --filename-prefix=foo- initial..side\n\nHeh, clever.  I wondered what the point of testing with --stdout was\nfor a patch that affects the generated filename.  The magic of --attach ;-)\n"},{"id":"116270","messageId":"1244963400-1739-1-git-send-email-pclouds@gmail.com","threadId":"19758","inReplyTo":"7vr5xsozcm.fsf@alter.siamese.dyndns.org","subject":"[PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2009-06-14T07:10:00Z","receivedAt":"2009-06-14T07:10:00Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"In Linux packaging, patches are usually saved along with the \"package\nspec\" (to suit distro specific needs or just to back port some\nfixes). Those patches are usually prefixed with either the package\nname, or package version for various reasons. With --filename-prefix\nit comes handy to produce such patches, for example:\n\ngit format-patch --filename-prefix dbus-1.2.3- HEAD~5\n\nwill generate patches for dbus-1.2.3 for me, all starting with \"dbus-1.2.3-\".\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n On Wed, Jun 10, 2009 at 08:58:01AM -0700, Junio C Hamano wrote:\n > Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n > \n > > I use git to manage patches in my Gentoo development. In Gentoo, all\n > > ebuilds (another form of RPM spec) corresponding to different versions\n > > of the same package are grouped into one directory. So patches for\n > > each version usually have a prefix to separate them from ones for\n > > other versions. With --filename-prefix it comes handy to produce such\n > > patches, for example:\n > >\n > > git format-patch --filename-prefix dbus-1.2.3- HEAD~5\n > >\n > > will generate patches for dbus-1.2.3 for me, all starting with \"dbus-1.2.3-\".\n > >\n > > This might be handy for RPM developers as well.\n > \n > If this patch needs another round, I would prefer seeing the explanation\n > done in a different order.  When a busy person who is uninterested in\n > Gentoo starts reading the above paragraph, the patch will (incorrectly) be\n > dismissed with an \"Ah, Gentoo specific feature?  Not interesting.\" after\n > reading the first two lines.  I.e. \"Add X that does Y.  This is useful in\n > such and such situations because ...\".\n\n Done\n\n > \n > > +--filename-prefix=.<pfx>::\n > > +\tPrepend specified prefix in front of generated filenames.\n > \n > Hmm... ;-)\n > \n > What happens when I feed a path with a slash in it with --filename-prefix?\n > We will fail in open/creat if the leading path does not exist?\n > \n > I am not saying we must allow a slash in the prefix and create necessary\n > leading paths ourselves, nor we must check for a slash and fail in the\n > input validation phase, but I am wondering if we can have some clever way\n > to internally unify the handling of this new option with --outdir.\n\n Hardly, the way it is handled now (chdir()ing to --outdir, then write patches)\n\n Documentation/git-format-patch.txt                 |    6 ++-\n builtin-log.c                                      |    9 ++-\n log-tree.c                                         |   10 ++-\n log-tree.h                                         |    4 +-\n revision.h                                         |    1 +\n t/t4013-diff-various.sh                            |    1 +\n ...h_--stdout_--filename-prefix=foo-_initial..side |   61 ++++++++++++++++++++\n 7 files changed, 83 insertions(+), 9 deletions(-)\n create mode 100644 t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 6f1fc80..052a3b8 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -15,7 +15,8 @@ SYNOPSIS\n \t\t   [-s | --signoff]\n \t\t   [-n | --numbered | -N | --no-numbered]\n \t\t   [--start-number <n>] [--numbered-files]\n-\t\t   [--in-reply-to=Message-Id] [--suffix=.<sfx>]\n+\t\t   [--in-reply-to=Message-Id]\n+\t\t   [--filename-prefix=<pfx>] [--suffix=.<sfx>]\n \t\t   [--ignore-if-in-upstream]\n \t\t   [--subject-prefix=Subject-Prefix]\n \t\t   [--cc=<email>]\n@@ -168,6 +169,9 @@ if that is not set.\n \tcontaining the shortlog and the overall diffstat.  You can\n \tfill in a description in the file before sending it out.\n \n+--filename-prefix=<pfx>::\n+\tPrepend specified prefix in front of generated filenames.\n+\n --suffix=.<sfx>::\n \tInstead of using `.patch` as the suffix for generated\n \tfilenames, use specified suffix.  A common alternative is\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 0d34050..d458753 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -419,6 +419,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)\n \n /* format-patch */\n \n+static const char *fmt_patch_prefix = \"\";\n static const char *fmt_patch_suffix = \".patch\";\n static int numbered = 0;\n static int auto_number = 1;\n@@ -524,18 +525,19 @@ static int outdir_offset;\n static int reopen_stdout(struct commit *commit, struct rev_info *rev)\n {\n \tstruct strbuf filename = STRBUF_INIT;\n+\tint prefix_len = strlen(fmt_patch_prefix);\n \tint suffix_len = strlen(fmt_patch_suffix) + 1;\n \n \tif (output_directory) {\n \t\tstrbuf_addstr(&filename, output_directory);\n \t\tif (filename.len >=\n-\t\t    PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)\n+\t\t    PATH_MAX - FORMAT_PATCH_NAME_MAX - prefix_len - suffix_len)\n \t\t\treturn error(\"name of output directory is too long\");\n \t\tif (filename.buf[filename.len - 1] != '/')\n \t\t\tstrbuf_addch(&filename, '/');\n \t}\n \n-\tget_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);\n+\tget_patch_filename(commit, rev->nr, fmt_patch_prefix, fmt_patch_suffix, &filename);\n \n \tif (!DIFF_OPT_TST(&rev->diffopt, QUIET))\n \t\tfprintf(realstdout, \"%s\\n\", filename.buf + outdir_offset);\n@@ -877,6 +879,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    \"generate a cover letter\"),\n \t\tOPT_BOOLEAN(0, \"numbered-files\", &numbered_files,\n \t\t\t    \"use simple number sequence for output file names\"),\n+\t\tOPT_STRING(0, \"filename-prefix\", &fmt_patch_prefix, \"pfx\",\n+\t\t\t    \"prepend <pfx> to output file names\"),\n \t\tOPT_STRING(0, \"suffix\", &fmt_patch_suffix, \"sfx\",\n \t\t\t    \"use <sfx> instead of '.patch'\"),\n \t\tOPT_INTEGER(0, \"start-number\", &start_number,\n@@ -1093,6 +1097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tstring_list_append(msgid, rev.ref_message_ids);\n \t}\n \trev.numbered_files = numbered_files;\n+\trev.patch_prefix = fmt_patch_prefix;\n \trev.patch_suffix = fmt_patch_suffix;\n \tif (cover_letter) {\n \t\tif (thread)\ndiff --git a/log-tree.c b/log-tree.c\nindex 59d63eb..139c8b5 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -180,12 +180,13 @@ static int has_non_ascii(const char *s)\n \treturn 0;\n }\n \n-void get_patch_filename(struct commit *commit, int nr, const char *suffix,\n-\t\t\tstruct strbuf *buf)\n+void get_patch_filename(struct commit *commit, int nr, const char *prefix,\n+\t\t\tconst char *suffix, struct strbuf *buf)\n {\n \tint suffix_len = strlen(suffix) + 1;\n-\tint start_len = buf->len;\n+\tint start_len = buf->len + strlen(prefix);\n \n+\tstrbuf_addstr(buf, prefix);\n \tstrbuf_addf(buf, commit ? \"%04d-\" : \"%d\", nr);\n \tif (commit) {\n \t\tint max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;\n@@ -263,7 +264,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n \t\textra_headers = subject_buffer;\n \n \t\tget_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,\n-\t\t\t\t    opt->patch_suffix, &filename);\n+\t\t\t\t    opt->patch_prefix, opt->patch_suffix,\n+\t\t\t\t    &filename);\n \t\tsnprintf(buffer, sizeof(buffer) - 1,\n \t\t\t \"\\n--%s%s\\n\"\n \t\t\t \"Content-Type: text/x-patch;\"\ndiff --git a/log-tree.h b/log-tree.h\nindex 20b5caf..566c85d 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -20,7 +20,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n void load_ref_decorations(void);\n \n #define FORMAT_PATCH_NAME_MAX 64\n-void get_patch_filename(struct commit *commit, int nr, const char *suffix,\n-\t\t\tstruct strbuf *buf);\n+void get_patch_filename(struct commit *commit, int nr, const char *prefix,\n+\t\t\tconst char *suffix, struct strbuf *buf);\n \n #endif\ndiff --git a/revision.h b/revision.h\nindex 227164c..b35c038 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -85,6 +85,7 @@ struct rev_info {\n \tstruct log_info *loginfo;\n \tint\t\tnr, total;\n \tconst char\t*mime_boundary;\n+\tconst char\t*patch_prefix;\n \tconst char\t*patch_suffix;\n \tint\t\tnumbered_files;\n \tchar\t\t*message_id;\ndiff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\nindex 8b33321..cf16c0a 100755\n--- a/t/t4013-diff-various.sh\n+++ b/t/t4013-diff-various.sh\n@@ -246,6 +246,7 @@ format-patch --stdout initial..master\n format-patch --stdout --no-numbered initial..master\n format-patch --stdout --numbered initial..master\n format-patch --attach --stdout initial..side\n+format-patch --attach --stdout --filename-prefix=foo- initial..side\n format-patch --attach --stdout --suffix=.diff initial..side\n format-patch --attach --stdout initial..master^\n format-patch --attach --stdout initial..master\ndiff --git a/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side b/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side\nnew file mode 100644\nindex 0000000..72127eb\n--- /dev/null\n+++ b/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side\n@@ -0,0 +1,61 @@\n+$ git format-patch --attach --stdout --filename-prefix=foo- initial..side\n+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001\n+From: A U Thor <author@example.com>\n+Date: Mon, 26 Jun 2006 00:03:00 +0000\n+Subject: [PATCH] Side\n+MIME-Version: 1.0\n+Content-Type: multipart/mixed; boundary=\"------------g-i-t--v-e-r-s-i-o-n\"\n+\n+This is a multi-part message in MIME format.\n+--------------g-i-t--v-e-r-s-i-o-n\n+Content-Type: text/plain; charset=UTF-8; format=fixed\n+Content-Transfer-Encoding: 8bit\n+\n+---\n+ dir/sub |    2 ++\n+ file0   |    3 +++\n+ file3   |    4 ++++\n+ 3 files changed, 9 insertions(+), 0 deletions(-)\n+ create mode 100644 file3\n+\n+\n+--------------g-i-t--v-e-r-s-i-o-n\n+Content-Type: text/x-patch; name=\"foo-0001-Side.patch\"\n+Content-Transfer-Encoding: 8bit\n+Content-Disposition: attachment; filename=\"foo-0001-Side.patch\"\n+\n+diff --git a/dir/sub b/dir/sub\n+index 35d242b..7289e35 100644\n+--- a/dir/sub\n++++ b/dir/sub\n+@@ -1,2 +1,4 @@\n+ A\n+ B\n++1\n++2\n+diff --git a/file0 b/file0\n+index 01e79c3..f4615da 100644\n+--- a/file0\n++++ b/file0\n+@@ -1,3 +1,6 @@\n+ 1\n+ 2\n+ 3\n++A\n++B\n++C\n+diff --git a/file3 b/file3\n+new file mode 100644\n+index 0000000..7289e35\n+--- /dev/null\n++++ b/file3\n+@@ -0,0 +1,4 @@\n++A\n++B\n++1\n++2\n+\n+--------------g-i-t--v-e-r-s-i-o-n--\n+\n+\n+$\n-- \n1.6.3.2.318.g2fd57\n"},{"id":"116275","messageId":"7vk53fql1l.fsf@alter.siamese.dyndns.org","threadId":"19758","inReplyTo":"1244963400-1739-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-06-14T08:25:26Z","receivedAt":"2009-06-14T08:25:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n>  > I am not saying we must allow a slash in the prefix and create necessary\n>  > leading paths ourselves, nor we must check for a slash and fail in the\n>  > input validation phase, but I am wondering if we can have some clever way\n>  > to internally unify the handling of this new option with --outdir.\n>\n>  Hardly, the way it is handled now (chdir()ing to --outdir, then write patches)\n\nAh, true enough.  Thanks.\n"},{"id":"116277","messageId":"4A34B4ED.6060301@gmail.com","threadId":"19758","inReplyTo":"1244963400-1739-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-06-14T08:29:33Z","receivedAt":"2009-06-14T08:29:33Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Nguyễn Thái Ngọc Duy wrote:\n> diff --git a/log-tree.c b/log-tree.c\n> index 59d63eb..139c8b5 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -180,12 +180,13 @@ static int has_non_ascii(const char *s)\n>  \treturn 0;\n>  }\n>  \n> -void get_patch_filename(struct commit *commit, int nr, const char *suffix,\n> -\t\t\tstruct strbuf *buf)\n> +void get_patch_filename(struct commit *commit, int nr, const char *prefix,\n> +\t\t\tconst char *suffix, struct strbuf *buf)\n>  {\n>  \tint suffix_len = strlen(suffix) + 1;\n> -\tint start_len = buf->len;\n> +\tint start_len = buf->len + strlen(prefix);\n>  \n> +\tstrbuf_addstr(buf, prefix);\n>  \tstrbuf_addf(buf, commit ? \"%04d-\" : \"%d\", nr);\n>  \tif (commit) {\n>  \t\tint max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;\n>   \n\nWhy does the prefix length not count against the filename length? I\nthink you want to subtract a prefix_len.\n\nAlso, this doesn't replace the numbering (0001, 0002, etc.) which I\nconsider to be a prefix. Does anyone else feel the same way?\n\nThis is kind of a funny thought, but I'll throw it out there. Could you\njust put the desired prefix in your patch subjects, and then add an\noption for no-numbered-files? So in your case, you add \"dbus 1.2.3\" at\nthe start of each subject during git-commit and then format-patch with\n--no-numbered-files. This way you get git to insert the dashes you want,\nother people get files with no numbers, and you don't have to deal with\nslashes and directory prefixes.\n\nI'm kind of confused about this though. The patches you're generating\nfor Gentoo are not being read by humans; merely being applied by portage\ncorrect? Are you going back and removing the mail headers and commit\nmessages from these patches? What I'm getting at is for your case\nformat-patch may be overkill.\n"},{"id":"116279","messageId":"7vd497qjhm.fsf@alter.siamese.dyndns.org","threadId":"19758","inReplyTo":"4A34B4ED.6060301@gmail.com","subject":"Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-06-14T08:59:01Z","receivedAt":"2009-06-14T08:59:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stephen Boyd <bebarino@gmail.com> writes:\n\n> Also, this doesn't replace the numbering (0001, 0002, etc.) which I\n> consider to be a prefix. Does anyone else feel the same way?\n\nIsn't the point of the exercise to come up with something like:\n\n      frotz-0001-first-patch-in-frotz-topic.patch\n      frotz-0002-second-patch-in-frotz-topic.patch\n      frotz-0003-third-patch-in-frotz-topic.patch\n\n      nitfol-0001-first-patch-in-nitfol-topic.patch\n      nitfol-0002-second-patch-in-nitfol-topic.patch\n\nwith two invocations of format-patch, and when they are dropped in the\nsame directory, the patches from the same series clump together?\n\nI personally do not think this is worth the additional code (you can\neasily run with --outdir=frotz and then with --outdir=nitfol and obtain\nfrotz/000?-*.patch and nitfol/000?-*.patch to get the same clumping) but\nif the convention is to use dash instead of slash, the patch will save one\nstep from users.\n"},{"id":"116285","messageId":"4A3553A5.3060209@gmail.com","threadId":"19758","inReplyTo":"7vd497qjhm.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-06-14T19:46:45Z","receivedAt":"2009-06-14T19:46:45Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Junio C Hamano wrote:\n> Isn't the point of the exercise to come up with something like:\n>\n>       frotz-0001-first-patch-in-frotz-topic.patch\n>       frotz-0002-second-patch-in-frotz-topic.patch\n>       frotz-0003-third-patch-in-frotz-topic.patch\n>\n>       nitfol-0001-first-patch-in-nitfol-topic.patch\n>       nitfol-0002-second-patch-in-nitfol-topic.patch\n>\n> with two invocations of format-patch, and when they are dropped in the\n> same directory, the patches from the same series clump together?\n\nOk. Maybe spelling out the full example in the commit message would be\nclearer.\n\n>\n> I personally do not think this is worth the additional code (you can\n> easily run with --outdir=frotz and then with --outdir=nitfol and obtain\n> frotz/000?-*.patch and nitfol/000?-*.patch to get the same clumping) but\n> if the convention is to use dash instead of slash, the patch will save one\n> step from users.\n\nI agree. How is it any harder to do 'git send-email frotz' instead of\n'git send-email frotz-*.patch'? The only advantage I see is you get\nattachment filenames with a prefix.\n"},{"id":"116302","messageId":"fcaeb9bf0906141632l5f39e6et7b37cfad9d274df8@mail.gmail.com","threadId":"19758","inReplyTo":"4A34B4ED.6060301@gmail.com","subject":"Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2009-06-14T23:32:37Z","receivedAt":"2009-06-14T23:32:37Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2009/6/14 Stephen Boyd <bebarino@gmail.com>:\n> Nguyễn Thái Ngọc Duy wrote:\n>> diff --git a/log-tree.c b/log-tree.c\n>> index 59d63eb..139c8b5 100644\n>> --- a/log-tree.c\n>> +++ b/log-tree.c\n>> @@ -180,12 +180,13 @@ static int has_non_ascii(const char *s)\n>>       return 0;\n>>  }\n>>\n>> -void get_patch_filename(struct commit *commit, int nr, const char *suffix,\n>> -                     struct strbuf *buf)\n>> +void get_patch_filename(struct commit *commit, int nr, const char *prefix,\n>> +                     const char *suffix, struct strbuf *buf)\n>>  {\n>>       int suffix_len = strlen(suffix) + 1;\n>> -     int start_len = buf->len;\n>> +     int start_len = buf->len + strlen(prefix);\n>>\n>> +     strbuf_addstr(buf, prefix);\n>>       strbuf_addf(buf, commit ? \"%04d-\" : \"%d\", nr);\n>>       if (commit) {\n>>               int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;\n>>\n>\n> Why does the prefix length not count against the filename length? I\n> think you want to subtract a prefix_len.\n>\n> Also, this doesn't replace the numbering (0001, 0002, etc.) which I\n> consider to be a prefix. Does anyone else feel the same way?\n>\n> This is kind of a funny thought, but I'll throw it out there. Could you\n> just put the desired prefix in your patch subjects, and then add an\n> option for no-numbered-files? So in your case, you add \"dbus 1.2.3\" at\n> the start of each subject during git-commit and then format-patch with\n> --no-numbered-files. This way you get git to insert the dashes you want,\n> other people get files with no numbers, and you don't have to deal with\n> slashes and directory prefixes.\n\nWell, for true flexibility, I would implement something like printf\nformat. But that would be overkill.\n\n> I'm kind of confused about this though. The patches you're generating\n> for Gentoo are not being read by humans; merely being applied by portage\n> correct? Are you going back and removing the mail headers and commit\n> messages from these patches? What I'm getting at is for your case\n> format-patch may be overkill.\n\nThey are read by human, i.e. ebuild developers, and uptream developers\ntoo when they are submitted upstream (which is great because if\nupstream uses Git, you don't have to do anything else). Plain patches\nare enough for portage, other information is for human ;-)\n-- \nDuy\n"}]}