git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Is there a way to get the "format-patch" formatted file name?
@ 2023-08-31  9:49 Vít Ondruch
  2023-08-31 11:04 ` Oswald Buddenhagen
  2023-08-31 17:19 ` Junio C Hamano
  0 siblings, 2 replies; 10+ messages in thread
From: Vít Ondruch @ 2023-08-31  9:49 UTC (permalink / raw)
  To: git


[-- Attachment #1.1: Type: text/plain, Size: 1831 bytes --]

Hi,

My typical use case is to download patches from GH, e.g.:

~~~

$ curl -OL https://github.com/rails/sprockets/pull/791.patch
   % Total    % Received % Xferd  Average Speed   Time    Time Time  Current
                                  Dload  Upload   Total   Spent Left  Speed
   0     0    0     0    0     0      0      0 --:--:-- --:--:-- 
--:--:--     0
100 12717    0 12717    0     0  21765      0 --:--:-- --:--:-- --:--:-- 
58603

~~~


The problem with this is that I end up with the "791.patch" file, while 
I'd like have a file with similar name as if I have used the git command:


~~~

$ git format-patch -1 6554b6d
0001-Fix-Minitest-constant-name-in-tests.patch

~~~


So I wonder, is there a way to get such file name?


The basic use case which would be enough for me would be to obtain the 
string:

~~~

$ head -4 791.patch | tail -1
Subject: [PATCH] Fix Minitest constant name in tests
~~~

and then use something like:

~~~

$ echo "Fix Minitest constant name in tests" | git 
sanitize-string-into-filename

Fix-Minitest-constant-name-in-tests

~~~


Of course I can imagine something more fancy such as:


~~~

$ git extract-filenames-from-patch 791.patch

0001-Fix-Minitest-constant-name-in-tests.patch

~~~


IOW, I'd like if the `fmt_output_subject` method (if that is the right one):

https://github.com/git/git/blob/6e8611e90a629e38da1e7c0e1f986bc6ec23a330/log-tree.c#L388

was more user exposed.


Of course I could put some script like this together myself, but I think 
that Git already has all the pluming.


Thank you in advance


Vít



P.S.: Please keep me in the CC, because I am not subscribed to this ML


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-08-31  9:49 Is there a way to get the "format-patch" formatted file name? Vít Ondruch
@ 2023-08-31 11:04 ` Oswald Buddenhagen
  2023-08-31 12:13   ` Vít Ondruch
  2023-08-31 17:19 ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: Oswald Buddenhagen @ 2023-08-31 11:04 UTC (permalink / raw)
  To: Vít Ondruch; +Cc: git

On Thu, Aug 31, 2023 at 11:49:10AM +0200, Vít Ondruch wrote:
>$ git extract-filenames-from-patch 791.patch
>
>0001-Fix-Minitest-constant-name-in-tests.patch
>
`git log --pretty=format:%f` does that.
of course you need to apply the patch first for that to work, which is a 
bit inefficient and arguably inelegant if you don't intend to do that 
anyway.

>P.S.: Please keep me in the CC
>
that's this list's policy anyway.

regards

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-08-31 11:04 ` Oswald Buddenhagen
@ 2023-08-31 12:13   ` Vít Ondruch
  2023-08-31 12:46     ` Oswald Buddenhagen
  0 siblings, 1 reply; 10+ messages in thread
From: Vít Ondruch @ 2023-08-31 12:13 UTC (permalink / raw)
  To: Oswald Buddenhagen; +Cc: git


[-- Attachment #1.1: Type: text/plain, Size: 649 bytes --]

Dne 31. 08. 23 v 13:04 Oswald Buddenhagen napsal(a):
> On Thu, Aug 31, 2023 at 11:49:10AM +0200, Vít Ondruch wrote:
>> $ git extract-filenames-from-patch 791.patch
>>
>> 0001-Fix-Minitest-constant-name-in-tests.patch
>>
> `git log --pretty=format:%f` does that.
> of course you need to apply the patch first for that to work


That (applying the patch) is the problem actually. I am looking for 
functionality like this in the context of  Fedora packaging, where we 
work with source tarballs. Therefore I don't typically have an 
repository around.

And if I had a repository, I could possibly use `git format-patch`.


Vít


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-08-31 12:13   ` Vít Ondruch
@ 2023-08-31 12:46     ` Oswald Buddenhagen
  0 siblings, 0 replies; 10+ messages in thread
From: Oswald Buddenhagen @ 2023-08-31 12:46 UTC (permalink / raw)
  To: Vít Ondruch; +Cc: git

On Thu, Aug 31, 2023 at 02:13:30PM +0200, Vít Ondruch wrote:
>Dne 31. 08. 23 v 13:04 Oswald Buddenhagen napsal(a):
>> On Thu, Aug 31, 2023 at 11:49:10AM +0200, Vít Ondruch wrote:
>>> $ git extract-filenames-from-patch 791.patch
>>>
>>> 0001-Fix-Minitest-constant-name-in-tests.patch
>>>
>> `git log --pretty=format:%f` does that.
>> of course you need to apply the patch first for that to work
>
>
>That (applying the patch) is the problem actually. I am looking for 
>functionality like this in the context of  Fedora packaging, where we 
>work with source tarballs. Therefore I don't typically have an 
>repository around.
>
well, you can just `git init` and add and commit the entire tree.
less inefficient would be creating a dummy repo, and cutting down the 
patch to be empty before applying it.

of course these are ludicrous suggestions in practice, and just 
replicating the cleanup function with a few regexes in a perl one-liner 
should do.

regards

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-08-31  9:49 Is there a way to get the "format-patch" formatted file name? Vít Ondruch
  2023-08-31 11:04 ` Oswald Buddenhagen
@ 2023-08-31 17:19 ` Junio C Hamano
  2023-09-01  8:56   ` Vít Ondruch
  1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2023-08-31 17:19 UTC (permalink / raw)
  To: Vít Ondruch; +Cc: git

Vít Ondruch <vondruch@redhat.com> writes:

> My typical use case is to download patches from GH, e.g.:
>
> ~~~
>
> $ curl -OL https://github.com/rails/sprockets/pull/791.patch
...
> The problem with this is that I end up with the "791.patch" file,
> while I'd like have a file with similar name as if I have used the git
> command:
>
>
> ~~~
>
> $ git format-patch -1 6554b6d
> 0001-Fix-Minitest-constant-name-in-tests.patch
>
> ~~~
>
>
> So I wonder, is there a way to get such file name?

Do you mean: GitHub should let me run this command instead

  $ curl -OL https://github.com/rails/sprockets/pull/0001-Fix-Minitest-constant-name-in-tests.patch

It may be nice for them to give a more meaningful name to their pull
request (not just the output file name) than just an integer.  But
that is not a question/request we can answer here (this is not a
help forum for GitHub users).

Something along the lines of

    sed -ne '/^Subject: /{
            s/^Subject: *\[PATCH[^]]*\] *//;
            s/[^a-zA-Z0-9]/-/g;
            s/--*/-/g;
            s/$/\.patch/;
	    p;
	    q;
    }' 791.patch

