diff mbox

[dim,v2,1/2] dim: Add extract-tags command

Message ID 20170315150904.3374-1-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ville Syrjälä March 15, 2017, 3:09 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Add a command for extracting various tags (eg. Reviwed-by:) from
emails. You can give the comamnd a rangeish to add the tags from
the same email to multiple already applied patches.

The regexp used to pick up tags is purposefully quite broad. People
tend to typo these things, or add extra whitespace etc. However the
broad regexp does mean this occasionally picks up stuff that isn't
a tag. So manually amending the commit is probably a wise idea,
and so I simply decided to also leave a '--- extracted tags ---'
separator in the commit message just before the extracted tags,
which can be cleaned up manually when verifying that the tags look
correct.

v2: Drop the aliases
    Remove the temp file
    Clean up locals
    Other codingstyle cleanups
    Use '# *** ... ***' for the separator

Cc: Jani Nikula <jani.nikula@linux.intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 dim | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

Comments

Chris Wilson March 15, 2017, 3:15 p.m. UTC | #1
On Wed, Mar 15, 2017 at 05:09:04PM +0200, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Add a command for extracting various tags (eg. Reviwed-by:) from
> emails. You can give the comamnd a rangeish to add the tags from
> the same email to multiple already applied patches.
> 
> The regexp used to pick up tags is purposefully quite broad. People
> tend to typo these things, or add extra whitespace etc. However the
> broad regexp does mean this occasionally picks up stuff that isn't
> a tag. So manually amending the commit is probably a wise idea,
> and so I simply decided to also leave a '--- extracted tags ---'
> separator in the commit message just before the extracted tags,
> which can be cleaned up manually when verifying that the tags look
> correct.

An example of typical use would be nice.
-Chris
Jani Nikula March 16, 2017, 7:40 a.m. UTC | #2
On Wed, 15 Mar 2017, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Wed, Mar 15, 2017 at 05:09:04PM +0200, ville.syrjala@linux.intel.com wrote:
>> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> 
>> Add a command for extracting various tags (eg. Reviwed-by:) from
>> emails. You can give the comamnd a rangeish to add the tags from
>> the same email to multiple already applied patches.
>> 
>> The regexp used to pick up tags is purposefully quite broad. People
>> tend to typo these things, or add extra whitespace etc. However the
>> broad regexp does mean this occasionally picks up stuff that isn't
>> a tag. So manually amending the commit is probably a wise idea,
>> and so I simply decided to also leave a '--- extracted tags ---'
>> separator in the commit message just before the extracted tags,
>> which can be cleaned up manually when verifying that the tags look
>> correct.
>
> An example of typical use would be nice.

I believe you can pipe an email to 'dim extract-tags' or one of its
variants, and have the tags in the email applied to the commits in the
branch in question.

BR,
Jani.
Ville Syrjälä March 16, 2017, 9:49 a.m. UTC | #3
On Thu, Mar 16, 2017 at 09:40:05AM +0200, Jani Nikula wrote:
> On Wed, 15 Mar 2017, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > On Wed, Mar 15, 2017 at 05:09:04PM +0200, ville.syrjala@linux.intel.com wrote:
> >> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >> 
> >> Add a command for extracting various tags (eg. Reviwed-by:) from
> >> emails. You can give the comamnd a rangeish to add the tags from
> >> the same email to multiple already applied patches.
> >> 
> >> The regexp used to pick up tags is purposefully quite broad. People
> >> tend to typo these things, or add extra whitespace etc. However the
> >> broad regexp does mean this occasionally picks up stuff that isn't
> >> a tag. So manually amending the commit is probably a wise idea,
> >> and so I simply decided to also leave a '--- extracted tags ---'
> >> separator in the commit message just before the extracted tags,
> >> which can be cleaned up manually when verifying that the tags look
> >> correct.
> >
> > An example of typical use would be nice.
> 
> I believe you can pipe an email to 'dim extract-tags' or one of its
> variants, and have the tags in the email applied to the commits in the
> branch in question.

