{"thread":{"id":"3262","subject":"[PATCH 3/3] cg-patch: Add -d option to apply patch directory","startedAt":"2006-02-07T22:44:41Z","lastAt":"2006-02-07T22:44:41Z","messageCount":1,"participants":["Jonas Fonseca"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"15696","messageId":"20060207224441.GC24790@diku.dk","threadId":"3262","inReplyTo":null,"subject":"[PATCH 3/3] cg-patch: Add -d option to apply patch directory","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2006-02-07T22:44:41Z","receivedAt":"2006-02-07T22:44:41Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"It tries to do some minimal sanity checking on the individual patch\nfiles, to ensure that they are created with cg-mkpatch. This includes\nchecking that the filename starts with [0-9]*-, the patch is non-empty,\nand it contains author information from git-cat-file output.\n\nSigned-off-by: Jonas Fonseca <fonseca@diku.dk>\n---\ncommit 35f920438f1c9f7413d708eeb57da7ea3dd8909a\ntree 602514ba6eed872f936fdd133f17a12933fce38b\nparent 77defc166986330f4285db8faf206c1176a6c4ae\nauthor Jonas Fonseca <fonseca@diku.dk> Tue, 07 Feb 2006 23:30:42 +0100\ncommitter Jonas Fonseca <fonseca@antimatter.localdomain> Tue, 07 Feb 2006 23:30:42 +0100\n\n cg-patch |   26 ++++++++++++++++++++++++++\n 1 files changed, 26 insertions(+), 0 deletions(-)\n\ndiff --git a/cg-patch b/cg-patch\nindex 90dfd30..e783985 100755\n--- a/cg-patch\n+++ b/cg-patch\n@@ -12,6 +12,11 @@\n #\n # OPTIONS\n # -------\n+# -d DIRNAME:: Apply all patches in directory\n+#\tInstead of applying the patch from stdin, apply all patches in the\n+#\tspecified directory. This can be used to import a range of patches\n+#\tmade with cg-mkpatch -d.\n+#\n # -R:: Apply in reverse\n #\tApplies the patch in reverse (therefore effectively unapplies it)\n #\n@@ -68,11 +73,32 @@ redzone_border()\n \tredzone_reset\n }\n \n+apply_directory() {\n+\tdirectory=\"$1\"\n+\tpatch=\"$(mktemp -t gitpatch.XXXXXX)\"\n+\n+\tfind \"$directory\" -name '[0-9]*-*' | while read file; do\n+\t\tsed -n '/^---$/,$p' < \"$file\" > \"$patch\"\n+\t\t[ -s \"$patch\" ] || die \"No patch found in '$file'\"\n+\n+\t\tauthor=\"$(sed -n '/^author /p' < \"$patch\")\"\n+\t\t[ \"$author\" ] || die \"No author info found in '$file'\"\n+\n+\t\teval \"$(echo \"$author\" | pick_author)\"\n+\t\techo \"Applying ${file#$directory/}\"\n+\t\tcg-patch < \"$patch\"\n+\t\tsed '/^---$/,$d' < \"$file\" | cg-commit\n+\tdone\n+}\n \n reverse=\n while optparse; do\n \tif optparse -R; then\n \t\treverse=1\n+\telif optparse -d=; then\n+\t\t[ -d \"$OPTARG\" ] || die \"Not a directory '$OPTARG'.\"\n+\t\tapply_directory \"$(echo \"$OPTARG\" | sed 's,/*$,,')\"\n+\t\texit\n \telse\n \t\toptfail\n \tfi\n\n-- \nJonas Fonseca\n"}]}