[Fwd: [Lunar-commits] r21957 - lunar/trunk/var/lib/lunar/functions]

Auke Kok sofar at foo-projects.org
Thu Oct 26 18:34:12 CEST 2006



I just committed a new alias handling core patch to theedge. This should simplify and 
make the alias code more robust, and also allows the user to set/unset alias choices 
manually.

See below for a short explanation.

Cheers,

Auke



-------- Original Message --------
Subject: [Lunar-commits] r21957 - lunar/trunk/var/lib/lunar/functions
Date: Thu, 26 Oct 2006 18:16:17 +0200 (CEST)
From: Auke Kok <sofar at lunar-linux.org>
Reply-To: lunar-dev at lunar-linux.org
To: lunar-commits at lunar-linux.org

Author: sofar
Date: 2006-10-26 18:16:17 +0200 (Thu, 26 Oct 2006)
New Revision: 21957

Modified:
    lunar/trunk/var/lib/lunar/functions/aliases.lunar
Log:
[PATCH] new alias code

This new alias algorithm stores the users' choice when asked for %X
as LUNAR_ALIAS_X in the local config. This speeds up lookups later
and eliminates the need to detect aliases on the fly. We can delete
all the detection code and the user will only once ever get asked.

unsetting an alias choice is as easy as `lunar unset LUANR_ALIAS_X`


Modified: lunar/trunk/var/lib/lunar/functions/aliases.lunar
===================================================================
--- lunar/trunk/var/lib/lunar/functions/aliases.lunar	2006-10-26 16:07:14 UTC (rev 21956)
+++ lunar/trunk/var/lib/lunar/functions/aliases.lunar	2006-10-26 16:16:17 UTC (rev 21957)
@@ -12,13 +12,20 @@
  # translate %ALIAS if needed to a module name that is installed
  # and add it to the dependency chain if needed
  unalias() {
-  local TARGET TARGETS TARGETBYNUM N CHOICE
+  local TARGET TARGETS TARGETBYNUM N CHOICE CACHED_ALIAS
    # quick exit code
    if [ "${1:0:1}" != "%" ] ; then
      echo $1
      return
    fi

+  # lookup in cache
+  CACHED_ALIAS=$(get_local_config `echo LUNAR_ALIAS_${1:1}`)
+  if [ -n "$CACHED_ALIAS" ]; then
+    echo $CACHED_ALIAS
+    return
+  fi
+
    debug_msg "unalias($@)"
    # try to figure out where the aliases file is:
    if [[ -z "$ALIASES" ]] || [[ ! -f "$ALIASES" ]]; then
@@ -28,47 +35,8 @@
        ALIASES="/var/lib/lunar/aliases"
      fi
    fi
-
+
    TARGETS=$(awk -F: -v mod=$1 '{if ($1==mod){print $2}}' $ALIASES)
-  # dumb algorithm: pick the first installed one
-  for TARGET in $TARGETS ; do
-    if module_installed $TARGET ; then
-      debug_msg "unaliased \"$1\"->\"$TARGET\""
-      echo $TARGET
-      return
-    fi
-  done
-  # shortcut out: in the satisfy_depends stage we should NOT ask this again
-  if [[ -z "$DEPS_ONLY" ]] ; then
-    # first we check if this dependency is already existant in the exact
-    # way: does this MODULE depends on TARGET already ?
-    for TARGET in $TARGETS ; do
-      if in_depends $MODULE $TARGET ; then
-        debug_msg "unaliased \"$1\"->\"$TARGET\""
-        echo $TARGET
-        return
-      fi
-    done
-    # not so... other possibility is that something else already depends
-    # on TARGET?
-    for TARGET in $TARGETS ; do
-      if is_depends $TARGET ; then
-        debug_msg "unaliased \"$1\"->\"$TARGET\""
-        echo $TARGET
-        return
-      fi
-    done
-    # also not so. our last attempt is for a DISABLED dependency, but
-    # we can only use this method for OPTIONAL dependencies
-    for TARGET in $TARGETS ; do
-      # there's no function for this yet
-      if grep -q ":$TARGET:off:" $DEPENDS_STATUS ; then
-        debug_msg "unaliased \"$1\"->\"$TARGET\""
-        echo $TARGET
-        return
-      fi
-    done
-  fi

    # shortcut out when explicitly instructed so
    if [[ -n "$NEVER_ASK" ]] ; then
@@ -90,10 +58,14 @@
      read CHOICE
      # test directly first
      if echo $TARGETS | grep -qw "$CHOICE" ; then
+      verbose_msg "Stored alias mapping $1 -> $TARGET"
+      set_local_config `echo LUNAR_ALIAS_${1:1}` $TARGET
        echo $TARGET
        return
      # then the number
      elif [[ -n "$CHOICE" ]] && [[ -n "${TARGETBYNUM[$CHOICE]}" ]] ; then
+      verbose_msg "Stored alias mapping $1 -> ${TARGETBYNUM[$CHOICE]}"
+      set_local_config `echo LUNAR_ALIAS_${1:1}` ${TARGETBYNUM[$CHOICE]}
        echo ${TARGETBYNUM[$CHOICE]}
        return
      fi

_______________________________________________
Lunar-commits mailing list
Lunar-commits at lunar-linux.org
http://foo-projects.org/mailman/listinfo/lunar-commits


More information about the Lunar mailing list