Re: [Quilt-dev] Quilt vs gmail

From: Greg KH
Date: Wed Jun 13 2018 - 09:35:36 EST


On Wed, Jun 13, 2018 at 03:00:25PM +0200, Jean Delvare wrote:
> On Tue, 12 Jun 2018 12:23:26 -0700, Linus Torvalds wrote:
> > On Tue, Jun 12, 2018 at 11:52 AM Andreas Grünbacher
> > <andreas.gruenbacher@xxxxxxxxx> wrote:
> > >
> > > Quilt uses those Content-Disposition headers to preserve the patch
> > > filenames;
> >
> > That' what I was assuming, but does anybody really care?
>
> Long ago (probably a decade by now, literally) I wrote a shell script
> named "rename-patch" for Greg KH which suggests a file name for a patch
> received by e-mail. The script first looks for a "filename" attribute
> in the Content-Disposition header, and only if not found, falls back to
> a heuristic which attempts to generate a good-looking file name based
> on the e-mail's subject.
>
> The script used to be published on my kernel.org personal web space,
> but went away when kernel.org got hacked, and I never bothered
> publishing my few scripts again, sorry about that.
>
> I'm still using that script myself, to name patches generated with "git
> show --pretty=email", however there is no Content-Disposition header
> there, so the subject heuristic is always used. I don't know if Greg is
> still using rename-patch in combination with quilt. Greg?

Yes I am, I also use it for other things, it's quite useful to me. It's
attached below if anyone else wants it.

But I don't really use the Content-Disposition portion of the logic in
that script much, if any, anymore as I handle most of my normal kernel
work using git. I only use quilt these days for local work before using
git, and for all of my stable kernel work.

So if that logic goes away in quilt, I'm not going to miss it :)

thanks,

greg k-h
#!/bin/bash

# Rename patch files according to the Content-Disposition header line
# if they do have one, or Subject if they don't.
#
# Copyright (C) 2005, 2006, 2008 Jean Delvare <khali@xxxxxxxxxxxx>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details:
# http://www.gnu.org/copyleft/gpl.html
#
# The latest official version of this script can be found at:
# ftp://ftp.kernel.org/pub/linux/kernel/people/jdelvare/scripts/rename-patch

# Avoid nasty locale effects
export LC_ALL=C

findname()
{
local file="$1" pattern;

# Try Content-Disposition first
pattern='^Content-Disposition:[[:space:]]*inline[[:space:]]*;[[:space:]]*filename[[:space:]]*=';
if grep -q $pattern "$file"
then
sed -ne "/$pattern/{s/$pattern[[:space:]]*//p;q}" "$file"
return
fi

# Fallback to Subject
pattern='^Subject:';
if grep -q $pattern "$file"
then
sed -ne "/$pattern/{
s/$pattern[[:space:]]*//;
s/\[[^]]*\]//g;
s/[^a-z0-9._-]/-/ig;
s/--*/-/g;
s/^-//;
s/^re-//i;
s/[.-]*$/.patch/;
p;q}" "$file" | \
tr A-Z a-z
return
fi
}

if [ $# -eq 0 ]
then
echo "Usage: rename-patch file [file...]" >&2
exit 1
fi

for file in "$@"
do
name=$(findname "$file")
if echo "$file" | grep -q '/'
then
path=$(echo "$file" | sed -e 's/\/[^/]*$/\//')
else
path=''
fi

if [ -z "$name" ]
then
echo "No name found for $file" >&2
continue
fi

if [ "$path$name" == "$file" ]
then
# It's already OK
continue
fi

if [ -e "$path$name" ]
then
echo "Can't rename $file to $path$name which already exists" >&2
continue
fi

mv -f "$file" "$path$name"
# echo "$file renamed to $path$name"
echo "$path$name"
done