{"thread":{"id":"60177","subject":"Is there a way to get the \"format-patch\" formatted file name?","startedAt":"2023-08-31T09:50:06Z","lastAt":"2023-09-01T16:39:07Z","messageCount":10,"participants":["Vít Ondruch","Oswald Buddenhagen","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"481230","messageId":"aa35fbdb-cca4-ae04-4124-9498d682ec06@redhat.com","threadId":"60177","inReplyTo":null,"subject":"Is there a way to get the \"format-patch\" formatted file name?","fromName":"Vít Ondruch","fromEmail":"vondruch@redhat.com","sentAt":"2023-08-31T09:49:10Z","receivedAt":"2023-08-31T09:50:06Z","isPatch":false,"sender":{"key":"vondruch@redhat.com","avatar":"https://gravatar.com/avatar/a970a28d3861748910124659b43dbb020284a26b591f29cd27c126284e44bfa3?d=mp&s=160"},"body":"Hi,\n\nMy typical use case is to download patches from GH, e.g.:\n\n~~~\n\n$ curl -OL https://github.com/rails/sprockets/pull/791.patch\n   % Total    % Received % Xferd  Average Speed   Time    Time Time  Current\n                                  Dload  Upload   Total   Spent Left  Speed\n   0     0    0     0    0     0      0      0 --:--:-- --:--:-- \n--:--:--     0\n100 12717    0 12717    0     0  21765      0 --:--:-- --:--:-- --:--:-- \n58603\n\n~~~\n\n\nThe problem with this is that I end up with the \"791.patch\" file, while \nI'd like have a file with similar name as if I have used the git command:\n\n\n~~~\n\n$ git format-patch -1 6554b6d\n0001-Fix-Minitest-constant-name-in-tests.patch\n\n~~~\n\n\nSo I wonder, is there a way to get such file name?\n\n\nThe basic use case which would be enough for me would be to obtain the \nstring:\n\n~~~\n\n$ head -4 791.patch | tail -1\nSubject: [PATCH] Fix Minitest constant name in tests\n~~~\n\nand then use something like:\n\n~~~\n\n$ echo \"Fix Minitest constant name in tests\" | git \nsanitize-string-into-filename\n\nFix-Minitest-constant-name-in-tests\n\n~~~\n\n\nOf course I can imagine something more fancy such as:\n\n\n~~~\n\n$ git extract-filenames-from-patch 791.patch\n\n0001-Fix-Minitest-constant-name-in-tests.patch\n\n~~~\n\n\nIOW, I'd like if the `fmt_output_subject` method (if that is the right one):\n\nhttps://github.com/git/git/blob/6e8611e90a629e38da1e7c0e1f986bc6ec23a330/log-tree.c#L388\n\nwas more user exposed.\n\n\nOf course I could put some script like this together myself, but I think \nthat Git already has all the pluming.\n\n\nThank you in advance\n\n\nVít\n\n\n\nP.S.: Please keep me in the CC, because I am not subscribed to this ML\n\n"},{"id":"481233","messageId":"ZPBzz3vvv9Ryn2tz@ugly","threadId":"60177","inReplyTo":"aa35fbdb-cca4-ae04-4124-9498d682ec06@redhat.com","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Oswald Buddenhagen","fromEmail":"oswald.buddenhagen@gmx.de","sentAt":"2023-08-31T11:04:47Z","receivedAt":"2023-08-31T11:04:50Z","isPatch":false,"sender":{"key":"oswald.buddenhagen@gmx.de","avatar":"https://avatars.githubusercontent.com/u/812380?v=4"},"body":"On Thu, Aug 31, 2023 at 11:49:10AM +0200, Vít Ondruch wrote:\n>$ git extract-filenames-from-patch 791.patch\n>\n>0001-Fix-Minitest-constant-name-in-tests.patch\n>\n`git log --pretty=format:%f` does that.\nof course you need to apply the patch first for that to work, which is a \nbit inefficient and arguably inelegant if you don't intend to do that \nanyway.\n\n>P.S.: Please keep me in the CC\n>\nthat's this list's policy anyway.\n\nregards\n"},{"id":"481235","messageId":"3a7837fa-d7fb-1a85-dc67-94e94f4058c6@redhat.com","threadId":"60177","inReplyTo":"ZPBzz3vvv9Ryn2tz@ugly","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Vít Ondruch","fromEmail":"vondruch@redhat.com","sentAt":"2023-08-31T12:13:30Z","receivedAt":"2023-08-31T12:14:26Z","isPatch":false,"sender":{"key":"vondruch@redhat.com","avatar":"https://gravatar.com/avatar/a970a28d3861748910124659b43dbb020284a26b591f29cd27c126284e44bfa3?d=mp&s=160"},"body":"Dne 31. 08. 23 v 13:04 Oswald Buddenhagen napsal(a):\n> On Thu, Aug 31, 2023 at 11:49:10AM +0200, Vít Ondruch wrote:\n>> $ git extract-filenames-from-patch 791.patch\n>>\n>> 0001-Fix-Minitest-constant-name-in-tests.patch\n>>\n> `git log --pretty=format:%f` does that.\n> of course you need to apply the patch first for that to work\n\n\nThat (applying the patch) is the problem actually. I am looking for \nfunctionality like this in the context of  Fedora packaging, where we \nwork with source tarballs. Therefore I don't typically have an \nrepository around.\n\nAnd if I had a repository, I could possibly use `git format-patch`.\n\n\nVít\n\n"},{"id":"481236","messageId":"ZPCLi5iiYsf6XQc6@ugly","threadId":"60177","inReplyTo":"3a7837fa-d7fb-1a85-dc67-94e94f4058c6@redhat.com","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Oswald Buddenhagen","fromEmail":"oswald.buddenhagen@gmx.de","sentAt":"2023-08-31T12:46:03Z","receivedAt":"2023-08-31T12:46:08Z","isPatch":false,"sender":{"key":"oswald.buddenhagen@gmx.de","avatar":"https://avatars.githubusercontent.com/u/812380?v=4"},"body":"On Thu, Aug 31, 2023 at 02:13:30PM +0200, Vít Ondruch wrote:\n>Dne 31. 08. 23 v 13:04 Oswald Buddenhagen napsal(a):\n>> On Thu, Aug 31, 2023 at 11:49:10AM +0200, Vít Ondruch wrote:\n>>> $ git extract-filenames-from-patch 791.patch\n>>>\n>>> 0001-Fix-Minitest-constant-name-in-tests.patch\n>>>\n>> `git log --pretty=format:%f` does that.\n>> of course you need to apply the patch first for that to work\n>\n>\n>That (applying the patch) is the problem actually. I am looking for \n>functionality like this in the context of  Fedora packaging, where we \n>work with source tarballs. Therefore I don't typically have an \n>repository around.\n>\nwell, you can just `git init` and add and commit the entire tree.\nless inefficient would be creating a dummy repo, and cutting down the \npatch to be empty before applying it.\n\nof course these are ludicrous suggestions in practice, and just \nreplicating the cleanup function with a few regexes in a perl one-liner \nshould do.\n\nregards\n"},{"id":"481248","messageId":"xmqqo7inw2na.fsf@gitster.g","threadId":"60177","inReplyTo":"aa35fbdb-cca4-ae04-4124-9498d682ec06@redhat.com","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-31T17:19:21Z","receivedAt":"2023-08-31T17:19:32Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Vít Ondruch <vondruch@redhat.com> writes:\n\n> My typical use case is to download patches from GH, e.g.:\n>\n> ~~~\n>\n> $ curl -OL https://github.com/rails/sprockets/pull/791.patch\n...\n> The problem with this is that I end up with the \"791.patch\" file,\n> while I'd like have a file with similar name as if I have used the git\n> command:\n>\n>\n> ~~~\n>\n> $ git format-patch -1 6554b6d\n> 0001-Fix-Minitest-constant-name-in-tests.patch\n>\n> ~~~\n>\n>\n> So I wonder, is there a way to get such file name?\n\nDo you mean: GitHub should let me run this command instead\n\n  $ curl -OL https://github.com/rails/sprockets/pull/0001-Fix-Minitest-constant-name-in-tests.patch\n\nIt may be nice for them to give a more meaningful name to their pull\nrequest (not just the output file name) than just an integer.  But\nthat is not a question/request we can answer here (this is not a\nhelp forum for GitHub users).\n\nSomething along the lines of\n\n    sed -ne '/^Subject: /{\n            s/^Subject: *\\[PATCH[^]]*\\] *//;\n            s/[^a-zA-Z0-9]/-/g;\n            s/--*/-/g;\n            s/$/\\.patch/;\n\t    p;\n\t    q;\n    }' 791.patch\n\nshould be doable, but I am not sure what the benefit is.  Once you\nget it in Git, you'd park it on a branch with a useful name and we\ncan forget about \"791\", so the \"The files we get from GitHub are\nnamed in a way that makes it hard to identify them\" does not sound\nlike a Git issue, at least to me.\n\n\n\n"},{"id":"481281","messageId":"24e10903-29a0-497a-c8d8-b26c02de7336@redhat.com","threadId":"60177","inReplyTo":"xmqqo7inw2na.fsf@gitster.g","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Vít Ondruch","fromEmail":"vondruch@redhat.com","sentAt":"2023-09-01T08:56:28Z","receivedAt":"2023-09-01T08:57:17Z","isPatch":false,"sender":{"key":"vondruch@redhat.com","avatar":"https://gravatar.com/avatar/a970a28d3861748910124659b43dbb020284a26b591f29cd27c126284e44bfa3?d=mp&s=160"},"body":"\nDne 31. 08. 23 v 19:19 Junio C Hamano napsal(a):\n> Vít Ondruch <vondruch@redhat.com> writes:\n>\n>> My typical use case is to download patches from GH, e.g.:\n>>\n>> ~~~\n>>\n>> $ curl -OL https://github.com/rails/sprockets/pull/791.patch\n> ...\n>> The problem with this is that I end up with the \"791.patch\" file,\n>> while I'd like have a file with similar name as if I have used the git\n>> command:\n>>\n>>\n>> ~~~\n>>\n>> $ git format-patch -1 6554b6d\n>> 0001-Fix-Minitest-constant-name-in-tests.patch\n>>\n>> ~~~\n>>\n>>\n>> So I wonder, is there a way to get such file name?\n> Do you mean: GitHub should let me run this command instead\n>\n>    $ curl -OL https://github.com/rails/sprockets/pull/0001-Fix-Minitest-constant-name-in-tests.patch\n>\n> It may be nice for them to give a more meaningful name to their pull\n> request (not just the output file name) than just an integer.\n\n\nThis URL would be hard to compile and it could potentially lead me to \nthe same question ;) But maybe in combination with `-J` option, GH (but \nalso all other forges) could probably do something about it.\n\n\n> But\n> that is not a question/request we can answer here (this is not a\n> help forum for GitHub users).\n\n\nRight.\n\n\n>\n> Something along the lines of\n>\n>      sed -ne '/^Subject: /{\n>              s/^Subject: *\\[PATCH[^]]*\\] *//;\n>              s/[^a-zA-Z0-9]/-/g;\n>              s/--*/-/g;\n>              s/$/\\.patch/;\n> \t    p;\n> \t    q;\n>      }' 791.patch\n>\n> should be doable, but I am not sure what the benefit is.\n\n\nIf this was provided as a some convenient script, then I would not need \nto know what the sanitation of the subject is done to get the file name. \nHowever, so far I was mostly fine with manually replacing spaces by \ndashes, so what is sanitized is not really that important to me. I just \nthough that if Git has already some opinion about it and it is already \nimplemented, it would be nice to reuse the functionality.\n\n\n>    Once you\n> get it in Git,\n\n\nBut I typically don't have a Git.\n\n\n>   you'd park it on a branch with a useful name and we\n> can forget about \"791\", so the \"The files we get from GitHub are\n> named in a way that makes it hard to identify them\" does not sound\n> like a Git issue, at least to me.\n>\n>\n>\n\nIt does not seems I have convinced you (and that is fine). I'll probably \nlook around. patchutils project could be probably good candidate for \nsuch script. I'll try to ask there. Maybe I'll also try to explore if GH \nwould be open to provide some better filename, leveraging the `-J` curl \noption.\n\n\nThx for you help! Appreciate that.\n\n\nVít\n\n"},{"id":"481282","messageId":"ZPHEOYyyX+l3AGP1@ugly","threadId":"60177","inReplyTo":"24e10903-29a0-497a-c8d8-b26c02de7336@redhat.com","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Oswald Buddenhagen","fromEmail":"oswald.buddenhagen@gmx.de","sentAt":"2023-09-01T11:00:09Z","receivedAt":"2023-09-01T11:00:15Z","isPatch":false,"sender":{"key":"oswald.buddenhagen@gmx.de","avatar":"https://avatars.githubusercontent.com/u/812380?v=4"},"body":"On Fri, Sep 01, 2023 at 10:56:28AM +0200, Vít Ondruch wrote:\n>If this was provided as a some convenient script,\n>\nwell, that's the key here: to be actually useful, it needs to be \nintegrated into a highly specialized tool. the poor discoverability of \nthat in conjunction with its somewhat minor utility is probably a \nsufficient argument for not going that route (beyond personal tool \ncollections).\ngithub & co. providing a sensible content-disposition otoh is a \n(somewhat) well-known, generic solution to this problem.\n\nbut i wouldn't be opposed to for example git-mailinfo learning to \nunderstand the --pretty argument, if the implementation doesn't turn out \nto be completely out of proportion.\n\nregards\n"},{"id":"481291","messageId":"xmqqwmx9ritx.fsf@gitster.g","threadId":"60177","inReplyTo":"ZPHEOYyyX+l3AGP1@ugly","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-01T15:53:14Z","receivedAt":"2023-09-01T15:53:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Oswald Buddenhagen <oswald.buddenhagen@gmx.de> writes:\n\n> but i wouldn't be opposed to for example git-mailinfo learning to\n> understand the --pretty argument, if the implementation doesn't turn\n> out to be completely out of proportion.\n\nExcellent suggestion.  I agree that 'mailinfo' would be the closest\nplace we have for such a new feature.  It's \"info\" output (i.e. what\ncomes out to the standard output of the command) is designed to be\nextensible, and I vaguely recall that we indeed have added new\nfield(s) during its lifetime with existing users already.\n\nWe can just invent a new label (e.g. \"Filesystem-safe-subject:\"),\npass the subject string to pretty.c:format_sanitized_subject() and\nemit the result next to the existing \"Subject:\" with that label, and\nwe can even do so unconditionally without breaking anybody.\n\n\nHaving it in 'mailinfo' may still not be a good solution to the\nissue, given that Vit says\n\n>> But I typically don't have a Git.\n\nthough.\n\n\nOn a related not-so-distant tangent, we probably should redo the\nsupport for --message-id to emit it as an extra entry to the \"info\"\noutput, instead of contaminating the \"message\" output.  The option\nwas added only to support \"git am --message-id\", and as long as the\ncalling \"am\" and \"mailinfo\" are updated in sync to use the \"info\"\noutput to carry the Message-Id: information, we should be able to do\nsuch a clean-up without changing the externally visible behaviour.\n"},{"id":"481292","messageId":"xmqqsf7xribk.fsf@gitster.g","threadId":"60177","inReplyTo":"xmqqwmx9ritx.fsf@gitster.g","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-01T16:04:15Z","receivedAt":"2023-09-01T16:04:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> We can just invent a new label (e.g. \"Filesystem-safe-subject:\"),\n> pass the subject string to pretty.c:format_sanitized_subject() and\n> emit the result next to the existing \"Subject:\" with that label, and\n> we can even do so unconditionally without breaking anybody.\n\nSuch a change would be quite small and simple.\n\n mailinfo.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git c/mailinfo.c w/mailinfo.c\nindex 931505363c..b0eb646f4e 100644\n--- c/mailinfo.c\n+++ w/mailinfo.c\n@@ -5,6 +5,7 @@\n #include \"utf8.h\"\n #include \"strbuf.h\"\n #include \"mailinfo.h\"\n+#include \"pretty.h\"\n \n static void cleanup_space(struct strbuf *sb)\n {\n@@ -1166,11 +1167,16 @@ static void handle_info(struct mailinfo *mi)\n \t\t}\n \n \t\tif (!strcmp(header[i], \"Subject\")) {\n+\t\t\tstruct strbuf san = STRBUF_INIT;\n+\n \t\t\tif (!mi->keep_subject) {\n \t\t\t\tcleanup_subject(mi, hdr);\n \t\t\t\tcleanup_space(hdr);\n \t\t\t}\n \t\t\toutput_header_lines(mi->output, \"Subject\", hdr);\n+\t\t\tformat_sanitized_subject(&san, hdr->buf, hdr->len);\n+\t\t\toutput_header_lines(mi->output, \"Filesystem-Safe-Subject\", &san);\n+\t\t\tstrbuf_release(&san);\n \t\t} else if (!strcmp(header[i], \"From\")) {\n \t\t\tcleanup_space(hdr);\n \t\t\thandle_from(mi, hdr);\n"},{"id":"481297","messageId":"36fcd3ae-19c8-23c6-fcb0-a20230ee4622@redhat.com","threadId":"60177","inReplyTo":"xmqqwmx9ritx.fsf@gitster.g","subject":"Re: Is there a way to get the \"format-patch\" formatted file name?","fromName":"Vít Ondruch","fromEmail":"vondruch@redhat.com","sentAt":"2023-09-01T16:37:45Z","receivedAt":"2023-09-01T16:39:07Z","isPatch":false,"sender":{"key":"vondruch@redhat.com","avatar":"https://gravatar.com/avatar/a970a28d3861748910124659b43dbb020284a26b591f29cd27c126284e44bfa3?d=mp&s=160"},"body":"\nDne 01. 09. 23 v 17:53 Junio C Hamano napsal(a):\n> Oswald Buddenhagen <oswald.buddenhagen@gmx.de> writes:\n>\n>> but i wouldn't be opposed to for example git-mailinfo learning to\n>> understand the --pretty argument, if the implementation doesn't turn\n>> out to be completely out of proportion.\n> Excellent suggestion.  I agree that 'mailinfo' would be the closest\n> place we have for such a new feature.  It's \"info\" output (i.e. what\n> comes out to the standard output of the command) is designed to be\n> extensible, and I vaguely recall that we indeed have added new\n> field(s) during its lifetime with existing users already.\n>\n> We can just invent a new label (e.g. \"Filesystem-safe-subject:\"),\n> pass the subject string to pretty.c:format_sanitized_subject() and\n> emit the result next to the existing \"Subject:\" with that label, and\n> we can even do so unconditionally without breaking anybody.\n\n\n'mailinfo' is new to me. I am not really sure what is the proper use of \nthis tool, but it sound as a neat idea. I could certainly extract the \nstring from the 'mailinfo' output and it works just above the .patch \nfile, which is great.\n\n\n>\n>\n> Having it in 'mailinfo' may still not be a good solution to the\n> issue, given that Vit says\n>\n>>> But I typically don't have a Git.\n> though.\n\n\nWell, this should have been \"I typically don't have a Git *repository*\", \nbecause I certainly have a Git. Otherwise I would not ask for this \nfunctionality.\n\nJust to explain, I would need to expand the sources, which I typically \ndon't do. I'd need initialize the repository and commit everything, \napply the patch, etc. In that case, I'd rater keep manually changing the \npatch names :)\n\n\nVít\n"}]}