[PATCH 3/3] cg-patch: Add -d option to apply patch directory
From: Jonas Fonseca <hidden>
Date: 2016-06-15 22:42:18
Subsystem:
the rest · Maintainer:
Linus Torvalds
It tries to do some minimal sanity checking on the individual patch files, to ensure that they are created with cg-mkpatch. This includes checking that the filename starts with [0-9]*-, the patch is non-empty, and it contains author information from git-cat-file output. Signed-off-by: Jonas Fonseca <redacted> --- commit 35f920438f1c9f7413d708eeb57da7ea3dd8909a tree 602514ba6eed872f936fdd133f17a12933fce38b parent 77defc166986330f4285db8faf206c1176a6c4ae author Jonas Fonseca [off-list ref] Tue, 07 Feb 2006 23:30:42 +0100 committer Jonas Fonseca [off-list ref] Tue, 07 Feb 2006 23:30:42 +0100 cg-patch | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/cg-patch b/cg-patch
index 90dfd30..e783985 100755
--- a/cg-patch
+++ b/cg-patch@@ -12,6 +12,11 @@ # # OPTIONS # ------- +# -d DIRNAME:: Apply all patches in directory +# Instead of applying the patch from stdin, apply all patches in the +# specified directory. This can be used to import a range of patches +# made with cg-mkpatch -d. +# # -R:: Apply in reverse # Applies the patch in reverse (therefore effectively unapplies it) #
@@ -68,11 +73,32 @@ redzone_border() redzone_reset } +apply_directory() { + directory="$1" + patch="$(mktemp -t gitpatch.XXXXXX)" + + find "$directory" -name '[0-9]*-*' | while read file; do + sed -n '/^---$/,$p' < "$file" > "$patch" + [ -s "$patch" ] || die "No patch found in '$file'" + + author="$(sed -n '/^author /p' < "$patch")" + [ "$author" ] || die "No author info found in '$file'" + + eval "$(echo "$author" | pick_author)" + echo "Applying ${file#$directory/}" + cg-patch < "$patch" + sed '/^---$/,$d' < "$file" | cg-commit + done +} reverse= while optparse; do if optparse -R; then reverse=1 + elif optparse -d=; then + [ -d "$OPTARG" ] || die "Not a directory '$OPTARG'." + apply_directory "$(echo "$OPTARG" | sed 's,/*$,,')" + exit else optfail fi
--
Jonas Fonseca