[devel] [PATCH v5 1/2] Add diff exclude option for gear-rules

Vladimir D. Seleznev vseleznv на altlinux.org
Пн Дек 7 21:22:34 MSK 2020


The option specifies a glob pattern that defines files that should be
excluded from diff generation.

Signed-off-by: Vladimir D. Seleznev <vseleznv на altlinux.org>
---
 gear            | 20 ++++++++++++++++----
 gear-rules.5.in | 19 +++++++++++++++++++
 gear-store-tags |  2 ++
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/gear b/gear
index 6282c92..2d93971 100755
--- a/gear
+++ b/gear
@@ -337,7 +337,7 @@ make_archive()
 	write_git_archive "$format" "$optional" "$cmd" "$tar_tree" "$dir_name" "$tar_name" "$tar_base" "$tar_suffix"
 }
 
-get_diff_name()
+get_diff_opts()
 {
 	local old_d="$1" && shift
 	local new_d="$1" && shift
@@ -376,6 +376,13 @@ get_diff_name()
 				;;
 			name=*) diff_name="${opt#name=}"
 				;;
+			exclude=*)
+				[ -z "$(printf %s "${opt#exclude=}" |tr -d '[:alnum:]_.?*-/![]')" ] ||
+					rules_error "Invalid diff exclude pattern specified: ${opt#exclude=}"
+				[ -n "${opt#exclude=}" ] ||
+					rules_error "Invalid diff exclude pattern specified: empty pattern"
+				diff_exclude="$diff_exclude :^${opt#exclude=}"
+				;;
 			*) rules_error "Unrecognized option: $opt"
 				;;
 		esac
@@ -402,6 +409,7 @@ write_git_diff()
 {
 	local optional="$1" && shift
 	local cmd="$1" && shift
+	local diff_exclude="$1" && shift
 	local old_tree="$1" && shift
 	local old_dir="$1" && shift
 	local new_tree="$1" && shift
@@ -423,7 +431,7 @@ write_git_diff()
 		}
 
 	git diff-tree --patch-with-stat --text --no-renames --no-ext-diff \
-		"$old_id" "$new_id" >"$outdir/$name"
+		"$old_id" "$new_id" -- $diff_exclude >"$outdir/$name"
 	verbose "Extracted diff: $name"
 
 	compress_file "$cmd" "$name" ''
@@ -449,14 +457,18 @@ make_difference()
 	diff_new_tree="${new_dir%%:*}"
 	new_dir="${new_dir#*:}"
 
-	get_diff_name "$old_dir" "$new_dir" "$@"
+	local diff_exclude=
+	get_diff_opts "$old_dir" "$new_dir" "$@"
 
 	diff_old_tree="$(resolve_tree_base_name "$diff_old_tree")" ||
 		rules_error "Invalid old tree: $diff_old_tree"
 	diff_new_tree="$(resolve_tree_base_name "$diff_new_tree")" ||
 		rules_error "Invalid new tree: $diff_new_tree"
 
-	write_git_diff "$optional" "$cmd" "$diff_old_tree" "$old_dir" "$diff_new_tree" "$new_dir" "$diff_name"
+	write_git_diff \
+		"$optional" "$cmd" "$diff_exclude" \
+		"$diff_old_tree" "$old_dir" \
+		"$diff_new_tree" "$new_dir" "$diff_name"
 }
 
 extract_pattern()
diff --git a/gear-rules.5.in b/gear-rules.5.in
index 5469199..f826a07 100644
--- a/gear-rules.5.in
+++ b/gear-rules.5.in
@@ -380,6 +380,12 @@ unless the path part of
 .I new_tree_path
 is \*(lq.\*(rq, in which case the default is
 .BR @name@\- на version@\- на release@.patch .
+.TP
+.BI exclude= glob_pattern
+All files matching the
+.I glob_pattern
+are excluded from the generated diff file. This option can be specified multiple
+times.
 .RE
 .IP
 Value of the
@@ -541,6 +547,19 @@ However, if a prerelease version is packaged, parts like
 \*(lqpreN\*(rq or \*(lqrcN\*(rq should not be included in the package
 version, therefore the rule file will need some modifications for such
 versions.
+.PP
+You may want to exclude
+.BR .gear
+subdirectory and spec file from diff generation:
+.RS 4
+.PP
+.ft CW
+.nf
+tar: v на version@:.
+diff: v на version@:. . exclude=.gear/** exclude=*.spec
+.fi
+.RE
+.PP
 .
 .SS "Archive with unmodified sources and separate patch files"
 If you prefer to maintain patch files for local modifications instead
diff --git a/gear-store-tags b/gear-store-tags
index a649b66..cff2e79 100755
--- a/gear-store-tags
+++ b/gear-store-tags
@@ -162,6 +162,8 @@ find_tags_in_diff_options()
 				;;
 			name=*)
 				;;
+			exclude=*)
+				;;
 			*) rules_info "Unrecognized option \"$opt\" ignored"
 				;;
 		esac
-- 
2.29.2



Подробная информация о списке рассылки Devel