should be doable, but I am not sure what the benefit is.  Once you
get it in Git, you'd park it on a branch with a useful name and we
can forget about "791", so the "The files we get from GitHub are
named in a way that makes it hard to identify them" does not sound
like a Git issue, at least to me.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-08-31 17:19 ` Junio C Hamano
@ 2023-09-01  8:56   ` Vít Ondruch
  2023-09-01 11:00     ` Oswald Buddenhagen
  0 siblings, 1 reply; 10+ messages in thread
From: Vít Ondruch @ 2023-09-01  8:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git


[-- Attachment #1.1: Type: text/plain, Size: 2663 bytes --]


Dne 31. 08. 23 v 19:19 Junio C Hamano napsal(a):
> Vít Ondruch <vondruch@redhat.com> writes:
>
>> My typical use case is to download patches from GH, e.g.:
>>
>> ~~~
>>
>> $ curl -OL https://github.com/rails/sprockets/pull/791.patch
> ...
>> The problem with this is that I end up with the "791.patch" file,
>> while I'd like have a file with similar name as if I have used the git
>> command:
>>
>>
>> ~~~
>>
>> $ git format-patch -1 6554b6d
>> 0001-Fix-Minitest-constant-name-in-tests.patch
>>
>> ~~~
>>
>>
>> So I wonder, is there a way to get such file name?
> Do you mean: GitHub should let me run this command instead
>
>    $ curl -OL https://github.com/rails/sprockets/pull/0001-Fix-Minitest-constant-name-in-tests.patch
>
> It may be nice for them to give a more meaningful name to their pull
> request (not just the output file name) than just an integer.


This URL would be hard to compile and it could potentially lead me to 
the same question ;) But maybe in combination with `-J` option, GH (but 
also all other forges) could probably do something about it.


> But
> that is not a question/request we can answer here (this is not a
> help forum for GitHub users).


Right.


>
> Something along the lines of
>
>      sed -ne '/^Subject: /{
>              s/^Subject: *\[PATCH[^]]*\] *//;
>              s/[^a-zA-Z0-9]/-/g;
>              s/--*/-/g;
>              s/$/\.patch/;
> 	    p;
> 	    q;
>      }' 791.patch
>
> should be doable, but I am not sure what the benefit is.


If this was provided as a some convenient script, then I would not need 
to know what the sanitation of the subject is done to get the file name. 
However, so far I was mostly fine with manually replacing spaces by 
dashes, so what is sanitized is not really that important to me. I just 
though that if Git has already some opinion about it and it is already 
implemented, it would be nice to reuse the functionality.


>    Once you
> get it in Git,


But I typically don't have a Git.


>   you'd park it on a branch with a useful name and we
> can forget about "791", so the "The files we get from GitHub are
> named in a way that makes it hard to identify them" does not sound
> like a Git issue, at least to me.
>
>
>

It does not seems I have convinced you (and that is fine). I'll probably 
look around. patchutils project could be probably good candidate for 
such script. I'll try to ask there. Maybe I'll also try to explore if GH 
would be open to provide some better filename, leveraging the `-J` curl 
option.


Thx for you help! Appreciate that.


Vít


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-09-01  8:56   ` Vít Ondruch
@ 2023-09-01 11:00     ` Oswald Buddenhagen
  2023-09-01 15:53       ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Oswald Buddenhagen @ 2023-09-01 11:00 UTC (permalink / raw)
  To: Vít Ondruch; +Cc: Junio C Hamano, git

On Fri, Sep 01, 2023 at 10:56:28AM +0200, Vít Ondruch wrote:
>If this was provided as a some convenient script,
>
well, that's the key here: to be actually useful, it needs to be 
integrated into a highly specialized tool. the poor discoverability of 
that in conjunction with its somewhat minor utility is probably a 
sufficient argument for not going that route (beyond personal tool 
collections).
github & co. providing a sensible content-disposition otoh is a 
(somewhat) well-known, generic solution to this problem.

but i wouldn't be opposed to for example git-mailinfo learning to 
understand the --pretty argument, if the implementation doesn't turn out 
to be completely out of proportion.

regards

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-09-01 11:00     ` Oswald Buddenhagen
@ 2023-09-01 15:53       ` Junio C Hamano
  2023-09-01 16:04         ` Junio C Hamano
  2023-09-01 16:37         ` Vít Ondruch
  0 siblings, 2 replies; 10+ messages in thread
From: Junio C Hamano @ 2023-09-01 15:53 UTC (permalink / raw)
  To: Oswald Buddenhagen; +Cc: Vít Ondruch, git

Oswald Buddenhagen <oswald.buddenhagen@gmx.de> writes:

> but i wouldn't be opposed to for example git-mailinfo learning to
> understand the --pretty argument, if the implementation doesn't turn
> out to be completely out of proportion.

Excellent suggestion.  I agree that 'mailinfo' would be the closest
place we have for such a new feature.  It's "info" output (i.e. what
comes out to the standard output of the command) is designed to be
extensible, and I vaguely recall that we indeed have added new
field(s) during its lifetime with existing users already.

We can just invent a new label (e.g. "Filesystem-safe-subject:"),
pass the subject string to pretty.c:format_sanitized_subject() and
emit the result next to the existing "Subject:" with that label, and
we can even do so unconditionally without breaking anybody.


Having it in 'mailinfo' may still not be a good solution to the
issue, given that Vit says

>> But I typically don't have a Git.

though.


On a related not-so-distant tangent, we probably should redo the
support for --message-id to emit it as an extra entry to the "info"
output, instead of contaminating the "message" output.  The option
was added only to support "git am --message-id", and as long as the
calling "am" and "mailinfo" are updated in sync to use the "info"
output to carry the Message-Id: information, we should be able to do
such a clean-up without changing the externally visible behaviour.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-09-01 15:53       ` Junio C Hamano
@ 2023-09-01 16:04         ` Junio C Hamano
  2023-09-01 16:37         ` Vít Ondruch
  1 sibling, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2023-09-01 16:04 UTC (permalink / raw)
  To: Oswald Buddenhagen; +Cc: Vít Ondruch, git

