From: Eric Lesh <eclesh@ucla.edu>
To: jsipek@cs.sunysb.edu
Cc: git@vger.kernel.org, Eric Lesh <eclesh@ucla.edu>
Subject: [GUILT PATCH 2/5] guilt-guard: Assign guards to patches in series
Date: Mon, 30 Jul 2007 20:11:18 -0700 [thread overview]
Message-ID: <1185851481271-git-send-email-eclesh@ucla.edu> (raw)
In-Reply-To: <1185851481190-git-send-email-eclesh@ucla.edu>
guilt-guard will assign guards to a patch. They work so that:
* Patches with no guards are always pushed.
* Patches with positive guards (i.e. +foo) are pushed *only if* the
guard is selected.
* Patches with negative guards (i.e. -foo) are pushed *unless* the
guard is selected.
This also introduces a number of guard-related utility functions into
guilt. get_guarded_series is used to get the list of patches that are
applicable given the current guard status. It replaces get_series in
a later patch.
Signed-off-by: Eric Lesh <eclesh@ucla.edu>
---
Documentation/guilt-guard.txt | 40 +++++++++++++++++++++++
guilt | 66 +++++++++++++++++++++++++++++++++++++++
guilt-guard | 69 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 175 insertions(+), 0 deletions(-)
create mode 100644 Documentation/guilt-guard.txt
create mode 100755 guilt-guard
diff --git a/Documentation/guilt-guard.txt b/Documentation/guilt-guard.txt
new file mode 100644
index 0000000..6290bf7
--- /dev/null
+++ b/Documentation/guilt-guard.txt
@@ -0,0 +1,40 @@
+guilt-guard(1)
+===============
+
+NAME
+----
+guilt-guard - Assign guards to patches
+
+SYNOPSIS
+--------
+include::usage-guilt-guard.txt[]
+
+DESCRIPTION
+-----------
+Assign guards to the specified patch, or to the patch on top of the
+stack if no patch is given on the command line.
+
+An unguarded patch is always pushed.
+
+A positive guard begins with a +. A patch with a positive guard is
+pushed *only if* the guard is selected.
+
+A negative guard begins with a -. A patch with a negative guard is
+always pushed, *unless* the guard is selected.
+
+OPTIONS
+-------
+-l|--list::
+ List all patches and their guards
+-n|--none::
+ Remove all guards from a patch
+
+Author
+------
+Written by Eric Lesh <eclesh@ucla.edu>
+
+Documentation
+-------------
+Documentation by Eric Lesh <eclesh@ucla.edu>
+
+include::footer.txt[]
diff --git a/guilt b/guilt
index 700c167..6af590c 100755
--- a/guilt
+++ b/guilt
@@ -187,6 +187,72 @@ get_series()
" $series
}
+get_guarded_series()
+{
+ get_series | while read p
+ do
+ check_guards "$p" && echo "$p"
+ done
+}
+
+# usage: check_guards <patch>
+# Returns 0 if the patch should be pushed
+check_guards()
+{
+ get_guards "$1" | while read guard
+ do
+ pos=`printf %s $guard | grep -e "^+"`
+ guard=`printf %s $guard | sed -e 's/^[+-]//'`
+ if [ "$pos" ]; then
+ # Push +guard *only if* guard selected
+ push=`grep -e "^$guard\$" "$guards_file" >/dev/null 2>/dev/null; echo $?`
+ [ $push -ne 0 ] && return 1
+ else
+ # Push -guard *unless* guard selected
+ push=`grep -e "^$guard\$" "$guards_file" >/dev/null 2>/dev/null; echo $?`
+ [ $push -eq 0 ] && return 1
+ fi
+ return 0
+ done
+ return $?
+}
+
+# usage: get_guards <patch>
+get_guards()
+{
+ sed -n -e "\,^$1[[:space:]]*#, {
+ s,^$1[[:space:]]*,,
+ s,#[^+-]*,,g
+
+ p
+ }
+ " $series
+}
+
+# usage: set_guards <patch> <guards...>
+set_guards()
+{
+ p="$1"
+ shift
+ for x in "$@"; do
+ if [ -z $(printf %s "$x" | grep -e "^[+-]") ]; then
+ echo "'$x' is not a valid guard name"
+ else
+ sed -i -e "s,^\($p[[:space:]]*.*\)$,\1 #$x," "$series"
+ fi
+ done
+}
+
+# usage: unset_guards <patch> <guards...>
+unset_guards()
+{
+ p="$1"
+ shift
+ for x in "$@"; do
+ sed -i -e "/^$p[[:space:]]/s/ #$x//" "$series"
+ done
+}
+
# usage: do_make_header <hash>
do_make_header()
{
diff --git a/guilt-guard b/guilt-guard
new file mode 100755
index 0000000..a0cac2e
--- /dev/null
+++ b/guilt-guard
@@ -0,0 +1,69 @@
+#!/bin/sh
+#
+# Copyright (c) Eric Lesh, 2007
+#
+
+USAGE="[-l|--list|-n|--none|[<patchname>] [(+|-)<guard>...]]"
+. `dirname $0`/guilt
+
+print_guards()
+{
+ guards=`get_guards "$1"`
+ echo "$1: $guards"
+}
+
+if [ "$1" == "-l" ] || [ "$1" == "--list" ]; then
+ get_series | while read patch; do
+ print_guards "$patch"
+ done
+ exit 0
+elif [ "$1" == "-n" ] || [ "$1" == "--none" ]; then
+ patch="$2"
+ if [ -z "$patch" ]; then
+ patch=`get_top`
+ fi
+ unset_guards "$patch" `get_guards "$patch"`
+ exit 0
+fi
+
+case $# in
+ 0)
+ if [ ! -s "$applied" ]; then
+ die "No patches applied."
+ fi
+ print_guards `get_top`
+ ;;
+ 1)
+ if [ -z $(printf %s "$1" | grep -e '^[+-]') ]; then
+ if [ -z $(get_series | grep -e "^$1\$") ]; then
+ die "Patch $1 does not exist."
+ else
+ print_guards "$1"
+ fi
+ else
+ patch=`get_top`
+ if [ -z "$patch" ]; then
+ die "You must specify a patch."
+ fi
+ unset_guards "$patch" `get_guards "$patch"`
+ set_guards "$patch" "$1"
+ fi
+ ;;
+ *)
+ if [ -z $(printf %s "$1" | grep -e '^[+-]') ]; then
+ if [ -z $(get_series | grep -e "^$1\$") ]; then
+ die "Patch $1 does not exist."
+ else
+ patch="$1"
+ fi
+ shift
+ else
+ patch=`get_top`
+ if [ -z "$patch" ]; then
+ die "You must specify a patch."
+ fi
+ fi
+ unset_guards "$patch" `get_guards "$patch"`
+ set_guards "$patch" "$@"
+ ;;
+esac
--
1.5.2
next prev parent reply other threads:[~2007-07-31 3:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-31 3:11 [GUILT PATCH v2 0/5] Add guards to guilt Eric Lesh
2007-07-31 3:11 ` [GUILT PATCH 1/5] get_series: Remove comments from end of series lines Eric Lesh
2007-07-31 3:50 ` Josef Sipek
2007-07-31 3:11 ` Eric Lesh [this message]
2007-07-31 4:05 ` [GUILT PATCH 2/5] guilt-guard: Assign guards to patches in series Josef Sipek
2007-08-09 7:34 ` Eric Lesh
2007-08-09 8:17 ` David Kastrup
2007-08-09 8:22 ` Thomas Adam
2007-08-09 8:43 ` David Kastrup
2007-08-09 8:53 ` Eric Lesh
2007-08-09 9:01 ` Eric Lesh
2007-08-09 13:47 ` Josef Sipek
2007-07-31 3:11 ` [GUILT PATCH 3/5] guilt-select: Select guards to apply when pushing patches Eric Lesh
2007-07-31 3:11 ` [GUILT PATCH 4/5] get_series: return guarded patches only Eric Lesh
2007-07-31 3:11 ` [GUILT PATCH 5/5] Guards test suite Eric Lesh
2007-07-31 3:42 ` [GUILT PATCH v2 0/5] Add guards to guilt Josef Sipek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1185851481271-git-send-email-eclesh@ucla.edu \
--to=eclesh@ucla.edu \
--cc=git@vger.kernel.org \
--cc=jsipek@cs.sunysb.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).