twaugh / patchutils

Manipulate patch files
GNU General Public License v2.0
139 stars 22 forks source link

Rename git formatted patch to some nice name #58

Open voxik opened 1 year ago

voxik commented 1 year ago

Packaging SW for Fedora, I sometimes need to apply patch, which I'll download 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, would you consider to implement some tool, which would renamed the patch in this way?

I have originally tried to convince Git folks to expose such functionality somewhere, but I failed :/ So maybe this project might be interested in this.

voxik commented 1 year ago

This is my naive implementation:

$ cat rename-patch 
#!/usr/bin/bash

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