Merge branch 'rs/work-around-grep-opt-insanity'
authorJunio C Hamano <gitster@pobox.com>
Wed, 25 Nov 2009 19:45:07 +0000 (11:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Nov 2009 19:45:07 +0000 (11:45 -0800)
* rs/work-around-grep-opt-insanity:
Protect scripted Porcelains from GREP_OPTIONS insanity
mergetool--lib: simplify guess_merge_tool()

Conflicts:
git-instaweb.sh

1  2 
git-am.sh
git-bisect.sh
git-filter-branch.sh
git-instaweb.sh
git-mergetool--lib.sh
git-rebase--interactive.sh
git-rebase.sh
git-sh-setup.sh
git-submodule.sh
diff --combined git-am.sh
index 151512afd383ed86b5a8310c53e7910db5b87e90,b49f26a49c3af272ef454c5f6e05d0266177a3bd..512891d217fc34ed5ff9992ed0b3dc7ff23f0bb0
+++ b/git-am.sh
@@@ -205,7 -205,7 +205,7 @@@ check_patch_format () 
                        # and see if it looks like that they all begin with the
                        # header field names...
                        sed -n -e '/^$/q' -e '/^[       ]/d' -e p "$1" |
-                       LC_ALL=C egrep -v '^[!-9;-~]+:' >/dev/null ||
+                       sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
                        patch_format=mbox
                fi
        } < "$1" || clean_abort
@@@ -289,7 -289,7 +289,7 @@@ split_patches () 
  prec=4
  dotest="$GIT_DIR/rebase-apply"
  sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
 -resolvemsg= resume= scissors=
 +resolvemsg= resume= scissors= no_inbody_headers=
  git_apply_opt=
  committer_date_is_author_date=
  ignore_date=
@@@ -322,7 -322,7 +322,7 @@@ d
        --abort)
                abort=t ;;
        --rebasing)
 -              rebasing=t threeway=t keep=t scissors=f ;;
 +              rebasing=t threeway=t keep=t scissors=f no_inbody_headers=t ;;
        -d|--dotest)
                die "-d option is no longer supported.  Do not use."
                ;;
@@@ -448,7 -448,6 +448,7 @@@ els
        echo "$utf8" >"$dotest/utf8"
        echo "$keep" >"$dotest/keep"
        echo "$scissors" >"$dotest/scissors"
 +      echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
        echo "$GIT_QUIET" >"$dotest/quiet"
        echo 1 >"$dotest/next"
        if test -n "$rebasing"
  f)
        scissors=--no-scissors ;;
  esac
 +if test "$(cat "$dotest/no_inbody_headers")" = t
 +then
 +      no_inbody_headers=--no-inbody-headers
 +else
 +      no_inbody_headers=
 +fi
  if test "$(cat "$dotest/quiet")" = t
  then
        GIT_QUIET=t
        # by the user, or the user can tell us to do so by --resolved flag.
        case "$resume" in
        '')
 -              git mailinfo $keep $scissors $utf8 "$dotest/msg" "$dotest/patch" \
 +              git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
                        <"$dotest/$msgnum" >"$dotest/info" ||
                        stop_here $this
  
                # skip pine's internal folder data
-               grep '^Author: Mail System Internal Data$' \
+               sane_grep '^Author: Mail System Internal Data$' \
                        <"$dotest"/info >/dev/null &&
                        go_next && continue
  
                [eE]*) git_editor "$dotest/final-commit"
                       action=again ;;
                [vV]*) action=again
 -                     LESS=-S ${PAGER:-less} "$dotest/patch" ;;
 +                     : ${GIT_PAGER=$(git var GIT_PAGER)}
 +                     : ${LESS=-FRSX}
 +                     export LESS
 +                     $GIT_PAGER "$dotest/patch" ;;
                *)     action=again ;;
                esac
            done
