git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Campbell <brian.p.campbell@dartmouth.edu>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: git@vger.kernel.org, Petr Baudis <pasky@suse.cz>,
	Brian Campbell <brian.p.campbell@dartmouth.edu>
Subject: [PATCH 2/2] [TopGit] Portability: Don't use alternation ("|") in sed regular expressions
Date: Thu, 12 Mar 2009 01:56:29 -0400	[thread overview]
Message-ID: <1236837389-35687-2-git-send-email-brian.p.campbell@dartmouth.edu> (raw)
In-Reply-To: <1236837389-35687-1-git-send-email-brian.p.campbell@dartmouth.edu>

There is no portable way in sed to express alternation (the "|"
operator).  POSIX does not specify any way of expressing alternation;
according to POSIX, sed uses basic regular expressions which do not
support alternation.  GNU sed allows "\|" to express alternation,
and BSD sed (as tested on Mac OS X) allows for the use of extended
regular expressions with the -E flag, but there appears to be no
portable way to express this.

This patch works around the problem by changing a single sed
expression into two.  This patch also factors out all the call
sites that were doing this, to determing the current branch,
into a single function current_branch in tg.sh.

Signed-off-by: Brian Campbell <brian.p.campbell@dartmouth.edu>
---
 tg-info.sh    |    2 +-
 tg-patch.sh   |    2 +-
 tg-summary.sh |    2 +-
 tg-update.sh  |    2 +-
 tg.sh         |    5 +++++
 5 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/tg-info.sh b/tg-info.sh
index 7d6a34c..25c753c 100644
--- a/tg-info.sh
+++ b/tg-info.sh
@@ -20,7 +20,7 @@ while [ -n "$1" ]; do
 	esac
 done
 
-[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
+[ -n "$name" ] || name="$(current_branch)"
 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
 	die "not a TopGit-controlled branch"
 
diff --git a/tg-patch.sh b/tg-patch.sh
index d701c54..ba788c8 100644
--- a/tg-patch.sh
+++ b/tg-patch.sh
@@ -35,7 +35,7 @@ done
 [ -n "$name"  -a  -z "$diff_committed_only" ]  &&
 	die "-i/-w are mutually exclusive with NAME"
 
-[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
+[ -n "$name" ] || name="$(current_branch)"
 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
 	die "not a TopGit-controlled branch"
 
diff --git a/tg-summary.sh b/tg-summary.sh
index 50ee883..62b499e 100644
--- a/tg-summary.sh
+++ b/tg-summary.sh
@@ -22,7 +22,7 @@ while [ -n "$1" ]; do
 	esac
 done
 
-curname="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
+curname="$(current_branch)"
 
 ! [ -n "$terse" -a -n "$graphviz" ] ||
 	die "-t and --graphviz options are mutual exclusive"
diff --git a/tg-update.sh b/tg-update.sh
index 288ec14..0cff0ac 100644
--- a/tg-update.sh
+++ b/tg-update.sh
@@ -14,7 +14,7 @@ if [ -n "$1" ]; then
 fi
 
 
-name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
+name="$(current_branch)"
 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
 	die "not a TopGit-controlled branch"
 
diff --git a/tg.sh b/tg.sh
index 43d1c9f..232a8b7 100644
--- a/tg.sh
+++ b/tg.sh
@@ -18,6 +18,11 @@ die()
 	exit 1
 }
 
+current_branch()
+{
+	echo "$(git symbolic-ref HEAD | sed -e 's#^refs/heads/##' -e 's#^refs/top-bases/##')"
+}
+
 # cat_file "topic:file"
 # Like `git cat-file blob $1`, but topics '(i)' and '(w)' means index and worktree
 cat_file()
-- 
1.6.2.185.g8b635.dirty

  reply	other threads:[~2009-03-12  6:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-12  5:56 [PATCH 1/2] [TopGit] Portability: Use tr instead of sed for translating spaces to newlines Brian Campbell
2009-03-12  5:56 ` Brian Campbell [this message]
2009-03-12  6:55   ` [PATCH 2/2] [TopGit] Portability: Don't use alternation ("|") in sed regular expressions Junio C Hamano
2009-03-12  7:45     ` Uwe Kleine-König
2009-03-12 15:00       ` Brian Campbell
2009-03-12 15:20         ` Uwe Kleine-König
2009-03-12 15:26           ` martin f krafft
2009-03-14  5:54             ` Junio C Hamano
2009-03-14 12:47               ` Uwe Kleine-König
2009-03-12 16:41           ` Brian Campbell
2009-03-12 17:04             ` Uwe Kleine-König
2009-03-12 15:09   ` Uwe Kleine-König

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=1236837389-35687-2-git-send-email-brian.p.campbell@dartmouth.edu \
    --to=brian.p.campbell@dartmouth.edu \
    --cc=git@vger.kernel.org \
    --cc=pasky@suse.cz \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).