Junio C Hamano <gitster@pobox.com> writes:

> We can just invent a new label (e.g. "Filesystem-safe-subject:"),
> pass the subject string to pretty.c:format_sanitized_subject() and
> emit the result next to the existing "Subject:" with that label, and
> we can even do so unconditionally without breaking anybody.

Such a change would be quite small and simple.

 mailinfo.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git c/mailinfo.c w/mailinfo.c
index 931505363c..b0eb646f4e 100644
--- c/mailinfo.c
+++ w/mailinfo.c
@@ -5,6 +5,7 @@
 #include "utf8.h"
 #include "strbuf.h"
 #include "mailinfo.h"
+#include "pretty.h"
 
 static void cleanup_space(struct strbuf *sb)
 {
@@ -1166,11 +1167,16 @@ static void handle_info(struct mailinfo *mi)
 		}
 
 		if (!strcmp(header[i], "Subject")) {
+			struct strbuf san = STRBUF_INIT;
+
 			if (!mi->keep_subject) {
 				cleanup_subject(mi, hdr);
 				cleanup_space(hdr);
 			}
 			output_header_lines(mi->output, "Subject", hdr);
+			format_sanitized_subject(&san, hdr->buf, hdr->len);
+			output_header_lines(mi->output, "Filesystem-Safe-Subject", &san);
+			strbuf_release(&san);
 		} else if (!strcmp(header[i], "From")) {
 			cleanup_space(hdr);
 			handle_from(mi, hdr);

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: Is there a way to get the "format-patch" formatted file name?
  2023-09-01 15:53       ` Junio C Hamano
  2023-09-01 16:04         ` Junio C Hamano
@ 2023-09-01 16:37         ` Vít Ondruch
  1 sibling, 0 replies; 10+ messages in thread
From: Vít Ondruch @ 2023-09-01 16:37 UTC (permalink / raw)
  To: Junio C Hamano, Oswald Buddenhagen; +Cc: git


[-- Attachment #1.1: Type: text/plain, Size: 1731 bytes --]


Dne 01. 09. 23 v 17:53 Junio C Hamano napsal(a):
> Oswald Buddenhagen <oswald.buddenhagen@gmx.de> writes:
>
>> but i wouldn't be opposed to for example git-mailinfo learning to
>> understand the --pretty argument, if the implementation doesn't turn
>> out to be completely out of proportion.
> Excellent suggestion.  I agree that 'mailinfo' would be the closest
> place we have for such a new feature.  It's "info" output (i.e. what
> comes out to the standard output of the command) is designed to be
> extensible, and I vaguely recall that we indeed have added new
> field(s) during its lifetime with existing users already.
>
> We can just invent a new label (e.g. "Filesystem-safe-subject:"),
> pass the subject string to pretty.c:format_sanitized_subject() and
> emit the result next to the existing "Subject:" with that label, and
> we can even do so unconditionally without breaking anybody.


'mailinfo' is new to me. I am not really sure what is the proper use of 
this tool, but it sound as a neat idea. I could certainly extract the 
string from the 'mailinfo' output and it works just above the .patch 
file, which is great.


>
>
> Having it in 'mailinfo' may still not be a good solution to the
> issue, given that Vit says
>
>>> But I typically don't have a Git.
> though.


Well, this should have been "I typically don't have a Git *repository*", 
because I certainly have a Git. Otherwise I would not ask for this 
functionality.

Just to explain, I would need to expand the sources, which I typically 
don't do. I'd need initialize the repository and commit everything, 
apply the patch, etc. In that case, I'd rater keep manually changing the 
patch names :)


Vít

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-09-01 16:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-31  9:49 Is there a way to get the "format-patch" formatted file name? Vít Ondruch
2023-08-31 11:04 ` Oswald Buddenhagen
2023-08-31 12:13   ` Vít Ondruch
2023-08-31 12:46     ` Oswald Buddenhagen
2023-08-31 17:19 ` Junio C Hamano
2023-09-01  8:56   ` Vít Ondruch
2023-09-01 11:00     ` Oswald Buddenhagen
2023-09-01 15:53       ` Junio C Hamano
2023-09-01 16:04         ` Junio C Hamano
2023-09-01 16:37         ` Vít Ondruch

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 NNTP newsgroup(s).