git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] cg-patch: Add -d option to apply patch directory

From
Jonas Fonseca <fonseca@diku.dk>
Date
Feb 7, 2006, 22:44 UTC
Message-ID
<20060207224441.GC24790@diku.dk>

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 <fonseca@diku.dk>
---
commit 35f920438f1c9f7413d708eeb57da7ea3dd8909a
tree 602514ba6eed872f936fdd133f17a12933fce38b
parent 77defc166986330f4285db8faf206c1176a6c4ae
author Jonas Fonseca <fonseca@diku.dk> Tue, 07 Feb 2006 23:30:42 +0100
committer Jonas Fonseca <fonseca@antimatter.localdomain> 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
Message 1 of 1 in “cg-patch: Add -d option to apply patch directory”
  1. 3/3 cg-patch: Add -d option to apply patch directoryJonas Fonseca, Feb 7, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.