OpenPKG CVS Repository
  http://cvs.openpkg.org/
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Thomas Lotterer
  Root:   /e/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-re                       Date:   01-Apr-2003 10:42:45
  Branch: HEAD                             Handle: 2003040109424400

  Modified files:
    openpkg-re              openpkg-dev

  Log:
    replace branch2instance() with more powerful matchinstance()

  Summary:
    Revision    Changes     Path
    1.81        +101 -35    openpkg-re/openpkg-dev
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openpkg-re/openpkg-dev
  ============================================================================
  $ cvs diff -u -r1.80 -r1.81 openpkg-dev
  --- openpkg-re/openpkg-dev    31 Mar 2003 21:20:18 -0000      1.80
  +++ openpkg-re/openpkg-dev    1 Apr 2003 08:42:44 -0000       1.81
  @@ -141,20 +141,20 @@
   }
   
   setup () {
  -    #   honor optional parameters [[[spec]ctag]exec]
  -    [ ".$1" != . ] && OPENPKG_SPEC="$1";
  -    [ ".$2" != . ] && OPENPKG_CTAG="$2";
  -    [ ".$3" != . ] && OPENPKG_EXEC="$3";
  +    #   honor optional parameters [[[spec]ctag]exec]; use "" to specify a empty 
parameter and use it's default
  +    [ ".$1" != . ] && OPENPKG_SPEC="$1"
  +    [ ".$2" != . ] && OPENPKG_CTAG="$2"
  +    [ ".$3" != . ] && OPENPKG_EXEC="$3"
   
       #   OPENPKG_SPEC in setup() is only a flag to indicate minimal checkout
   
  -    #   canonify OPENPKG_CTAG
  +    #   canonify OPENPKG_CTAG, default to HEAD
       canonifybranch "${OPENPKG_CTAG}"
  -    OPENPKG_CTAG="${RV}"
  +    OPENPKG_CTAG="${RV:-HEAD}"
   
  -    #   canonify OPENPKG_EXEC
  +    #   canonify OPENPKG_EXEC, default to HEAD
       canonifybranch "${OPENPKG_EXEC:-$OPENPKG_CTAG}"
  -    branch2instance "${RV}"
  +    matchinstance "${RV-HEAD}"
       OPENPKG_EXEC="${RV}"
   
       #   set P,B,E without having "cd()" already in place
  @@ -377,7 +377,7 @@
   
       #   setup variables for use or query
       canonifybranch "${1}"
  -    branch="${RV}"
  +    branch="${RV:-HEAD}"
   
       #   execute query, if any
       if [ ".${query}" != . ]; then
  @@ -400,7 +400,7 @@
   execute () {
       #   no parameter means guessing
       if [ ".$1" = . ]; then
  -        branch2instance "${B}"
  +        matchinstance "${B}"
           E=${RV}
           echo "${E}"
           return
  @@ -463,7 +463,10 @@
   #
   canonifybranch () {
       #   remove surrounding whitespaces, take first arg only, toupper
  -    RV=`echo ${1:-HEAD} | cut -f 1 -d" " | tr '[a-z]' '[A-Z]'`
  +    RV=`echo ${1} | cut -f 1 -d" " | tr '[a-z]' '[A-Z]'`
  +
  +    #   empty in, empty return (mapping emtpy to HEAD is the task of the caller)
  +    [ ".${RV}" = . ] && return
   
       #   strip off any abbreviated form of a leading OPENPKG_
       RV=`echo "${RV}" | sed -e 
's;^O\{0,1\}P\{0,1\}E\{0,1\}N\{0,1\}P\{0,1\}K\{0,1\}G\{0,1\}_\{0,1\};;'`
  @@ -474,10 +477,8 @@
       #   replace dots from (SOLID name) and dashes (STABLE name) with underscore for 
convenience
       RV=`echo "${RV}" | sed -e 's;[\.-];_;g'`
   
  -    #   emptiness means invalid branch
  -    if [ ".${RV}" = . ]; then
  -        return
  -    fi
  +    #   invalid branch, empty return (mapping emtpy to HEAD is the task of the 
caller)
  +    [ ".${RV}" = . ] && return
   
       #   check for HEAD (branch) aka CURRENT (name)
       echo "CURRENT" | egrep -q "^${RV}" && RV="HEAD"
  @@ -502,41 +503,106 @@
       fi
   }
   
  -branch2instance () {
  +#   find matching instance with a executeable rpm for a given branch $1; return "" 
if none found
  +#   $1 = requested branch
  +#   $2 = optional mode one of "exact", "best", "any"; if omitted, defaults to "any"
  +#        exact = find executable rpm exactly matching branch
  +#        best  = see "exact" with fallback SOLID->STABLE->HEAD (no fallback if HEAD 
itself was requested)
  +#        any   = see "best" with fallback to any other out-of-branch rpm (no 
fallback if HEAD itself was requested)
  +matchinstance () {
  +    mode="${2:-any}"
  +    [ ".$mode" != .exact -a ".$mode" != .best -a ".$mode" != .any ] && die 
"matchinstance() assertion"
  +
       INSTANCE=`echo "$1" | sed -e 's;^OPENPKG_;;' -e 's;_STABLE$;;' -e 's;SOLID$;;' 
-e 's;^HEAD$;;' -e 's;_;;g'`
       OPMAJORV=`echo ${INSTANCE} | cut -c 1`
       OPMINORV=`echo ${INSTANCE} | cut -c 2`
  -    AVAILINS=`echo ${OPENPKG_INST}${OPENPKG_WILD} | tr ' ' '\n' | sort`
  +
  +    #   find all available instances with executable rpm
  +    AVAILINS=""
  +    for INSTANCE in `echo ${OPENPKG_INST}${OPENPKG_WILD}`; do
  +        [ -x "${INSTANCE}/bin/rpm" ] && AVAILINS="${AVAILINS} ${INSTANCE}"
  +    done
  +    AVAILINS=`echo ${AVAILINS} | tr ' ' '\n' | sort`
  +
       INSTANCE=""
  -    if [ ".${OPMINORV}" != "." ]; then  # SOLID
  -        ADD=`echo "${AVAILINS}" | egrep "^${OPENPKG_INST}${OPMAJORV}${OPMINORV}$"`
  +    if [ ".$1" = .HEAD ]; then         # HEAD (explicitly requested)
  +        if [ ".$mode" = .exact ]; then
  +            ADD=`echo "${AVAILINS}"      | egrep    "^${OPENPKG_INST}$"`
  +            AVAILINS=`echo "${AVAILINS}" | egrep -v "^${OPENPKG_INST}$"`
  +            INSTANCE="${INSTANCE} ${ADD}"
  +            RV="`echo ${INSTANCE} | tr ' ' '\n' | head -n 1`"
  +            unset ADD AVAILINS OPMINORV OPMAJORV INSTANCE
  +            return
  +        else
  +            RV="`echo ${AVAILINS} | tr ' ' '\n' | head -n 1`"
  +            unset ADD AVAILINS OPMINORV OPMAJORV INSTANCE
  +            return
  +        fi
  +    fi
  +    if [ ".${OPMINORV}" != . ]; then  # SOLID (explicitly requested)
  +        ADD=`echo "${AVAILINS}"      | egrep    
"^${OPENPKG_INST}${OPMAJORV}${OPMINORV}$"`
  +        AVAILINS=`echo "${AVAILINS}" | egrep -v 
"^${OPENPKG_INST}${OPMAJORV}${OPMINORV}$"`
           INSTANCE="${INSTANCE} ${ADD}"
  +        if [ ".$mode" = .exact ]; then
  +            RV="`echo ${INSTANCE} | tr ' ' '\n' | head -n 1`"
  +            unset ADD AVAILINS OPMINORV OPMAJORV INSTANCE
  +            return
  +        fi
       fi
  -    if [ ".${OPMAJORV}" != "." ]; then  # STABLE
  -        ADD=`echo "${AVAILINS}" | egrep "^${OPENPKG_INST}${OPMAJORV}$"`
  +    if [ ".${OPMAJORV}" != . ]; then  # STABLE (explicitly requested or implicit 
fallback from SOLID)
  +        ADD=`echo "${AVAILINS}"      | egrep    "^${OPENPKG_INST}${OPMAJORV}$"`
  +        AVAILINS=`echo "${AVAILINS}" | egrep -v "^${OPENPKG_INST}${OPMAJORV}$"`
           INSTANCE="${INSTANCE} ${ADD}"
  +        if [ ".$mode" = .exact ]; then
  +            RV="`echo ${INSTANCE} | tr ' ' '\n' | head -n 1`"
  +            unset ADD AVAILINS OPMINORV OPMAJORV INSTANCE
  +            return
  +        fi
       fi
  -    if [ true ]; then                   # HEAD
  -        ADD=`echo "${AVAILINS}" | egrep "^${OPENPKG_INST}$"`
  +    if [ true ]; then                 # HEAD (implicit fallback from STABLE)
  +        ADD=`echo "${AVAILINS}"      | egrep    "^${OPENPKG_INST}$"`
  +        AVAILINS=`echo "${AVAILINS}" | egrep -v "^${OPENPKG_INST}$"`
           INSTANCE="${INSTANCE} ${ADD}"
       fi
  -    RV="`echo ${INSTANCE} | tr ' ' '\n' | head -n 1`"
  +
  +    if [ ".$mode" = .best ]; then
  +        RV="`echo ${INSTANCE} | tr ' ' '\n' | head -n 1`"
  +        unset ADD AVAILINS OPMINORV OPMAJORV INSTANCE
  +        return
  +    fi
  +
  +    if [ ".$mode" = .any ]; then
  +        RV="`echo ${INSTANCE} ${AVAILINS} | tr ' ' '\n' | head -n 1`"
  +        unset ADD AVAILINS OPMINORV OPMAJORV INSTANCE
  +        return
  +    fi
  +
  +    RV=""
       unset ADD AVAILINS OPMINORV OPMAJORV INSTANCE
   }
   
   bash () {
  -    cd ${OPENPKG_WORK} || die "cannot cd to ${OPENPKG_WORK}"
  +    #   honor optional parameters [[[spec]ctag]exec]; use "" to specify a empty 
parameter and use it's default
  +    [ ".$1" != . ] && OPENPKG_SPEC="$1"
  +    [ ".$2" != . ] && OPENPKG_CTAG="$2"
  +    [ ".$3" != . ] && OPENPKG_EXEC="$3"
   
  -    #   honor optional parameters [[[spec]ctag]exec]
  -    if [ ".$1" != . ]; then
  -        OPENPKG_SPEC="$1"
  -    fi
  -    if [ ".$2" != . ]; then
  -        OPENPKG_CTAG="$2"
  -    fi
  -    if [ ".$3" != . ]; then
  -        OPENPKG_EXEC="$3"
  -    fi
  +    #   enter working directory
  +    cd "${OPENPKG_WORK}" || die "cannot cd to ${OPENPKG_WORK}"
  +
  +    #   canonify OPENPKG_CTAG
  +    canonifybranch "${OPENPKG_CTAG}"
  +    OPENPKG_CTAG="${RV}"
  +
  +    #   canonify OPENPKG_EXEC, default to HEAD
  +    canonifybranch "${OPENPKG_EXEC:-$OPENPKG_CTAG}"
  +    matchinstance "${RV}" exact
  +    OPENPKG_EXEC="${RV}"
  +
  +    #   set P,B,E without having "cd()" already in place
  +    P="${OPENPKG_SPEC}"
  +    B="${OPENPKG_CTAG}"
  +    E="${OPENPKG_EXEC}"
   
       #   create a .bashrc
       cat <<-EOF >.bashrc
  @@ .
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     [EMAIL PROTECTED]

Reply via email to