Yes. My typical work flow with mutt is something like 'open patch mail ;
 | dim apply... ; open reply mail with tag(s) ; | dim extract...'. 
Or if someone has r-b'd an entire series I apply everything first,
and then do 'dim extract... <remote>/drm-intel-next-queued..HEAD' to
slap the tag(s) onto all the commits.
Jani Nikula March 16, 2017, 1:33 p.m. UTC | #4
On Thu, 16 Mar 2017, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote:
> On Thu, Mar 16, 2017 at 09:40:05AM +0200, Jani Nikula wrote:
>> On Wed, 15 Mar 2017, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>> > On Wed, Mar 15, 2017 at 05:09:04PM +0200, ville.syrjala@linux.intel.com wrote:
>> >> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> >> 
>> >> Add a command for extracting various tags (eg. Reviwed-by:) from
>> >> emails. You can give the comamnd a rangeish to add the tags from
>> >> the same email to multiple already applied patches.
>> >> 
>> >> The regexp used to pick up tags is purposefully quite broad. People
>> >> tend to typo these things, or add extra whitespace etc. However the
>> >> broad regexp does mean this occasionally picks up stuff that isn't
>> >> a tag. So manually amending the commit is probably a wise idea,
>> >> and so I simply decided to also leave a '--- extracted tags ---'
>> >> separator in the commit message just before the extracted tags,
>> >> which can be cleaned up manually when verifying that the tags look
>> >> correct.
>> >
>> > An example of typical use would be nice.
>> 
>> I believe you can pipe an email to 'dim extract-tags' or one of its
>> variants, and have the tags in the email applied to the commits in the
>> branch in question.
>
> Yes. My typical work flow with mutt is something like 'open patch mail ;
>  | dim apply... ; open reply mail with tag(s) ; | dim extract...'. 
> Or if someone has r-b'd an entire series I apply everything first,
> and then do 'dim extract... <remote>/drm-intel-next-queued..HEAD' to
> slap the tag(s) onto all the commits.

Pushed both patches (though I guess you could have yourself too). Please
update the dim.rst man page too.

BR,
Jani.
diff mbox

Patch

diff --git a/dim b/dim
index 6d3b9734b348..8d76953d1746 100755
--- a/dim
+++ b/dim
@@ -333,6 +333,28 @@  if message_id is not None:
 EOF
 }
 
+message_print_body ()
+{
+	python2 <<EOF
+import email
+
+def print_part(part):
+    mtype = part.get_content_maintype()
+    if mtype == 'text':
+        print(part.get_payload(decode=True))
+
+def print_msg(file):
+    msg = email.message_from_file(file)
+    if msg.is_multipart():
+        for part in msg.get_payload():
+            print_part(part)
+    else:
+        print_part(msg)
+
+print_msg(open('$1', 'r'))
+EOF
+}
+
 # append all arguments as tags at the end of the commit message of HEAD
 function dim_commit_add_tag
 {
@@ -973,6 +995,48 @@  function rangeish()
 	fi
 }
 
+function dim_extract_tags
+{
+	local branch range file tags
+
+	branch=$1
+	shift
+	range=$(rangeish "$1")
+	file=$(mktemp)
+
+	assert_branch $branch
+	assert_repo_clean
+
+	cat > $file
+
+	tags=$(message_print_body "$file" | grep -ai '^[^>]*[A-Za-z-]\+: [^ ]')
+
+	rm -f $file
+
+	if [[ -z "$tags" ]]; then
+		return 0
+	fi
+
+	tags=$(printf -- "# *** extracted tags ***\n%s" "$tags")
+
+	git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range
+}
+
+function dim_extract_queued
+{
+	dim_extract_tags drm-intel-next-queued "$@"
+}
+
+function dim_extract_fixes
+{
+	dim_extract_tags drm-intel-fixes "$@"
+}
+
+function dim_extract_next_fixes
+{
+	dim_extract_tags drm-intel-next-fixes "$@"
+}
+
 dim_alias_check_patch=checkpatch
 dim_alias_cp=checkpatch
 function dim_checkpatch