diff --combined git-bisect.sh
index a5ea843fbf9d8dca682fefe10bb91f3b3e6d30b3,0c422d5fb501418a6c761710aff9c47c8968eb36..6e2acb8ef29e5003945bed17014a68b141ada454
@@@ -13,8 -13,8 +13,8 @@@ git bisect skip [(<rev>|<range>)...
          mark <rev>... untestable revisions.
  git bisect next
          find next bisection to test and check it out.
 -git bisect reset [<branch>]
 -        finish bisection search and go back to branch.
 +git bisect reset [<commit>]
 +        finish bisection search and go back to commit.
  git bisect visualize
          show bisect status in gitk.
  git bisect replay <logfile>
@@@ -300,7 -300,8 +300,7 @@@ bisect_visualize() 
                esac
        fi
  
 -      not=$(git for-each-ref --format='%(refname)' "refs/bisect/good-*")
 -      eval '"$@"' refs/bisect/bad --not $not -- $(cat "$GIT_DIR/BISECT_NAMES")
 +      eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES")
  }
  
  bisect_reset() {
        }
        case "$#" in
        0) branch=$(cat "$GIT_DIR/BISECT_START") ;;
 -      1) git show-ref --verify --quiet -- "refs/heads/$1" ||
 -             die "$1 does not seem to be a valid branch"
 +      1) git rev-parse --quiet --verify "$1^{commit}" > /dev/null ||
 +             die "'$1' is not a valid commit"
           branch="$1" ;;
        *)
            usage ;;
@@@ -392,7 -393,7 +392,7 @@@ bisect_run () 
  
        cat "$GIT_DIR/BISECT_RUN"
  
-       if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
+       if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
                > /dev/null; then
          echo >&2 "bisect run cannot continue any more"
          exit $res
          exit $res
        fi
  
-       if grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
+       if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
          echo "bisect run success"
          exit 0;
        fi
diff --combined git-filter-branch.sh
index 6b8b6a4f26a60c325a2c76e1d5b0e747b9d1d99b,8ef1bde710c5fc6c3debd19440d423424046fd95..cb9d2022cc93f1f371264098828a52e0d6bf1d7c
@@@ -125,7 -125,6 +125,7 @@@ filter_subdir
  orig_namespace=refs/original/
  force=
  prune_empty=
 +remap_to_ancestor=
  while :
  do
        case "$1" in
                force=t
                continue
                ;;
 +      --remap-to-ancestor)
 +              shift
 +              remap_to_ancestor=t
 +              continue
 +              ;;
        --prune-empty)
                shift
                prune_empty=t
                ;;
        --subdirectory-filter)
                filter_subdir="$OPTARG"
 +              remap_to_ancestor=t
                ;;
        --original)
                orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/
@@@ -264,24 -257,15 +264,24 @@@ git read-tree || die "Could not seed th
  # map old->new commit ids for rewriting parents
  mkdir ../map || die "Could not create map/ directory"
  
 +# we need "--" only if there are no path arguments in $@
 +nonrevs=$(git rev-parse --no-revs "$@") || exit
 +test -z "$nonrevs" && dashdash=-- || dashdash=
 +rev_args=$(git rev-parse --revs-only "$@")
 +
  case "$filter_subdir" in
  "")
 -      git rev-list --reverse --topo-order --default HEAD \
 -              --parents --simplify-merges "$@"
 +      eval set -- "$(git rev-parse --sq --no-revs "$@")"
        ;;
  *)
 -      git rev-list --reverse --topo-order --default HEAD \
 -              --parents --simplify-merges "$@" -- "$filter_subdir"
 -esac > ../revs || die "Could not get the commits"
 +      eval set -- "$(git rev-parse --sq --no-revs "$@" $dashdash \
 +              "$filter_subdir")"
 +      ;;
 +esac
 +
 +git rev-list --reverse --topo-order --default HEAD \
 +      --parents --simplify-merges $rev_args "$@" > ../revs ||
 +      die "Could not get the commits"
  commits=$(wc -l <../revs | tr -d " ")
  
  test $commits -eq 0 && die "Found nothing to rewrite"
@@@ -361,19 -345,19 +361,19 @@@ while read commit parents; d
                        die "could not write rewritten commit"
  done <../revs
  
 -# In case of a subdirectory filter, it is possible that a specified head
 -# is not in the set of rewritten commits, because it was pruned by the
 -# revision walker.  Fix it by mapping these heads to the unique nearest
 -# ancestor that survived the pruning.
 +# If we are filtering for paths, as in the case of a subdirectory
 +# filter, it is possible that a specified head is not in the set of
 +# rewritten commits, because it was pruned by the revision walker.
 +# Ancestor remapping fixes this by mapping these heads to the unique
 +# nearest ancestor that survived the pruning.
  
 -if test "$filter_subdir"
 +if test "$remap_to_ancestor" = t
  then
        while read ref
        do
                sha1=$(git rev-parse "$ref"^0)
                test -f "$workdir"/../map/$sha1 && continue
 -              ancestor=$(git rev-list --simplify-merges -1 \
 -                              $ref -- "$filter_subdir")
 +              ancestor=$(git rev-list --simplify-merges -1 "$ref" "$@")
                test "$ancestor" && echo $(map $ancestor) >> "$workdir"/../map/$sha1
        done < "$tempdir"/heads
  fi
@@@ -473,7 -457,7 +473,7 @@@ if [ "$filter_tag_name" ]; the
                                git mktag) ||
                                die "Could not create new tag object for $ref"
                        if git cat-file tag "$ref" | \
-                          grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
+                          sane_grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
                        then
                                warn "gpg signature stripped from tag object $sha1t"
                        fi
diff --combined git-instaweb.sh
index ffc2ab62bca8a93b42d74f6b276b1daa8a846f6f,84805c61e584f7cd01145805c43944b5ba8b8311..341930ca9d74867cf334952fc47bb3afe95552b7
@@@ -41,7 -41,7 +41,7 @@@ resolve_full_httpd () 
        case "$httpd" in
        *apache2*|*lighttpd*)
                # ensure that the apache2/lighttpd command ends with "-f"
-               if ! echo "$httpd" | grep -- '-f *$' >/dev/null 2>&1
+               if ! echo "$httpd" | sane_grep -- '-f *$' >/dev/null 2>&1
                then
                        httpd="$httpd -f"
                fi
  }
  
  start_httpd () {
 +      if test -f "$fqgitdir/pid"; then
 +              say "Instance already running. Restarting..."
 +              stop_httpd
 +      fi
 +
        # here $httpd should have a meaningful value
        resolve_full_httpd
  
@@@ -302,8 -297,8 +302,8 @@@ EO
  
        # check to see if Dennis Stosberg's mod_perl compatibility patch
        # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
-       if test -f "$module_path/mod_perl.so" && grep 'MOD_PERL' \
-                               "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
+       if test -f "$module_path/mod_perl.so" &&
+          sane_grep 'MOD_PERL' "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
        then
                # favor mod_perl if available
                cat >> "$conf" <<EOF
@@@ -321,22 -316,8 +321,22 @@@ EO
                # plain-old CGI
                resolve_full_httpd
                list_mods=$(echo "$full_httpd" | sed "s/-f$/-l/")
-               $list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \
+               $list_mods | sane_grep 'mod_cgi\.c' >/dev/null 2>&1 || \
 -              echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
 +              if test -f "$module_path/mod_cgi.so"
 +              then
 +                      echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
 +              else
 +                      $list_mods | grep 'mod_cgid\.c' >/dev/null 2>&1 || \
 +                      if test -f "$module_path/mod_cgid.so"
 +                      then
 +                              echo "LoadModule cgid_module $module_path/mod_cgid.so" \
 +                                      >> "$conf"
 +                      else
 +                              echo "You have no CGI support!"
 +                              exit 2
 +                      fi
 +                      echo "ScriptSock logs/gitweb.sock" >> "$conf"
 +              fi
                cat >> "$conf" <<EOF
  AddHandler cgi-script .cgi
  <Location /gitweb.cgi>
diff --combined git-mergetool--lib.sh
index f7c571e73cdf471148b606242066536361ac7c3d,334af7c3478bd6e4fa3f29e360b6be4fbaf6f8cb..5b6278572a48569a806a5a976cdd08eb7c117fb7
@@@ -46,7 -46,7 +46,7 @@@ check_unchanged () 
  valid_tool () {
        case "$1" in
        kdiff3 | tkdiff | xxdiff | meld | opendiff | \
 -      emerge | vimdiff | gvimdiff | ecmerge | diffuse | araxis)
 +      emerge | vimdiff | gvimdiff | ecmerge | diffuse | araxis | p4merge)
                ;; # happy
        tortoisemerge)
                if ! merge_mode; then
@@@ -130,19 -130,6 +130,19 @@@ run_merge_tool () 
                        "$merge_tool_path" "$LOCAL" "$REMOTE"
                fi
                ;;
 +      p4merge)
 +              if merge_mode; then
 +                  touch "$BACKUP"
 +                      if $base_present; then
 +                              "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
 +                      else
 +                              "$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
 +                      fi
 +                      check_unchanged
 +              else
 +                      "$merge_tool_path" "$LOCAL" "$REMOTE"
 +              fi
 +              ;;
        meld)
                if merge_mode; then
                        touch "$BACKUP"
@@@ -336,17 -323,16 +336,16 @@@ guess_merge_tool () 
                else
                        tools="opendiff kdiff3 tkdiff xxdiff meld $tools"
                fi
 -              tools="$tools gvimdiff diffuse ecmerge araxis"
 +              tools="$tools gvimdiff diffuse ecmerge p4merge araxis"
        fi
-       if echo "${VISUAL:-$EDITOR}" | grep emacs > /dev/null 2>&1; then
-               # $EDITOR is emacs so add emerge as a candidate
-               tools="$tools emerge vimdiff"
-       elif echo "${VISUAL:-$EDITOR}" | grep vim > /dev/null 2>&1; then
-               # $EDITOR is vim so add vimdiff as a candidate
+       case "${VISUAL:-$EDITOR}" in
+       *vim*)
                tools="$tools vimdiff emerge"
-       else
+               ;;
+       *)
                tools="$tools emerge vimdiff"
-       fi
+               ;;
+       esac
        echo >&2 "merge tool candidates: $tools"
  
        # Loop over each candidate and stop when a valid merge tool is found.
index 27daaa9ded9745b6747dc2995ea344ad038443a5,6268e76bd922af99088c3ed840876f0ea186df55..0bd3bf78b8563f29a24dbc7dcc4ef308b3381157
@@@ -106,8 -106,8 +106,8 @@@ mark_action_done () 
        sed -e 1q < "$TODO" >> "$DONE"
        sed -e 1d < "$TODO" >> "$TODO".new
        mv -f "$TODO".new "$TODO"
-       count=$(grep -c '^[^#]' < "$DONE")
-       total=$(($count+$(grep -c '^[^#]' < "$TODO")))
+       count=$(sane_grep -c '^[^#]' < "$DONE")
+       total=$(($count+$(sane_grep -c '^[^#]' < "$TODO")))
        if test "$last_count" != "$count"
        then
                last_count=$count
@@@ -147,7 -147,7 +147,7 @@@ die_abort () 
  }
  
  has_action () {
-       grep '^[^#]' "$1" >/dev/null
+       sane_grep '^[^#]' "$1" >/dev/null
  }
  
  pick_one () {
                output git reset --hard $sha1
                test "a$1" = a-n && output git reset --soft $current_sha1
                sha1=$(git rev-parse --short $sha1)
 -              output warn Fast forward to $sha1
 +              output warn Fast-forward to $sha1
        else
                output git cherry-pick "$@"
        fi
@@@ -248,9 -248,9 +248,9 @@@ pick_one_preserving_merges () 
        done
        case $fast_forward in
        t)
 -              output warn "Fast forward to $sha1"
 +              output warn "Fast-forward to $sha1"
                output git reset --hard $sha1 ||
 -                      die "Cannot fast forward to $sha1"
 +                      die "Cannot fast-forward to $sha1"
                ;;
        f)
                first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
@@@ -340,14 -340,6 +340,14 @@@ do_next () 
                pick_one $sha1 ||
                        die_with_patch $sha1 "Could not apply $sha1... $rest"
                ;;
 +      reword|r)
 +              comment_for_reflog reword
 +
 +              mark_action_done
 +              pick_one $sha1 ||
 +                      die_with_patch $sha1 "Could not apply $sha1... $rest"
 +              git commit --amend
 +              ;;
        edit|e)
                comment_for_reflog edit
  
                ;;
        *)
                warn "Unknown command: $command $sha1 $rest"
 -              die_with_patch $sha1 "Please fix this in the file $TODO."
 +              if git rev-parse --verify -q "$sha1" >/dev/null
 +              then
 +                      die_with_patch $sha1 "Please fix this in the file $TODO."
 +              else
 +                      die "Please fix this in the file $TODO."
 +              fi
                ;;
        esac
        test -s "$TODO" && return
@@@ -744,7 -731,7 +744,7 @@@ first and then run 'git rebase --contin
                        git rev-list $REVISIONS |
                        while read rev
                        do
-                               if test -f "$REWRITTEN"/$rev -a "$(grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+                               if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
                                then
                                        # Use -f2 because if rev-list is telling us this commit is
                                        # not worthwhile, we don't want to track its multiple heads,
                                        # be rebasing on top of it
                                        git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
                                        short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
-                                       grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
+                                       sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
                                        rm "$REWRITTEN"/$rev
                                fi
                        done
  #
  # Commands:
  #  p, pick = use commit
 +#  r, reword = use commit, but edit the commit message
  #  e, edit = use commit, but stop for amending
  #  s, squash = use commit, but meld into previous commit
  #
diff --combined git-rebase.sh
index 6830e1627d67c59407885a3cfa44e83a802613bc,0ec435558f8ad59e96766cd3f34cbb541f2dbaed..b121f4537ccb173d9f289734f1fe2e89b28d7562
@@@ -467,7 -467,7 +467,7 @@@ orig_head=$branc
  mb=$(git merge-base "$onto" "$branch")
  if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
        # linear history?
-       ! (git rev-list --parents "$onto".."$branch" | grep " .* ") > /dev/null
+       ! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null
  then
        if test -z "$force_rebase"
        then
@@@ -496,7 -496,7 +496,7 @@@ the
  fi
  
  # If the $onto is a proper descendant of the tip of the branch, then
 -# we just fast forwarded.
 +# we just fast-forwarded.
  if test "$mb" = "$branch"
  then
        say "Fast-forwarded $branch_name to $onto_name."
diff --combined git-sh-setup.sh
index 99cceeb858dcd2c83a040b0dd3117744e177e316,aa07cc3d188df9744d50d8e0487c86a2cb30b1ac..dfcb8078f508d6cc26d312d61b64e0185e90b74b
@@@ -99,14 -99,29 +99,22 @@@ set_reflog_action() 
  }
  
  git_editor() {
 -      : "${GIT_EDITOR:=$(git config core.editor)}"
 -      : "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
 -      case "$GIT_EDITOR,$TERM" in
 -      ,dumb)
 -              echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
 -              echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
 -              echo >&2 "Please set one of these variables to an appropriate"
 -              echo >&2 "editor or run $0 with options that will not cause an"
 -              echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
 -              exit 1
 -              ;;
 -      esac
 -      eval "${GIT_EDITOR:=vi}" '"$@"'
 +      if test -z "${GIT_EDITOR:+set}"
 +      then
 +              GIT_EDITOR="$(git var GIT_EDITOR)" || return $?
 +      fi
 +
 +      eval "$GIT_EDITOR" '"$@"'
  }
  
+ sane_grep () {
+       GREP_OPTIONS= LC_ALL=C grep "$@"
+ }
+ sane_egrep () {
+       GREP_OPTIONS= LC_ALL=C egrep "$@"
+ }
  is_bare_repository () {
        git rev-parse --is-bare-repository
  }
diff --combined git-submodule.sh
index 850d4235a003a9934681b319199e82da07a865dd,b7ccd12d722469d353896fa85c7af6e0cf77afc8..77d223292c5b167a8a33b04b10b46426b68e0576
@@@ -5,7 -5,7 +5,7 @@@
  # Copyright (c) 2007 Lars Hjemli
  
  dashless=$(basename "$0" | sed -e 's/-/ /')
 -USAGE="[--quiet] add [-b branch] [--reference <repository>] [--] <repository> <path>
 +USAGE="[--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
     or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] init [--] [<path>...]
     or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
@@@ -57,7 -57,7 +57,7 @@@ resolve_relative_url (
  #
  module_list()
  {
-       git ls-files --error-unmatch --stage -- "$@" | grep '^160000 '
+       git ls-files --error-unmatch --stage -- "$@" | sane_grep '^160000 '
  }
  
  #
@@@ -160,11 -160,6 +160,11 @@@ cmd_add(
        repo=$1
        path=$2
  
 +      if test -z "$path"; then
 +              path=$(echo "$repo" |
 +                      sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
 +      fi
 +
        if test -z "$repo" -o -z "$path"; then
                usage
        fi
@@@ -572,7 -567,7 +572,7 @@@ cmd_summary() 
        cd_to_toplevel
        # Get modified modules cared by user
        modules=$(git $diff_cmd $cached --raw $head -- "$@" |
-               egrep '^:([0-7]* )?160000' |
+               sane_egrep '^:([0-7]* )?160000' |
                while read mod_src mod_dst sha1_src sha1_dst status name
                do
                        # Always show modules deleted or type-changed (blob<->module)
        test -z "$modules" && return
  
        git $diff_cmd $cached --raw $head -- $modules |
-       egrep '^:([0-7]* )?160000' |
+       sane_egrep '^:([0-7]* )?160000' |
        cut -c2- |
        while read mod_src mod_dst sha1_src sha1_dst status name
        do