dim: Add support for multiple messages in extract-tags
PATCH 1/2 dim: Add support for multiple messages in extract-tags
Make extract-tags process tags from all messages in the supplied mbox. This allows the user to tag multiple replies and extract all tags at once.
--- dim | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
dim +7 -5
@@ -342,25 +342,27 @@ if message_id is not None: EOF } -message_print_body () +mbox_cat_messages () { python2 <<EOF import email +import mailbox 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) +def print_msg(msg): if msg.is_multipart(): for part in msg.get_payload(): print_part(part) else: print_part(msg) -print_msg(open('$1', 'r')) +mbox = mailbox.mbox('$1', create=False) +for m in mbox.values(): + print_msg(m) EOF }
@@ -1157,7 +1159,7 @@ function dim_extract_tags cat > $file - tags=$(message_print_body "$file" | grep -ai '^[^>]*[A-Za-z-]\+: [^ ]') + tags=$(mbox_cat_messages "$file" | grep -ai '^[^>]*[A-Za-z-]\+: [^ ]') rm -f $file
Signature · 6 lines
2.12.1.500.gab5fba24ee-goog _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/2 dim: Curate and insert tags into patch(es)
Launch $EDITOR when extracting tags to curate the tags immediately. Once the tags are proper, automatically add them before the first Signed-off-by line to all patches in the range.
--- dim | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
dim +10 -3
@@ -1145,6 +1145,12 @@ function rangeish() fi } +function insert_extracted_tags +{ + new_tabs=`cat $1 | awk '{ORS="\\\\n"} {print $0}' | head -c-3` + awk "/Signed-off-by/{p++} p==1{print \"$new_tabs\"; p++} p!=1{print}" +} + function dim_extract_tags { local branch range file tags
@@ -1167,9 +1173,10 @@ function dim_extract_tags return 0 fi - tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") - - git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range + echo "$tags" > $file + $EDITOR $file + export -f insert_extracted_tags + git filter-branch -f --msg-filter "insert_extracted_tags $file" $range } function dim_extract_queued
Signature · 6 lines
2.12.1.500.gab5fba24ee-goog _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH dim 2/2] dim: Curate and insert tags into patch(es)
Quoted 3 lines · Sean Paul
Launch $EDITOR when extracting tags to curate the tags immediately. Once the tags are proper, automatically add them before the first Signed-off-by line to all patches in the range.
Two problems I have with this. First, I like to edit the final commit message, not an intermediate file. Second, I pipe messages to dim extract-tags *from* my $EDITOR, so I'd rather not have it launch $EDITOR again.
BR,
Jani.
Quoted 37 lines
Signed-off-by Sean Paul <[email protected]>--- dim | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)dim +10
-3@@ -1145,6 +1145,12 @@ function rangeish() fi } +function insert_extracted_tags +{ + new_tabs=`cat $1 | awk '{ORS="\\\\n"} {print $0}' | head -c-3` + awk "/Signed-off-by/{p++} p==1{print \"$new_tabs\"; p++} p!=1{print}" +} + function dim_extract_tags { local branch range file tags@@ -1167,9 +1173,10 @@ function dim_extract_tags return 0 fi - tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") - - git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range + echo "$tags" > $file + $EDITOR $file + export -f insert_extracted_tags + git filter-branch -f --msg-filter "insert_extracted_tags $file" $range } function dim_extract_queued
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH dim 2/2] dim: Curate and insert tags into patch(es)
Quoted 7 lines · Jani Nikula
Quoted 3 lines · Sean Paul
Launch $EDITOR when extracting tags to curate the tags immediately. Once the tags are proper, automatically add them before the first Signed-off-by line to all patches in the range.
Two problems I have with this. First, I like to edit the final commit message, not an intermediate file.
Hi Jani,
Thanks for your review.
The intermediate file includes just the extracted tags, not the entire commit message. This allows you to reorder them as appropriate, or remove any false positives before it hits the log.
Quoted 4 lines
Second, I pipe messages to dim
extract-tags *from* my $EDITOR, so I'd rather not have it launch $EDITOR again.
The idea is that you approve the tags as soon as you extract them and saves you having to commit --amend later to remove the "*** extracted tags ***" lines. This can be meaningful if you've extracted tags to a large set, since you'd need to go through each commit to make any necessary changes.
As Ville suggested, I can make the editor step optional (and restore the "*** extracted tags ***" for the disabled case).
Sean
Quoted 43 lines
BR,
Jani.Quoted 37 lines
Signed-off-by Sean Paul <[email protected]>--- dim | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)dim +10
-3@@ -1145,6 +1145,12 @@ function rangeish() fi } +function insert_extracted_tags +{ + new_tabs=`cat $1 | awk '{ORS="\\\\n"} {print $0}' | head -c-3` + awk "/Signed-off-by/{p++} p==1{print \"$new_tabs\"; p++} p!=1{print}" +} + function dim_extract_tags { local branch range file tags@@ -1167,9 +1173,10 @@ function dim_extract_tags return 0 fi - tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") - - git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range + echo "$tags" > $file + $EDITOR $file + export -f insert_extracted_tags + git filter-branch -f --msg-filter "insert_extracted_tags $file" $range } function dim_extract_queuedSignature · 1 line
Jani Nikula, Intel Open Source Technology Center
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 2/2 dim: Curate and insert tags into patch(es)
In reply to Jani NikulaLaunch $EDITOR when extracting tags to curate the tags immediately. Once the tags are proper, automatically add them before the first Signed-off-by line to all patches in the range.
---
Changes in v2:
- Append the tags before the committer's SoB (Ville)
- Make launching $EDITOR contingent on -i flag (Ville/Jani)
- Fix tty issues when launching editor
dim | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-)
dim +35 -9
@@ -670,13 +670,23 @@ function dim_push_fixes dim_push_branch drm-intel-fixes "$@" } +function get_committer_email +{ + local committer_email + + if ! committer_email=$(git config --get user.email) ; then + committer_email=$EMAIL + fi + echo -n $committer_email +} + # ensure we're on branch $1, and apply patches. the rest of the arguments are # passed to git am. dim_alias_ab=apply-branch dim_alias_sob=apply-branch function dim_apply_branch { - local branch file message_id commiter_email patch_from sob rv + local branch file message_id committer_email patch_from sob rv branch=${1:?$usage} shift
@@ -688,13 +698,10 @@ function dim_apply_branch cat > $file message_id=$(message_get_id $file) - - if ! commiter_email=$(git config --get user.email) ; then - commiter_email=$EMAIL - fi + committer_email=$(get_committer_email) patch_from=$(grep "From:" "$file" | head -1) - if [[ "$patch_from" != *"$commiter_email"* ]] ; then + if [[ "$patch_from" != *"$committer_email"* ]] ; then sob=-s fi
@@ -1156,6 +1163,15 @@ function rangeish() fi } +function insert_extracted_tags +{ + local committer_email new_tags sob + committer_email=$(get_committer_email) + new_tags=$(awk '{ORS="\\\\n"} {print $0}' $1 | head -c-3) + sob="Signed-off-by: .*<$committer_email>" + awk "/$sob/{p++} p==1{print \"$new_tags\"; p++} p!=1{print}" +} + function dim_extract_tags { local branch range file tags
@@ -1177,9 +1193,19 @@ function dim_extract_tags return 0 fi - tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") - - git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range + # If interactive is selected, launch an editor to allow tag editing + # If it's not, just append the tags at the bottom of the commit + if [ "$INTERACTIVE" ]; then + echo "$tags" > $file + ${EDITOR:-vi} $file >/dev/tty</dev/tty + export -f get_committer_email insert_extracted_tags + insert_extracted_tags $file >/dev/tty + cmd="insert_extracted_tags $file" + else + tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") + cmd="cat ; echo \"$tags\"" + fi + git filter-branch -f --msg-filter "$cmd" $range } function dim_extract_queued
Signature · 6 lines
2.12.2.715.g7642488e1d-goog _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [maintainer-tools PATCH v2 2/2] dim: Curate and insert tags into patch(es)
[Apologies, I thought I'd sent this, but it was in drafts...]
Quoted 77 lines · Sean Paul
Launch $EDITOR when extracting tags to curate the tags immediately. Once the tags are proper, automatically add them before the first Signed-off-by line to all patches in the range.
Signed-off-by Sean Paul <[email protected]>---
Changes in v2:
- Append the tags before the committer's SoB (Ville)
- Make launching $EDITOR contingent on -i flag (Ville/Jani)
- Fix tty issues when launching editordim | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-)dim +22
-6@@ -670,13 +670,23 @@ function dim_push_fixes dim_push_branch drm-intel-fixes "$@" } +function get_committer_email +{ + local committer_email + + if ! committer_email=$(git config --get user.email) ; then + committer_email=$EMAIL + fi + echo -n $committer_email +} + # ensure we're on branch $1, and apply patches. the rest of the arguments are # passed to git am. dim_alias_ab=apply-branch dim_alias_sob=apply-branch function dim_apply_branch { - local branch file message_id commiter_email patch_from sob rv + local branch file message_id committer_email patch_from sob rv branch=${1:?$usage} shift@@ -688,13 +698,10 @@ function dim_apply_branch cat > $file message_id=$(message_get_id $file) - - if ! commiter_email=$(git config --get user.email) ; then - commiter_email=$EMAIL - fi + committer_email=$(get_committer_email) patch_from=$(grep "From:" "$file" | head -1) - if [[ "$patch_from" != *"$commiter_email"* ]] ; then + if [[ "$patch_from" != *"$committer_email"* ]] ; then sob=-s fi@@ -1156,6 +1163,15 @@ function rangeish() fi } +function insert_extracted_tags +{ + local committer_email new_tags sob + committer_email=$(get_committer_email) + new_tags=$(awk '{ORS="\\\\n"} {print $0}' $1 | head -c-3) + sob="Signed-off-by: .*<$committer_email>" + awk "/$sob/{p++} p==1{print \"$new_tags\"; p++} p!=1{print}" +} + function dim_extract_tags { local branch range file tags
dim function dim_extract_tags · line 1198
Quoted 9 lines
dim +3
-3@@ -1177,9 +1193,19 @@ function dim_extract_tags return 0 fi - tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") - - git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range + # If interactive is selected, launch an editor to allow tag editing + # If it's not, just append the tags at the bottom of the commit + if [ "$INTERACTIVE" ]; then
Sorry, interactive doesn't do what you think it does. It just pauses. Blame Daniel. ;)
Which again means that this will fail for my workflow. :(
dim function dim_extract_tags · line 1200
Quoted 2 lines
dim +2
-0+ echo "$tags" > $file + ${EDITOR:-vi} $file >/dev/tty</dev/tty
Why vi? Why the redirects?
BR,
Jani.
Quoted 11 lines
dim +8
-0+ export -f get_committer_email insert_extracted_tags + insert_extracted_tags $file >/dev/tty + cmd="insert_extracted_tags $file" + else + tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") + cmd="cat ; echo \"$tags\"" + fi + git filter-branch -f --msg-filter "$cmd" $range } function dim_extract_queued
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 2/2 dim: Curate and insert tags into patch(es)
Launch $EDITOR when extracting tags to curate the tags immediately. Once the tags are proper, automatically add them before the committer's Signed-off-by line to all patches in the range.
Changes in v2:
- Append the tags before the committer's SoB (Ville)
- Make launching $EDITOR contingent on -i flag (Ville/Jani)
- Fix tty issues when launching editor
Changes in v3:
- Don't overload interactive mode (add new edit mode) (Jani)
- Don't default to vi, use non-edit mode if EDITOR not set (Jani)
- Fix newline escaping in insert_extracted_tags
--- dim | 49 +++++++++++++++++++++++++++++++++++++++---------- dim.rst | 5 +++++ 2 files changed, 44 insertions(+), 10 deletions(-)
dim +39 -10
@@ -144,13 +144,17 @@ INTERACTIVE= DRY= FORCE= HELP= +EDIT= -while getopts hdfis opt; do +while getopts hdefis opt; do case "$opt" in d) DRY_RUN=--dry-run DRY=echo ;; + e) + EDIT=1 + ;; f) FORCE=1 ;;
@@ -670,13 +674,23 @@ function dim_push_fixes dim_push_branch drm-intel-fixes "$@" } +function get_committer_email +{ + local committer_email + + if ! committer_email=$(git config --get user.email) ; then + committer_email=$EMAIL + fi + echo -n $committer_email +} + # ensure we're on branch $1, and apply patches. the rest of the arguments are # passed to git am. dim_alias_ab=apply-branch dim_alias_sob=apply-branch function dim_apply_branch { - local branch file message_id commiter_email patch_from sob rv + local branch file message_id committer_email patch_from sob rv branch=${1:?$usage} shift
@@ -688,13 +702,10 @@ function dim_apply_branch cat > $file message_id=$(message_get_id $file) - - if ! commiter_email=$(git config --get user.email) ; then - commiter_email=$EMAIL - fi + committer_email=$(get_committer_email) patch_from=$(grep "From:" "$file" | head -1) - if [[ "$patch_from" != *"$commiter_email"* ]] ; then + if [[ "$patch_from" != *"$committer_email"* ]] ; then sob=-s fi
@@ -1213,6 +1224,15 @@ function rangeish() fi } +function insert_extracted_tags +{ + local committer_email new_tags sob + committer_email=$(get_committer_email) + new_tags=$(awk '{ORS="\\n"} {print $0}' $1 | head -c-3) + sob="Signed-off-by: .*<$committer_email>" + awk "/$sob/{p++} p==1{print \"$new_tags\"; p++} p!=1{print}" +} + function dim_extract_tags { local branch range file tags
@@ -1234,9 +1254,18 @@ function dim_extract_tags return 0 fi - tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") - - git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range + # If edit is selected, launch an editor to allow tag editing + # If it's not, just append the tags at the bottom of the commit + if [ "$EDIT" ] && [ -n $EDITOR ]; then + echo "$tags" > $file + $EDITOR $file >/dev/tty</dev/tty + export -f get_committer_email insert_extracted_tags + cmd="insert_extracted_tags $file" + else + tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") + cmd="cat ; echo \"$tags\"" + fi + git filter-branch -f --msg-filter "$cmd" $range } function dim_extract_queued
dim.rst +5 -0
@@ -96,6 +96,7 @@ OPTIONS -f Ignore some error conditions. -d Dry run. +-e Edit mode. -i Interactive mode. COMMANDS
@@ -204,6 +205,10 @@ This extracts various tags (e.g. Reviewed-by:) from emails and applies them to t top commit on the given branch. You can give the command a rangeish to add the tags from the same email to multiple already applied patches. +Use the -e argument to launch $EDITOR, allowing you to immediately edit the +extracted tags. Once finished, the tags will be inserted above your +Signed-off-by tag. + extract-fixes [*git-rangeish*] ------------------------------
Signature · 6 lines
2.12.2.762.g0e3151a226-goog _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH dim 2/2] dim: Curate and insert tags into patch(es)
In reply to Sean PaulQuoted 3 lines · Sean Paul
Launch $EDITOR when extracting tags to curate the tags immediately. Once the tags are proper, automatically add them before the first Signed-off-by line to all patches in the range.
Not sure adding them before the first sob is the right thing. If we want the tags to reflect the history somehow, then I suppose they should go just before *your* sob, which may or may not be the first sob in the commit message. Personally I've just started slapping them to the end which also maintains the history, but granted it doesn't really show who signed off on those tags. Or is there some "official" rule how tags should be sorted in commit messages?
And I don't like the $EDITOR idea either, so at least make it optional.
Quoted 39 lines
Signed-off-by Sean Paul <[email protected]>--- dim | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)dim +10
-3@@ -1145,6 +1145,12 @@ function rangeish() fi } +function insert_extracted_tags +{ + new_tabs=`cat $1 | awk '{ORS="\\\\n"} {print $0}' | head -c-3` + awk "/Signed-off-by/{p++} p==1{print \"$new_tabs\"; p++} p!=1{print}" +} + function dim_extract_tags { local branch range file tags@@ -1167,9 +1173,10 @@ function dim_extract_tags return 0 fi - tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") - - git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range + echo "$tags" > $file + $EDITOR $file + export -f insert_extracted_tags + git filter-branch -f --msg-filter "insert_extracted_tags $file" $range } function dim_extract_queuedSignature · 1 line
2.12.1.500.gab5fba24ee-goog
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH dim 2/2] dim: Curate and insert tags into patch(es)
Quoted 5 lines · Ville Syrjälä
Quoted 3 lines · Sean Paul
Launch $EDITOR when extracting tags to curate the tags immediately. Once the tags are proper, automatically add them before the first Signed-off-by line to all patches in the range.
Quoted 7 lines
Not sure adding them before the first sob is the right thing. If we want the tags to reflect the history somehow, then I suppose they should go just before *your* sob, which may or may not be the first sob in the commit message. Personally I've just started slapping them to the end which also maintains the history, but granted it doesn't really show who signed off on those tags. Or is there some "official" rule how tags should be sorted in commit messages?
Hi Ville,
Thanks for your review.
I usually sort them based on my perceived strength of the tag and put them before the first SoB.
Cc:
Reviewed-by:
Tested-by:
Acked-by:
Signed-off-by:
I'm fine with putting them above the first SoB of the committer, that makes sense to me. I'm not sure this is something we'll get consensus on, so that seems like a sensible approach.
Sean
Quoted 47 lines
And I don't like the $EDITOR idea either, so at least make it optional.
Quoted 39 lines
Signed-off-by Sean Paul <[email protected]>--- dim | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)dim +10
-3@@ -1145,6 +1145,12 @@ function rangeish() fi } +function insert_extracted_tags +{ + new_tabs=`cat $1 | awk '{ORS="\\\\n"} {print $0}' | head -c-3` + awk "/Signed-off-by/{p++} p==1{print \"$new_tabs\"; p++} p!=1{print}" +} + function dim_extract_tags { local branch range file tags@@ -1167,9 +1173,10 @@ function dim_extract_tags return 0 fi - tags=$(printf -- "# *** extracted tags ***\n%s" "$tags") - - git filter-branch -f --msg-filter "cat ; echo \"$tags\"" $range + echo "$tags" > $file + $EDITOR $file + export -f insert_extracted_tags + git filter-branch -f --msg-filter "insert_extracted_tags $file" $range } function dim_extract_queuedSignature · 1 line
2.12.1.500.gab5fba24ee-googSignature · 2 lines
Ville Syrjälä Intel OTC
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx