{"thread":{"id":"8453","subject":"[PATCH] Add the --numbered-files option to git-format-patch.","startedAt":"2007-06-05T20:06:53Z","lastAt":"2007-06-06T07:50:25Z","messageCount":2,"participants":["Jon Loeliger","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"44098","messageId":"1181074013.2585.14.camel@ld0161-tx32","threadId":"8453","inReplyTo":null,"subject":"[PATCH] Add the --numbered-files option to git-format-patch.","fromName":"Jon Loeliger","fromEmail":"jdl@freescale.com","sentAt":"2007-06-05T20:06:53Z","receivedAt":"2007-06-05T20:06:53Z","isPatch":true,"sender":{"key":"jdl@jdl.com","avatar":"https://gravatar.com/avatar/75ce9a10b151acd2c28ec4ab2136dba7b2ff1634530bd04b155981a749d08a64?d=mp&s=160"},"body":"With this option, git-format-patch will generate simple\nnumbered files as output instead of the default using\nwith the first commit line appended.\n\nThis simplifies the ability to generate an MH-style\ndrafts folder with each message to be sent.\n\nSigned-off-by: Jon Loeliger <jdl@freescale.com>\n---\n\nMost of this patch is indenting the \"if (sol)\"\nclause by one level.  Maybe apply it and \"diff -w\"\nto see if you believe the patch.\n\nAmazingly, some old guys in the crowd still use MH.\n\nYep, I used the new option to set up sending this message!\n\nAnd, yes, I debated a more generalized option like:\n\n    --filenames=<fmt>\n\nwith <fmt> being generalized for interpolatable things,\nbut I don't know what other things would have been\ninteresting.  So I opted for KISS.\n\njdl\n\n\n Documentation/git-format-patch.txt |   14 ++++-\n builtin-log.c                      |   97 +++++++++++++++++++++---------------\n 2 files changed, 67 insertions(+), 44 deletions(-)\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex a33d157..363edb0 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -11,7 +11,8 @@ SYNOPSIS\n [verse]\n 'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]\n                    [--attach[=<boundary>] | --inline[=<boundary>]]\n-                   [-s | --signoff] [<common diff options>] [--start-number <n>]\n+                   [-s | --signoff] [<common diff options>]\n+                   [--start-number <n>] [--numbered-files]\n                    [--in-reply-to=Message-Id] [--suffix=.<sfx>]\n                    [--ignore-if-in-upstream]\n                    [--subject-prefix=Subject-Prefix]\n@@ -30,9 +31,11 @@ gitlink:git-rev-parse[1].\n The output of this command is convenient for e-mail submission or\n for use with gitlink:git-am[1].\n \n-Each output file is numbered sequentially from 1, and uses the\n+By default, each output file is numbered sequentially from 1, and uses the\n first line of the commit message (massaged for pathname safety) as\n-the filename. The names of the output files are printed to standard\n+the filename. With the --numbered-files option, the output file names\n+will only be numbers, without the first line of the commit appended.\n+The names of the output files are printed to standard\n output, unless the --stdout option is specified.\n \n If -o is specified, output files are created in <dir>.  Otherwise\n@@ -60,6 +63,11 @@ include::diff-options.txt[]\n --start-number <n>::\n \tStart numbering the patches at <n> instead of 1.\n \n+--numbered-files::\n+\tOutput file names will be a simple number sequence\n+\twithout the default first line of the commit appended.\n+\tMutually exclusive with the --stdout option.\n+\n -k|--keep-subject::\n \tDo not strip/add '[PATCH]' from the first line of the\n \tcommit log message.\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 3744712..212cdfc 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -298,7 +298,8 @@ static int git_format_config(const char *var, const char *value)\n static FILE *realstdout = NULL;\n static const char *output_directory = NULL;\n \n-static int reopen_stdout(struct commit *commit, int nr, int keep_subject)\n+static int reopen_stdout(struct commit *commit, int nr, int keep_subject,\n+\t\t\t int numbered_files)\n {\n \tchar filename[PATH_MAX];\n \tchar *sol;\n@@ -315,53 +316,61 @@ static int reopen_stdout(struct commit *commit, int nr, int keep_subject)\n \t\t\tfilename[len++] = '/';\n \t}\n \n-\tsprintf(filename + len, \"%04d\", nr);\n-\tlen = strlen(filename);\n-\n-\tsol = strstr(commit->buffer, \"\\n\\n\");\n-\tif (sol) {\n-\t\tint j, space = 1;\n-\n-\t\tsol += 2;\n-\t\t/* strip [PATCH] or [PATCH blabla] */\n-\t\tif (!keep_subject && !prefixcmp(sol, \"[PATCH\")) {\n-\t\t\tchar *eos = strchr(sol + 6, ']');\n-\t\t\tif (eos) {\n-\t\t\t\twhile (isspace(*eos))\n-\t\t\t\t\teos++;\n-\t\t\t\tsol = eos;\n-\t\t\t}\n-\t\t}\n+\tif (numbered_files) {\n+\t\tsprintf(filename + len, \"%d\", nr);\n+\t\tlen = strlen(filename);\n \n-\t\tfor (j = 0;\n-\t\t     j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 &&\n-\t\t\t     len < sizeof(filename) - suffix_len &&\n-\t\t\t     sol[j] && sol[j] != '\\n';\n-\t\t     j++) {\n-\t\t\tif (istitlechar(sol[j])) {\n-\t\t\t\tif (space) {\n-\t\t\t\t\tfilename[len++] = '-';\n-\t\t\t\t\tspace = 0;\n+\t} else {\n+\t\tsprintf(filename + len, \"%04d\", nr);\n+\t\tlen = strlen(filename);\n+\n+\t\tsol = strstr(commit->buffer, \"\\n\\n\");\n+\t\tif (sol) {\n+\t\t\tint j, space = 1;\n+\n+\t\t\tsol += 2;\n+\t\t\t/* strip [PATCH] or [PATCH blabla] */\n+\t\t\tif (!keep_subject && !prefixcmp(sol, \"[PATCH\")) {\n+\t\t\t\tchar *eos = strchr(sol + 6, ']');\n+\t\t\t\tif (eos) {\n+\t\t\t\t\twhile (isspace(*eos))\n+\t\t\t\t\t\teos++;\n+\t\t\t\t\tsol = eos;\n \t\t\t\t}\n-\t\t\t\tfilename[len++] = sol[j];\n-\t\t\t\tif (sol[j] == '.')\n-\t\t\t\t\twhile (sol[j + 1] == '.')\n-\t\t\t\t\t\tj++;\n-\t\t\t} else\n-\t\t\t\tspace = 1;\n+\t\t\t}\n+\n+\t\t\tfor (j = 0;\n+\t\t\t     j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 &&\n+\t\t\t\t     len < sizeof(filename) - suffix_len &&\n+\t\t\t\t     sol[j] && sol[j] != '\\n';\n+\t\t\t     j++) {\n+\t\t\t\tif (istitlechar(sol[j])) {\n+\t\t\t\t\tif (space) {\n+\t\t\t\t\t\tfilename[len++] = '-';\n+\t\t\t\t\t\tspace = 0;\n+\t\t\t\t\t}\n+\t\t\t\t\tfilename[len++] = sol[j];\n+\t\t\t\t\tif (sol[j] == '.')\n+\t\t\t\t\t\twhile (sol[j + 1] == '.')\n+\t\t\t\t\t\t\tj++;\n+\t\t\t\t} else\n+\t\t\t\t\tspace = 1;\n+\t\t\t}\n+\t\t\twhile (filename[len - 1] == '.'\n+\t\t\t       || filename[len - 1] == '-')\n+\t\t\t\tlen--;\n+\t\t\tfilename[len] = 0;\n \t\t}\n-\t\twhile (filename[len - 1] == '.' || filename[len - 1] == '-')\n-\t\t\tlen--;\n-\t\tfilename[len] = 0;\n+\t\tif (len + suffix_len >= sizeof(filename))\n+\t\t\treturn error(\"Patch pathname too long\");\n+\t\tstrcpy(filename + len, fmt_patch_suffix);\n \t}\n-\tif (len + suffix_len >= sizeof(filename))\n-\t\treturn error(\"Patch pathname too long\");\n-\tstrcpy(filename + len, fmt_patch_suffix);\n+\n \tfprintf(realstdout, \"%s\\n\", filename);\n \tif (freopen(filename, \"w\", stdout) == NULL)\n \t\treturn error(\"Cannot open patch file %s\",filename);\n-\treturn 0;\n \n+\treturn 0;\n }\n \n static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const char *prefix)\n@@ -431,6 +440,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tint numbered = 0;\n \tint start_number = -1;\n \tint keep_subject = 0;\n+\tint numbered_files = 0;\t\t/* _just_ numbers */\n \tint subject_prefix = 0;\n \tint ignore_if_in_upstream = 0;\n \tint thread = 0;\n@@ -465,6 +475,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\tnumbered = 1;\n \t\telse if (!prefixcmp(argv[i], \"--start-number=\"))\n \t\t\tstart_number = strtol(argv[i] + 15, NULL, 10);\n+\t\telse if (!strcmp(argv[i], \"--numbered-files\"))\n+\t\t\tnumbered_files = 1;\n \t\telse if (!strcmp(argv[i], \"--start-number\")) {\n \t\t\ti++;\n \t\t\tif (i == argc)\n@@ -540,6 +552,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tdie (\"-n and -k are mutually exclusive.\");\n \tif (keep_subject && subject_prefix)\n \t\tdie (\"--subject-prefix and -k are mutually exclusive.\");\n+\tif (numbered_files && use_stdout)\n+\t\tdie (\"--numbered-files and --stdout are mutually exclusive.\");\n \n \targc = setup_revisions(argc, argv, &rev, \"HEAD\");\n \tif (argc > 1)\n@@ -614,7 +628,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\trev.message_id = message_id;\n \t\t}\n \t\tif (!use_stdout)\n-\t\t\tif (reopen_stdout(commit, rev.nr, keep_subject))\n+\t\t\tif (reopen_stdout(commit, rev.nr, keep_subject,\n+\t\t\t\t\t  numbered_files))\n \t\t\t\tdie(\"Failed to create output files\");\n \t\tshown = log_tree_commit(&rev, commit);\n \t\tfree(commit->buffer);\n-- \n1.5.2.1.116.g9f308-dirty\n"},{"id":"44133","messageId":"7vps497c8u.fsf@assigned-by-dhcp.cox.net","threadId":"8453","inReplyTo":"1181074013.2585.14.camel@ld0161-tx32","subject":"Re: [PATCH] Add the --numbered-files option to git-format-patch.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-06-06T07:50:25Z","receivedAt":"2007-06-06T07:50:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jon Loeliger <jdl@freescale.com> writes:\n\n> With this option, git-format-patch will generate simple\n> numbered files as output instead of the default using\n> with the first commit line appended.\n>\n> This simplifies the ability to generate an MH-style\n> drafts folder with each message to be sent.\n\nI'll take the patch but wouldn't something like:\n\n\tgit-format-patch --stdout $args |\n        FILENO=7 formail -s sh -c 'cat >.junk/$FILENO'\n\nbe equivalent to\n\n\tgit-format-patch -o .junk/ --numbered-files --start-number=7 $args\n\nand more flexible?\n"}]}