Skip to contentSkip to conversation

pull: replace unnecessary sed invocation

PATCH In review Stephen Boyd 4 participants 4 messages Jun 15, 2016 – Aug 13, 2016

lore
Share & tools
lore
#1 lore raw
In reply to Stephen Boyd

git-pull.sh strategy_args= diffstat= no_commit= squash= no_ff= ff_only= · line 44

Quoted 6 lines · Stephen Boyd

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

curr_branch=$(git symbolic-ref -q HEAD)

git-pull.sh +1 -1
-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.

Signature · 1 line
Gabriel Filion
#2 lore raw
Quoted 10 lines · Gabriel Filion

git-pull.sh strategy_args= diffstat= no_commit= squash= no_ff= ff_only= · line 44

Quoted 6 lines · Stephen Boyd

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

curr_branch=$(git symbolic-ref -q HEAD)

git-pull.sh +1 -1
-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#./}"
#3 lore raw
In reply to Gabriel Filion
Quoted 4 lines · Gabriel Filion
Quoted 1 line

+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.

#0 lore raw

PATCH 1/1 pull: replace unnecessary sed invocation

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

---

Saw this while reading the code.

 git-pull.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
git-pull.sh +1 -1
index 38331a8..246a3a4 100755
@@ -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
Signature · 1 line
1.7.0.2.276.g60daf