# Re: [PATCH] pull: replace unnecessary sed invocation

4 messages from 2010-03-18 to 2010-03-18. Participants: Gabriel Filion, Brandon Casey, Junio C Hamano, Stephen Boyd.
Thread: https://gitlist.dev/t/23061

## Stephen Boyd, 2010-03-18 05:10

Subject: [PATCH] pull: replace unnecessary sed invocation
Message-ID: <1268889045-21751-1-git-send-email-bebarino@gmail.com>
URL: https://gitlist.dev/e/1268889045-21751-1-git-send-email-bebarino%40gmail.com

```
Getting the shortened branch name is as easy as using the shell's
parameter expansion.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---

Saw this while reading the code.

 git-pull.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-pull.sh b/git-pull.sh
index 38331a8..246a3a4 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -41,7 +41,7 @@ strategy_args= diffstat= no_commit= squash= no_ff= ff_only=
 log_arg= verbosity=
 merge_args=
 curr_branch=$(git symbolic-ref -q HEAD)
-curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
+curr_branch_short="${curr_branch#refs/heads/}"
 rebase=$(git config --bool branch.$curr_branch_short.rebase)
 while :
 do
-- 
1.7.0.2.276.g60daf


```

## Gabriel Filion, 2010-03-18 13:30

Subject: Re: [PATCH] pull: replace unnecessary sed invocation
Message-ID: <4BA22AEE.8000606@gmail.com>
URL: https://gitlist.dev/e/4BA22AEE.8000606%40gmail.com
In-Reply-To: <1268889045-21751-1-git-send-email-bebarino@gmail.com>

```
On 2010-03-18 01:10, Stephen Boyd wrote:
> Getting the shortened branch name is as easy as using the shell's
> parameter expansion.
> 
>  curr_branch=$(git symbolic-ref -q HEAD)
> -curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
> +curr_branch_short="${curr_branch#refs/heads/}"

This modification is a bashism. This syntax is not compatible with other
shells.

-- 
Gabriel Filion

```

## Brandon Casey, 2010-03-18 14:46

Subject: Re: [PATCH] pull: replace unnecessary sed invocation
Message-ID: <5rEymC6ZWmCbugaX54NzNsnDmRUKU5-au3DQ0l_p5YIjUz7xRlUzXA@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/5rEymC6ZWmCbugaX54NzNsnDmRUKU5-au3DQ0l_p5YIjUz7xRlUzXA%40cipher.nrlssc.navy.mil
In-Reply-To: <4BA22AEE.8000606@gmail.com>

```
On 03/18/2010 08:30 AM, Gabriel Filion wrote:
> On 2010-03-18 01:10, Stephen Boyd wrote:
>> Getting the shortened branch name is as easy as using the shell's
>> parameter expansion.
>>
>>  curr_branch=$(git symbolic-ref -q HEAD)
>> -curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
>> +curr_branch_short="${curr_branch#refs/heads/}"
> 
> This modification is a bashism. This syntax is not compatible with other
> shells.

But, there is already precedence for using syntax in scripts, so it
is probably ok.

$ egrep -- '\$\{[^}]+#[^}]+\}' *.sh
git-bisect.sh:                  start_head="${head#refs/heads/}"
git-filter-branch.sh:           ref="${ref#refs/tags/}"
git-parse-remote.sh:        heads/*) remote=${remote#heads/} ;;
git-parse-remote.sh:        refs/heads/*) remote=${remote#refs/heads/} ;;
git-pull.sh:    curr_branch=${curr_branch#refs/heads/}
git-pull.sh:            echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
git-rebase--interactive.sh:             pend="${pend# $p}"
git-rebase--interactive.sh:                     new_parents=${new_parents# $first_parent}
git-rebase--interactive.sh:             if      left=${1%...*} right=${1#*...} &&
git-rebase.sh:  eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
git-rebase.sh:  if      left=${onto_name%...*} right=${onto_name#*...} &&
git-stash.sh:           branch=${branch#refs/heads/}
git-submodule.sh:                       url="${url#../}"
git-submodule.sh:                       url="${url#./}"

```

## Junio C Hamano, 2010-03-18 14:48

Subject: Re: [PATCH] pull: replace unnecessary sed invocation
Message-ID: <7vwrx9vg6w.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwrx9vg6w.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4BA22AEE.8000606@gmail.com>

```
Gabriel Filion <lelutin@gmail.com> writes:

>> +curr_branch_short="${curr_branch#refs/heads/}"
>
> This modification is a bashism. This syntax is not compatible with other
> shells.

To me, the above looks like "${parameter#word}", which is a plain vanilla
POSIX shell construct that we adopted to use in our scripts.

There are bash-only constructs we decided never to use in our scripts;
among them are "${parameter/pattern/string}" and "${parameter:offset}",
both are not in POSIX.

```
