[maintainer-tools PATCH v3 2/2] dim: Curate and insert tags into patch(es)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Sean Paul <seanpaul@xxxxxxxxxxxx>
---
 dim     | 49 +++++++++++++++++++++++++++++++++++++++----------
 dim.rst |  5 +++++
 2 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/dim b/dim
index 750f737..d791df3 100755
--- a/dim
+++ b/dim
@@ -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
diff --git a/dim.rst b/dim.rst
index 3dd19f9..71c09ee 100644
--- a/dim.rst
+++ b/dim.rst
@@ -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*]
 ------------------------------
 
-- 
2.12.2.762.g0e3151a226-goog

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux